From 3d2087c9af2ff5e56ba05b3b82e617bce5acfccf Mon Sep 17 00:00:00 2001 From: Kevin Khao Date: Thu, 9 Jan 2025 16:32:00 +0200 Subject: [PATCH] [16.0][MIG] pricelist_cache: Migration to 16.0 --- pricelist_cache/models/product_pricelist.py | 9 ++++----- pricelist_cache/models/product_pricelist_cache.py | 8 ++++---- pricelist_cache/tests/common.py | 10 +++++----- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/pricelist_cache/models/product_pricelist.py b/pricelist_cache/models/product_pricelist.py index b7138ac84d4..0f34ba3145a 100644 --- a/pricelist_cache/models/product_pricelist.py +++ b/pricelist_cache/models/product_pricelist.py @@ -50,7 +50,7 @@ def _get_parent_list_tree(self): ) SELECT id FROM parent_pricelist; """ - self.flush() + self.env.flush_all() self.env.cr.execute(query, {"pricelist_id": self.id}) return self.search([("id", "in", [row[0] for row in self.env.cr.fetchall()])]) @@ -74,8 +74,7 @@ def _get_product_prices(self, product_ids): # between the time where records have been created / modified # and the time this method is executed. products = self.env["product.product"].search([("id", "in", product_ids)]) - products_qty_partner = [(p, 1, False) for p in products] - results = self._compute_price_rule(products_qty_partner, date.today()) + results = self._compute_price_rule(products, 1, date=date.today()) product_prices = {prod: price[0] for prod, price in results.items()} return product_prices @@ -97,7 +96,7 @@ def _get_root_pricelist_ids(self): ) AND active = TRUE; """ - self.flush() + self.env.flush_all() self.env.cr.execute(no_parent_query) return [row[0] for row in self.env.cr.fetchall()] @@ -124,7 +123,7 @@ def _get_factor_pricelist_ids(self): ) AND active = TRUE; """ - self.flush() + self.env.flush_all() self.env.cr.execute(factor_pricelist_query) return [row[0] for row in self.env.cr.fetchall()] diff --git a/pricelist_cache/models/product_pricelist_cache.py b/pricelist_cache/models/product_pricelist_cache.py index cf0cb0243c7..7581fa7c62d 100644 --- a/pricelist_cache/models/product_pricelist_cache.py +++ b/pricelist_cache/models/product_pricelist_cache.py @@ -67,10 +67,10 @@ def _update_existing_records(self, product_prices): c.id = pricelist_cache.id; """ ).format(sql.SQL("), (").join(values)) - self.flush() + self.env.flush_all() self.env.cr.execute(query) - self.invalidate_cache(["price"]) - self.recompute() + self.invalidate_model(["price"]) + self.env.flush_all() def _create_cache_records(self, pricelist_id, product_ids, product_prices): """Create price cache records for a given pricelist, applied to a list of @@ -95,7 +95,7 @@ def _create_cache_records(self, pricelist_id, product_ids, product_prices): VALUES ({}); """ ).format(sql.SQL("), (").join(values)) - self.flush() + self.env.flush_all() self.env.cr.execute(query) def _update_pricelist_cache(self, pricelist_id, product_prices): diff --git a/pricelist_cache/tests/common.py b/pricelist_cache/tests/common.py index 26c2fa4c025..e52f95363c3 100644 --- a/pricelist_cache/tests/common.py +++ b/pricelist_cache/tests/common.py @@ -66,7 +66,7 @@ class TestPricelistCacheCommon(TransactionCase): @classmethod def setUpClassBaseCache(cls): cls.cache_model.cron_reset_pricelist_cache() - cls.env["product.pricelist"].invalidate_cache(["is_pricelist_cache_available"]) + cls.env["product.pricelist"].invalidate_model(["is_pricelist_cache_available"]) @classmethod def set_currency(cls): @@ -136,15 +136,15 @@ def setUpClass(cls): def _flush_cache(self): self.cache_model.flush_pricelist_cache() - self.env["res.partner"].invalidate_cache(["is_pricelist_cache_available"]) - self.env["product.pricelist"].invalidate_cache(["is_pricelist_cache_available"]) + self.env["res.partner"].invalidate_model(["is_pricelist_cache_available"]) + self.env["product.pricelist"].invalidate_model(["is_pricelist_cache_available"]) def _update_cache(self, pricelist_ids=None, product_ids=None): self.cache_model.update_product_pricelist_cache( product_ids=product_ids, pricelist_ids=pricelist_ids ) - self.env["res.partner"].invalidate_cache(["is_pricelist_cache_available"]) - self.env["product.pricelist"].invalidate_cache(["is_pricelist_cache_available"]) + self.env["res.partner"].invalidate_model(["is_pricelist_cache_available"]) + self.env["product.pricelist"].invalidate_model(["is_pricelist_cache_available"]) def assert_cache_available(self, lists): self.assertTrue(all(lists.mapped("is_pricelist_cache_available")))