首页 文章

Acumatica - 覆盖业务逻辑,访问受保护的方法

提问于
浏览
1

我想要覆盖业务逻辑中SOInvoiceEntry图的InvoiceOrder逻辑,因此如果未选择“Bill Separately'选项,我可以更改聚合发票的逻辑 .

我在下面编写了一个扩展方法来替换内置的InvoiceOrder方法 .

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
}

我'm unsure how to access the original object'的受保护方法 . 通常我只是调用 Base.DoSomething(); ,但我认为我无法访问受保护的方法,因为扩展对象不是直接从SOInvoiceEntry派生的 .

我是否还需要覆盖我想要使用的受保护方法,或者是否有办法从扩展中访问它们?

任何帮助都是极好的 .

谢谢 .

1 回答

  • 0

    您使用传递给方法的委托作为基本调用 . 对于InvoiceCreated,您应该能够覆盖它并调用它,如下所示:

    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);
        }
    }
    

相关问题