Skip to content

[ADD] stock_ux: auto-activate multi-warehouse group for branch warehouses - #970

Open
mav-adhoc wants to merge 1 commit into
ingadhoc:19.0from
adhoc-dev:19.0-t-69369-mav
Open

[ADD] stock_ux: auto-activate multi-warehouse group for branch warehouses#970
mav-adhoc wants to merge 1 commit into
ingadhoc:19.0from
adhoc-dev:19.0-t-69369-mav

Conversation

@mav-adhoc

@mav-adhoc mav-adhoc commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

What

Make the standard Manage Multiple Warehouses group
(stock.group_stock_multi_warehouses) follow the warehouses of the whole
company tree: activate it when a company has branches (child
companies) that own warehouses — even with a single warehouse each — and turn
it off again when those warehouses, or their branches, are archived.

Why

Native stock.warehouse._check_multiwarehouse_group() counts active
warehouses grouped by company_id, and only activates the group when a
single company has more than one warehouse. A branch is a child
res.company with its own company_id, so a setup with one warehouse per
branch leaves the per-company count at 1 and the multi-warehouse UI is never
enabled. The behaviour is the same on 18.0; this generalizes the counting.

The other half is the way back. Archiving a company does not archive its
warehouses, and the native check only runs on warehouse create / archive /
unlink, so archiving a branch left the count untouched and the permission
on — with no way to turn it off from the interface: Settings refuses to
untick Storage Locations while multi-warehouse is implied
(res.config.settings.set_values), and multi-warehouse itself is not a
user-facing checkbox.

How

Override the method in stock_ux:

  • _multiwarehouse_count_by_root_company() counts active warehouses of
    active companies
    , aggregated by company_id.root_id (the top of the
    company tree), so a parent company and its branches count together.
  • _check_multiwarehouse_group() activates / deactivates on that count. For
    a company without branches root_id is the company itself, so nothing
    changes for non-branch setups.
  • res.company.write() re-runs the check when a company is archived or
    restored — the events that change which warehouses are in play and that the
    native method never sees. (The hierarchy itself cannot change afterwards:
    res.company.write refuses parent_id.)

Test plan

stock_ux/tests/test_multiwarehouse_group.py:

  • test_warehouses_are_counted_by_company_tree: parent + branch, one
    warehouse each, count 1 per company_id natively but 2 under the root.
  • test_branch_warehouse_activates_multi_wh_group: starting with the group
    not implied, creating a branch with a warehouse activates it.
  • test_archived_branch_deactivates_group: archiving the branch (its
    warehouse stays active) drops the count and removes the group.
  • test_unarchived_branch_activates_group_again: and restoring it puts the
    group back.
  • test_archived_branch_warehouse_deactivates_group: same going through the
    warehouse instead of the company.
  • test_single_warehouse_per_company_deactivates_group: no regression for
    setups without branches.

0 failed, 0 error(s) of 8 tests locally with -u stock_ux --test-enable --test-tags /stock_ux. Each piece was checked in isolation: dropping the
res.company hook, or the active-company filter in the count, makes
test_archived_branch_deactivates_group and
test_unarchived_branch_activates_group_again fail.

Task: https://www.adhoc.inc/odoo/my-tasks/69369

Copilot AI review requested due to automatic review settings July 3, 2026 16:21
@roboadhoc

Copy link
Copy Markdown
Collaborator

Pull request status dashboard

Copilot AI 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.

Pull request overview

Este PR mejora la UX de inventario en stock_ux activando automáticamente el grupo estándar “Gestionar varios almacenes” cuando existen sucursales (compañías hijas) con almacenes, agregando el conteo por árbol de compañías (company_id.root_id) en lugar de por compañía individual.

Changes:

  • Override de stock.warehouse._check_multiwarehouse_group() para calcular el máximo de almacenes activos por root company mediante un helper _multiwarehouse_max_count().
  • Nuevos tests para cubrir el escenario “madre + sucursal, 1 almacén por compañía” y la activación del grupo.
  • Actualización de README y bump de versión del módulo.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
stock_ux/models/stock_warehouse.py Override de la lógica de activación del grupo multi-almacén agregando el conteo por root_id.
stock_ux/models/init.py Export del nuevo archivo de modelo.
stock_ux/tests/test_multiwarehouse_group.py Tests nuevos para el conteo agregado por árbol y la activación del grupo.
stock_ux/tests/init.py Import del módulo de tests para su carga.
stock_ux/README.rst Documenta la nueva funcionalidad de auto-activación.
stock_ux/manifest.py Bump de versión del módulo.

Comment on lines +25 to +27
Warehouse = self.env["stock.warehouse"]
parent = self._create_company("UX Madre")
branch = self._create_company("UX Sucursal", parent=parent)
Comment on lines +47 to +49
group_user = self.env.ref("base.group_user")
group_multi_wh = self.env.ref("stock.group_stock_multi_warehouses")

@mav-adhoc
mav-adhoc force-pushed the 19.0-t-69369-mav branch 2 times, most recently from 36046e0 to f3f68af Compare July 3, 2026 16:46
…uses

Native stock._check_multiwarehouse_group counts active warehouses grouped
by company_id, so it only activates "Manage Multiple Warehouses" when a
single company has more than one warehouse. When a company uses branches
(child companies), each branch is a separate company_id with its own
warehouse, so the count stays at 1 per company and the group is never
activated.

Override the method in stock_ux to count the warehouses by company tree
(company_id.root_id), so a parent company and its branches are counted
together. The count also skips the warehouses of archived companies, and
the check now runs when a company is archived or restored: archiving a
branch does not archive its warehouse, so the count never went down and
the permission stayed on with no way to turn it off from the interface.

Includes tests covering the aggregation by company tree, the group
activation, the deactivation when the branch (or its warehouse) is
archived, and the unchanged behaviour for companies without branches.
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