From c2c9d6d143af7f00bb07e391fe494c2496cdad88 Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Thu, 8 Aug 2019 14:46:12 +0000 Subject: [PATCH] [FIX] stock: virtual_available and to_date When updating the schedule date of a picking, the schedule dates of its stock moves are updated. However, their date field isn't. According to the help of the date field, its value should be equal to the expected_date field until the move is done. That's probably why the virtal_available computed field only take care of the date field its `to_date` domain. As this is a long standing issue, it seems safer to adapt the computed field's domain instead of fixing the date should be equal to expected date until done thingy. task-2003485 --- addons/stock/models/product.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/addons/stock/models/product.py b/addons/stock/models/product.py index d3e079cdd70..1e230033233 100644 --- a/addons/stock/models/product.py +++ b/addons/stock/models/product.py @@ -125,11 +125,29 @@ class Product(models.Model): domain_move_in_done = list(domain_move_in) domain_move_out_done = list(domain_move_out) if from_date: - domain_move_in += [('date', '>=', from_date)] - domain_move_out += [('date', '>=', from_date)] + date_date_expected_domain_from = [ + '|', + '&', + ('state', '=', 'done'), + ('date', '<=', from_date), + '&', + ('state', '!=', 'done'), + ('date_expected', '<=', from_date), + ] + domain_move_in += date_date_expected_domain_from + domain_move_out += date_date_expected_domain_from if to_date: - domain_move_in += [('date', '<=', to_date)] - domain_move_out += [('date', '<=', to_date)] + date_date_expected_domain_to = [ + '|', + '&', + ('state', '=', 'done'), + ('date', '<=', to_date), + '&', + ('state', '!=', 'done'), + ('date_expected', '<=', to_date), + ] + domain_move_in += date_date_expected_domain_to + domain_move_out += date_date_expected_domain_to Move = self.env['stock.move'] Quant = self.env['stock.quant']