diff options
| author | Josse Colpaert <jco@odoo.com> | 2018-02-08 17:49:59 +0100 |
|---|---|---|
| committer | Josse Colpaert <jco@odoo.com> | 2018-05-23 14:38:13 +0200 |
| commit | 73e213edef053c2e08d7791efe0b1a399da0eed7 (patch) | |
| tree | 833bce1f10a98281b907ad557e3fe05118979912 /addons/stock/tests/test_quant.py | |
| parent | 0b412c250afc60131188ce248087dae2c2a53574 (diff) | |
[FIX] stock: non-tracked products should follow FIFO removal strategy too
In a warehouse, mostly most of the products have no lot. It stays
important however to avoid having old products in stock, certainly if
we can distinguish them by pack or location.
As now in stable, in_date is not put on the quant for non-tracked products,
databases might mix quants with and without in_date of the same product.
We should see those without in_date as the oldest.
That is why we need to be able to apply a ASC NULLS FIRST (ASC is NULLS LAST by default) for FIFO
or DESC NULLS LAST for LIFO.
In order to do that, we copied the code from the _search method of the ORM to
be able to do this special order as the orm itself is restrictive as it
supposes the order itself has no spaces.
We adapted and added some tests to check it handles the combination of NULL/NOT NULL well.
Diffstat (limited to 'addons/stock/tests/test_quant.py')
| -rw-r--r-- | addons/stock/tests/test_quant.py | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/addons/stock/tests/test_quant.py b/addons/stock/tests/test_quant.py index bff1f902ba5..4a41b7474a4 100644 --- a/addons/stock/tests/test_quant.py +++ b/addons/stock/tests/test_quant.py @@ -629,7 +629,24 @@ class StockQuant(TransactionCase): }) quantity, in_date = self.env['stock.quant']._update_available_quantity(product1, stock_location, 1.0) self.assertEqual(quantity, 1) - self.assertEqual(in_date, None) + self.assertNotEqual(in_date, None) + + + def test_in_date_1b(self): + stock_location = self.env.ref('stock.stock_location_stock') + product1 = self.env['product.product'].create({ + 'name': 'Product A', + 'type': 'product', + }) + self.env['stock.quant'].create({ + 'product_id': product1.id, + 'location_id': stock_location.id, + 'quantity': 1.0, + }) + quantity, in_date = self.env['stock.quant']._update_available_quantity(product1, stock_location, 2.0) + self.assertEqual(quantity, 3) + self.assertNotEqual(in_date, None) + def test_in_date_2(self): """ Check that an incoming date is correctly set when updating the quantity of a tracked @@ -707,6 +724,34 @@ class StockQuant(TransactionCase): # Removal strategy is LIFO, so lot1 should be received as it was received later. self.assertEqual(quants[0][0].lot_id.id, lot1.id) + def test_in_date_4b(self): + """ Check for LIFO and max with/without in_date that it handles the LIFO NULLS LAST well + """ + stock_location = self.env.ref('stock.stock_location_stock') + stock_location1 = self.env.ref('stock.stock_location_components') + stock_location2 = self.env.ref('stock.stock_location_14') + lifo_strategy = self.env['product.removal'].search([('method', '=', 'lifo')]) + stock_location.removal_strategy_id = lifo_strategy + product1 = self.env['product.product'].create({ + 'name': 'Product A', + 'type': 'product', + 'tracking': 'serial', + }) + + self.env['stock.quant'].create({ + 'product_id': product1.id, + 'location_id': stock_location1.id, + 'quantity': 1.0, + }) + + in_date_location2 = datetime.now() + self.env['stock.quant']._update_available_quantity(product1, stock_location2, 1.0, in_date=in_date_location2) + + quants = self.env['stock.quant']._update_reserved_quantity(product1, stock_location, 1) + + # Removal strategy is LIFO, so the one with date is the most recent one and should be selected + self.assertEqual(quants[0][0].location_id.id, stock_location2.id) + def test_in_date_5(self): """ Receive the same lot at different times, once they're in the same location, the quants are merged and only the earliest incoming date is kept. |
