summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnold Moyaux <arm@odoo.com>2019-08-14 14:05:51 +0000
committerArnold Moyaux <arm@odoo.com>2019-08-19 15:03:59 +0000
commita3aeabd44d36dd735d4bfd78c65fc8f850578c60 (patch)
tree1789d82e22d3d25bbee05751a27586fae5f7cbef
parentd15137394153a912460f664653b359b3d2c17b53 (diff)
[FIX] mrp: do not base default on active_id
Since active_id do not works allows to use a context key that will not be modified magically.
-rw-r--r--addons/mrp/wizard/mrp_product_produce.py9
-rw-r--r--addons/mrp_subcontracting/models/stock_move.py16
-rw-r--r--addons/mrp_subcontracting/models/stock_picking.py12
3 files changed, 19 insertions, 18 deletions
diff --git a/addons/mrp/wizard/mrp_product_produce.py b/addons/mrp/wizard/mrp_product_produce.py
index 1c8c26fbd96..6cdde0f8ae4 100644
--- a/addons/mrp/wizard/mrp_product_produce.py
+++ b/addons/mrp/wizard/mrp_product_produce.py
@@ -16,8 +16,11 @@ class MrpProductProduce(models.TransientModel):
@api.model
def default_get(self, fields):
res = super(MrpProductProduce, self).default_get(fields)
- if self._context and self._context.get('active_id'):
- production = self.env['mrp.production'].browse(self._context['active_id'])
+ production = self.env['mrp.production']
+ production_id = self.env.context.get('default_production_id') or self.env.context.get('active_id')
+ if production_id:
+ production = self.env['mrp.production'].browse(production_id)
+ if production.exists():
serial_finished = (production.product_id.tracking == 'serial')
todo_uom = production.product_uom_id.id
todo_quantity = self._get_todo(production)
@@ -68,7 +71,7 @@ class MrpProductProduce(models.TransientModel):
self.ensure_one()
self._record_production()
action = self.production_id.open_produce_product()
- action['context'] = {'active_id': self.production_id.id}
+ action['context'] = {'default_production_id': self.production_id.id}
return action
def action_generate_serial(self):
diff --git a/addons/mrp_subcontracting/models/stock_move.py b/addons/mrp_subcontracting/models/stock_move.py
index 008275b1796..617c4684942 100644
--- a/addons/mrp_subcontracting/models/stock_move.py
+++ b/addons/mrp_subcontracting/models/stock_move.py
@@ -54,18 +54,12 @@ class StockMove(models.Model):
"""
self.ensure_one()
if self.is_subcontract:
- production = self.move_orig_ids.production_id
rounding = self.product_uom.rounding
production = self.move_orig_ids.production_id
if self._has_tracked_subcontract_components() and\
float_compare(production.qty_produced, production.product_uom_qty, precision_rounding=rounding) < 0 and\
float_compare(self.quantity_done, self.product_uom_qty, precision_rounding=rounding) < 0:
- action = self.env.ref('mrp.act_mrp_product_produce').read()[0]
- action['context'] = dict(
- active_id=production.id,
- default_subcontract_move_id=self.id
- )
- return action
+ return self._action_record_components()
action = super(StockMove, self).action_show_details()
if self.is_subcontract:
action['views'] = [(self.env.ref('stock.view_stock_move_operations').id, 'form')]
@@ -108,6 +102,14 @@ class StockMove(models.Model):
picking._subcontracted_produce(subcontract_details)
return super(StockMove, self)._action_confirm(merge=merge, merge_into=merge_into)
+ def _action_record_components(self):
+ action = self.env.ref('mrp.act_mrp_product_produce').read()[0]
+ action['context'] = dict(
+ default_production_id=self.move_orig_ids.production_id.id,
+ default_subcontract_move_id=self.id
+ )
+ return action
+
def _check_overprocessed_subcontract_qty(self):
""" If a subcontracted move use tracked components. Do not allow to add
quantity without the produce wizard. Instead update the initial demand
diff --git a/addons/mrp_subcontracting/models/stock_picking.py b/addons/mrp_subcontracting/models/stock_picking.py
index 6a16740a951..cd310f5ea3f 100644
--- a/addons/mrp_subcontracting/models/stock_picking.py
+++ b/addons/mrp_subcontracting/models/stock_picking.py
@@ -60,7 +60,7 @@ class StockPicking(models.Model):
})
else:
for move_line in move.move_line_ids:
- produce = self.env['mrp.product.produce'].create({
+ produce = self.env['mrp.product.produce'].with_context(default_production_id=production.id).create({
'production_id': production.id,
'qty_producing': move_line.qty_done,
'product_uom_id': move_line.product_uom_id.id,
@@ -83,16 +83,12 @@ class StockPicking(models.Model):
def action_record_components(self):
self.ensure_one()
for move in self.move_lines:
+ if not move._has_tracked_subcontract_components():
+ continue
production = move.move_orig_ids.production_id
if not production or production.state in ('done', 'to_close'):
continue
- action = self.env.ref('mrp.act_mrp_product_produce').read()[0]
- action['context'] = dict(
- self.env.context,
- active_id=production.id,
- default_subcontract_move_id=move.id
- )
- return action
+ return move._action_record_components()
# -------------------------------------------------------------------------
# Subcontract helpers