[FIX] product: flush before invalidate in write override

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] 5361706e5e
[2] 9920f20e4c

closes odoo/odoo#43483

X-original-commit: f721bfe2860293d1456770d57be7805920929ca0
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
Sébastien Theys
2020-01-17 12:37:24 +00:00
parent 51de5eb041
commit 69f0f765bd
4 changed files with 4 additions and 0 deletions
+1
View File
@@ -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()
@@ -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.
@@ -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
@@ -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