From 104c782fd94fa6eca0e40e7fa98d4255712649a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marques?= Date: Tue, 22 Jun 2021 13:05:50 +0100 Subject: [PATCH] [FIX] stock_move_location: Improve tests to reflect real usage When setting the product quantities, force a small difference in the creation time. This is important because Odoo then sorts the quantities by in_date, and when they all have the same time, sorting is a bit left to chance, and random integration errors are introduces This is also closer to a real flow, as we woulnd't create 2 quantities at the same time. --- stock_move_location/tests/test_common.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/stock_move_location/tests/test_common.py b/stock_move_location/tests/test_common.py index 8877f2537..df59206e8 100644 --- a/stock_move_location/tests/test_common.py +++ b/stock_move_location/tests/test_common.py @@ -2,6 +2,9 @@ # Copyright 2018 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) +from datetime import timedelta + +from odoo.fields import Datetime from odoo.tests import common @@ -71,20 +74,29 @@ class TestsCommon(common.SavepointCase): ) def setup_product_amounts(self): + now = Datetime.now() self.set_product_amount(self.product_no_lots, self.internal_loc_1, 123) self.set_product_amount( - self.product_lots, self.internal_loc_1, 1.0, lot_id=self.lot1 + self.product_lots, + self.internal_loc_1, + 1.0, + lot_id=self.lot1, + in_date=(now - timedelta(seconds=4)), ) self.set_product_amount( - self.product_lots, self.internal_loc_1, 1.0, lot_id=self.lot2 + self.product_lots, + self.internal_loc_1, + 1.0, + lot_id=self.lot2, + in_date=(now - timedelta(seconds=2)), ) self.set_product_amount( self.product_lots, self.internal_loc_1, 1.0, lot_id=self.lot3 ) - def set_product_amount(self, product, location, amount, lot_id=None): + def set_product_amount(self, product, location, amount, lot_id=None, in_date=None): self.env["stock.quant"]._update_available_quantity( - product, location, amount, lot_id=lot_id + product, location, amount, lot_id=lot_id, in_date=in_date ) def check_product_amount(self, product, location, amount, lot_id=None):