Skip to main content

Hello Community,

I’m trying to update the Unit Price field when I update the Quantity but it is not working but the same code is working in the Sales Orders screen. 

Not sure why it is not working in the Sales Quotes screen. Below is the simple code I’m using but still not working, can anyone review and help on this?

 

public class QuoteMaintExt : PXGraphExtension<QuoteMaint>
{
public static bool IsActive() => true;
protected virtual void CROpportunityProducts_Quantity_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseMethod)
{
InvokeBaseMethod?.Invoke(cache, e);
CROpportunityProducts row = e.Row as CROpportunityProducts;



if (row != null)
{
cache.SetValueExt<CROpportunityProducts.curyUnitPrice>(row, 10m);
}
}
}

 

Yeah, that is tricky one. 

Reason why your code doesn’t work for Sales quote is plenty of attributes, which applied to curyUnitPrice by Acumatica itself. Below goes one example:

         PXDefault(TypeCode.Decimal, "0.0")]
PXDBCurrencyPriceCost(typeof(CROpportunityProducts.curyInfoID), typeof(CROpportunityProducts.unitPrice))]
PXUIField(DisplayName = "Unit Price", Visibility = PXUIVisibility.SelectorVisible)]
public virtual Decimal? CuryUnitPrice { get; set; }

and that is far from the only one. I’ve tried initially to use CacheAttached, and remove section PXDBCurrencyPriceCost, but it didn’t work, some additional overridings may be needed to apply. So instead, I’d suggest to use one level higher, and go with RowUpdated:

    public class QuoteMaintExt : PXGraphExtension<QuoteMaint>
{
public static bool IsActive() => true;

protected virtual void _(Events.RowUpdated<CROpportunityProducts> e)
{
var nR = e.Row;
nR.CuryUnitPrice = 15;
}

}

on my machine worked perfectly fine:

 

 


Hi @Yuriy Zaletskyy  I have tried with the RowUpdated event and verified it is working fine but if I wanted to change the UnitPrice for reason, system will not allow this.

Hence I would like to affect the UnitPrice only when InventoryID is added. 

 

 


What about this approach:

    public class QuoteMaintExt : PXGraphExtension<QuoteMaint>
{
public static bool IsActive() => true;

protected virtual void _(Events.RowUpdated<CROpportunityProducts> e)
{
var nR = e.Row;
var oR = e.OldRow;
if (nR.InventoryID != oR.InventoryID) // InventoryID was changed
{
nR.CuryUnitPrice = 15;
}

}

}

with provided code sample, setting of CuryUnitPrice will happen, if InventoryID was updated.


Reply