Skip to content

Commit

Permalink
Merge pull request #411 from frePPLe/15.0
Browse files Browse the repository at this point in the history
Syncing from upstream frePPLe/odoo (15.0)
  • Loading branch information
bt-admin authored Feb 16, 2024
2 parents 1791f4f + 53020fd commit 09eeb33
Showing 1 changed file with 111 additions and 37 deletions.
148 changes: 111 additions & 37 deletions frepple/controllers/inbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def run(self):
stck_move = self.env["stock.move"].with_user(self.actual_user)
stck_warehouse = self.env["stock.warehouse"].with_user(self.actual_user)
stck_location = self.env["stock.location"].with_user(self.actual_user)
change_product_qty = self.env["change.production.qty"].with_user(
self.actual_user
)
else:
proc_order = self.env["purchase.order"]
proc_orderline = self.env["purchase.order.line"]
Expand All @@ -101,6 +104,7 @@ def run(self):
stck_move = self.env["stock.move"]
stck_warehouse = self.env["stock.warehouse"]
stck_location = self.env["stock.location"]
change_product_qty = self.env["change.production.qty"]
if self.mode == 1:
# Cancel previous draft purchase quotations
m = self.env["purchase.order"]
Expand Down Expand Up @@ -141,7 +145,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 @@ -436,26 +451,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 Expand Up @@ -487,29 +531,59 @@ def run(self):
"ignore_secondary_workcenters": True,
}
)
if (elem.get("status") or "proposed") == "proposed":
# MO creation
mo = mfg_order.with_context(context).create(
{
"product_qty": elem.get("quantity"),
"date_planned_start": elem.get("start"),
"date_planned_finished": elem.get("end"),
"product_id": int(item_id),
"company_id": self.company.id,
"product_uom_id": int(uom_id),
"picking_type_id": picking.id,
"bom_id": int(
elem.get("operation").rsplit(" ", 1)[1]
),
"qty_producing": 0.00,
# TODO no place to store the criticality
# elem.get('criticality'),
"origin": "frePPLe",
}
)
mo_references[elem.get("reference")] = mo
mo._onchange_product_qty()
mo._onchange_workorder_ids()
mo._onchange_move_raw()
mo._create_update_move_finished()
else:
# MO update
mo = mfg_order.with_context(context).search(
[("name", "=", elem.get("reference"))]
)[0]
if mo:
new_qty = float(elem.get("quantity"))
if mo.product_qty != new_qty:
cpq = change_product_qty.create(
{
"mo_id": mo.id,
"product_qty": new_qty,
}
)
cpq.change_prod_qty()
mo.write(
{
"date_planned_start": elem.get("start"),
"date_planned_finished": elem.get("end"),
"origin": "frePPLe",
}
)
mo_references[elem.get("reference")] = mo

mo = mfg_order.with_context(context).create(
{
"product_qty": elem.get("quantity"),
"date_planned_start": elem.get("start"),
"date_planned_finished": elem.get("end"),
"product_id": int(item_id),
"company_id": self.company.id,
"product_uom_id": int(uom_id),
"picking_type_id": picking.id,
"bom_id": int(elem.get("operation").rsplit(" ", 1)[1]),
"qty_producing": 0.00,
# TODO no place to store the criticality
# elem.get('criticality'),
"origin": "frePPLe",
}
)
# Remember odoo name for the MO reference passed by frepple.
# This mapping is later used when importing WO.
mo_references[elem.get("reference")] = mo
mo._onchange_workorder_ids()
mo._onchange_move_raw()
mo._create_update_move_finished()
# if mo:

# mo.action_confirm() # confirm MO
# mo._plan_workorders() # plan MO
# mo.action_assign() # reserve material
Expand Down

0 comments on commit 09eeb33

Please sign in to comment.