@@ -1478,20 +1478,20 @@ def export_boms(self):
1478
1478
quoteattr (location ),
1479
1479
)
1480
1480
else :
1481
- duration_per = (i ["produce_delay" ] or 0 ) + (
1481
+ duration = (i ["produce_delay" ] or 0 ) + (
1482
1482
i ["days_to_prepare_mo" ] or 0
1483
1483
)
1484
1484
1485
- yield '<operation name=%s %ssize_multiple="1" duration_per ="%s" posttime="P%dD" priority="%s" xsi:type="operation_time_per ">\n ' "<item name=%s/><location name=%s/>\n " % (
1485
+ yield '<operation name=%s %ssize_multiple="1" duration ="%s" posttime="P%dD" priority="%s" xsi:type="operation_fixed_time ">\n ' "<item name=%s/><location name=%s/>\n " % (
1486
1486
quoteattr (operation ),
1487
1487
(
1488
1488
("description=%s " % quoteattr (i ["code" ]))
1489
1489
if i ["code" ]
1490
1490
else ""
1491
1491
),
1492
1492
(
1493
- self .convert_float_time (duration_per )
1494
- if duration_per and duration_per > 0
1493
+ self .convert_float_time (duration )
1494
+ if duration and duration > 0
1495
1495
else "P0D"
1496
1496
),
1497
1497
self .manufacturing_lead ,
@@ -2060,7 +2060,12 @@ def getReservedQuantity(stock_move_id):
2060
2060
),
2061
2061
due ,
2062
2062
priority ,
2063
- qty - reserved_quantity if j ["picking_policy" ] == "one" and qty - reserved_quantity > 0 else 0.0 ,
2063
+ (
2064
+ qty - reserved_quantity
2065
+ if j ["picking_policy" ] == "one"
2066
+ and qty - reserved_quantity > 0
2067
+ else 0.0
2068
+ ),
2064
2069
"open" if qty - reserved_quantity > 0 else "closed" ,
2065
2070
quoteattr (product ["name" ]),
2066
2071
quoteattr (customer ),
@@ -2448,9 +2453,12 @@ def export_manufacturingorders(self):
2448
2453
startdate = self .formatDateTime (
2449
2454
i .date_start if i .date_start else i .date_planned_start
2450
2455
)
2451
- # enddate = self.formatDateTime(i.date_planned_finished)
2452
2456
except Exception :
2453
2457
continue
2458
+ try :
2459
+ enddate = self .formatDateTime (i .date_finished )
2460
+ except Exception :
2461
+ enddate = None
2454
2462
qty = self .convert_qty_uom (
2455
2463
i .qty_producing if i .qty_producing else i .product_qty ,
2456
2464
i .product_uom_id .id ,
@@ -2470,40 +2478,33 @@ def export_manufacturingorders(self):
2470
2478
batch = mto_mo [0 ].display_name if mto_mo else i .name
2471
2479
2472
2480
# Create a record for the MO
2473
- # Option 1: compute MO end date based on the start date
2474
- yield '<operationplan type="MO" reference=%s batch=%s start="%s" quantity="%s" status="%s">\n ' % (
2481
+ yield '<operationplan type="MO" reference=%s batch=%s %s="%s" quantity="%s" status="%s">\n ' % (
2475
2482
quoteattr (i .name ),
2476
2483
quoteattr (batch ),
2477
- startdate ,
2484
+ (
2485
+ "start" # Option 1: compute MO end date based on the start date
2486
+ if self .manage_work_orders or not enddate
2487
+ else "end" # Option 2: compute MO start date based on the end date
2488
+ ),
2489
+ (startdate if self .manage_work_orders or not enddate else enddate ),
2478
2490
qty ,
2479
- "approved" , # In the "approved" status, frepple can still reschedule the MO in function of material and capacity
2480
- # "confirmed", # In the "confirmed" status, frepple sees the MO as frozen and unchangeable
2481
- # "approved" if i["status"] == "confirmed" else "confirmed", # In-progress can't be rescheduled in frepple, but confirmed MOs
2491
+ # In the "approved" status, frepple can still reschedule the MO in function of material and capacity
2492
+ # In the "confirmed" status, frepple sees the MO as frozen and unchangeable
2493
+ (
2494
+ "approved"
2495
+ if self .manage_work_orders or i .state in ("confirmed" , "draft" )
2496
+ else "confirmed"
2497
+ ),
2482
2498
)
2483
- # Option 2: compute MO start date based on the end date
2484
- # yield '<operationplan type="MO" reference=%s end="%s" quantity="%s" status="%s"><operation name=%s/><flowplans>\n' % (
2485
- # quoteattr(i["name"]),
2486
- # enddate,
2487
- # qty,
2488
- # # "approved", # In the "approved" status, frepple can still reschedule the MO in function of material and capacity
2489
- # "confirmed", # In the "confirmed" status, frepple sees the MO as frozen and unchangeable
2490
- # quoteattr(operation),
2491
- # )
2492
-
2493
- # Collect work order info
2494
- if self .manage_work_orders :
2495
- wo_list = i .workorder_ids
2496
- else :
2497
- wo_list = []
2498
2499
2499
2500
# Collect move info
2500
2501
if i .move_raw_ids :
2501
2502
mv_list = i .move_raw_ids
2502
2503
else :
2503
2504
mv_list = []
2504
2505
2505
- if not wo_list :
2506
- # There are no workorders on the manufacturing order
2506
+ if not self . manage_work_orders or not getattr ( i , "workorder_ids" , None ) :
2507
+ # There are no workorders on the manufacturing order (or we don't want to see them in frepple)
2507
2508
yield '<operation name=%s xsi:type="operation_fixed_time" priority="0"><location name=%s/><item name=%s/><flows>' % (
2508
2509
quoteattr (operation ),
2509
2510
quoteattr (location ),
@@ -2543,7 +2544,37 @@ def export_manufacturingorders(self):
2543
2544
yield '<flow xsi:type="flow_end" quantity="1"><item name=%s/></flow>\n ' % (
2544
2545
quoteattr (item ["name" ]),
2545
2546
)
2546
- yield "</flows></operation></operationplan>"
2547
+ yield "</flows>"
2548
+ # Pick up work center loading of all work orders
2549
+ loads = {}
2550
+ for wo in getattr (i , "workorder_ids" , []):
2551
+ # Get remaining duration of the WO
2552
+ time_left = wo .duration_expected - wo .duration_unit
2553
+ if wo .is_user_working and wo .time_ids :
2554
+ # The WO is currently being worked on
2555
+ for tm in wo .time_ids :
2556
+ if tm .date_start and not tm .date_end :
2557
+ time_left -= round (
2558
+ (now - tm .date_start ).total_seconds () / 60
2559
+ )
2560
+ if (
2561
+ time_left > 0
2562
+ and wo .workcenter_id .id in self .map_workcenters
2563
+ and wo .state not in ("done" , "cancel" )
2564
+ ):
2565
+ loads [self .map_workcenters [wo .workcenter_id .id ]] = (
2566
+ loads .get (self .map_workcenters [wo .workcenter_id .id ], 0 )
2567
+ + time_left
2568
+ )
2569
+ if loads :
2570
+ yield "<loads>"
2571
+ for r , q in loads .items ():
2572
+ yield '<load quantity_fixed="%s" quantity="0"><resource name=%s/></load>' % (
2573
+ q ,
2574
+ quoteattr (r ),
2575
+ )
2576
+ yield "</loads>"
2577
+ yield "</operation></operationplan>"
2547
2578
else :
2548
2579
# Define an operation for the MO
2549
2580
yield '<operation name=%s xsi:type="operation_routing" priority="0"><item name=%s/><location name=%s/><suboperations>' % (
@@ -2554,7 +2585,7 @@ def export_manufacturingorders(self):
2554
2585
# Define operations for each WO
2555
2586
idx = 10
2556
2587
first_wo = True
2557
- for wo in wo_list :
2588
+ for wo in i . workorder_ids :
2558
2589
suboperation = wo .display_name
2559
2590
if len (suboperation ) > 300 :
2560
2591
suboperation = suboperation [0 :300 ]
@@ -2679,7 +2710,7 @@ def export_manufacturingorders(self):
2679
2710
2680
2711
# Create operationplans for each WO, starting with the last one
2681
2712
idx = 0
2682
- for wo in reversed (wo_list ):
2713
+ for wo in reversed (i . workorder_ids ):
2683
2714
idx += 1.0
2684
2715
suboperation = wo .display_name
2685
2716
if len (suboperation ) > 300 :
0 commit comments