Skip to content

[16.0][IMP]stock_warehouse_flow#1144

Open
AdrianaSaiz wants to merge 3 commits into
OCA:16.0from
factorlibre:16.0-imp-stock_warehouse_flow
Open

[16.0][IMP]stock_warehouse_flow#1144
AdrianaSaiz wants to merge 3 commits into
OCA:16.0from
factorlibre:16.0-imp-stock_warehouse_flow

Conversation

@AdrianaSaiz
Copy link
Copy Markdown

@AdrianaSaiz AdrianaSaiz commented Mar 16, 2026

Summary
Add a computed field wh_total_products on stock.move that sums product_uom_qty of sibling moves sharing the same sale order and warehouse, excluding cancelled moves.

This allows flow domains to evaluate per-warehouse quantities instead of the global sale.order.total_products, which is critical when a single SO is split across multiple warehouses.

Problem
When SO lines are routed to different warehouses, flow domains referencing sale_line_id.order_id.total_products still see the global SO total. For example, a warehouse handling 10 units gets routed as B2B because the SO total is 25.

Solution
New field wh_total_products (Float, compute, non-stored) on stock.move
Helper method _get_wh_sibling_moves() returns moves from the same SO + warehouse
Compute batches all involved orders in a single query grouped by (order_id, warehouse_id) to avoid N+1
Falls back to the move's own product_uom_qty when there is no sale_line_id
Flow domain usage

No new dependencies added
Compatible with single-warehouse scenarios (same value as total_products)
Field is computed on-the-fly during _action_confirm(), when moves already have warehouse_id and sale_line_id set by procurement

Tests
All moves in one warehouse (total = full SO sum)
Moves split across 2 warehouses (each one sees only its qty in the new field)
Move without sale_line_id (fallback to own qty)
Cancelled moves excluded from total
_get_wh_sibling_moves() returns correct subset
Integration: SO confirm generates moves with correct field value

@AdrianaSaiz AdrianaSaiz force-pushed the 16.0-imp-stock_warehouse_flow branch 2 times, most recently from a54646f to d7f6417 Compare March 16, 2026 10:37
all_siblings = self.search(
[
("sale_line_id.order_id", "in", order_ids),
("state", "!=", "cancel"),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should state be present on api.depends?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hello Sergio, the state we filter on (!= cancel) belongs to sibling moves fetched via search(), not to the record itself.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

understood, thanks!

for line in order.order_line:
moves |= self._create_move(line, self.wh1)

for move in moves:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

missing determinism. If moves is empty tests will silently pass, consider using mapped() + set().

    self.assertEqual(len(moves), 2)
    self.assertEqual(set(moves.mapped("wh_total_products")), {18.0})

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Changes applied, thanks

@AdrianaSaiz AdrianaSaiz force-pushed the 16.0-imp-stock_warehouse_flow branch 2 times, most recently from 884f72b to 4495306 Compare March 16, 2026 10:54
@AdrianaSaiz AdrianaSaiz force-pushed the 16.0-imp-stock_warehouse_flow branch 3 times, most recently from 3c124aa to 13e5d9f Compare March 16, 2026 12:55
…k.move

Add a computed field that sums product_uom_qty of sibling moves
from the same sale order and warehouse. This allows flow domains
to evaluate per-warehouse quantities instead of global SO totals,
which is critical when a single SO is split across multiple
warehouses.

Without this field, all warehouses see the same total_products
from the SO, causing incorrect flow routing (e.g., a warehouse
handling 10 units gets routed as B2B because the SO total is 25).
@AdrianaSaiz AdrianaSaiz force-pushed the 16.0-imp-stock_warehouse_flow branch from 13e5d9f to 194b8d1 Compare March 16, 2026 14:55
AdrianaSaiz and others added 2 commits March 17, 2026 18:51
[FIX] stock_warehouse_flow : exclude not outgoing moves from wh_total…
Copy link
Copy Markdown
Contributor

@jbaudoux jbaudoux left a comment

Choose a reason for hiding this comment

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

The new field doesn't bring value to the engine itself.
It should be in a separate module.

If you have one delivery per warehouse, why you need to go back to the SO to count the total quantity per warehouse. Why don't you just sum the quantity of all the moves in the delivery?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants