[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.
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user