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)