Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] pricelist_cache: update price cache in chuncks #3060

Open
wants to merge 5 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pricelist_cache/models/product_pricelist.py
Expand Up @@ -61,7 +61,7 @@ def create(self, vals_list):
if record._is_factor_pricelist() or record._is_global_pricelist():
product_ids_to_cache = None
else:
product_ids_to_cache = record.item_ids.mapped("product_id").ids
product_ids_to_cache = record.item_ids._get_pricelist_products()
cache_model = self.env["product.pricelist.cache"].with_delay()
cache_model.update_product_pricelist_cache(
product_ids=product_ids_to_cache, pricelist_ids=record.ids
Expand Down
21 changes: 19 additions & 2 deletions pricelist_cache/models/product_pricelist_item.py
Expand Up @@ -25,6 +25,19 @@ def _has_date_range(self):
"""Returns whether any of the item records in recordset is based on dates."""
return any(bool(record.date_start or record.date_end) for record in self)

def _get_pricelist_products(self):
products = []
for rec in self:
if rec.product_tmpl_id.id:
products = (
self.env["product.product"]
.search([("product_tmpl_id", "=", rec.product_tmpl_id.id)])
.ids
)
else:
products = rec.product_id.ids
return products

vuwnevska marked this conversation as resolved.
Show resolved Hide resolved
def _get_pricelist_products_group(self):
"""Returns a mapping of products grouped by pricelist.

Expand All @@ -34,15 +47,19 @@ def _get_pricelist_products_group(self):
"""
pricelist_products = defaultdict(list)
for item in self:
pricelist_products[item.pricelist_id.id].append(item.product_id.id)
pricelist_products[item.pricelist_id.id].extend(
item._get_pricelist_products()
)
return pricelist_products

def update_product_pricelist_cache(self):
"""Executed when a product item is modified. Filters items not based
on variants or based on dates, then updates the cache.
"""
# Filter items applied on variants
items = self.filtered(lambda i: i.applied_on == "0_product_variant")
items = self.filtered(
lambda i: i.applied_on in ["0_product_variant", "1_product"]
vuwnevska marked this conversation as resolved.
Show resolved Hide resolved
)
# Filter items based on dates
item_ids_to_update = []
for item in items:
Expand Down