[FIX] stock: avoid a warning in internal transfer with tracked product
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) <arm@odoo.com>
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
This commit is contained in:
@@ -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'))])
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user