Skip to content

Commit

Permalink
[16.0][MIG] pricelist_cache: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkhao committed Jan 9, 2025
1 parent 189615e commit 3d2087c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
9 changes: 4 additions & 5 deletions pricelist_cache/models/product_pricelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()])])

Expand All @@ -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

Expand All @@ -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()]

Expand All @@ -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()]

Expand Down
8 changes: 4 additions & 4 deletions pricelist_cache/models/product_pricelist_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions pricelist_cache/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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")))
Expand Down

0 comments on commit 3d2087c

Please sign in to comment.