From 98e51c2627ab1b421ec405e239ea2520115120ca Mon Sep 17 00:00:00 2001 From: Djamel Touati Date: Mon, 19 Feb 2024 15:47:32 +0100 Subject: [PATCH] [FIX] stock: avoid a warning in internal transfer with tracked product MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - Create a storable product “P1”: - Tracked by “SN” - Update the qty to 1 in “WH/stock” with “SN1” - Create an internal transfer: - Location: wh/Stock - Dest location: wh2/stock - Mark as todo - Try to select SN1 in the `stock.move` Problem: A warning is triggered: `Existing Serial numbers. Please correct the serial numbers encoded: (001) exists in location WH/Stock` We do a search to find all the quants in every location to verify if the same serial number is not being used, but we do not exclude the source location. opw-3734300 closes odoo/odoo#155651 X-original-commit: c6e5b2b4c98f702f9108e75bdc669397ae5e0081 Signed-off-by: Arnold Moyaux (arm) Signed-off-by: Djamel Touati (otd) --- addons/stock/models/stock_move.py | 1 + addons/stock/tests/test_move.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index b2b3501f61b..55a59324244 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -1128,6 +1128,7 @@ Please change the quantity done or the rounding precision of your unit of measur quants = self.env['stock.quant'].search([('product_id', '=', self.product_id.id), ('lot_id', 'in', self.lot_ids.ids), ('quantity', '!=', 0), + ('location_id', '!=', self.location_id.id),# Exclude the source location '|', ('location_id.usage', '=', 'customer'), '&', ('company_id', '=', self.company_id.id), ('location_id.usage', 'in', ('internal', 'transit'))]) diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index 3216139135b..bab7a8ca090 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -6265,3 +6265,27 @@ class StockMove(TransactionCase): self.assertEqual(picking.scheduled_date, today + relativedelta(day=5)) self.assertEqual(backorder.scheduled_date, today + relativedelta(day=10)) + + def test_internal_transfer_with_tracked_product(self): + """ + Test That we can do an internal transfer with a tracked products + """ + sn01 = self.env['stock.lot'].create({ + 'name': 'sn_1', + 'product_id': self.product_serial.id, + }) + self.env['stock.quant']._update_available_quantity(self.product_serial, self.stock_location, 1.0, lot_id=sn01) + with Form(self.env['stock.picking']) as picking_form: + picking_form.picking_type_id = self.env.ref('stock.picking_type_internal') + with picking_form.move_ids_without_package.new() as move: + move.product_id = self.product_serial + move.product_uom_qty = 1 + picking = picking_form.save() + + picking.action_confirm() + self.assertEqual(picking.state, 'assigned') + + with picking_form.move_ids_without_package.edit(0) as line_form: + line_form.lot_ids.add(sn01) + picking = picking_form.save() + self.assertEqual(picking.move_ids_without_package.lot_ids, sn01)