Skip to content

[17.0][IMP] website_sale_stock_provisioning_date: reuse computed free quantity - #1345

Closed
pilarvargas-tecnativa wants to merge 1 commit into
OCA:17.0from
Tecnativa:17.0-imp-website_sale_stock_provisioning_date
Closed

pilarvargas-tecnativa wants to merge 1 commit into
OCA:17.0from
Tecnativa:17.0-imp-website_sale_stock_provisioning_date

Conversation

@pilarvargas-tecnativa

Copy link
Copy Markdown
Contributor

The combination info already contains the available quantity computed by website_sale_stock, but the provisioning date computation calculates it again.

For products with many variants displayed in a matrix, this redundant stock computation is repeated for every combination, significantly increasing the number of queries and the page loading time.

Reuse the already computed free_qty instead.

@Tecnativa TT64745

@pedrobaeza @carlos-lopez-tecnativa please review

@OCA-git-bot OCA-git-bot added series:17.0 mod:website_sale_stock_provisioning_date Module website_sale_stock_provisioning_date labels Oct 6, 2026
@pedrobaeza pedrobaeza added this to the 17.0 milestone Oct 6, 2026
@pedrobaeza

Copy link
Copy Markdown
Member

Oh, check the CI (maybe a glitch?)

The combination info already contains the available quantity computed by
`website_sale_stock`, but the provisioning date computation calculates it
again.

For products with many variants displayed in a matrix, this redundant stock
computation is repeated for every combination, significantly increasing the
number of queries and the page loading time.

Reuse the already computed `free_qty` instead.

TT64745
@pilarvargas-tecnativa
pilarvargas-tecnativa force-pushed the 17.0-imp-website_sale_stock_provisioning_date branch from 0487959 to f948225 Compare October 6, 2026 09:53
@pilarvargas-tecnativa

Copy link
Copy Markdown
Contributor Author

Oh, check the CI (maybe a glitch?)

This change was proposed as part of a broader effort to optimize the overall performance of the installed website sale modules. Several modules extend the combination computation and add relatively small additional costs which, when accumulated, can have a noticeable impact on product page loading times.

However, the failing test revealed an interaction with website_sale_stock_available. That module changes the stock quantity used in the combination info, so combination_info["free_qty"] is not necessarily equivalent to the value returned by website._get_product_available_qty(product).

website_sale_stock_provisioning_date needs the latter value to determine the current stock availability before computing the next provisioning date. Therefore, reusing the value already present in combination_info, although more efficient, changes the expected behavior when both modules are installed.
It seems that the way to keep both modules compatible without introducing a glue module is to compute free_qty again here.

Unfortunately, this means keeping an additional stock computation. Individually these computations have a relatively small cost, but as more modules extend the same flow, the accumulated overhead becomes significant. With the current optimizations, a product with around 240 variants takes about 2.30 seconds on average to load.

In this particular case, however, the optimization does not seem appropriate because the duplicated computation is required to preserve the expected behavior of both modules.

@pedrobaeza

Copy link
Copy Markdown
Member

Why don't you group all of them in the same PR in different commits?

@pilarvargas-tecnativa

Copy link
Copy Markdown
Contributor Author

Why don't you group all of them in the same PR in different commits?

This change won't be merged, as we've found that the duplicated computation is needed for compatibility with website_sale_stock_available. The rest still needs further analysis, as there are many modules involved, and I'd prefer to analyze each case separately rather than group everything in a single PR that could end up blocked if one of the proposed optimizations doesn't fit, as happened with this one.

@pedrobaeza

Copy link
Copy Markdown
Member

Uhm, but isn't a fact that this is calling again the method? We should optimize that and also a duplicated call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:website_sale_stock_provisioning_date Module website_sale_stock_provisioning_date series:17.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants