nicksurname
nicksurname

Reputation: 37

Acumatica - PXDBScalar with calculation

I'm looking to write add a calculated field for the ARTran table, which converts the Qty to a specified universal UOM.

Normally I'd use one of the calculation attributes but I'm unsure how to add operands to the Search<> query. Ideally the logic would be

Search2<Mult<ARTran.baseQty, INUnit.unitRate>, 
     InnerJoin<InventoryItem, On<InventoryItem.inventoryID, Equal<ARTran.inventoryID>>,
     InnerJoin<INUnit, On<INUnit.fromUnit, Equal<InventoryItem.baseUnit>, And<INUnit.toUnit, Equal<InventoryItem.purchaseUnit>>>>>,

Failing that, I've been trying to write an attribute which will subscribe a RowSelected event to calculate the value. This works on the Invoices screen correctly, however when the DAC is used in a GI the row data is empty when the RowSelected event is called.

Any help with either solution would be awesome.

Thanks

Upvotes: 0

Views: 1317

Answers (1)

Hugues Beaus&#233;jour
Hugues Beaus&#233;jour

Reputation: 8278

The difficulty is that each record selection method has it's own limitations.

You could use PXFormula for the Mult clause but not for the Join clauses.

You could use PXDBScalar for the Join clauses but not for the Mult clause.

This inconsistency is vexing but you could use 2 custom fields to get around the limitation by using both PXFormula and PXDBScalar:

using PX.Data;
using PX.Objects.IN;
using System;

namespace PX.Objects.AR
{
    public class ARTranExt : PXCacheExtension<ARTran>
    {
        #region UsrUniversalUOM 
        [PXDecimal]
        [PXFormula(typeof(Mult<ARTran.baseQty, usrUnitRate>))]
        [PXUIField(DisplayName = "Universal UOM")]
        public virtual Decimal? UsrUniversalUOM { get; set; }
        public abstract class usrUniversalUOM : IBqlField { }
        #endregion

        #region UsrUnitRate
        [PXDBScalar(typeof(Search2<INUnit.unitRate,
                           InnerJoin<InventoryItem, On<InventoryItem.inventoryID, Equal<ARTran.inventoryID>>>,
                           Where<INUnit.inventoryID, Equal<ARTran.inventoryID>,
                           And<INUnit.fromUnit, Equal<InventoryItem.baseUnit>,
                           And<INUnit.toUnit, Equal<InventoryItem.purchaseUnit>>>>>))]
        [PXUIField(DisplayName = "Unit Rate")]
        public virtual Decimal? UsrUnitRate { get; set; }
        public abstract class usrUnitRate : IBqlField { }
        #endregion
    }
}

If you need Unit Rate to be invisible in the grid you can set it's Visibility property to invisible.

enter image description here

Upvotes: 0

Related Questions