Skip to main content

Hello Everyone,

 

I have been battling on what the best way is to get unit costs to auto-populate onto the Sales Quotes (CR304500) screen.

Initially I had used a FieldUpdated handler for inventory ID but as we import plenty of worksheets from excel, this breaks and pushes the values a line down.

Yesterday, I was doing the T230 course and I was inspired so I recreated it but for recalculating unit costs on Sales Quotes.

Here is the code for the button, hope it helps someone!

public class QuoteMaintCostExt : PXGraphExtension<PX.Objects.CR.QuoteMaint>
{
public static bool IsActive() => true;
//Make sure you have the views
public PXOrderedSelect<CRQuote, CROpportunityProducts,
Where<CROpportunityProducts.quoteID, Equal<Current<CRQuote.quoteID>>>,
OrderBy<Asc<CROpportunityProducts.sortOrder>>>
Products;


public PXSelect<CRQuote,
Where<CRQuote.opportunityID, Equal<Optional<CRQuote.opportunityID>>,
And<CRQuote.quoteType, Equal<CRQuoteTypeAttribute.distribution>>>> Quote;



#region Actions
public PXAction<CRQuote> UpdateCosts;
PXButton(DisplayOnMainToolbar = true)]
PXUIField(DisplayName = "Update Costs")]
protected virtual void updateCosts()
{

var quote = Products.Current;
if (quote.QuoteID == null || quote.InventoryID == null) return;
var lines = Products.Select();
foreach(CROpportunityProducts product in lines)
{
if (quote.POCreate == true) return;
if (quote.POCreate == false)
{



INItemSite site = SelectFrom<INItemSite>
.Where<INItemSite.inventoryID.IsEqual<@P.AsInt>>
.View
.Select(Base, product.InventoryID);

if (site != null)
{
product.CuryUnitCost = site.TranUnitCost;

Products.Update(product);
}
}
}

}
#endregion
}

 

Hi @aiwan  You are updating the caches but not committing.

After foreach loop, just write a Base.Save.Press(); and check if the values are updated and saved into the database.

And, as per your requirement, I recommend you to use the InventoryID fieldupdated event and as you mentioned you already used it, but I did not understand the problem that you are facing. Can you please elaborate?


Hi @Naveen Boga 

 

When using FieldUpdated and importing from excel, the values for unit cost within the details shift down one line, we have a very bespoke nature of manufacturing and this  damages profit margin reliability.

The reason for the lack of Base.Save.Press() is that we need to double check any items which are bought in and make sure the unit costs are correct as they are also bespoke so prices are not constant.

Once the costs are checked by the member of staff they persist the changes.


Reply