Reputation: 37
I'm looking to override the InvoiceOrder logic of the SOInvoiceEntry graph in the business logic, so I can change the logic that aggregates invoices if the 'Bill Separately' option is not selected.
I've written an extension method below to replace the built in InvoiceOrder method.
public delegate void InvoiceOrderDelegate(DateTime invoiceDate, PXResult<SOOrderShipment, SOOrder, CurrencyInfo, SOAddress, SOContact, SOOrderType> order, PXResultset<SOShipLine, SOLine> details, Customer customer, DocumentList<ARInvoice, SOInvoice> list);
[PXOverride]
public virtual void InvoiceOrder(DateTime invoiceDate, PXResult<SOOrderShipment, SOOrder, CurrencyInfo, SOAddress, SOContact, SOOrderType> order, PXResultset<SOShipLine, SOLine> details, Customer customer, DocumentList<ARInvoice, SOInvoice> list, InvoiceOrderDelegate baseMethod)
{
//Do Stuff
}
I'm unsure how to access the original object's protected methods. Normally I'd just call Base.DoSomething();
, but I presume I can't access protected methods as the extension object is not directly derived from SOInvoiceEntry.
Do I need to override the protected methods I want to use as well, or is there a way to access them from the extension?
Any help would be awesome.
Thanks.
Upvotes: 2
Views: 1528
Reputation: 5613
You use the delegate you pass into the method as the base call. For InvoiceCreated you should be able to override it and call it as shown below:
public class SOInvoiceEntryExtension : PXGraphExtension<SOInvoiceEntry>
{
public delegate void InvoiceOrderDelegate(DateTime invoiceDate,
PXResult<SOOrderShipment, SOOrder, CurrencyInfo, SOAddress, SOContact, SOOrderType> order,
PXResultset<SOShipLine, SOLine> details,
Customer customer,
DocumentList<ARInvoice, SOInvoice> list);
[PXOverride]
public virtual void InvoiceOrder(DateTime invoiceDate,
PXResult<SOOrderShipment, SOOrder, CurrencyInfo, SOAddress, SOContact, SOOrderType> order,
PXResultset<SOShipLine, SOLine> details,
Customer customer,
DocumentList<ARInvoice, SOInvoice> list,
InvoiceOrderDelegate baseMethod)
{
//Code before
baseMethod?.Invoke(invoiceDate, order, details, customer, list);
//Code after
// This also works, but the delegate should be used.
//Base.InvoiceOrder(invoiceDate, order, details, customer, list);
//InvoiceCreated(someInvoice, someSource);
}
[PXOverride]
public virtual void InvoiceCreated(ARInvoice invoice, SOOrder source, SOInvoiceEntry.InvoiceCreatedDelegate baseMethod)
{
baseMethod?.Invoke(invoice, source);
}
}
Upvotes: 2