diff --git a/frepple/controllers/inbound.py b/frepple/controllers/inbound.py index f6e34cc8..b05887d1 100644 --- a/frepple/controllers/inbound.py +++ b/frepple/controllers/inbound.py @@ -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"] @@ -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"] @@ -527,31 +531,56 @@ 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._compute_workorder_ids() - # mo.action_confirm() # confirm MO - # mo._plan_workorders() # plan MO - # mo.action_assign() # reserve material - + # Process the workorder information we received if wo_data: for wo in mo.workorder_ids: