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

Copy link
Copy Markdown
Contributor

What

Auto-activate the standard Manage Several Warehouses group
(stock.group_stock_multi_warehouses) when a company has branches
(child companies) that own warehouses — even if each branch holds a single
warehouse.

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.

How

Override the method in stock_ux and aggregate the active-warehouse count by
company_id.root_id (the top of the company tree) via a small
_multiwarehouse_max_count() helper, so a parent company and its branches
are counted together. For a company without branches root_id is the
company itself, so behaviour is identical to the native method (no regression
for non-branch setups). The toggle logic (activate / deactivate) is kept
in sync with the native method.

Test plan

New stock_ux/tests/test_multiwarehouse_group.py:

  • test_branch_warehouses_share_root_and_aggregate: a parent + branch, each
    with one warehouse, count 1 per company_id natively but aggregate to >=2
    by root company tree.
  • test_branch_warehouse_activates_multi_wh_group: creating a branch with a
    warehouse activates the multi-warehouse group.

Both green locally (--test-tags /stock_ux).

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")

…uses

Native stock._check_multiwarehouse_group counts active warehouses grouped
by company_id, so it only activates the "Manage Several Warehouses" group
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 aggregate the warehouse count by
company_id.root_id (the top of the company tree), so a parent company and
its branches are counted together. For a company without branches root_id
is the company itself, so behaviour is identical to the native one.

Includes tests covering the tree aggregation and the effective group
activation.
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