From 607741fa5df9d90b7b006363f0218e5395aab9f4 Mon Sep 17 00:00:00 2001 From: "Denis Vermylen (dve)" Date: Thu, 17 Nov 2016 16:58:20 +0100 Subject: [PATCH] [FIX] sale_stock: add flexibility to tests test_sale_stock_lead_time.py compares dates and expect them to be the same. Sometimes, the dates would differ by a second, because they are generated at different moment during the execution. This commit adds a tolerance of 1 second when comparing the dates. (and changed from comparing Datetime strings to comparing timedeltas) --- .../tests/test_sale_stock_lead_time.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/addons/sale_stock/tests/test_sale_stock_lead_time.py b/addons/sale_stock/tests/test_sale_stock_lead_time.py index 43cc996b356..af6a05890ea 100644 --- a/addons/sale_stock/tests/test_sale_stock_lead_time.py +++ b/addons/sale_stock/tests/test_sale_stock_lead_time.py @@ -39,7 +39,6 @@ class TestSaleStockLeadTime(TestStockCommon): 'product_uom': self.uom_unit.id, 'customer_lead': self.product_1.sale_delay})]}) - # Confirm our standard sale order order.action_confirm() @@ -48,8 +47,8 @@ class TestSaleStockLeadTime(TestStockCommon): # Check schedule date of picking out_date = fields.Datetime.from_string(order.date_order) + timedelta(days=self.product_1.sale_delay) - timedelta(days=company.security_lead) - schedule_date = fields.Datetime.to_string(out_date) - self.assertEqual(order.picking_ids[0].min_date, schedule_date, 'Schedule date of picking should be equal to: order date + Customer Lead Time - Sales Safety Days.') + min_date = fields.Datetime.from_string(order.picking_ids[0].min_date) + self.assertTrue(abs(min_date - out_date) <= timedelta(seconds=1), 'Schedule date of picking should be equal to: order date + Customer Lead Time - Sales Safety Days.') def test_01_product_route_level_delays(self): """ In order to check schedule dates, set product's Customer Lead Time @@ -84,18 +83,18 @@ class TestSaleStockLeadTime(TestStockCommon): # Check schedule date of ship type picking out = order.picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse_1.out_type_id) + out_min_date = fields.Datetime.from_string(out.min_date) out_date = fields.Datetime.from_string(order.date_order) + timedelta(days=self.product_1.sale_delay) - timedelta(days=out.move_lines[0].rule_id.delay) - out_schedule_date = fields.Datetime.to_string(out_date) - self.assertEqual(out.min_date, out_schedule_date, 'Schedule date of ship type picking should be equal to: order date + Customer Lead Time - pull rule delay.') + self.assertTrue(abs(out_min_date - out_date) <= timedelta(seconds=1), 'Schedule date of ship type picking should be equal to: order date + Customer Lead Time - pull rule delay.') # Check schedule date of pack type picking pack = order.picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse_1.pack_type_id) + pack_min_date = fields.Datetime.from_string(pack.min_date) pack_date = out_date - timedelta(days=pack.move_lines[0].rule_id.delay) - pack_schedule_date = fields.Datetime.to_string(pack_date) - self.assertEqual(pack.min_date, pack_schedule_date, 'Schedule date of pack type picking should be equal to: Schedule date of ship type picking - pull rule delay.') + self.assertTrue(abs(pack_min_date - pack_date) <= timedelta(seconds=1), 'Schedule date of pack type picking should be equal to: Schedule date of ship type picking - pull rule delay.') # Check schedule date of pick type picking pick = order.picking_ids.filtered(lambda r: r.picking_type_id == self.warehouse_1.pick_type_id) + pick_min_date = fields.Datetime.from_string(pick.min_date) pick_date = pack_date - timedelta(days=pick.move_lines[0].rule_id.delay) - pick_schedule_date = fields.Datetime.to_string(pick_date) - self.assertEqual(pick.min_date, pick_schedule_date, 'Schedule date of pick type picking should be equal to: Schedule date of pack type picking - pull rule delay.') + self.assertTrue(abs(pick_min_date - pick_date) <= timedelta(seconds=1), 'Schedule date of pick type picking should be equal to: Schedule date of pack type picking - pull rule delay.')