diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index b893f86b14f..3178e38ea62 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -688,7 +688,11 @@ class StockQuant(models.Model): self = self.sudo() quants = self._gather(product_id, location_id, lot_id=lot_id, package_id=package_id, owner_id=owner_id, strict=True) - incoming_dates = [d for d in quants.mapped('in_date') if d] + if location_id.should_bypass_reservation(): + incoming_dates = [] + else: + incoming_dates = [quant.in_date for quant in quants if quant.in_date and + float_compare(quant.quantity, 0, precision_rounding=quant.product_uom_id.rounding) > 0] if in_date: incoming_dates += [in_date] # If multiple incoming dates are available for a given lot_id/package_id/owner_id, we diff --git a/addons/stock/tests/test_quant.py b/addons/stock/tests/test_quant.py index 7840ef95186..5617259ab87 100644 --- a/addons/stock/tests/test_quant.py +++ b/addons/stock/tests/test_quant.py @@ -3,7 +3,9 @@ from contextlib import closing from datetime import datetime, timedelta +from unittest.mock import patch +from odoo import fields from odoo.addons.mail.tests.common import mail_new_test_user from odoo.exceptions import ValidationError from odoo.tests.common import TransactionCase @@ -687,3 +689,42 @@ class StockQuant(TransactionCase): self.assertEqual(quants[0][0].reserved_quantity, 2) # The last one should then be taken in stock_location/subloc3 since the first location doesn't have enough products self.assertEqual(quants[1][0].reserved_quantity, 1) + + def test_in_date_6(self): + """ + One P in stock, P is delivered. Later on, a stock adjustement adds one P. This test checks + the date value of the related quant + """ + self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 1.0) + + move = self.env['stock.move'].create({ + 'name': 'OUT 1 product', + 'product_id': self.product.id, + 'product_uom_qty': 1, + 'product_uom': self.product.uom_id.id, + 'location_id': self.stock_location.id, + 'location_dest_id': self.ref('stock.stock_location_customers'), + }) + move._action_confirm() + move._action_assign() + move.quantity_done = 1 + move._action_done() + + + tomorrow = fields.Datetime.now() + timedelta(days=1) + with patch.object(fields.Datetime, 'now', lambda: tomorrow): + move = self.env['stock.move'].create({ + 'name': 'IN 1 product', + 'product_id': self.product.id, + 'product_uom_qty': 1, + 'product_uom': self.product.uom_id.id, + 'location_id': self.ref('stock.stock_location_suppliers'), + 'location_dest_id': self.stock_location.id, + }) + move._action_confirm() + move._action_assign() + move.quantity_done = 1 + move._action_done() + + quant = self.env['stock.quant'].search([('product_id', '=', self.product.id), ('location_id', '=', self.stock_location.id), ('quantity', '>', 0)]) + self.assertEqual(quant.in_date, tomorrow)