Solved

How to override a avg cost field in acuamtica

  • 14 April 2023
  • 1 reply
  • 79 views

Userlevel 2

Hello 

I want to set the avg  field value with a desired value as seen in the below screen.
But It is being applied.  

 

I am handling it on FieldUpdated.t

Code Example:

        protected void _(Events.FieldUpdated<INItemSite, INItemSite.inventoryID> e)
        {          

            if (e.Row.InventoryID != null)
            {
                ………….
                    e.Row.AvgCost = (decimal?)100.00;
            }
        }

 




The problem is Avg Cost field is having the PXDBPriceCostCalced attribute , therefore its not setting my desired value.

public abstract class avgCost : PX.Data.BQL.BqlDecimal.Field<avgCost> { }protected Decimal? _AvgCost;[PXPriceCost()][PXDefault(TypeCode.Decimal, "0.0")][PXUIField(DisplayName = "Average Cost", Enabled = false)][PXDBPriceCostCalced(typeof(Switch<Case<Where<INItemStats.qtyOnHand, Equal<decimal0>>, decimal0>, Div<INItemStats.totalCost, INItemStats.qtyOnHand>>), typeof(Decimal), CastToScale = 9, CastToPrecision = 25)][CurySymbol(siteID: typeof(siteID))]public virtual Decimal? AvgCost{	get	{		return this._AvgCost;	}	set	{		this._AvgCost = value;	}}

 

Any suggestion, on how can I set my avg cost value , with a desired value.

icon

Best answer by Vignesh Ponnusamy 14 April 2023, 21:19

View original

1 reply

Userlevel 7
Badge +4

Hi @vramkrishna26,

As you have mentioned, the value is set in PXDBPriceCostCalced attribute, so you can remove the attribute in the CacheAttached and set the field value in the RowSelected.

As the field is not a bound field, you can set in on the go in the RowSelected. Below is an example you can try,

  public class INItemSiteMaint_Extension : PXGraphExtension<PX.Objects.IN.INItemSiteMaint>
{
#region Event Handlers
[PXPriceCost()]
[PXDefault(TypeCode.Decimal, "0.0")]
[PXUIField(DisplayName = "Average Cost", Enabled = false)]
//[PXDBPriceCostCalced(typeof(Switch<Case<Where<INItemStats.qtyOnHand, Equal<decimal0>>, decimal0>, Div<INItemStats.totalCost, INItemStats.qtyOnHand>>), typeof(Decimal), CastToScale = 9, CastToPrecision = 25)]
[CurySymbol(siteID: typeof(INItemSite.siteID))]
protected virtual void INItemSite_AvgCost_CacheAttached(PXCache cache)
{

}
protected void INItemSite_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected baseHandler)
{
baseHandler?.Invoke(cache, e);
var row = (INItemSite)e.Row;
if (row == null) return;

Base.itemsitesettings.Current.AvgCost = (decimal?)210.00;

}
#endregion
}

 

I am not aware of your requirement but I hope that helps. Thanks,

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