Skip to content

Commit f28d582

Browse files
authored
Merge pull request #489 from frePPLe/17.0
Syncing from upstream frePPLe/odoo (17.0)
2 parents 6557f73 + 44988be commit f28d582

File tree

1 file changed

+63
-32
lines changed

1 file changed

+63
-32
lines changed

frepple/controllers/outbound.py

Lines changed: 63 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,20 +1478,20 @@ def export_boms(self):
14781478
quoteattr(location),
14791479
)
14801480
else:
1481-
duration_per = (i["produce_delay"] or 0) + (
1481+
duration = (i["produce_delay"] or 0) + (
14821482
i["days_to_prepare_mo"] or 0
14831483
)
14841484

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" % (
14861486
quoteattr(operation),
14871487
(
14881488
("description=%s " % quoteattr(i["code"]))
14891489
if i["code"]
14901490
else ""
14911491
),
14921492
(
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
14951495
else "P0D"
14961496
),
14971497
self.manufacturing_lead,
@@ -2060,7 +2060,12 @@ def getReservedQuantity(stock_move_id):
20602060
),
20612061
due,
20622062
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+
),
20642069
"open" if qty - reserved_quantity > 0 else "closed",
20652070
quoteattr(product["name"]),
20662071
quoteattr(customer),
@@ -2448,9 +2453,12 @@ def export_manufacturingorders(self):
24482453
startdate = self.formatDateTime(
24492454
i.date_start if i.date_start else i.date_planned_start
24502455
)
2451-
# enddate = self.formatDateTime(i.date_planned_finished)
24522456
except Exception:
24532457
continue
2458+
try:
2459+
enddate = self.formatDateTime(i.date_finished)
2460+
except Exception:
2461+
enddate = None
24542462
qty = self.convert_qty_uom(
24552463
i.qty_producing if i.qty_producing else i.product_qty,
24562464
i.product_uom_id.id,
@@ -2470,40 +2478,33 @@ def export_manufacturingorders(self):
24702478
batch = mto_mo[0].display_name if mto_mo else i.name
24712479

24722480
# 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' % (
24752482
quoteattr(i.name),
24762483
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),
24782490
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+
),
24822498
)
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 = []
24982499

24992500
# Collect move info
25002501
if i.move_raw_ids:
25012502
mv_list = i.move_raw_ids
25022503
else:
25032504
mv_list = []
25042505

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)
25072508
yield '<operation name=%s xsi:type="operation_fixed_time" priority="0"><location name=%s/><item name=%s/><flows>' % (
25082509
quoteattr(operation),
25092510
quoteattr(location),
@@ -2543,7 +2544,37 @@ def export_manufacturingorders(self):
25432544
yield '<flow xsi:type="flow_end" quantity="1"><item name=%s/></flow>\n' % (
25442545
quoteattr(item["name"]),
25452546
)
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>"
25472578
else:
25482579
# Define an operation for the MO
25492580
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):
25542585
# Define operations for each WO
25552586
idx = 10
25562587
first_wo = True
2557-
for wo in wo_list:
2588+
for wo in i.workorder_ids:
25582589
suboperation = wo.display_name
25592590
if len(suboperation) > 300:
25602591
suboperation = suboperation[0:300]
@@ -2679,7 +2710,7 @@ def export_manufacturingorders(self):
26792710

26802711
# Create operationplans for each WO, starting with the last one
26812712
idx = 0
2682-
for wo in reversed(wo_list):
2713+
for wo in reversed(i.workorder_ids):
26832714
idx += 1.0
26842715
suboperation = wo.display_name
26852716
if len(suboperation) > 300:

0 commit comments

Comments
 (0)