From 45a66e4b90e20ddbca145f616bcc3020bcd43c3c Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Tue, 4 Aug 2020 14:42:16 +0200 Subject: [PATCH] [FIX] mrp_subcontracting: Avoid singleton error fetching production order On v12 and with chained moves coming from sales, procurement, etc, move_orig_ids contains that full chain, so we get a singleton error. But as we want the subcontracting production, using mapped, we get that single record, so we apply this solution everywhere where it's needed. --- mrp_subcontracting/__manifest__.py | 2 +- mrp_subcontracting/models/stock_move.py | 12 ++++++------ mrp_subcontracting/models/stock_picking.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mrp_subcontracting/__manifest__.py b/mrp_subcontracting/__manifest__.py index 0fdb69d4b..c0f9e0a16 100644 --- a/mrp_subcontracting/__manifest__.py +++ b/mrp_subcontracting/__manifest__.py @@ -5,7 +5,7 @@ { 'name': "Subcontract Productions", - 'version': '12.0.1.0.0', + 'version': '12.0.1.0.1', "author": "Odoo S.A., Tecnativa, Odoo Community Association (OCA)", 'website': 'https://github.com/OCA/manufacture', 'category': 'Manufacturing Orders & BOMs', diff --git a/mrp_subcontracting/models/stock_move.py b/mrp_subcontracting/models/stock_move.py index 072db4a16..c6581b61c 100644 --- a/mrp_subcontracting/models/stock_move.py +++ b/mrp_subcontracting/models/stock_move.py @@ -72,7 +72,7 @@ class StockMove(models.Model): self.ensure_one() if self.is_subcontract: rounding = self.product_uom.rounding - production = self.move_orig_ids.production_id + production = self.move_orig_ids.mapped("production_id") if self._has_tracked_subcontract_components() and\ float_compare(production.qty_produced, production.product_uom_qty, @@ -93,7 +93,7 @@ class StockMove(models.Model): def action_show_subcontract_details(self): """ Display moves raw for subcontracted product self. """ - moves = self.move_orig_ids.production_id.move_raw_ids + moves = self.move_orig_ids.mapped("production_id").move_raw_ids tree_view = self.env.ref( 'mrp_subcontracting.mrp_subcontracting_move_tree_view') form_view = self.env.ref( @@ -110,7 +110,7 @@ class StockMove(models.Model): def _action_cancel(self): for move in self: if move.is_subcontract: - move.move_orig_ids.production_id.action_cancel() + move.move_orig_ids.mapped("production_id").action_cancel() return super()._action_cancel() def _action_confirm(self, merge=True, merge_into=False): @@ -119,7 +119,7 @@ class StockMove(models.Model): if move.location_id.usage != 'supplier' \ or move.location_dest_id.usage == 'supplier': continue - if move.move_orig_ids.production_id: + if move.move_orig_ids.mapped("production_id"): continue bom = move._get_subcontract_bom() if not bom: @@ -163,7 +163,7 @@ class StockMove(models.Model): def _action_record_components(self): action = self.env.ref('mrp.act_mrp_product_produce').read()[0] action['context'] = dict( - active_id=self.move_orig_ids.production_id.id, + active_id=self.move_orig_ids.mapped("production_id").id, default_subcontract_move_id=self.id ) return action @@ -227,7 +227,7 @@ operations.""") % ('\n'.join(overprocessed_moves.mapped( def _update_subcontract_order_qty(self, quantity): for move in self: quantity_change = quantity - move.product_uom_qty - production = move.move_orig_ids.production_id + production = move.move_orig_ids.mapped("production_id") if production: self.env['change.production.qty'].create({ 'mo_id': production.id, diff --git a/mrp_subcontracting/models/stock_picking.py b/mrp_subcontracting/models/stock_picking.py index 589ae708c..aad44c69d 100644 --- a/mrp_subcontracting/models/stock_picking.py +++ b/mrp_subcontracting/models/stock_picking.py @@ -109,7 +109,7 @@ class StockPicking(models.Model): for move in self.move_lines: if not move._has_tracked_subcontract_components(): continue - production = move.move_orig_ids.production_id + production = move.move_orig_ids.mapped("production_id") if not production or production.state in ('done', 'to_close'): continue return move._action_record_components()