Reputation: 804
When a Sales Order is created via a REST API call applicable Discounts are not applied automatically like they are when creating the same SO via the standard Acumatica screen. The Discounts should apply and are not "Manual" -- running the "Recalculate Prices" action after being created via the API will apply the Discounts.
Do the Discount Codes have to be specified in the API call or is there some way to get them to be automatically applied like on the screen? Orders received via the API are given a unique Order Type so we could reasonably do a customization to the SOOrderEntry graph for these particular order types that when the SO is initially created to run the "Recalculate Prices" but I couldn't find a way to successfully trigger the Base Action either.
Upvotes: 0
Views: 501
Reputation: 804
Based on RuslanDev's answer and a couple changes this was the action implemented and then executed in a subsequent API call:
public PXAction<SOOrder> RecalculateDiscountsFromImport;
[PXButton]
[PXUIField(DisplayName = "Recalculate Discounts",
MapEnableRights = PXCacheRights.Select,
MapViewRights = PXCacheRights.Select,
Visible = false)]
public void recalculateDiscountsFromImport()
{
foreach (SOLine line in Base.Transactions.Select())
{
DiscountEngine<SOLine>.RecalculateDiscountsLine<SOOrderDiscountDetail>(
Base.Transactions.Cache,
Base.Transactions,
line,
line,
Base.DiscountDetails,
Base.Document.Current.BranchID,
Base.Document.Current.CustomerLocationID,
Base.Document.Current.OrderDate.Value);
Base.Transactions.Update(line);
Base.Transactions.SetValueExt<SOLine.manualDisc>(line, false);
}
Base.Actions.PressSave();
}
Upvotes: 0
Reputation: 6778
Currently, discounts are completely skipped for all Sales Orders and AR Invoices created or updated via Web API or Import Scenarios. To launch discounts calculation through Web API, you should proceed as follows:
Create a hidden action in the SOOrderEntry BLC extension to recalculate discounts for the current order:
public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
public PXAction<SOOrder> RecalculateDiscountsFromImport;
[PXButton]
[PXUIField(DisplayName = "Recalculate Discounts",
MapEnableRights = PXCacheRights.Select,
MapViewRights = PXCacheRights.Select,
Visible = false)]
public void recalculateDiscountsFromImport()
{
foreach (SOLine line in Base.Transactions.Select())
{
SOLine oldLine = Base.Transactions.Cache.CreateCopy(line) as SOLine;
DiscountEngine<SOLine>.RecalculateDiscountsLine<SOOrderDiscountDetail>(
Base.Transactions.Cache,
Base.Transactions,
line,
line,
Base.DiscountDetails,
Base.Document.Current.BranchID,
Base.Document.Current.CustomerLocationID,
Base.Document.Current.OrderDate.Value);
TX.TaxAttribute.Calculate<SOLine.taxCategoryID>(
Base.Transactions.Cache,
new PXRowUpdatedEventArgs(line, oldLine, false));
}
Base.Transactions.Cache.IsDirty = true;
}
}
Add mapping for the custom action above in an extended endpoint and invoke the action via the Contract API in a separate request after Sales Order was created and saved in Acumatica.
Upvotes: 2