A Reorder Report by Script
The Needs Reordering widget shows the parts to buy on a dashboard. Purchasing may want that list in an email or a file instead. system.kanoa.inventory.getPartInventoryStock returns the same information to a script.
It returns a dataset with one row per part and storeroom. Each row joins the stock balance with the stocking policy. Pass filters in a dictionary, or an empty dictionary for every row. The filters you need are:
| Filter | Value | Meaning |
|---|---|---|
isStocked | True | Only parts with an active stocking policy |
isBelowReorderThreshold | True | Only parts below their reorder point |
inventoryAssetName or inventoryAssetPath | 'Parts Room' or the full path | Only one storeroom |
Each row has columns such as partNumber, inventoryAssetName, quantityOnHand, quantityOnOrder, reorderPointQty, reorderQty, uomCode and isBelowSafetyStock.
-
In Inventory → Parts, check that
CF-FLT-COOL10has 2 on hand, below its reorder point. You did this in Adjust Stock and Find Reorders. -
In the Ignition Designer, open the Script Console and run:
rows = system.kanoa.utilities.convertDatasetToJSON(system.kanoa.inventory.getPartInventoryStock({'inventoryAssetName': 'Parts Room','isStocked': True,'isBelowReorderThreshold': True,}))for row in rows:print row.get('partNumber'), row.get('quantityOnHand'), row.get('reorderPointQty'), row.get('reorderQty'), row.get('uomCode') -
Check the output.
CF-FLT-COOL10is listed with2.0on hand, and its reorder point and reorder quantity. -
Receive some filters into the Parts Room so it rises above its reorder point, and run the script again. The part drops off the list.
Turn it into a report
Put the query in a project script library function that returns text, so any caller can use it:
def reorderText(storeroomName):
"""
One line per part to reorder. Returns None when nothing needs ordering.
"""
rows = system.kanoa.utilities.convertDatasetToJSON(
system.kanoa.inventory.getPartInventoryStock({
'inventoryAssetName': storeroomName,
'isStocked': True,
'isBelowReorderThreshold': True,
}))
if not rows:
return None
lines = ['Part, On hand, On order, Reorder qty, UOM']
for row in rows:
lines.append('%s, %s, %s, %s, %s' % (row.get('partNumber'), row.get('quantityOnHand'),
row.get('quantityOnOrder'), row.get('reorderQty'), row.get('uomCode')))
return '\n'.join(lines)
Save the library as inventoryReports in your project, then call inventoryReports.reorderText('Parts Room') from the Script Console to check it.
Run it on a schedule
A gateway timer script can call inventoryReports.reorderText('Parts Room') once a day. If it returns text, the script sends it to purchasing with Ignition's email function, or writes it to a file. If it returns None, it does nothing.
Scheduling, email and file writing are standard Ignition features, not Kanoa functions. See the Ignition documentation for gateway timer scripts and system.net.sendEmail.
A daily email that repeats the same parts becomes noise. Filter with hasOnOrder set to False to skip parts that already have an order open.
You built a script that finds every stocked part below its reorder point, turned it into a report function, and learned how to run it on a schedule.