From 19af717773c117c9067b39410e4d582c22b534d2 Mon Sep 17 00:00:00 2001 From: luis Date: Thu, 4 Dec 2025 18:28:18 +0100 Subject: [PATCH] Criptomart/red-supermercados-coop#6 add stock_valuation_layer_category_groupby --- .../README.md | 57 +++++++++++++++++++ .../__init__.py | 1 + .../__manifest__.py | 13 +++++ .../i18n/es.po | 32 +++++++++++ ...stock_valuation_layer_category_groupby.pot | 32 +++++++++++ .../models/__init__.py | 1 + .../models/stock_valuation_layer.py | 11 ++++ .../views/stock_valuation_layer_views.xml | 20 +++++++ 8 files changed, 167 insertions(+) create mode 100644 stock_valuation_layer_category_groupby/README.md create mode 100644 stock_valuation_layer_category_groupby/__init__.py create mode 100644 stock_valuation_layer_category_groupby/__manifest__.py create mode 100644 stock_valuation_layer_category_groupby/i18n/es.po create mode 100644 stock_valuation_layer_category_groupby/i18n/stock_valuation_layer_category_groupby.pot create mode 100644 stock_valuation_layer_category_groupby/models/__init__.py create mode 100644 stock_valuation_layer_category_groupby/models/stock_valuation_layer.py create mode 100644 stock_valuation_layer_category_groupby/views/stock_valuation_layer_views.xml diff --git a/stock_valuation_layer_category_groupby/README.md b/stock_valuation_layer_category_groupby/README.md new file mode 100644 index 0000000..786397b --- /dev/null +++ b/stock_valuation_layer_category_groupby/README.md @@ -0,0 +1,57 @@ +# Stock Valuation Layer Category Groupby + +## Description + +This module allows grouping by product category in the stock valuation layer reports. + +### Problem + +By default, the `categ_id` field in `stock.valuation.layer` is a related field without storage (`store=False`). This means it cannot be used for grouping in reports and pivot views, even though it can be used for filtering and searching. + +### Solution + +This module makes the `categ_id` field stored (`store=True`) and indexed, which enables: +- Grouping by product category in list views +- Grouping by product category in pivot views +- Grouping by product category in graph views +- Better performance when filtering by category + +## Installation + +1. Install the module from the Apps menu +2. The field will be automatically populated for existing records + +## Usage + +After installation: +1. Go to Inventory > Reporting > Inventory Valuation +2. Switch to Pivot or Graph view +3. Click on "Measures" or group options +4. You will now see "Product Category" available for grouping + +## Technical Details + +The module extends `stock.valuation.layer` model and modifies the `categ_id` field to: +- `store=True`: Store the value in the database +- `index=True`: Add database index for better performance + +The field remains a related field, so it will automatically update when the product category changes. + +## Bug Tracker + +Bugs are tracked on [GitHub Issues](https://github.com/OCA/stock-logistics-warehouse/issues). + +## Credits + +### Contributors + +* Criptomart + +### Maintainers + +This module is maintained by the OCA. + +## Compatibility + +- Odoo 16.0 +- stock_account diff --git a/stock_valuation_layer_category_groupby/__init__.py b/stock_valuation_layer_category_groupby/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/stock_valuation_layer_category_groupby/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_valuation_layer_category_groupby/__manifest__.py b/stock_valuation_layer_category_groupby/__manifest__.py new file mode 100644 index 0000000..441c065 --- /dev/null +++ b/stock_valuation_layer_category_groupby/__manifest__.py @@ -0,0 +1,13 @@ +# Copyright 2025 Criptomart +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Stock Valuation Layer Category Groupby", + "version": "16.0.1.0.0", + "summary": "Allow grouping by product category in stock valuation layer reports", + "license": "AGPL-3", + "author": "Criptomart", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "depends": ["stock_account"], + "data": ["views/stock_valuation_layer_views.xml"], + "installable": True, +} diff --git a/stock_valuation_layer_category_groupby/i18n/es.po b/stock_valuation_layer_category_groupby/i18n/es.po new file mode 100644 index 0000000..ed1f2fd --- /dev/null +++ b/stock_valuation_layer_category_groupby/i18n/es.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_valuation_layer_category_groupby +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-12-04 17:24+0000\n" +"PO-Revision-Date: 2025-12-04 17:24+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: stock_valuation_layer_category_groupby +#: model:ir.model.fields,field_description:stock_valuation_layer_category_groupby.field_stock_valuation_layer__categ_id +#: model_terms:ir.ui.view,arch_db:stock_valuation_layer_category_groupby.view_inventory_valuation_search_category +msgid "Product Category" +msgstr "Categoría de producto" + +#. module: stock_valuation_layer_category_groupby +#: model:ir.model.fields,field_description:stock_valuation_layer_category_groupby.field_stock_valuation_layer__smart_search +msgid "Smart Search" +msgstr "Búsqueda inteligente" + +#. module: stock_valuation_layer_category_groupby +#: model:ir.model,name:stock_valuation_layer_category_groupby.model_stock_valuation_layer +msgid "Stock Valuation Layer" +msgstr "Nivel de Valoración de Existencias" diff --git a/stock_valuation_layer_category_groupby/i18n/stock_valuation_layer_category_groupby.pot b/stock_valuation_layer_category_groupby/i18n/stock_valuation_layer_category_groupby.pot new file mode 100644 index 0000000..3cb8e99 --- /dev/null +++ b/stock_valuation_layer_category_groupby/i18n/stock_valuation_layer_category_groupby.pot @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_valuation_layer_category_groupby +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-12-04 17:24+0000\n" +"PO-Revision-Date: 2025-12-04 17:24+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: stock_valuation_layer_category_groupby +#: model:ir.model.fields,field_description:stock_valuation_layer_category_groupby.field_stock_valuation_layer__categ_id +#: model_terms:ir.ui.view,arch_db:stock_valuation_layer_category_groupby.view_inventory_valuation_search_category +msgid "Product Category" +msgstr "" + +#. module: stock_valuation_layer_category_groupby +#: model:ir.model.fields,field_description:stock_valuation_layer_category_groupby.field_stock_valuation_layer__smart_search +msgid "Smart Search" +msgstr "" + +#. module: stock_valuation_layer_category_groupby +#: model:ir.model,name:stock_valuation_layer_category_groupby.model_stock_valuation_layer +msgid "Stock Valuation Layer" +msgstr "" diff --git a/stock_valuation_layer_category_groupby/models/__init__.py b/stock_valuation_layer_category_groupby/models/__init__.py new file mode 100644 index 0000000..f75b2df --- /dev/null +++ b/stock_valuation_layer_category_groupby/models/__init__.py @@ -0,0 +1 @@ +from . import stock_valuation_layer diff --git a/stock_valuation_layer_category_groupby/models/stock_valuation_layer.py b/stock_valuation_layer_category_groupby/models/stock_valuation_layer.py new file mode 100644 index 0000000..bba7017 --- /dev/null +++ b/stock_valuation_layer_category_groupby/models/stock_valuation_layer.py @@ -0,0 +1,11 @@ +# Copyright 2025 Criptomart +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class StockValuationLayer(models.Model): + _inherit = "stock.valuation.layer" + + # Make categ_id stored to allow grouping in reports + categ_id = fields.Many2one(store=True, index=True) diff --git a/stock_valuation_layer_category_groupby/views/stock_valuation_layer_views.xml b/stock_valuation_layer_category_groupby/views/stock_valuation_layer_views.xml new file mode 100644 index 0000000..c202e4b --- /dev/null +++ b/stock_valuation_layer_category_groupby/views/stock_valuation_layer_views.xml @@ -0,0 +1,20 @@ + + + + + + stock.valuation.layer.search.category + stock.valuation.layer + + + + + + + + +