3

In our add-on, we are modifying the UnitPrice when creating the invoice from the shipment based on our own calculation with a Regex expression. Everything seems fine for all fields, except the taxes who always take the SOOrder taxes.

We created a PXGraphExtension and used the following:

public void InvoiceOrder(DateTime invoiceDate, PXResult<SOOrderShipment, SOOrder, CurrencyInfo, SOAddress, SOContact, SOOrderType> order, PXResultset<SOShipLine, SOLine> details, Customer customer, DocumentList<ARInvoice, SOInvoice> list,
        Action<DateTime, PXResult<SOOrderShipment, SOOrder, CurrencyInfo, SOAddress, SOContact, SOOrderType>, PXResultset<SOShipLine, SOLine>, Customer, DocumentList<ARInvoice, SOInvoice>> method)
    {
        using (var scope = new PXTransactionScope())
        {                
            method(invoiceDate, order, details, customer, list);
            LookupBalesFromOrderAndShipment();
            scope.Complete();
        }
    }

In the LookupBalesFromOrderAndShipment(); is where we modify the UnitPrice based on our calculation, and call a Base.Transactions.Update(updatedLine); with our new value and then Base.Persist();

All data seems fine except the Tax Details tab, which still uses the old CuryLineAmt instead of the new CuryLineAmt of the newly created invoice.

I have tried forcing tax recalculation in the RowUpdated event but it doesn't seem to be doing anything.

        protected virtual void ARTran_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e, PXRowUpdated InvokeBaseHandler)
    {

        if (InvokeBaseHandler != null)
            InvokeBaseHandler(cache, e);


            TaxAttribute.Calculate<ARTran.taxCategoryID>(cache, e);


    }

Declaring var row = (ARTran)e.Row; and inspecting the variable tells me the right new CuryLineAmt, but that taxes still seem to be calculated on what came in from the SOOrder.

Is there any other way to force a tax calculation or update the ARTax and ARTaxTran table without any risks?

1 Answers1

3

The base function InvoiceOrder changes the tax calculation methods to fit the initial SalesInvoice creation:

TaxAttribute.SetTaxCalc<ARTran.taxCategoryID>(this.Transactions.Cache, null, TaxCalc.ManualCalc);

Every other time you access this page, the tax calculation method used is the one set in SOInvoiceEntry's constructor:

TaxAttribute.SetTaxCalc<ARTran.taxCategoryID>(Transactions.Cache, null, TaxCalc.ManualLineCalc);

Your solution would be to set back the appropriate tax calculation method after calling your base delegate:

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 void InvoiceOrder(DateTime invoiceDate, PXResult<SOOrderShipment,SOOrder,CurrencyInfo,SOAddress,SOContact,SOOrderType> order, PXResultset<SOShipLine,SOLine> details, Customer customer, DocumentList<ARInvoice,SOInvoice> list, InvoiceOrderDelegate baseMethod)
{
    baseMethod(invoiceDate,order,details,customer,list);

    TaxAttribute.SetTaxCalc<ARTran.taxCategoryID>(Base.Transactions.Cache, null, TaxCalc.ManualLineCalc);

    var tran = Base.Transactions.Current;
    tran.CuryUnitPrice = tran.CuryUnitPrice + 10m;
    Base.Transactions.Update(tran);
    Base.Actions.PressSave();
}
Philippe
  • 986
  • 1
  • 6
  • 17