Skip to main content
Answer

How to override the calculation behind the Sales order estimated margin amount and percent.

  • October 27, 2025
  • 2 replies
  • 47 views

I have a customer that would like the estimated margin amount on the sales order to show a value even if the unit cost is zero, i.e. 100%. I have located the formula in the SO/GraphExtensions/SOOrderEntryExt/Margin.cs code file. That code appears to be an override of the existing DAC attributes of the field.  Is it possible to override this from a customization project or is there another approach that should be used?

Code from Margin.cs:

        [PXMergeAttributes]
        [PXFormula(typeof(Switch<
            Case<
                Where<
                    SOLine.curyExtCost.IsEqual<decimal0>
                    .Or<SOLine.behavior.IsEqual<SOBehavior.tR>>
                    .Or<SOLine.pOCreate.IsEqual<True>.And<SOLine.pOSource.IsIn<INReplenishmentSource.dropShipToOrder, INReplenishmentSource.blanketDropShipToOrder>>>>,
                Null,
            Case<
                Where<
                    SOLine.curyExtPrice.IsEqual<decimal0>>,
                decimal0>>,
            SOLine.curyNetSales
                .Subtract<SOLine.curyExtCost
                    .Multiply<int_1.When<SOLine.invtMult.IsEqual<short0>>.Else<SOLine.invtMult>>
                    .Multiply<int_1>>>))]
        [PXUnboundFormula(typeof(int1
            .When<SOLine.behavior.IsNotEqual<SOBehavior.tR>
                .And<SOLine.curyUnitCost.IsEqual<decimal0>
                    .Or<SOLine.pOCreate.IsEqual<True>.And<SOLine.pOSource.IsIn<INReplenishmentSource.dropShipToOrder, INReplenishmentSource.blanketDropShipToOrder>>>>>
            .Else<int0>), typeof(SumCalc<SOOrder.noMarginLineCntr>))]
        protected virtual void _(Events.CacheAttached<SOLine.curyMarginAmt> e) { }   

Best answer by Django

That’s what I’m doing and the important bit is how the class declaration is done.

You can decide if you’re going to update the SOOrder.noMarginLineCntr field or not.


public class SOOrderEntryMarginExt: PXGraphExtension<Margin, SOOrderEntry>
{
#region Margin Amount on the Lines
[PXMergeAttributes(Method = MergeMethod.Replace)]

[PXFormula(typeof(
//PUT YOUR UPDATED FORMULA HERE
))]
[PXUIField(DisplayName = "Est. Margin Amount", Enabled = false)]
protected virtual void _(Events.CacheAttached<SOLine.curyMarginAmt> e) { }
#endregion

...
}

In the end, I removed all of the other logic because this client isn’t using RT type documents, nor do they dropship.

2 replies

Forum|alt.badge.img+7
  • Captain II
  • Answer
  • October 27, 2025

That’s what I’m doing and the important bit is how the class declaration is done.

You can decide if you’re going to update the SOOrder.noMarginLineCntr field or not.


public class SOOrderEntryMarginExt: PXGraphExtension<Margin, SOOrderEntry>
{
#region Margin Amount on the Lines
[PXMergeAttributes(Method = MergeMethod.Replace)]

[PXFormula(typeof(
//PUT YOUR UPDATED FORMULA HERE
))]
[PXUIField(DisplayName = "Est. Margin Amount", Enabled = false)]
protected virtual void _(Events.CacheAttached<SOLine.curyMarginAmt> e) { }
#endregion

...
}

In the end, I removed all of the other logic because this client isn’t using RT type documents, nor do they dropship.


  • Author
  • Freshman I
  • October 31, 2025

Thank you very much for the response Django. I will try implementing your example once I get approval.