summaryrefslogtreecommitdiff
path: root/addons/mrp_subcontracting/wizard
diff options
context:
space:
mode:
authorWilliam Henrotin <whe@odoo.com>2020-04-27 11:56:02 +0200
committerSimon Lejeune <sle@openerp.com>2020-06-15 16:59:41 +0200
commit0e2765f5fd0ca0079f1f024ec3a1448b6d2ea3db (patch)
tree90ea03d1aca1bf87a080775e7db07977b645c5cc /addons/mrp_subcontracting/wizard
parent1b6421285c6bc4c61be3242cea30c2813251cbc7 (diff)
[REF] mrp: no more produce wizard
Use a view similar as the pickings one. task-2241471
Diffstat (limited to 'addons/mrp_subcontracting/wizard')
-rw-r--r--addons/mrp_subcontracting/wizard/mrp_product_produce.py80
1 files changed, 39 insertions, 41 deletions
diff --git a/addons/mrp_subcontracting/wizard/mrp_product_produce.py b/addons/mrp_subcontracting/wizard/mrp_product_produce.py
index ceb803858e0..0dd804ad9f4 100644
--- a/addons/mrp_subcontracting/wizard/mrp_product_produce.py
+++ b/addons/mrp_subcontracting/wizard/mrp_product_produce.py
@@ -2,42 +2,36 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
-from odoo.tools.float_utils import float_is_zero, float_compare
+from odoo.tools.float_utils import float_compare, float_is_zero
-class MrpProductProduce(models.TransientModel):
- _inherit = 'mrp.product.produce'
- subcontract_move_id = fields.Many2one('stock.move', 'stock move from the subcontract picking', check_company=True)
+class MrpProduction(models.Model):
+ _inherit = 'mrp.production'
- def continue_production(self):
- action = super(MrpProductProduce, self).continue_production()
- action['context'] = dict(action['context'], default_subcontract_move_id=self.subcontract_move_id.id)
- return action
+ def write(self, vals):
+ res = super().write(vals)
+ if self.env.context.get('subcontract_move_id'):
+ for production in self:
+ if production.state not in ('cancel', 'done') and \
+ ('lot_producing_id' in vals or 'qty_producing' in vals):
+ production._update_finished_move()
- def _generate_produce_lines(self):
- """ When the wizard is called in backend, the onchange that create the
- produce lines is not trigger. This method generate them and is used with
- _record_production to appropriately set the lot_produced_id and
- appropriately create raw stock move lines.
- """
- self.ensure_one()
- moves = (self.move_raw_ids | self.move_finished_ids).filtered(
- lambda move: move.state not in ('done', 'cancel')
- )
- for move in moves:
- qty_to_consume = self._prepare_component_quantity(move, self.qty_producing)
- line_values = self._generate_lines_values(move, qty_to_consume)
- self.env['mrp.product.produce.line'].create(line_values)
+ def _pre_button_mark_done(self):
+ if self.env.context.get('subcontract_move_id'):
+ return True
+ return super()._pre_button_mark_done()
def _update_finished_move(self):
""" After producing, set the move line on the subcontract picking. """
- res = super(MrpProductProduce, self)._update_finished_move()
- if self.subcontract_move_id:
+ subcontract_move_id = self.env.context.get('subcontract_move_id')
+ res = None
+ if subcontract_move_id:
+ subcontract_move_id = self.env['stock.move'].browse(subcontract_move_id)
quantity = self.qty_producing
- if self.finished_lot_id:
- move_lines = self.subcontract_move_id.move_line_ids.filtered(lambda ml: ml.lot_id == self.finished_lot_id or not ml.lot_id)
+ if self.lot_producing_id:
+ move_lines = subcontract_move_id.move_line_ids.filtered(lambda ml: ml.lot_id == self.lot_producing_id or not ml.lot_id)
else:
- move_lines = self.subcontract_move_id.move_line_ids.filtered(lambda ml: not ml.lot_id)
+ move_lines = subcontract_move_id.move_line_ids.filtered(lambda ml: not ml.lot_id)
# Update reservation and quantity done
for ml in move_lines:
rounding = ml.product_uom_id.rounding
@@ -52,16 +46,14 @@ class MrpProductProduce(models.TransientModel):
if float_compare(new_quantity_done, ml.product_uom_qty, precision_rounding=rounding) >= 0:
ml.write({
'qty_done': new_quantity_done,
- 'lot_id': self.finished_lot_id and self.finished_lot_id.id,
- 'lot_name': self.finished_lot_id and self.finished_lot_id.name,
+ 'lot_id': self.lot_producing_id and self.lot_producing_id.id,
})
else:
new_qty_reserved = ml.product_uom_qty - new_quantity_done
default = {
'product_uom_qty': new_quantity_done,
'qty_done': new_quantity_done,
- 'lot_id': self.finished_lot_id and self.finished_lot_id.id,
- 'lot_name': self.finished_lot_id and self.finished_lot_id.name,
+ 'lot_id': self.lot_producing_id and self.lot_producing_id.id,
}
ml.copy(default=default)
ml.with_context(bypass_reservation_update=True).write({
@@ -71,24 +63,30 @@ class MrpProductProduce(models.TransientModel):
if float_compare(quantity, 0, precision_rounding=self.product_uom_id.rounding) > 0:
self.env['stock.move.line'].create({
- 'move_id': self.subcontract_move_id.id,
- 'picking_id': self.subcontract_move_id.picking_id.id,
+ 'move_id': subcontract_move_id.id,
+ 'picking_id': subcontract_move_id.picking_id.id,
'product_id': self.product_id.id,
- 'location_id': self.subcontract_move_id.location_id.id,
- 'location_dest_id': self.subcontract_move_id.location_dest_id.id,
+ 'location_id': subcontract_move_id.location_id.id,
+ 'location_dest_id': subcontract_move_id.location_dest_id.id,
'product_uom_qty': 0,
'product_uom_id': self.product_uom_id.id,
'qty_done': quantity,
- 'lot_id': self.finished_lot_id and self.finished_lot_id.id,
- 'lot_name': self.finished_lot_id and self.finished_lot_id.name,
+ 'lot_id': self.lot_producing_id and self.lot_producing_id.id,
})
- if not self._get_todo(self.production_id):
- ml_reserved = self.subcontract_move_id.move_line_ids.filtered(lambda ml:
+ if not self._get_todo():
+ ml_reserved = subcontract_move_id.move_line_ids.filtered(lambda ml:
float_is_zero(ml.qty_done, precision_rounding=ml.product_uom_id.rounding) and
not float_is_zero(ml.product_uom_qty, precision_rounding=ml.product_uom_id.rounding))
ml_reserved.unlink()
- for ml in self.subcontract_move_id.move_line_ids:
+ for ml in subcontract_move_id.move_line_ids:
ml.product_uom_qty = ml.qty_done
- self.subcontract_move_id._recompute_state()
+ subcontract_move_id._recompute_state()
return res
+
+ def _get_todo(self):
+ """ This method will return remaining todo quantity of production. """
+ main_product_moves = self.move_finished_ids.filtered(lambda x: x.product_id.id == self.product_id.id)
+ todo_quantity = self.product_qty - sum(main_product_moves.mapped('quantity_done'))
+ todo_quantity = todo_quantity if (todo_quantity > 0) else 0
+ return todo_quantity