From 40803fcfa23f15768c708612c338c09d8d7439e9 Mon Sep 17 00:00:00 2001 From: Johan De Taeye Date: Tue, 7 Jan 2025 15:32:59 +0100 Subject: [PATCH] avoid creating MO on nonexisting boms and kit boms --- frepple/controllers/inbound.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/frepple/controllers/inbound.py b/frepple/controllers/inbound.py index 6554fa0..3565b7e 100644 --- a/frepple/controllers/inbound.py +++ b/frepple/controllers/inbound.py @@ -90,6 +90,7 @@ def run(self): stck_picking_type = self.env["stock.picking.type"].with_user( self.actual_user ) + bom_type = self.env["mrp.bom"].with_user(self.actual_user) stck_picking = self.env["stock.picking"].with_user(self.actual_user) stck_move = self.env["stock.move"].with_user(self.actual_user) stck_warehouse = self.env["stock.warehouse"].with_user(self.actual_user) @@ -706,6 +707,19 @@ def run(self): remark = "frePPLe - %s" % remark else: remark = "frePPLe" + bom_id = int(elem.get("operation").rsplit(" ", 1)[1]) + try: + bom = bom_type.search( + [ + ("id", "=", bom_id), + ], + limit=1, + ) + if not bom and bom.type == "phantom": + # Avoid creating MO on a) non-existing BOMs and b) phantom/kit BOMs + continue + except Exception: + pass mo = mfg_order.with_context(context).create( { "product_qty": elem.get("quantity"), @@ -715,9 +729,7 @@ def run(self): "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] - ), + "bom_id": bom_id, "qty_producing": 0.00, # TODO no place to store the criticality # elem.get('criticality'),