@@ -56,7 +56,9 @@ def get_alternative_workstations_from_operation(
5656):
5757 alternatives = []
5858 seen_workstations = set ()
59+ default_workstation = operation_doc .workstation
5960
61+ # Add the operation's default workstation first if it's not the current one
6062 if operation_doc .workstation and operation_doc .workstation != current_workstation :
6163 alternative_data = {
6264 "workstation" : operation_doc .workstation ,
@@ -65,11 +67,12 @@ def get_alternative_workstations_from_operation(
6567 ),
6668 "next_available" : get_next_available_time (operation_doc .workstation , planned_start_time ),
6769 "capacity" : get_workstation_capacity (operation_doc .workstation ),
68- "is_bom_default" : True ,
70+ "is_bom_default" : True , # This is the default from Operation master
6971 }
7072 alternatives .append (alternative_data )
7173 seen_workstations .add (operation_doc .workstation )
7274
75+ # Process alternative_workstations field (if it's a string or list)
7376 if hasattr (operation_doc , "alternative_workstations" ) and operation_doc .alternative_workstations :
7477 workstation_names = []
7578
@@ -95,29 +98,21 @@ def get_alternative_workstations_from_operation(
9598 if workstation_name in seen_workstations :
9699 continue
97100
101+ ws_name = (
102+ workstation_name .workstation if hasattr (workstation_name , "workstation" ) else workstation_name
103+ )
104+
98105 alternative_data = {
99- "workstation" : workstation_name .workstation
100- if hasattr (workstation_name , "workstation" )
101- else workstation_name ,
102- "availability" : get_workstation_availability_status (
103- workstation_name .workstation
104- if hasattr (workstation_name , "workstation" )
105- else workstation_name ,
106- planned_start_time ,
107- ),
108- "next_available" : get_next_available_time (
109- workstation_name .workstation
110- if hasattr (workstation_name , "workstation" )
111- else workstation_name ,
112- planned_start_time ,
113- ),
114- "capacity" : get_workstation_capacity (
115- workstation_name .workstation if hasattr (workstation_name , "workstation" ) else workstation_name
116- ),
106+ "workstation" : ws_name ,
107+ "availability" : get_workstation_availability_status (ws_name , planned_start_time ),
108+ "next_available" : get_next_available_time (ws_name , planned_start_time ),
109+ "capacity" : get_workstation_capacity (ws_name ),
110+ "is_bom_default" : ws_name == default_workstation , # Check if this matches the default
117111 }
118112 alternatives .append (alternative_data )
119- seen_workstations .add (alternative_data [ "workstation" ] )
113+ seen_workstations .add (ws_name )
120114
115+ # Process alternative_workstation child table
121116 if hasattr (operation_doc , "alternative_workstation" ) and operation_doc .alternative_workstation :
122117 for alt_row in operation_doc .alternative_workstation :
123118 if hasattr (alt_row , "workstation" ) and alt_row .workstation :
@@ -131,6 +126,8 @@ def get_alternative_workstations_from_operation(
131126 "availability" : get_workstation_availability_status (alt_row .workstation , planned_start_time ),
132127 "next_available" : get_next_available_time (alt_row .workstation , planned_start_time ),
133128 "capacity" : get_workstation_capacity (alt_row .workstation ),
129+ "is_bom_default" : alt_row .workstation
130+ == default_workstation , # Check if this matches the default
134131 }
135132 alternatives .append (alternative_data )
136133 seen_workstations .add (alt_row .workstation )
0 commit comments