Kyle Rilling
Kyle Rilling

Reputation: 15

Acumatica: Profit calculation on Sales Order grid

I am trying to add a very simple calculation to the Sales Order grid. While the field is created, it doesn't display (nor calculate) anything. Here is what I did:

  1. Added custom field to SOLine DAC (called TotalProfit)
    • Type: INT, column
  2. Published customization
  3. Added the TotoalProfit field to the SO order Document Details grid
  4. Customized the attributes:

    [PXDBCurrency(typeof(SOLine.curyInfoID), typeof(SOLine.extCost))]
    [PXUIField(DisplayName = "LineProfit")]
    [PXFormula(typeof(Sub<SOLine.curyLineAmt, SOLine.curyExtCost>))]
    [PXDefault(TypeCode.Decimal, "0.0")]
    

Published without errors, but the field is blank. I am trying to simply calculate the difference of two fields in the grid: CuryLineAmt - CuryExtCost

I also tried overriding on the screen level with no success. What am I missing?

Upvotes: 0

Views: 578

Answers (1)

billybob
billybob

Reputation: 2998

Since you are using a field that is using currency, you must always create 2 columns in the database. The first one will be the field without having the currency applied on it. The second one will have the currency applied on it.

When you use the attribute PXDBCurrency, like described in the documentation, the first parameter is used to pass currency information. The second parameter is used to pass the field without the currency applied on it.

enter image description here

So if you want to have the total profit for the SOLine, you need to create 2 fields in the SOLine DAC extension: TotalProfit and CuryTotalProfit.

Here's the code for the 2 fields:

#region CuryTotalProfit
public abstract class curyTotalProfit : PX.Data.IBqlField
{
}
protected Decimal? _CuryTotalProfit;
[PXDBCurrency(typeof(SOLine.curyInfoID), typeof(totalProfit))]
[PXUIField(DisplayName = "Total Profit")]
[PXFormula(typeof(Sub<SOLine.curyLineAmt, SOLine.curyExtCost>))]
[PXDefault(TypeCode.Decimal, "0.0")]
public virtual Decimal? CuryTotalProfit
{
    get
    {
        return this._CuryTotalProfit;
    }
    set
    {
        this._CuryTotalProfit = value;
    }
}
#endregion

#region TotalProfit
//This field has no Display UI
public abstract class totalProfit : PX.Data.IBqlField
{
}
protected Decimal? _TotalProfit;
[PXDBDecimal(4)]
[PXDefault(TypeCode.Decimal, "0.0")]
public virtual Decimal? TotalProfit
{
    get
    {
        return this._TotalProfit;
    }
    set
    {
        this._TotalProfit = value;
    }
}
#endregion

Upvotes: 1

Related Questions