Skip to main content
Solved

How to override a avg cost field in acuamtica

  • April 14, 2023
  • 1 reply
  • 94 views

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.

Best answer by Vignesh Ponnusamy

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,

View original
Did this topic help you find an answer to your question?

1 reply

Vignesh Ponnusamy
Acumatica Moderator
Forum|alt.badge.img+5

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings