Technical Articles
Proposed Minimum Sales Quantity
Setting Suggested Minimum Quantities.
Here is another partner-led idea that you can implement in your ByD tenant to add some flexibility to the standard order 2 cash process.
In ByDesign it is possible to set a Minimum Order Quantity for each product that is sold.
this is maintained in the sales area of the product master.
With this data an error message is generated in the Sales Order Entry process, if you try to supply less than the minimum.
The partner’s customer would like some flexibility. How about suggesting the minimum, but allowing the user to select less? Useful if you sell items in pairs maybe?
The solution is quite simple using the Cloud Application Studio.
Step 1, extend the product master to include a new field “Suggested Minimum Quantity” in the Sales Process Area, I have used Quantity as the data type, rather than a decimal so that I can suggest alternate units of measure. For example I may sell wine in bottles, but my suggested minimum is 1 crate (12 bottles) so I can utilise the UoM conversion tool built into ByD.
Step 2, enhance the screen of the product to add this field for user edits. MaterialOIF is the form name, and the
Now edit the material master record, to ensure that the field is visible and accepts data correctly.
Step 3 extend the Sales Order business object, by adding an indicator field on the item node, and defaulting it to false. This enables us to ensure that our process only runs once, and will override the data if there is a minimum quantity as well.
Now code some actions inside the sales order object to handle this new data.
Step 4 Create a script based on the Item>After Modify Event of the Sales Order
import ABSL;
import AP.FO.ProductDataMaintenance.Global;
//1 Retrieve material data and check for minimum suggested quantity,
foreach (var SO_Item in this){
//2 Check that the item is set, to avoid any errors with null data
if(!SO_Item.ItemProduct.ProductInternalID.IsInitial()){
//only run this is if the qty is not set, otherwise this code will continually overwrite the qty.
if(SO_Item.bUpdate == false){
//3 retrieve material data
var material = Material.Retrieve(SO_Item.ItemProduct.ProductInternalID);
//4 if material is set, get sales process data
if(material.IsSet()){
var salesOrg = SO_Item.ToParent.SalesAndServiceBusinessArea.SalesOrganisationID;
var distChannel = SO_Item.ToParent.SalesAndServiceBusinessArea.DistributionChannelCode;
var suggSales = material.SalesProcessInformation.Where(n => n.SalesOrganisationID == salesOrg && n.DistributionChannelCode.content == distChannel.content);
if(suggSales.Count() >0 ){
if(!suggSales.GetFirst().MinSugQty.IsInitial()){
SO_Item.FirstRequestedItemScheduleLine.Quantity.content = suggSales.GetFirst().MinSugQty.content;
SO_Item.FirstRequestedItemScheduleLine.Quantity.unitCode = suggSales.GetFirst().MinSugQty.unitCode;
SO_Item.bUpdate = true;
}
}
}
}
}
}
Code Explanation
Line 19 Import the Product Maintenance Namespace so we can directly access the Material Object and retrieve data.
Line 23 Checks that the Product ID is set on the Order, before running any script. If we dont check this we will get a dump when we try to call the retrieve function due to null values.
Line 28 If the quantities have been updated by this process then this variable will be true and the process will end here.
Line 31 retrieves the material data based on the productID
Line 34 if we successfully retrieve data, then we can set some variables (this is a “belts and braces” approach, since this shouldn’t run in the productID isn’t set and if it is an invalid code the UI will generate an error message to the user anyway)
Lines 35-38
Since our extension field is on the Sales Process Node, we need to get the correct one. On each material there can be Sales Process Information for each combination of Sales Org and Distribution Channel in the system. This code filters out the correct line, based on the sales data on the Sales Order Header.
Line 42 again we are checking that we do not have null values, only if data exists do we move on.
Line 42- 44 updates order quantity and sets the update to true.
Testing
You should be able to add a sales order, add an item and the system should now update the requested qty and UOM with the data from the suggested min qty, if there isn’t any it will add the minimum order qty, i there isn’t any data it will add a quantity of 1 (system default).
You should be able to update the quantity manually and move on.
Extra Step
How about adding a message to inform the user that the selected product has a suggested minimum and that the order has been updated to reflect this?
I hope this will inspire some more of these simple enhancements – quick to implement and easy to support!
John
Hey John,
I am working on Customer invoice Item save using the following code :
My issue is loop is only iterating 1 time whereas I can see in for each ObjSo variable have 3 tables corresponding to each item.
Can you please assist ?
Jay