Skip to content

Commit 8ce5926

Browse files
committed
[FIX] mrp: mass produce should fill qty_done
Usecase: - Create a BoM with a product tracked by SN - Create a MO with qty 5 - Mass produce - Generate -> All the `stock.move.line` in the move_raw_ids don't have the qty done prefilled. The purpose of the feature is to create and validate a lot of MO at once. Which is impossible if you have to fill all the quantity manualy. The choice of a new kwargs that directly set the qty_done is justified by the performance. -> For On a BoM with 10 components for a final product. For 1000 finished product with SN - If we do a loop on each `stock.move.line` to set qty_done as the reserved quantity. It goes from 40s to 135s - With the kwargs. It remaines 40s closes odoo#82996 Signed-off-by: William Henrotin (whe) <whe@odoo.com>
1 parent 8ec7b92 commit 8ce5926

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

addons/mrp/models/mrp_production.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@ def _generate_backorder_productions(self, close_mo=True):
15251525
wo.qty_producing = wo.qty_remaining
15261526
return backorders
15271527

1528-
def _split_productions(self, amounts=False, cancel_remaning_qty=False):
1528+
def _split_productions(self, amounts=False, cancel_remaning_qty=False, set_consumed_qty=False):
15291529
""" Splits productions into productions smaller quantities to produce, i.e. creates
15301530
its backorders.
15311531
:param dict amounts: a dict with a production as key and a list value containing
@@ -1650,12 +1650,17 @@ def _default_amounts(production):
16501650
taken_qty_uom = product_uom._compute_quantity(taken_qty, move_line.product_uom_id)
16511651
if move == initial_move:
16521652
move_line.with_context(bypass_reservation_update=True).product_uom_qty = taken_qty_uom
1653+
if set_consumed_qty:
1654+
move_line.qty_done = taken_qty_uom
16531655
elif not float_is_zero(taken_qty_uom, precision_rounding=move_line.product_uom_id.rounding):
1654-
move_lines_vals.append(dict(
1656+
new_ml_vals = dict(
16551657
ml_vals,
16561658
product_uom_qty=taken_qty_uom,
16571659
move_id=move.id
1658-
))
1660+
)
1661+
if set_consumed_qty:
1662+
new_ml_vals['qty_done'] = taken_qty_uom
1663+
move_lines_vals.append(new_ml_vals)
16591664
quantity -= taken_qty
16601665
move_qty_to_reserve -= taken_qty
16611666

addons/mrp/wizard/stock_assign_serial_numbers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ def _onchange_serial_numbers(self):
5757
self.produced_qty = len(serial_numbers)
5858
self.show_apply = self.produced_qty == self.expected_qty
5959
self.show_backorders = self.produced_qty > 0 and self.produced_qty < self.expected_qty
60-
60+
6161
def _assign_serial_numbers(self, cancel_remaining_quantity=False):
6262
serial_numbers = self._get_serial_numbers()
6363
productions = self.production_id._split_productions(
64-
{self.production_id: [1] * len(serial_numbers)}, cancel_remaining_quantity)
64+
{self.production_id: [1] * len(serial_numbers)}, cancel_remaining_quantity, set_consumed_qty=True)
6565
production_lots_vals = []
6666
for serial_name in serial_numbers:
6767
production_lots_vals.append({
@@ -76,6 +76,10 @@ def _assign_serial_numbers(self, cancel_remaining_quantity=False):
7676
for workorder in production.workorder_ids:
7777
workorder.qty_produced = workorder.qty_producing
7878

79+
if productions and len(production_lots) < len(productions):
80+
productions[-1].move_raw_ids.move_line_ids.write({'qty_done': 0})
81+
productions[-1].state = "confirmed"
82+
7983
def apply(self):
8084
self._assign_serial_numbers()
8185

0 commit comments

Comments
 (0)