Solved

Sales Quotes - Unable to Update the Unit Price Field

  • 10 February 2023
  • 3 replies
  • 112 views

Userlevel 3
Badge

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);
}
}
}

 

icon

Best answer by Yuriy Zaletskyy 12 February 2023, 14:28

View original

3 replies

Userlevel 5
Badge +3

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:

 

 

Userlevel 3
Badge

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. 

 

 

Userlevel 5
Badge +3

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


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