Skip to content

Commit

Permalink
Merge pull request #404 from frePPLe/16.0
Browse files Browse the repository at this point in the history
Syncing from upstream frePPLe/odoo (16.0)
  • Loading branch information
bt-admin authored Feb 11, 2024
2 parents 3d44e46 + 0ea0aa5 commit 9896981
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 57 deletions.
96 changes: 68 additions & 28 deletions frepple/controllers/inbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,18 @@ def run(self):
mo_references = {}
wo_data = []

# Workcenters of a workorder to update
resources = []

for event, elem in iterparse(self.datafile, events=("start", "end")):
if (
elem.tag == "operationplan"
and elem.get("ordertype") == "WO"
and event == "start"
):
resources = []
elif elem.tag == "resource" and event == "end":
resources.append(elem.get("id"))
if event == "start" and elem.tag == "workorder" and elem.get("operation"):
try:
wo = {
Expand Down Expand Up @@ -345,17 +356,17 @@ def run(self):
if not hasattr(self, "stock_picking_dict"):
self.stock_picking_dict = {}
if not self.stock_picking_dict.get((origin, destination)):
self.stock_picking_dict[
(origin, destination)
] = stck_picking.create(
{
"picking_type_id": picking_type_id,
"scheduled_date": date_shipping,
"location_id": location_id["id"],
"location_dest_id": location_dest_id["id"],
"move_type": "direct",
"origin": "frePPLe",
}
self.stock_picking_dict[(origin, destination)] = (
stck_picking.create(
{
"picking_type_id": picking_type_id,
"scheduled_date": date_shipping,
"location_id": location_id["id"],
"location_dest_id": location_dest_id["id"],
"move_type": "direct",
"origin": "frePPLe",
}
)
)
sp = self.stock_picking_dict.get((origin, destination))
if not hasattr(self, "sm_dict"):
Expand Down Expand Up @@ -411,26 +422,55 @@ def run(self):
# Can't filter on the computed display_name field in the search...
continue
if wo:
wo.write(
{
"date_planned_start": self.timezone.localize(
datetime.strptime(
elem.get("start"),
"%Y-%m-%d %H:%M:%S",
)
data = {
"date_planned_start": self.timezone.localize(
datetime.strptime(
elem.get("start"),
"%Y-%m-%d %H:%M:%S",
)
)
.astimezone(UTC)
.replace(tzinfo=None),
"date_planned_finished": self.timezone.localize(
datetime.strptime(
elem.get("end"),
"%Y-%m-%d %H:%M:%S",
)
.astimezone(UTC)
.replace(tzinfo=None),
"date_planned_finished": self.timezone.localize(
datetime.strptime(
elem.get("end"),
"%Y-%m-%d %H:%M:%S",
)
.astimezone(UTC)
.replace(tzinfo=None),
}
for res_id in resources:
res = mfg_workcenter.search(
[("id", "=", res_id)]
)
if not res:
continue
if (
not wo.operation_id # No operation defined
or (
wo.operation_id.workcenter_id
== res # Same workcenter
or (
# New member of a pool
wo.operation_id.workcenter_id
and wo.operation_id.workcenter_id
== res.owner
)
)
.astimezone(UTC)
.replace(tzinfo=None),
}
)
):
# Change primary work center
data["workcenter_id"] = res.id
else:
# Check assigned secondary resources
for sec in wo.secondary_workcenters:
if sec.workcenter_id.owner == res:
break
if sec.workcenter_id.owner == res.owner:
# Change secondary work center
sec.write({"workcenter_id": res.id})
break
wo.write(data)
break
else:
# Create manufacturing order
Expand Down
83 changes: 54 additions & 29 deletions frepple/controllers/outbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -2433,47 +2433,57 @@ def export_manufacturingorders(self):
yield "</flows>"
if (
wo.operation_id
and wo.workcenter_id
and wo.operation_id.workcenter_id
and wo.operation_id.workcenter_id.id in self.map_workcenters
and wo.workcenter_id.owner
and wo.workcenter_id.owner == wo.operation_id.workcenter_id
):
# Only send a load definition if the bom specifies a parent pool
yield "<loads><load><resource name=%s/></load></loads>" % quoteattr(
self.map_workcenters[wo.operation_id.workcenter_id.id]
)
elif (
wo["workcenter_id"]
and wo["workcenter_id"][0] in self.map_workcenters
wo.workcenter_id and wo.workcenter_id.id in self.map_workcenters
):
yield "<loads><load><resource name=%s/></load></loads>" % quoteattr(
self.map_workcenters[wo["workcenter_id"][0]]
self.map_workcenters[wo.workcenter_id.id]
)
if wo["secondary_workcenters"]:
yield "<loads>"
for secondary in self.generator.getData(
"mrp.workorder.secondary.workcenter",
ids=wo["secondary_workcenters"],
fields=["workcenter_id", "duration"],
):
if wo.operation_id:
for wo_sec in wo.secondary_workcenters:
if (
secondary["workcenter_id"]
and secondary["workcenter_id"][0]
in self.map_workcenters
and secondary["workcenter_id"][0]
!= wo["workcenter_id"][0]
not wo_sec.workcenter_id
or wo_sec.workcenter_id.id not in self.map_workcenters
or wo_sec.workcenter_id == wo.workcenter_id
):
yield '<load quantity="%f"><resource name=%s/></load>' % (
(
secondary["duration"] / wo["duration_expected"]
if secondary["duration"]
and wo["duration_expected"]
else 1
),
quoteattr(
self.map_workcenters[
secondary["workcenter_id"][0]
]
),
)
yield "</loads>"
continue
for sec in wo.operation_id.secondary_workcenter:
if (
wo_sec.workcenter_id.owner
and wo_sec.workcenter_id.owner == sec.workcenter_id
):
yield '<load quantity="%f" search=%s><resource name=%s/>%s</load>' % (
(
1
if not sec.duration
or wo.operation_id.time_cycle == 0
else sec.duration
/ wo.operation_idtime_cycle
),
quoteattr(sec.search_mode),
quoteattr(
self.map_workcenters[sec.workcenter_id.id]
),
(
(
"<skill name=%s/>"
% quoteattr(sec.skill.name)
)
if sec.skill
else ""
),
)
break
first_wo = False
yield "</operation></suboperation>"
yield "</suboperations></operation></operationplan>"
Expand Down Expand Up @@ -2534,6 +2544,21 @@ def export_manufacturingorders(self):
yield "<loadplans><loadplan><resource name=%s/></loadplan></loadplans>" % quoteattr(
self.map_workcenters[wo.workcenter_id.id]
)
if wo.secondary_workcenters:
yield "<loadplans>"
for secondary in wo.secondary_workcenters:
if (
secondary.workcenter_id
and secondary.workcenter_id.id in self.map_workcenters
and secondary.workcenter_id != wo.workcenter_id
):
yield "<loadplan><resource name=%s/></loadplan>" % (
quoteattr(
self.map_workcenters[secondary.workcenter_id.id]
),
)
yield "</loadplans>"

yield "</operationplan>\n"
yield "</operationplans>\n"

Expand Down

0 comments on commit 9896981

Please sign in to comment.