50 lines
1.9 KiB
Python
50 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
import json
|
|
|
|
with open('/home/mdares/.node-red/flows.json', 'r') as f:
|
|
flows = json.load(f)
|
|
|
|
# Fix restart-work-order to reset scrap as well
|
|
for node in flows:
|
|
if node.get('name') == 'Work Order buttons':
|
|
func = node['func']
|
|
|
|
# Update the SQL to also reset scrap_parts
|
|
old_sql = 'msg.topic = "UPDATE work_orders SET status = CASE WHEN work_order_id = ? THEN \'RUNNING\' ELSE \'PENDING\' END, cycle_count = 0, good_parts = 0, progress_percent = 0, updated_at = NOW() WHERE work_order_id = ? OR status = \'RUNNING\'";'
|
|
|
|
new_sql = 'msg.topic = "UPDATE work_orders SET status = CASE WHEN work_order_id = ? THEN \'RUNNING\' ELSE \'PENDING\' END, cycle_count = 0, good_parts = 0, scrap_parts = 0, progress_percent = 0, updated_at = NOW() WHERE work_order_id = ? OR status = \'RUNNING\'";'
|
|
|
|
func = func.replace(old_sql, new_sql)
|
|
|
|
# Update to reset scrap in global state
|
|
old_restart_state = ''' // Initialize global state to 0
|
|
global.set("activeWorkOrder", order);
|
|
global.set("cycleCount", 0);
|
|
flow.set("lastMachineState", 0);
|
|
global.set("scrapPromptIssuedFor", null);
|
|
|
|
node.warn(`[RESTART-WO] Reset cycleCount to 0`);'''
|
|
|
|
new_restart_state = ''' // Initialize global state to 0
|
|
order.scrap = 0;
|
|
order.good = 0;
|
|
|
|
global.set("activeWorkOrder", order);
|
|
global.set("cycleCount", 0);
|
|
flow.set("lastMachineState", 0);
|
|
global.set("scrapPromptIssuedFor", null);
|
|
|
|
node.warn(`[RESTART-WO] Reset cycleCount=0, scrap=0, good=0`);'''
|
|
|
|
func = func.replace(old_restart_state, new_restart_state)
|
|
|
|
node['func'] = func
|
|
print("✓ Updated restart-work-order to reset scrap_parts")
|
|
break
|
|
|
|
# Write back
|
|
with open('/home/mdares/.node-red/flows.json', 'w') as f:
|
|
json.dump(flows, f, indent=4)
|
|
|
|
print("✓ flows.json updated successfully")
|