From af8908b03c73f8bb5b6ff3a60171caedaf017e82 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Tue, 5 Dec 2017 15:00:07 +0100 Subject: [PATCH] [FIX] stock: do not propagate date when negative delta In Pick - Ship: - validate a sale order which scheduled date is an hour in the future. - validate the WH/PICK picking Before this commit the WH/OUT picking 's scheduled date was set a day in the **past** This was due to the implementation of datetime substraction and timedelta, which, in case of a negative value, would take -1 day and some complementary values (hours, minutes etc...) (the difference is complementary) After this commit, the WH/OUT picking 's scheduled date stays what it was in that particular use case. OPW 784452 --- addons/stock/models/stock_move.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 26db3fa010f..a5b97bc7938 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -283,7 +283,7 @@ class StockMove(models.Model): if propagated_date_field: current_date = datetime.strptime(move.date_expected, DEFAULT_SERVER_DATETIME_FORMAT) new_date = datetime.strptime(vals.get(propagated_date_field), DEFAULT_SERVER_DATETIME_FORMAT) - delta = new_date - current_date + delta = relativedelta.relativedelta(new_date, current_date) if abs(delta.days) >= move.company_id.propagation_minimum_delta: old_move_date = datetime.strptime(move.move_dest_id.date_expected, DEFAULT_SERVER_DATETIME_FORMAT) new_move_date = (old_move_date + relativedelta.relativedelta(days=delta.days or 0)).strftime(DEFAULT_SERVER_DATETIME_FORMAT)