From be7858d5f5fd26e43b727a9cc4b6fdcbdf5389bc Mon Sep 17 00:00:00 2001 From: Lois Rilo Date: Mon, 29 May 2023 12:16:18 +0200 Subject: [PATCH] [IMP] mrp_component_operation: enhance extensibility of scrap vals aditionally some adjustments have been done: - create_date is a magic field, no need to include it in the vals. - production_id is the inverse name of mo_id.scrap_ids. --- .../readme/CONTRIBUTORS.rst | 1 + .../wizards/mrp_component_operate.py | 28 +++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/mrp_component_operation/readme/CONTRIBUTORS.rst b/mrp_component_operation/readme/CONTRIBUTORS.rst index fcd081018..163495e5c 100644 --- a/mrp_component_operation/readme/CONTRIBUTORS.rst +++ b/mrp_component_operation/readme/CONTRIBUTORS.rst @@ -1 +1,2 @@ * David Jiménez +* Lois Rilo diff --git a/mrp_component_operation/wizards/mrp_component_operate.py b/mrp_component_operation/wizards/mrp_component_operate.py index 14b022e10..efbf566f0 100644 --- a/mrp_component_operation/wizards/mrp_component_operate.py +++ b/mrp_component_operation/wizards/mrp_component_operate.py @@ -84,21 +84,21 @@ class MrpComponentOperate(models.Model): res = [] return res + def _create_scrap_vals(self): + return { + "origin": self.mo_id.name, + "product_id": self.product_id.id, + "lot_id": self.lot_id.id, + "scrap_qty": self.product_qty, + "product_uom_id": self.product_id.product_tmpl_id.uom_id.id, + "location_id": self.operation_id.source_location_id.id, + "scrap_location_id": self.operation_id.scrap_location_id.id, + "company_id": self.env.company.id, + "production_id": self.mo_id.id, + } + def _create_scrap(self): - scrap = self.env["stock.scrap"].create( - { - "origin": self.mo_id.name, - "product_id": self.product_id.id, - "lot_id": self.lot_id.id, - "scrap_qty": self.product_qty, - "product_uom_id": self.product_id.product_tmpl_id.uom_id.id, - "location_id": self.operation_id.source_location_id.id, - "scrap_location_id": self.operation_id.scrap_location_id.id, - "create_date": fields.Datetime.now(), - "company_id": self.env.company.id, - } - ) - self.mo_id.scrap_ids |= scrap + scrap = self.env["stock.scrap"].create(self._create_scrap_vals()) scrap.action_validate() return scrap