Hello all!
With the script below I am querying the bill of materials from a query, comparing that against the bin inventory, and removing the quantity required from the inventory table.
So far, the script is working as intended based on the component_id matching with the part_id. Now, I am having trouble trying to get my script to not fire if the BOM has been removed from the inventory table based on the battery_id.
I have been able to grab the battery_id from the table within Ignition, but each time i do a print for the battery_id it prints like this: set([66933L])
. I am just trying to grab the numeric values within the set([])
. Although I have not been able to do so.
Any ideas where I am going wrong? Let me know if I need to provide any more information!
Script:
params = {"WOID":self.parent.parent.parent.getChild("Work Order Number").props.text}
ds = system.db.runNamedQuery("BOL/SELECT/BOM", params)
pyData = system.dataset.toPyDataSet(ds)
system.perspective.print(pyData[1])
ds2 = system.db.runNamedQuery("BOL/SELECT/Bin_Inv_Select")
pyData2 = system.dataset.toPyDataSet(ds2)
system.perspective.print(pyData[0])
components_to_update = []
processed_battery_ids = set()
battery_id = self.parent.parent.getChild("Batteries Table").props.selection.data[0].BatteryID
#Loop through each BOM Item for WO
inventory_dict = {}
for row in pyData2:
inventory_dict[row["Part_ID"]] = row["Quantity"]
# Loop through the BOM components
for row in pyData:
component_id = row["Component"]
quantity_required = row["Quantity Required"]
system.perspective.print(component_id)
if battery_id is not None and battery_id in processed_battery_ids:
continue # Skip this entry and move to the next one
#If they match, subtract from inventory
if component_id in inventory_dict:
system.perspective.print('found it')
# Subtract the BOM quantity from the inventory quantity
new_quantity = inventory_dict[component_id] - quantity_required
if new_quantity != inventory_dict[component_id]:
# Store the component for update
components_to_update.append({"NQ": new_quantity, "PID": component_id})
if battery_id is not None:
processed_battery_ids.add(self.parent.parent.getChild("Batteries Table").props.selection.data[0].BatteryID)
system.perspective.print(processed_battery_ids)
# Update the components that need updates
for component in components_to_update:
system.db.runNamedQuery("BOL/UPDATE/Sub_Bin_Inv", component)