Skip to content

Commit

Permalink
[FIX] mrp, sale_mrp: _run_pull creates many pickings
Browse files Browse the repository at this point in the history
The steps to reproduce:
- Go to a warehouse. Under the technical information tab, change the field sam_loc_id from "WH/Post-Production" to "WH/Stock".
- Create a sales order with 2 different products and confirm it.
- 2 pickings will be created with different group_id MO/XXXX instead of a single picking.

After this commit we only check the sam_loc_id if we are in 3 steps manufacturing.

OPW-3871886

closes odoo#164221

X-original-commit: f9125dd
Signed-off-by: Quentin Wolfs (quwo) <quwo@odoo.com>
Signed-off-by: Pedro Nogueira (pno) <pno@odoo.com>
  • Loading branch information
pno-odoo committed May 3, 2024
1 parent 6f3ba4a commit ee7e316
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
13 changes: 7 additions & 6 deletions addons/mrp/models/stock_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,17 @@ def _run_pull(self, procurements):
warehouse_id = rule.warehouse_id
if not warehouse_id:
warehouse_id = rule.location_dest_id.warehouse_id
if rule.picking_type_id == warehouse_id.sam_type_id or (warehouse_id.sam_loc_id and warehouse_id.sam_loc_id.parent_path in rule.location_src_id.parent_path):
manu_rule = rule.route_id.rule_ids.filtered(lambda r: r.action == 'manufacture' and r.warehouse_id == warehouse_id)
if warehouse_id.manufacture_steps != 'pbm_sam' or not manu_rule:
continue
if rule.picking_type_id == warehouse_id.sam_type_id or (
warehouse_id.sam_loc_id and warehouse_id.sam_loc_id.parent_path in rule.location_src_id.parent_path
):
if float_compare(procurement.product_qty, 0, precision_rounding=procurement.product_uom.rounding) < 0:
procurement.values['group_id'] = procurement.values['group_id'].stock_move_ids.filtered(
lambda m: m.state not in ['done', 'cancel']).move_orig_ids.group_id[:1]
continue
manu_rule = rule.route_id.rule_ids.filtered(lambda r: r.action == 'manufacture' and r.warehouse_id == warehouse_id)
if manu_rule:
manu_type_id = manu_rule[0].picking_type_id
else:
manu_type_id = warehouse_id.manu_type_id
manu_type_id = manu_rule[0].picking_type_id
if manu_type_id:
name = manu_type_id.sequence_id.next_by_id()
else:
Expand Down
32 changes: 32 additions & 0 deletions addons/sale_mrp/tests/test_sale_mrp_procurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from odoo.tests.common import TransactionCase, Form
from odoo.tools import mute_logger
from odoo import Command


class TestSaleMrpProcurement(TransactionCase):
Expand Down Expand Up @@ -356,3 +357,34 @@ def test_so_reordering_rule_02(self):
self.assertEqual(so_2.state, 'sale')
self.assertEqual(mo.product_uom_id, uom_gram)
self.assertEqual(mo.product_qty, 1020)

def test_sale_mrp_avoid_multiple_pickings(self):
"""
Test sale of multiple products. Avoid multiple pickings being
generated when we are not in 3 steps manufacturing.
"""

warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1)
warehouse.sam_loc_id = warehouse.lot_stock_id

so = self.env['sale.order'].create({
'partner_id': self.env['res.partner'].create({'name': 'My Partner'}).id,
'order_line': [
Command.create({
'name': 'sol_p1',
'product_id': self.env['product.product'].create({'name': 'p1'}).id,
'product_uom_qty': 1,
'product_uom': self.env.ref('uom.product_uom_unit').id,
}),
Command.create({
'name': 'sol_p2',
'product_id': self.env['product.product'].create({'name': 'p2'}).id,
'product_uom_qty': 1,
'product_uom': self.env.ref('uom.product_uom_unit').id,
}),
],
})

so.action_confirm()
self.assertEqual(len(so.picking_ids), 1)
self.assertEqual(so.picking_ids.picking_type_id, warehouse.out_type_id)

0 comments on commit ee7e316

Please sign in to comment.