From 66179e552bb419bd817af009ce0db7aadadf1247 Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Wed, 16 Feb 2022 12:15:06 +0000 Subject: [PATCH] [FIX] stock_picking_batch: new stock.move added to wave picking Usecase to reproduce: - Create a batch picking from a new location to customer - Put some `stock.move.line` in a wave - Validate the remaining of the initial `stock.picking` - Create a new `stock.move` with the same data and without `picking_id` Current behavior The stock.move is added to the existing wave. However the stock.move.line created could not match the current wave specification Expected behavior A new picking is created and it could be merge in the wave picking if wanted closes odoo/odoo#84875 X-original-commit: 4ea418ed1cceff4aee916cf791011a1dc67c77a1 Signed-off-by: Arnold Moyaux --- addons/stock_picking_batch/models/__init__.py | 1 + .../stock_picking_batch/models/stock_move.py | 14 +++++ .../tests/test_wave_picking.py | 52 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 addons/stock_picking_batch/models/stock_move.py diff --git a/addons/stock_picking_batch/models/__init__.py b/addons/stock_picking_batch/models/__init__.py index b3472b526c6..2b968a1faf4 100644 --- a/addons/stock_picking_batch/models/__init__.py +++ b/addons/stock_picking_batch/models/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from . import stock_move from . import stock_move_line from . import stock_picking from . import stock_picking_batch diff --git a/addons/stock_picking_batch/models/stock_move.py b/addons/stock_picking_batch/models/stock_move.py new file mode 100644 index 00000000000..6cd617e9193 --- /dev/null +++ b/addons/stock_picking_batch/models/stock_move.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models +from odoo.osv import expression + + +class StockMove(models.Model): + _inherit = "stock.move" + + def _search_picking_for_assignation_domain(self): + domain = super()._search_picking_for_assignation_domain() + domain = expression.AND([domain, ['|', ('batch_id', '=', False), ('batch_id.is_wave', '=', False)]]) + return domain diff --git a/addons/stock_picking_batch/tests/test_wave_picking.py b/addons/stock_picking_batch/tests/test_wave_picking.py index 75d43d15c6b..86fdee1ff61 100644 --- a/addons/stock_picking_batch/tests/test_wave_picking.py +++ b/addons/stock_picking_batch/tests/test_wave_picking.py @@ -342,3 +342,55 @@ class TestBatchPicking(TransactionCase): wizard_form.mode = 'new' wizard = wizard_form.save() wizard.attach_pickings() + + def test_not_assign_to_wave(self): + """ Picking + - Move line A 5 from Container to Cust -> Going to a wave picking + - Move line A 5 from Container to Cust -> Validate + --------------------------------------------- + Create + - Move A 5 from Container to Cust + Check it creates a new picking and it's not assign to the wave + """ + location = self.env['stock.location'].create({ + 'name': 'Container', + 'location_id': self.stock_location.id + }) + self.env['stock.quant']._update_available_quantity(self.productA, location, 5.0, lot_id=self.lots_p_a[0]) + self.env['stock.quant']._update_available_quantity(self.productA, location, 5.0, lot_id=self.lots_p_a[1]) + picking_1 = self.env['stock.picking'].create({ + 'location_id': location.id, + 'location_dest_id': self.customer_location.id, + 'picking_type_id': self.picking_type_out, + 'company_id': self.env.company.id, + }) + self.env['stock.move'].create({ + 'name': 'Test Wave', + 'product_id': self.productA.id, + 'product_uom_qty': 10, + 'product_uom': self.productA.uom_id.id, + 'picking_id': picking_1.id, + 'picking_type_id': self.picking_type_out, + 'location_id': location.id, + 'location_dest_id': self.customer_location.id, + }) + picking_1.action_confirm() + picking_1.action_assign() + self.assertEqual(len(picking_1.move_line_ids), 2) + move_line_to_wave = picking_1.move_line_ids[0] + move_line_to_wave._add_to_wave() + picking_1.move_line_ids.qty_done = 5 + picking_1._action_done() + + new_move = self.env['stock.move'].create({ + 'name': 'Test Wave', + 'product_id': self.productA.id, + 'product_uom_qty': 5, + 'product_uom': self.productA.uom_id.id, + 'picking_type_id': self.picking_type_out, + 'location_id': location.id, + 'location_dest_id': self.customer_location.id, + }) + new_move._action_confirm() + self.assertTrue(new_move.picking_id) + self.assertTrue(new_move.picking_id.id not in [picking_1.id, move_line_to_wave.picking_id.id])