diff options
| author | William Henrotin <whe@odoo.com> | 2020-04-27 11:56:02 +0200 |
|---|---|---|
| committer | Simon Lejeune <sle@openerp.com> | 2020-06-15 16:59:41 +0200 |
| commit | 0e2765f5fd0ca0079f1f024ec3a1448b6d2ea3db (patch) | |
| tree | 90ea03d1aca1bf87a080775e7db07977b645c5cc /addons/mrp_subcontracting/models/stock_picking.py | |
| parent | 1b6421285c6bc4c61be3242cea30c2813251cbc7 (diff) | |
[REF] mrp: no more produce wizard
Use a view similar as the pickings one.
task-2241471
Diffstat (limited to 'addons/mrp_subcontracting/models/stock_picking.py')
| -rw-r--r-- | addons/mrp_subcontracting/models/stock_picking.py | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/addons/mrp_subcontracting/models/stock_picking.py b/addons/mrp_subcontracting/models/stock_picking.py index 29c44aec51b..0ab1655a6dc 100644 --- a/addons/mrp_subcontracting/models/stock_picking.py +++ b/addons/mrp_subcontracting/models/stock_picking.py @@ -4,6 +4,7 @@ from datetime import timedelta from odoo import api, fields, models +from odoo.tools import float_is_zero class StockPicking(models.Model): @@ -43,7 +44,9 @@ class StockPicking(models.Model): for move in picking.move_lines: if not move.is_subcontract: continue - production = move.move_orig_ids.production_id + production = move.move_orig_ids.production_id.filtered(lambda p: p.state not in ('done', 'cancel')) + if len(production) > 1: + production = production[-1] if move._has_tracked_subcontract_components(): move.move_orig_ids.filtered(lambda m: m.state not in ('done', 'cancel')).move_line_ids.unlink() move_finished_ids = move.move_orig_ids.filtered(lambda m: m.state not in ('done', 'cancel')) @@ -58,16 +61,25 @@ class StockPicking(models.Model): 'location_dest_id': move_finished_ids.location_dest_id.id, }) else: - for move_line in move.move_line_ids: - 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, - 'finished_lot_id': move_line.lot_id.id, - 'consumption': 'strict', - }) - produce._generate_produce_lines() - produce._record_production() + if not move.move_line_ids.lot_id: + qty_done_production_uom = move.product_uom._compute_quantity(move.quantity_done, production.product_uom_id) + production.qty_producing += qty_done_production_uom + for move in (production.move_raw_ids | production.move_finished_ids.filtered(lambda m: m.product_id != production.product_id)): + if move.state in ('done', 'cancel'): + continue + if float_is_zero(move.product_uom_qty, precision_rounding=move.product_uom.rounding): + continue + new_qty = production.product_uom_id._compute_quantity( + (production.qty_producing - production.qty_produced) * move.unit_factor, production.product_uom_id, + rounding_method='HALF-UP') + move.move_line_ids.filtered(lambda ml: ml.state not in ('done', 'cancel')).qty_done = 0 + vals = move._set_quantity_done_prepare_vals(new_qty) + if vals['to_create']: + for res in vals['to_create']: + move.move_line_ids.create(res) + if vals['to_write']: + for move_line, res in vals['to_write']: + move_line.write(res) productions |= production for subcontracted_production in productions: if subcontracted_production.state == 'progress': |
