From 69f0f765bdf370c7f1dba6bbdc877863596fd5ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Thu, 16 Jan 2020 16:16:11 +0000 Subject: [PATCH] [FIX] product: flush before invalidate in write override MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since [1] `computer_hdd_attribute_lines` is archived instead of unlinked in `TestSaleProductAttributeValueConfig` which leads to indeterminism in tests due to the missing `flush`. Indeed `flush` is necessary before `invalidate_cache` since [2] if the data that are pending being written must be saved to the database before the cache invalidation. [1] which highlighted the issue was merged after v13.0, but it still makes sense to merge the current fix in the earliest version possible. [1] 5361706e5eb10eee991f3f0a2b10c1c877124752 [2] 9920f20e4c7753bc17bea71dea3a90f7de687196 closes odoo/odoo#43483 X-original-commit: f721bfe2860293d1456770d57be7805920929ca0 Signed-off-by: Sébastien Theys (seb) --- addons/product/models/product.py | 1 + addons/product/models/product_attribute.py | 1 + addons/product/models/product_pricelist.py | 1 + addons/product/models/product_template.py | 1 + 4 files changed, 4 insertions(+) diff --git a/addons/product/models/product.py b/addons/product/models/product.py index 610c10dd364..5f80efc0538 100644 --- a/addons/product/models/product.py +++ b/addons/product/models/product.py @@ -327,6 +327,7 @@ class ProductProduct(models.Model): if 'active' in values: # prefetched o2m have to be reloaded (because of active_test) # (eg. product.template: product_variant_ids) + self.flush() self.invalidate_cache() # `_get_first_possible_variant_id` depends on variants active state self.clear_caches() diff --git a/addons/product/models/product_attribute.py b/addons/product/models/product_attribute.py index 67404628f80..5ad2032a7c9 100644 --- a/addons/product/models/product_attribute.py +++ b/addons/product/models/product_attribute.py @@ -247,6 +247,7 @@ class ProductTemplateAttributeLine(models.Model): values['value_ids'] = [(5, 0, 0)] res = super(ProductTemplateAttributeLine, self).write(values) if 'active' in values: + self.flush() self.env['product.template'].invalidate_cache(fnames=['attribute_line_ids']) # If coming from `create`, no need to update the values and the variants # before all lines are created. diff --git a/addons/product/models/product_pricelist.py b/addons/product/models/product_pricelist.py index 55dad257b77..8c37bb1cef5 100644 --- a/addons/product/models/product_pricelist.py +++ b/addons/product/models/product_pricelist.py @@ -592,5 +592,6 @@ class PricelistItem(models.Model): res = super(PricelistItem, self).write(values) # When the pricelist changes we need the product.template price # to be invalided and recomputed. + self.flush() self.invalidate_cache() return res diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index 5bd332f7508..86bcf24abc8 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -595,6 +595,7 @@ class ProductTemplate(models.Model): # (eg. product.template: product_variant_ids) # We can't rely on existing invalidate_cache because of the savepoint # in _unlink_or_archive. + self.flush() self.invalidate_cache() return True