Skip to content
Snippets Groups Projects
Commit ab121290 authored by Ivàn Todorovich's avatar Ivàn Todorovich
Browse files

[IMP] product: price computation performance

This commit improves the performance of `_is_applicable_for`, by:

1) Leveraging the `product.category.parent_path` field.
2) Use `applied_on` for the `if` conditions, which is ~100% faster than using
   the many2one fields due to the related record initialization.

These micro-optimizations are important because of the way `_is_applicable_for`
is used.

See: https://github.com/odoo/odoo/blob/0a5d84289/addons/product/models/product_pricelist.py#L169-L193



Which, for demostration purposes, could be simplified to:

```
for product, qty, partner in products_qty_partner:
    for rule in items:
        if not rule._is_applicable_for(product, qty_in_product_uom):
            continue
```

On a database with 470 products, and about the same number of pricelist items,
these optimization result in a ~30% speedup when computing prices for all
products at once. It may be even better depending on how many nested product
categories are used in the database and in the pricelist rules.

closes odoo/odoo#124376

Signed-off-by: default avatarVictor Feyens (vfe) <vfe@odoo.com>
parent 24ccce77
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment