From f6df07020bf174b7e261f6fd19ede4b9bd572490 Mon Sep 17 00:00:00 2001 From: William Henrotin Date: Tue, 25 Aug 2020 15:00:33 +0000 Subject: [PATCH] [FIX] purchase_stock: mock datetime to avoid midnight The test test_update_date_planned issued starting just before midnight. a purchase was created at 23:59:59 then the variable `today` was assigned to 00:00:01. When comparing the activity generated by the test, taking 23:59:59.today() and 00:00:01.today() gave two different values. This commit force the test time to 09:00:00. Task : 2325270 closes odoo/odoo#56681 X-original-commit: 70c223eebe7edfa26564598c898cb9a8541e349b Signed-off-by: Arnold Moyaux Signed-off-by: William Henrotin --- addons/purchase_stock/tests/test_purchase_order.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/purchase_stock/tests/test_purchase_order.py b/addons/purchase_stock/tests/test_purchase_order.py index 63f59cda16c..4e6f24e3eab 100644 --- a/addons/purchase_stock/tests/test_purchase_order.py +++ b/addons/purchase_stock/tests/test_purchase_order.py @@ -27,7 +27,7 @@ class TestPurchaseOrder(ValuationReconciliationTestCommon): 'product_qty': 5.0, 'product_uom': cls.product_id_1.uom_po_id.id, 'price_unit': 500.0, - 'date_planned': datetime.today().strftime(DEFAULT_SERVER_DATETIME_FORMAT), + 'date_planned': datetime.today().replace(hour=9).strftime(DEFAULT_SERVER_DATETIME_FORMAT), }), (0, 0, { 'name': cls.product_id_2.name, @@ -35,7 +35,7 @@ class TestPurchaseOrder(ValuationReconciliationTestCommon): 'product_qty': 5.0, 'product_uom': cls.product_id_2.uom_po_id.id, 'price_unit': 250.0, - 'date_planned': datetime.today().strftime(DEFAULT_SERVER_DATETIME_FORMAT), + 'date_planned': datetime.today().replace(hour=9).strftime(DEFAULT_SERVER_DATETIME_FORMAT), })], } @@ -213,11 +213,11 @@ class TestPurchaseOrder(ValuationReconciliationTestCommon): self.assertEqual(po1.picking_ids[-1].move_lines.product_qty, 10) def test_update_date_planned(self): + today = datetime.today().replace(hour=9, microsecond=0) + tomorrow = datetime.today().replace(hour=9, microsecond=0) + timedelta(days=1) po = self.env['purchase.order'].create(self.po_vals) po.button_confirm() - today = datetime.today().replace(microsecond=0) - tomorrow = datetime.today().replace(microsecond=0) + timedelta(days=1) # update first line po._update_date_planned_for_lines([(po.order_line[0], tomorrow)]) self.assertEqual(po.order_line[0].date_planned, tomorrow)