Disable Discounts Calculation for API Calls

Hi All,

When you creating a multiple AR/SO documents with multiple lines through the API, you may have a nice trick to little-bit optimize system performance.

By default Acumatica business logic is optimized for entering data from UI, so all variables as taxes and discounts must be recalculated on each document line.
But during bulk load you actually can do it just once – before document save.

Here you have extension that will disable automatic discounts calculation if you loading data from API or Integration services.

public class SOOrderEntryExtension : PXGraphExtension<SOOrderEntry>
{
       [PXOverride]
       public virtual void RecalculateDiscounts(PXCache sender, SOLine line, Action<PXCache, SOLine> del)
       {
              if (!Base.IsImport) del(sender, line);
       }
}

To calculate discounts before saving the record you can manually call RecalculateDiscounts Action from your code. Here is example for Screen-Based API.

List<Command> list = new List<Command>();

list.Add(new Value() { Value = "False", LinkedCommand = schema.RecalculatePricesAndDiscounts.RecalcUnitPrices });
list.Add(new Value() { Value = "True", LinkedCommand = schema.RecalculatePricesAndDiscounts.RecalcDiscounts });
list.Add(schema.Actions.ActionRecalculateDiscountsAction);
list.Add(schema.Actions.Save);
list.Add(schema.OrderSummary.OrderNbr);

Content[] result = screen.Submit(list.ToArray());

You can use the similar code for AR invoices as well.

Have a nice integration!

Leave a Reply

Your email address will not be published. Required fields are marked *