Skip to content

[16.0] [FIX] stock_available_immediately: kit immediately_usable_qty computed from components#73

Open
alvaro-gmz wants to merge 1 commit into
OCA:16.0from
factorlibre:16.0-fix-stock_available_immediately
Open

[16.0] [FIX] stock_available_immediately: kit immediately_usable_qty computed from components#73
alvaro-gmz wants to merge 1 commit into
OCA:16.0from
factorlibre:16.0-fix-stock_available_immediately

Conversation

@alvaro-gmz
Copy link
Copy Markdown

For products with a phantom BoM (kits), the formula
immediately_usable_qty = virtual_available - incoming_qty applied to the
aggregated kit fields produces inconsistent results because each aggregated
kit field (virtual_available, incoming_qty, ...) is computed by Odoo MRP
as an independent min over the components and may be limited by different
components. Subtracting two such mins is not equivalent to
qty_available - outgoing_qty for kits, even though that algebraic
cancellation does hold for plain products.

Example

Kit with two components, need=2 each:

Component A: qty=8,    in=133, out=14   →  virtual=127,  immediately=-6
Component B: qty=4258, in=60,  out=168  →  virtual=4150, immediately=4090

Forecasted (kit) = min(127/2, 4150/2)  = 63    ← limited by A
Incoming   (kit) = min(133/2, 60/2)    = 30    ← limited by B
immediately_usable_qty (current bug) = 63 - 30 = 33   ← inflated, not physical
immediately_usable_qty (expected)    = min(-6/2, 4090/2) = -3

Fix

When the mrp module is installed, recompute immediately_usable_qty for
products with a phantom BoM directly from the components (whose individual
values do hold the correct cancellation) and aggregate them with
min(component / qty_per_kit). The other kit fields (qty_available,
virtual_available, incoming_qty, outgoing_qty, free_qty) are
intentionally left untouched and keep the standard Odoo MRP aggregation.

If mrp is not installed, behaviour is unchanged.

Tests

Added covering:

  • Unbalanced components reproducing the bug → expected negative result.
  • Balanced components → no change vs. previous behaviour.
  • All-positive components → standard healthy case.
  • Oversold components → propagation to the kit value.
  • Plain products without BoM → not affected (regression).
  • Consumable components → skipped in the ratio, only storable components limit.

@alvaro-gmz alvaro-gmz force-pushed the 16.0-fix-stock_available_immediately branch from 50c1c94 to f15ef58 Compare April 27, 2026 15:51
@OCA-git-bot OCA-git-bot added mod:stock_available_immediately Module stock_available_immediately series:16.0 labels Apr 27, 2026
@alvaro-gmz alvaro-gmz force-pushed the 16.0-fix-stock_available_immediately branch 2 times, most recently from e9cc43a to f1ad23b Compare April 28, 2026 11:08
Copy link
Copy Markdown

@AdrianaSaiz AdrianaSaiz left a comment

Choose a reason for hiding this comment

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

LGTM good job @alvaro-gmz

"incoming_qty",
"bom_ids",
"bom_ids.bom_line_ids",
"bom_ids.bom_line_ids.product_qty",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

you can add bom_ids.bom_line_ids.product_id

alvaro-gmz added a commit to factorlibre/stock-logistics-availability that referenced this pull request Apr 28, 2026
…epends

Address review comment from @AdrianaSaiz on PR OCA#73: extend the
@api.depends of _compute_available_quantities to also track
bom_ids.bom_line_ids.product_id so the kit cache is invalidated when a
component is replaced (not only when its quantity changes).
@alvaro-gmz alvaro-gmz force-pushed the 16.0-fix-stock_available_immediately branch 3 times, most recently from 65ec67a to 2024341 Compare April 28, 2026 16:21
@OCA-git-bot OCA-git-bot added the mod:stock_available_immediately_mrp Module stock_available_immediately_mrp label Apr 28, 2026
@alvaro-gmz alvaro-gmz force-pushed the 16.0-fix-stock_available_immediately branch from 98664d8 to 2024341 Compare April 28, 2026 17:12
@OCA-git-bot OCA-git-bot removed the mod:stock_available_immediately_mrp Module stock_available_immediately_mrp label Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:stock_available_immediately Module stock_available_immediately series:16.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants