Solved

Add a calculated field to SO Lines?

  • 20 May 2023
  • 7 replies
  • 311 views

Userlevel 2
Badge

Hello

I am trying to add a custom field to the SO Line details, which will calculate Available Qty - Line Qty for each line on the sales order.

We are trying to do this as we have orders which we import that contain thousands of lines, and after importing it is extremely tedious to scroll through to find the lines which have the “QTY will go negative” error tagged on them. We do not allow inventory to go negative in our system, and for our use case, we must put the “oversold” quantity of product onto separate orders.

I dont know where to start with this, and any help will be greatly appreciated!

icon

Best answer by Naveen Boga 20 May 2023, 07:00

View original

7 replies

Userlevel 7
Badge +17

Hi @Denham  We can do this with minor customization and please find the steps below for reference.

  1. Extend the SOLine DAC file, and introduce a new calculated field (Decimal type)
  2. Extend the SOOrderEntry Graph file
  3. Write a fieldselecting event, and inside this event, add logic to get the Qty available for this field and subtract with the line order qty. 

Hope this helps and let me know if you need any assistance.

Userlevel 2
Badge

Hi @Naveen Boga

Thank you for the quick response and explanation! 

Would you possibly be able to help me write the fieldselecting event. I am not the most experienced with writing customizations so far, but I am working on learning. Or if you could point me in the right direction as to where I can read up more on how to do this, that would be great!

Thank you

Userlevel 2
Badge

With some help from ChatGPT, I managed to get the code below to validate and published. The problem now is that the calculation is not correct. For example on an order with a line with a quantity of 901pcs, and 902pcs are available, the Remaining Qty column is showing 901pcs.

 

   // Field-Selecting event handler for the OrderQty field on the SOLine DAC
protected virtual void SOLine_OrderQty_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
{
if (e.Row == null)
return;

SOLine line = (SOLine)e.Row;

if (line.InventoryID != null && line.SiteID != null)
{
// Retrieve the Inventory Site Status record
INSiteStatus siteStatus = PXSelect<INSiteStatus,
Where<INSiteStatus.inventoryID, Equal<Required<INSiteStatus.inventoryID>>,
And<INSiteStatus.siteID, Equal<Required<INSiteStatus.siteID>>>>>
.Select(Base, line.InventoryID, line.SiteID);

if (siteStatus != null)
{
// Calculate the Quantity Available by subtracting the Ordered and Shipped quantities
decimal qtyAvailable = (siteStatus.QtyAvail.GetValueOrDefault() - siteStatus.QtySOShipping.GetValueOrDefault());
decimal orderQty = line.OrderQty.GetValueOrDefault();
decimal qtyRemaining = qtyAvailable - orderQty;

// Set the calculated remaining quantity to the UsrQtyRemaining field in the SOLineQtyRemaining DAC extension
SOLineQtyRemaining lineExt = PXCache<SOLine>.GetExtension<SOLineQtyRemaining>(line);
lineExt.UsrQtyRemaining = qtyRemaining;

// Set the calculated remaining quantity as the return value for the field-selecting event
e.ReturnValue = qtyRemaining;
}
}
}

#endregion
}
}

 

Userlevel 2
Badge

Figured out the issue. The code was over-writing the order qty due to the final ReturnValue portion.

Going to do a few more tests, but I think I got it figured out!

Thank you @Naveen Boga for pointing me in the right direction

 

Userlevel 7
Badge +17

Hi @Denham  Great! Thanks for sharing the update.

Let me know if you need any help.

Can you explain the purpose or intended use of the calculated field to be added to SO Lines?

Userlevel 2
Badge

Can you explain the purpose or intended use of the calculated field to be added to SO Lines?

Hi Kathlyn

In this case, we are using this field to tell us the remaining quantity of an inventory item after the sales order is fulfilled(Qty Available - Line Qty). We have some items which are extremely fast movers, that are also very difficult to acquire stock. So we are using this field to reduce quantity on orders as we see fit, depending on the amount of stock that will remain after the order is fulfilled.

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