Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FW][FIX] mrp, sale_mrp: _run_pull creates many pickings #164325

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions addons/mrp/models/stock_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,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)