Question

Custom amount field to append to the sales order total


Hello,

I would like to add a user entry currency field to the sales order header and would like that amount appended to the sales order total and remaining balance? Is there a way to do that in a view delegate so that the totals always accumulate correctly, or do I need to override the amount at every instance of recalculation of the order?

 

Thank you!


14 replies

Badge +11

You should be able to use the FieldUpdating for CuryOrderTotal to catch any changes being made to the total amount and include your custom field value.

Userlevel 7
Badge +17

@vineela95  Below is the code to calculate and automatically add the amount to the Sales Order Total field.

Hope this helps!

 

 

    public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
{
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXRemoveBaseAttribute(typeof(SOTaxAttribute))]
[SOTaxRCExtensionAttribute(typeof(SOOrder), typeof(SOTax), typeof(SOTaxTran), TaxCalc = TaxCalc.ManualLineCalc)]
protected virtual void _(Events.CacheAttached<SOLine.taxCategoryID> e) { }

[PXMergeAttributes(Method = MergeMethod.Append)]
[PXRemoveBaseAttribute(typeof(SOOrderTaxAttribute))]
[SOOrderTaxRCExtension(typeof(SOOrder), typeof(SOTax), typeof(SOTaxTran), TaxCalc = TaxCalc.ManualLineCalc)]
protected virtual void _(Events.CacheAttached<SOOrder.freightTaxCategoryID> e) { }

#region Event Handlers
protected void SOOrder_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e, PXRowUpdated baseEvent)
{
baseEvent?.Invoke(sender, e);
if (!sender.ObjectsEqual<SOOrderExt.usrAdditionalCharge>(e.OldRow, e.Row))
{
SOOrderTaxRCExtensionAttribute.Calculate<SOOrder.freightTaxCategoryID>(sender, e);
}
}
#endregion
}
public class SOTaxRCExtensionAttribute : SOTaxAttribute
{
public SOTaxRCExtensionAttribute(Type ParentType, Type TaxType, Type TaxSumType)
: base(ParentType, TaxType, TaxSumType)
{
}
#region Event Handlers
protected override void CalcDocTotals(PXCache sender, object row, decimal CuryTaxTotal, decimal CuryInclTaxTotal, decimal CuryWhTaxTotal, decimal CuryTaxDiscountTotal)
{
base.CalcDocTotals(sender, row, CuryTaxTotal, CuryInclTaxTotal, CuryWhTaxTotal, CuryTaxDiscountTotal);
decimal AdditionalCharge = (decimal)(ParentGetValue<SOOrderExt.usrAdditionalCharge>(sender.Graph) ?? 0m);
decimal CuryDocTotal = AdditionalCharge + (decimal)(ParentGetValue<SOOrder.curyOrderTotal>(sender.Graph) ?? 0m);
ParentSetValue<SOOrder.curyOrderTotal>(sender.Graph, CuryDocTotal);
}
#endregion
}
public class SOOrderTaxRCExtensionAttribute : SOOrderTaxAttribute
{
public SOOrderTaxRCExtensionAttribute(Type ParentType, Type TaxType, Type TaxSumType)
: base(ParentType, TaxType, TaxSumType)
{
}
#region Event Handlers
protected override void CalcDocTotals(PXCache sender, object row, decimal CuryTaxTotal, decimal CuryInclTaxTotal, decimal CuryWhTaxTotal, decimal CuryTaxDiscountTotal)
{
base.CalcDocTotals(sender, row, CuryTaxTotal, CuryInclTaxTotal, CuryWhTaxTotal, CuryTaxDiscountTotal);
decimal AdditionalCharge = (decimal)(ParentGetValue<SOOrderExt.usrAdditionalCharge>(sender.Graph) ?? 0m);
decimal CuryDocTotal = AdditionalCharge + (decimal)(ParentGetValue<SOOrder.curyOrderTotal>(sender.Graph) ?? 0m);
ParentSetValue<SOOrder.curyOrderTotal>(sender.Graph, CuryDocTotal);
}
#endregion
}

 

Badge +11

@Naveen Boga - I’m sure there’s a good reason, but I’m curious why you’re doing in ~50 lines of pretty complex code what can be done in ~10 lines of quite simple code.

Userlevel 7
Badge +17

Hi, @darylbowman   "I implemented this quite some time ago and thoroughly tested all the scenarios, including the suggestions you mentioned earlier, but unfortunately, it didn't work for me.

Consequently, I/my team reached out to the Acumatica team and shared this sample. Could you kindly provide a concise code snippet, preferably under 10 lines, that fulfills this requirement? Your assistance will greatly benefit everyone here.

Badge +11

...but unfortunately, it didn't work for me.

Well, you made me doubt the thoroughness of my testings, so I did more testing.

Turns out, this doesn’t work correctly in all cases. I believe it would work correctly if the original Order Total field was kept and an additional total field was added which would reflect the changes to the original. But trying to do all of that in one field just doesn’t work that well.

Userlevel 7
Badge +17

Yes @darylbowman  That’s right! It won’t work in on cases.

 

Therefore, I collaborated closely with the Acumatica team to ensure comprehensive support for every scenario, and after dedicated efforts, we successfully achieved functionality across all scenarios."

Badge +11

It actually worked surprisingly well in most situations that I tested. The problems arose when the lines totals changed by the same amount as the custom field amount. I couldn't figure out why even after several hours of testing 🙄

@Naveen Boga  Thank you for the response. I tried your solution and I noticed that the totals are updating correctly, however, when I try to apply a payment against the order, I receive “The order cannot be applied, the specified combination of the order type and order number cannot be found in the system.” error. I remove that code and don’t receive the error. Very confused as to why this error is occurring. 

Userlevel 7
Badge +17

Hi @vineela95 I've noticed a potential issue in the newer version that requires further investigation. I'll conduct a thorough analysis to verify and understand the root cause of the problem. I'll keep you informed of any findings related to this. 

Userlevel 7
Badge

Hi @Naveen Boga - were you able find anything for @vineela95! Thank you!

Thank you @Naveen Boga !. Please let me know if you are able to find anything!

Userlevel 7
Badge +17

Hi @vineela95  I have checked it but seems like there is a change in the Base code in the new version. I request you to check with the Acumatica team and confirm this logic.

Thank you for your help on this @Naveen Boga !

Userlevel 7
Badge

Hi @vineela95 were you able to find a solution? Thank you!

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved