Skip to content

[19.0][FIX] stock_available: fix the context keys the quantities depend on - #82

Closed
CarlosRoca13 wants to merge 1 commit into
OCA:19.0from
Tecnativa:19.0-FIX-stock_available
Closed

CarlosRoca13 wants to merge 1 commit into
OCA:19.0from
Tecnativa:19.0-FIX-stock_available

Conversation

@CarlosRoca13

Copy link
Copy Markdown

Since 19.0, stock only filters the quantities by the warehouse_id context key: warehouse isn't read anymore (https://github.com/odoo/odoo/blob/b0907482898d097054a432974a68eb1ecee65326/addons/stock/models/product.py#L370). As it was the key declared in depends_context, the ORM cache key of immediately_usable_qty didn't take the warehouse into account, so once the field was computed for one warehouse, every other warehouse got that very same value.

allowed_company_ids was missing as well, although virtual_available, which this field is computed from, does depend on it.

cc @Tecnativa

ping @sergio-teruel @Andrii9090-tecnativa

Since 19.0, `stock` only filters the quantities by the `warehouse_id` context key: `warehouse` isn't read anymore (https://github.com/odoo/odoo/blob/b0907482898d097054a432974a68eb1ecee65326/addons/stock/models/product.py#L370). As it was the key declared in `depends_context`, the ORM cache key of `immediately_usable_qty` didn't take the warehouse into account, so once the field was computed for one warehouse, every other warehouse got that very same value.

`allowed_company_ids` was missing as well, although `virtual_available`, which this field is computed from, does depend on it.
@pedrobaeza pedrobaeza added this to the 19.0 milestone Aug 17, 2026

@IJOL IJOL left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independently confirmed, and 18.0 is affected the same way: there too stock reads only the warehouse_id context key (_get_domain_locations, addons/stock/models/product.py, no fallback to warehouse), while _compute_available_quantities still declares warehouse — so immediately_usable_qty is cached once and every other warehouse gets that first value.

Measured on a database with two warehouses whose real quantities are 200 and 89:

  • with_context(warehouse=wh.id).immediately_usable_qty → 384 / 384 (the company-wide figure)
  • with_context(warehouse_id=wh.id).immediately_usable_qty → 200 / 200 (first value reused)
  • with_context(warehouse_id=wh.id).qty_available → 200 / 89 (correct)

It surfaced through pos_stock_available_online, which displays one figure per warehouse in the POS: with a single warehouse it looks correct, and it only lies when there is more than one.

What is missing to get this merged? And would a backport to 18.0 be welcome? I can open it.

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@pedrobaeza

Copy link
Copy Markdown
Member

/ocabot merge patch

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR looks fantastic, let's merge it!
Prepared branch 19.0-ocabot-merge-pr-82-by-pedrobaeza-bump-patch, awaiting test results.

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at f9f67ed. Thanks a lot for contributing to OCA. ❤️

@CarlosRoca13

Copy link
Copy Markdown
Author

@pedrobaeza I think this PR have been closed but not merged

@pedrobaeza
pedrobaeza restored the 19.0-FIX-stock_available branch September 2, 2026 06:33
@pedrobaeza

Copy link
Copy Markdown
Member

Uhm, it's true that I don't see the commit in https://github.com/OCA/stock-logistics-availability/commits/19.0/, so the GitHub error suffered yesterday is harder than thought. Let's try again another merge command:

/ocabot merge patch

@OCA-git-bot

Copy link
Copy Markdown
Contributor

On my way to merge this fine PR!
Prepared branch 19.0-ocabot-merge-pr-82-by-pedrobaeza-bump-patch, awaiting test results.

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at f9f67ed. Thanks a lot for contributing to OCA. ❤️

@pedrobaeza
pedrobaeza deleted the 19.0-FIX-stock_available branch September 2, 2026 06:39
@pedrobaeza

Copy link
Copy Markdown
Member

Oh, wait it's there, but ordered by commit date, and yours is 2 weeks ago:

image

cibexgit pushed a commit to cibex/stock-logistics-availability that referenced this pull request Sep 3, 2026
Signed-off-by pedrobaeza
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants