Solved

Warehouse filter in code to retrieve unit cost

  • 26 August 2021
  • 1 reply
  • 107 views

Good day,

We are trying to retrieve the unit cost, based on the warehouse selected inline on the sales quote screen. 

How would I go about properly filtering in code to get to the right value, currently I have the following code to retrieve the code based on conditions:

We want the process to look as follow:

  1. First look at valuation method
    1. If it is standard
      1. Retrieve the current cost from the item warehouse details screen that links to the chosen warehouse on the sales quote screen
      2. If the cost is 0, retrieve from the item screen
    2. If it is average
      1. Retrieve the average cost from the item warehouse details screen that links to the chosen warehouse on the sales quote screen
      2. If the cost is 0, retrieve from the item screen
    3. Else
      1. Throw exception
 protected void CROpportunityProducts_SiteID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{

var row = (CROpportunityProducts)e.Row;

InventoryItem temp = new InventoryItem();
temp = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(Base, row.InventoryID);

INItemCost tempCost = new INItemCost();
tempCost = PXSelect<INItemCost, Where<INItemCost.inventoryID, Equal<Required<INItemCost.inventoryID>>>>.Select(Base, row.InventoryID);

INItemSite tempWharehouseCost = new INItemSite();
tempWharehouseCost = PXSelect<INItemSite, Where<INItemSite.inventoryID, Equal<Required<INItemCost.inventoryID>>>>.Select(Base, row.InventoryID);


var wharehouse = row.SiteID;

if (temp.ValMethod == "A")
{
if (tempWharehouseCost.AvgCost != 0)
{
row.CuryUnitCost = tempWharehouseCost.AvgCost;
}
else {
row.CuryUnitCost = tempCost.AvgCost;
}
}
else if (temp.ValMethod == "S")
{
if (tempWharehouseCost.StdCost != 0)
{
row.CuryUnitCost = tempWharehouseCost.StdCost;

}
else
{
row.CuryUnitCost = temp.StdCost;
}
}
else
{
throw new Exception("Please choose correct valuation method");
}

 

 

The reason for this is that stock items, can be in mulitple warehouses which in return can have different costs to the item.

Any help would be greatly appreciated

icon

Best answer by Naveen Boga 26 August 2021, 11:13

View original

1 reply

Userlevel 7
Badge +17

Hi, @charlbester34 I have modified your code like below, please verify.

May this help you!!

protected void CROpportunityProducts_SiteID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
CROpportunityProducts row = (CROpportunityProducts)e.Row;
if (row != null)
{
InventoryItem objInventoryItem = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>>>.Select(Base, row?.InventoryID);
INItemCost objINItemCost = PXSelect<INItemCost, Where<INItemCost.inventoryID, Equal<Required<INItemCost.inventoryID>>>>.Select(Base, row?.InventoryID);
INItemSite tempWharehouseCost = PXSelect<INItemSite, Where<INItemSite.inventoryID, Equal<Required<INItemCost.inventoryID>>,
And<INItemSite.siteID, Equal<Required<INItemSite.siteID>>>>>.Select(Base, row.InventoryID, row.InventoryID);

if (objInventoryItem != null && objInventoryItem.ValMethod == "A")
{
if (tempWharehouseCost?.AvgCost != 0)
row.CuryUnitCost = tempWharehouseCost?.AvgCost;
else
row.CuryUnitCost = objINItemCost?.AvgCost;
}
else if (objInventoryItem != null && !string.IsNullOrEmpty(objInventoryItem.ValMethod) && objInventoryItem.ValMethod == "S")
{
if (tempWharehouseCost?.StdCost != 0)
row.CuryUnitCost = tempWharehouseCost?.StdCost;
else
row.CuryUnitCost = objInventoryItem?.StdCost;
}
else
{
throw new Exception("Please choose correct valuation method");
}
}
}

 

 

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