mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[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.
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user