18 lines
794 B
Python
18 lines
794 B
Python
import frappe
|
|
|
|
|
|
def execute():
|
|
"""'Close Process' used to overwrite SB Process.status with the literal string
|
|
'Closed' — but status Links to the Process Statuses master (Pass/Fail/Unknown only),
|
|
so 'Closed' was never a valid entry; it's a workflow_state, not a status. Restore
|
|
each affected record's status to its most recently logged cycle outcome (or
|
|
'Unknown' if it was never logged)."""
|
|
affected = frappe.get_all('SB Process', filters={'status': 'Closed'}, pluck='name')
|
|
for name in affected:
|
|
last_log = frappe.get_all(
|
|
'SB Process Cycle Log', filters={'parent': name}, fields=['status'],
|
|
order_by='cycle_date desc', limit=1
|
|
)
|
|
restored = last_log[0].status if last_log else 'Unknown'
|
|
frappe.db.set_value('SB Process', name, 'status', restored, update_modified=False)
|