Skip to content

Commit

Permalink
Merge pull request #407 from frePPLe/17.0
Browse files Browse the repository at this point in the history
Syncing from upstream frePPLe/odoo (17.0)
  • Loading branch information
bt-admin authored Feb 13, 2024
2 parents 45474d6 + 42d048c commit 6b00b29
Show file tree
Hide file tree
Showing 4 changed files with 596 additions and 297 deletions.
1 change: 1 addition & 0 deletions frepple/controllers/frepplexml.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def xml(self, **kwargs):
== "true",
version=version,
delta=float(kwargs.get("delta", 999)),
language=language,
)
# last empty double quote is to let python understand frepple is a folder.
xml_folder = os.path.join(str(Path.home()), "logs", "frepple", "")
Expand Down
105 changes: 73 additions & 32 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 @@ -182,7 +193,7 @@ def run(self):
ordertype = elem.get("ordertype")
if ordertype == "PO":
# Create purchase order
supplier_id = int(elem.get("supplier").split(" ", 1)[0])
supplier_id = int(elem.get("supplier").rsplit(" ", 1)[-1])
quantity = elem.get("quantity")
date_planned = elem.get("end")
if date_planned:
Expand All @@ -198,15 +209,16 @@ def run(self):
po = proc_order.create(
{
"company_id": self.company.id,
"partner_id": int(
elem.get("supplier").split(" ", 1)[0]
),
"partner_id": supplier_id,
# TODO Odoo has no place to store the location and criticality
# int(elem.get('location_id')),
# elem.get('criticality'),
"origin": "frePPLe",
}
)
po.payment_term_id = (
po.partner_id.property_supplier_payment_term_id.id
)
supplier_reference[supplier_id] = {
"id": po.id,
"min_planned": date_planned,
Expand Down Expand Up @@ -344,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 @@ -410,26 +422,55 @@ def run(self):
# Can't filter on the computed display_name field in the search...
continue
if wo:
wo.write(
{
"date_start": self.timezone.localize(
datetime.strptime(
elem.get("start"),
"%Y-%m-%d %H:%M:%S",
)
data = {
"date_start": self.timezone.localize(
datetime.strptime(
elem.get("start"),
"%Y-%m-%d %H:%M:%S",
)
)
.astimezone(UTC)
.replace(tzinfo=None),
"date_finished": self.timezone.localize(
datetime.strptime(
elem.get("end"),
"%Y-%m-%d %H:%M:%S",
)
.astimezone(UTC)
.replace(tzinfo=None),
"date_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
Loading

0 comments on commit 6b00b29

Please sign in to comment.