diff --git a/.copier-answers.yml b/.copier-answers.yml index 06da8898b..42e7b58e0 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -1,5 +1,5 @@ # Do NOT update manually; changes here will be overwritten by Copier -_commit: v1.29 +_commit: v1.39 _src_path: gh:oca/oca-addons-repo-template ci: GitHub convert_readme_fragments_to_markdown: false diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index ccf084dfe..7b384a12b 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -17,6 +17,8 @@ jobs: - uses: actions/setup-python@v5 with: python-version: "3.11" + cache: 'pip' + cache-dependency-path: '.pre-commit-config.yaml' - name: Get python version run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV - uses: actions/cache@v4 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e691905c0..0d0951911 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,6 +63,13 @@ jobs: run: oca_init_test_database - name: Run tests run: oca_run_tests + - name: Upload screenshots from JS tests + uses: actions/upload-artifact@v4 + if: ${{ failure() }} + with: + name: Screenshots of failed JS tests - ${{ matrix.name }}${{ join(matrix.include) }} + path: /tmp/odoo_tests/${{ env.PGDATABASE }} + if-no-files-found: ignore - uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ca6bd4a4f..538eef120 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,7 +39,7 @@ repos: language: fail files: '[a-zA-Z0-9_]*/i18n/en\.po$' - repo: https://github.com/oca/maintainer-tools - rev: d5fab7ee87fceee858a3d01048c78a548974d935 + rev: f9b919b9868143135a9c9cb03021089cabba8223 hooks: # update the NOT INSTALLABLE ADDONS section above - id: oca-update-pre-commit-excluded-addons @@ -104,6 +104,7 @@ repos: additional_dependencies: - "eslint@v7.32.0" - "eslint-plugin-jsdoc@" + - "globals@" - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.0.1 hooks: @@ -140,7 +141,7 @@ repos: - --settings=. exclude: /__init__\.py$ - repo: https://github.com/acsone/setuptools-odoo - rev: 3.1.8 + rev: 3.3.2 hooks: - id: setuptools-odoo-make-default - id: setuptools-odoo-get-requirements diff --git a/.pylintrc b/.pylintrc index 449108e9b..672060146 100644 --- a/.pylintrc +++ b/.pylintrc @@ -25,19 +25,25 @@ disable=all enable=anomalous-backslash-in-string, api-one-deprecated, api-one-multi-together, - assignment-from-none, - attribute-deprecated, class-camelcase, - dangerous-default-value, dangerous-view-replace-wo-priority, - development-status-allowed, duplicate-id-csv, - duplicate-key, duplicate-xml-fields, duplicate-xml-record-id, eval-referenced, - eval-used, incoherent-interpreter-exec-perm, + openerp-exception-warning, + redundant-modulename-xml, + relative-import, + rst-syntax-error, + wrong-tabs-instead-of-spaces, + xml-syntax-error, + assignment-from-none, + attribute-deprecated, + dangerous-default-value, + development-status-allowed, + duplicate-key, + eval-used, license-allowed, manifest-author-string, manifest-deprecated-key, @@ -48,72 +54,67 @@ enable=anomalous-backslash-in-string, method-inverse, method-required-super, method-search, - openerp-exception-warning, pointless-statement, pointless-string-statement, print-used, redundant-keyword-arg, - redundant-modulename-xml, reimported, - relative-import, return-in-init, - rst-syntax-error, sql-injection, too-few-format-args, translation-field, translation-required, unreachable, use-vim-comment, - wrong-tabs-instead-of-spaces, - xml-syntax-error, - attribute-string-redundant, character-not-valid-in-resource-link, - consider-merging-classes-inherited, - context-overridden, create-user-wo-reset-password, dangerous-filter-wo-user, dangerous-qweb-replace-wo-priority, deprecated-data-xml-node, deprecated-openerp-xml-node, duplicate-po-message-definition, - except-pass, file-not-used, + missing-newline-extrafiles, + old-api7-method-defined, + po-msgstr-variables, + po-syntax-error, + str-format-used, + unnecessary-utf8-coding-comment, + xml-attribute-translatable, + xml-deprecated-qweb-directive, + xml-deprecated-tree-attribute, + attribute-string-redundant, + consider-merging-classes-inherited, + context-overridden, + except-pass, invalid-commit, manifest-maintainers-list, - missing-newline-extrafiles, missing-readme, missing-return, odoo-addons-relative-import, - old-api7-method-defined, - po-msgstr-variables, - po-syntax-error, renamed-field-parameter, resource-not-exist, - str-format-used, test-folder-imported, translation-contains-variable, translation-positional-used, - unnecessary-utf8-coding-comment, website-manifest-key-not-valid-uri, - xml-attribute-translatable, - xml-deprecated-qweb-directive, - xml-deprecated-tree-attribute, - # messages that do not cause the lint step to fail - consider-merging-classes-inherited, + missing-manifest-dependency, + too-complex,, create-user-wo-reset-password, dangerous-filter-wo-user, - deprecated-module, file-not-used, - invalid-commit, - missing-manifest-dependency, missing-newline-extrafiles, - missing-readme, no-utf8-coding-comment, - odoo-addons-relative-import, old-api7-method-defined, + unnecessary-utf8-coding-comment, + # messages that do not cause the lint step to fail + consider-merging-classes-inherited, + deprecated-module, + invalid-commit, + missing-readme, + odoo-addons-relative-import, redefined-builtin, - too-complex, - unnecessary-utf8-coding-comment + manifest-external-assets [REPORTS] diff --git a/.pylintrc-mandatory b/.pylintrc-mandatory index 164c82fd7..f0c568c64 100644 --- a/.pylintrc-mandatory +++ b/.pylintrc-mandatory @@ -17,19 +17,25 @@ disable=all enable=anomalous-backslash-in-string, api-one-deprecated, api-one-multi-together, - assignment-from-none, - attribute-deprecated, class-camelcase, - dangerous-default-value, dangerous-view-replace-wo-priority, - development-status-allowed, duplicate-id-csv, - duplicate-key, duplicate-xml-fields, duplicate-xml-record-id, eval-referenced, - eval-used, incoherent-interpreter-exec-perm, + openerp-exception-warning, + redundant-modulename-xml, + relative-import, + rst-syntax-error, + wrong-tabs-instead-of-spaces, + xml-syntax-error, + assignment-from-none, + attribute-deprecated, + dangerous-default-value, + development-status-allowed, + duplicate-key, + eval-used, license-allowed, manifest-author-string, manifest-deprecated-key, @@ -40,56 +46,50 @@ enable=anomalous-backslash-in-string, method-inverse, method-required-super, method-search, - openerp-exception-warning, pointless-statement, pointless-string-statement, print-used, redundant-keyword-arg, - redundant-modulename-xml, reimported, - relative-import, return-in-init, - rst-syntax-error, sql-injection, too-few-format-args, translation-field, translation-required, unreachable, use-vim-comment, - wrong-tabs-instead-of-spaces, - xml-syntax-error, - attribute-string-redundant, character-not-valid-in-resource-link, - consider-merging-classes-inherited, - context-overridden, create-user-wo-reset-password, dangerous-filter-wo-user, dangerous-qweb-replace-wo-priority, deprecated-data-xml-node, deprecated-openerp-xml-node, duplicate-po-message-definition, - except-pass, file-not-used, + missing-newline-extrafiles, + old-api7-method-defined, + po-msgstr-variables, + po-syntax-error, + str-format-used, + unnecessary-utf8-coding-comment, + xml-attribute-translatable, + xml-deprecated-qweb-directive, + xml-deprecated-tree-attribute, + attribute-string-redundant, + consider-merging-classes-inherited, + context-overridden, + except-pass, invalid-commit, manifest-maintainers-list, - missing-newline-extrafiles, missing-readme, missing-return, odoo-addons-relative-import, - old-api7-method-defined, - po-msgstr-variables, - po-syntax-error, renamed-field-parameter, resource-not-exist, - str-format-used, test-folder-imported, translation-contains-variable, translation-positional-used, - unnecessary-utf8-coding-comment, - website-manifest-key-not-valid-uri, - xml-attribute-translatable, - xml-deprecated-qweb-directive, - xml-deprecated-tree-attribute + website-manifest-key-not-valid-uri [REPORTS] msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg} diff --git a/README.md b/README.md index 13435b7e1..ea24da0a5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ +[![Support the OCA](https://odoo-community.org/readme-banner-image)](https://odoo-community.org/get-involved?utm_source=repo-readme) + +# community-data-files [![Runboat](https://img.shields.io/badge/runboat-Try%20me-875A7B.png)](https://runboat.odoo-community.org/builds?repo=OCA/community-data-files&target_branch=15.0) [![Pre-commit Status](https://github.com/OCA/community-data-files/actions/workflows/pre-commit.yml/badge.svg?branch=15.0)](https://github.com/OCA/community-data-files/actions/workflows/pre-commit.yml?query=branch%3A15.0) [![Build Status](https://github.com/OCA/community-data-files/actions/workflows/test.yml/badge.svg?branch=15.0)](https://github.com/OCA/community-data-files/actions/workflows/test.yml?query=branch%3A15.0) @@ -7,8 +10,6 @@ -# community-data-files - TODO: add repo description. diff --git a/company_sanitary_registry/__manifest__.py b/company_sanitary_registry/__manifest__.py index 852f6457b..d76e4b8a1 100644 --- a/company_sanitary_registry/__manifest__.py +++ b/company_sanitary_registry/__manifest__.py @@ -2,14 +2,14 @@ # License AGPL-3 - See https://www.gnu.org/licenses/agpl-3.0.html { "name": "Sanitary Registry", - "version": "15.0.2.0.0", - "depends": ["product"], + "version": "15.0.2.0.1", + "depends": ["stock"], "data": [ "security/ir.model.access.csv", "templates/sanitary_registry_template.xml", - "views/product_category_view.xml", "views/res_company_view.xml", "views/sanitary_registry_view.xml", + "views/sanitary_registry_warehouse_category_views.xml", ], "author": "Tecnativa, Odoo Community Association (OCA)", "website": "https://github.com/OCA/community-data-files", diff --git a/company_sanitary_registry/i18n/company_sanitary_registry.pot b/company_sanitary_registry/i18n/company_sanitary_registry.pot index 54af98976..f7cacefcf 100644 --- a/company_sanitary_registry/i18n/company_sanitary_registry.pot +++ b/company_sanitary_registry/i18n/company_sanitary_registry.pot @@ -6,6 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 15.0\n" "Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-02-17 09:49+0000\n" +"PO-Revision-Date: 2026-02-17 09:49+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -18,43 +20,60 @@ msgstr "" msgid "UE" msgstr "" +#. module: company_sanitary_registry +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category__category_id +msgid "Category" +msgstr "" + #. module: company_sanitary_registry #: model:ir.model,name:company_sanitary_registry.model_res_company msgid "Companies" msgstr "" +#. module: company_sanitary_registry +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category__category_complete_name +msgid "Complete Name" +msgstr "" + #. module: company_sanitary_registry #: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry__create_uid +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category__create_uid msgid "Created by" msgstr "" #. module: company_sanitary_registry #: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry__create_date +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category__create_date msgid "Created on" msgstr "" #. module: company_sanitary_registry #: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry__display_name +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category__display_name msgid "Display Name" msgstr "" #. module: company_sanitary_registry #: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry__id +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category__id msgid "ID" msgstr "" #. module: company_sanitary_registry #: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry____last_update +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category____last_update msgid "Last Modified on" msgstr "" #. module: company_sanitary_registry #: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry__write_uid +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category__write_uid msgid "Last Updated by" msgstr "" #. module: company_sanitary_registry #: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry__write_date +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category__write_date msgid "Last Updated on" msgstr "" @@ -64,11 +83,6 @@ msgstr "" msgid "Name" msgstr "" -#. module: company_sanitary_registry -#: model:ir.model,name:company_sanitary_registry.model_product_category -msgid "Product Category" -msgstr "" - #. module: company_sanitary_registry #: model:ir.actions.act_window,name:company_sanitary_registry.action_sanitary_registry #: model:ir.ui.menu,name:company_sanitary_registry.menu_action_sanitary_registry @@ -77,13 +91,29 @@ msgstr "" #. module: company_sanitary_registry #: model:ir.model,name:company_sanitary_registry.model_sanitary_registry -#: model:ir.model.fields,field_description:company_sanitary_registry.field_product_category__sanitary_registry_id #: model:ir.model.fields,field_description:company_sanitary_registry.field_res_company__sanitary_registry_id +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category__sanitary_registry_id msgid "Sanitary Registry" msgstr "" +#. module: company_sanitary_registry +#: model:ir.model,name:company_sanitary_registry.model_sanitary_registry_warehouse_category +msgid "Sanitary Registry Warehouse Category" +msgstr "" + +#. module: company_sanitary_registry +#: model:ir.actions.act_window,name:company_sanitary_registry.sanitary_registry_warehouse_category_action +#: model:ir.ui.menu,name:company_sanitary_registry.sanitary_registry_warehouse_category_menuitem +msgid "Sanitary Registry by Category and Warehouse" +msgstr "" + #. module: company_sanitary_registry #: code:addons/company_sanitary_registry/models/sanitary_registry.py:0 #, python-format msgid "There are already sanitary registrations with values %s." msgstr "" + +#. module: company_sanitary_registry +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category__warehouse_id +msgid "Warehouse" +msgstr "" diff --git a/company_sanitary_registry/i18n/es.po b/company_sanitary_registry/i18n/es.po index ef0d467a0..1de1ba4d4 100644 --- a/company_sanitary_registry/i18n/es.po +++ b/company_sanitary_registry/i18n/es.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 15.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-09-30 09:56+0000\n" -"PO-Revision-Date: 2025-09-30 12:00+0200\n" +"POT-Creation-Date: 2026-02-17 09:49+0000\n" +"PO-Revision-Date: 2026-02-17 10:51+0100\n" "Last-Translator: \n" "Language-Team: \n" "Language: es\n" @@ -15,50 +15,67 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -"X-Generator: Poedit 3.4.2\n" +"X-Generator: Poedit 3.8\n" #. module: company_sanitary_registry #: model_terms:ir.ui.view,arch_db:company_sanitary_registry.sanitary_registry_template msgid "UE" msgstr "" +#. module: company_sanitary_registry +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category__category_id +msgid "Category" +msgstr "Categoría" + #. module: company_sanitary_registry #: model:ir.model,name:company_sanitary_registry.model_res_company msgid "Companies" msgstr "Compañías" +#. module: company_sanitary_registry +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category__category_complete_name +msgid "Complete Name" +msgstr "Nombre Completo" + #. module: company_sanitary_registry #: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry__create_uid +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category__create_uid msgid "Created by" msgstr "Creado por" #. module: company_sanitary_registry #: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry__create_date +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category__create_date msgid "Created on" msgstr "Creado el" #. module: company_sanitary_registry #: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry__display_name +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category__display_name msgid "Display Name" msgstr "Nombre a mostrar" #. module: company_sanitary_registry #: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry__id +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category__id msgid "ID" msgstr "ID" #. module: company_sanitary_registry #: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry____last_update +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category____last_update msgid "Last Modified on" msgstr "Última modificación el" #. module: company_sanitary_registry #: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry__write_uid +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category__write_uid msgid "Last Updated by" msgstr "Última actualización por" #. module: company_sanitary_registry #: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry__write_date +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category__write_date msgid "Last Updated on" msgstr "Última actualización el" @@ -68,11 +85,6 @@ msgstr "Última actualización el" msgid "Name" msgstr "Nombre" -#. module: company_sanitary_registry -#: model:ir.model,name:company_sanitary_registry.model_product_category -msgid "Product Category" -msgstr "Categoría de producto" - #. module: company_sanitary_registry #: model:ir.actions.act_window,name:company_sanitary_registry.action_sanitary_registry #: model:ir.ui.menu,name:company_sanitary_registry.menu_action_sanitary_registry @@ -81,13 +93,29 @@ msgstr "Registros sanitarios" #. module: company_sanitary_registry #: model:ir.model,name:company_sanitary_registry.model_sanitary_registry -#: model:ir.model.fields,field_description:company_sanitary_registry.field_product_category__sanitary_registry_id #: model:ir.model.fields,field_description:company_sanitary_registry.field_res_company__sanitary_registry_id +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category__sanitary_registry_id msgid "Sanitary Registry" msgstr "Registro sanitario" +#. module: company_sanitary_registry +#: model:ir.model,name:company_sanitary_registry.model_sanitary_registry_warehouse_category +msgid "Sanitary Registry Warehouse Category" +msgstr "Registro sanitario por almacén y categoría" + +#. module: company_sanitary_registry +#: model:ir.actions.act_window,name:company_sanitary_registry.sanitary_registry_warehouse_category_action +#: model:ir.ui.menu,name:company_sanitary_registry.sanitary_registry_warehouse_category_menuitem +msgid "Sanitary Registry by Category and Warehouse" +msgstr "Registro sanitario por categoría y almacén" + #. module: company_sanitary_registry #: code:addons/company_sanitary_registry/models/sanitary_registry.py:0 #, python-format msgid "There are already sanitary registrations with values %s." msgstr "Ya existen registros sanitarios con los valores %s." + +#. module: company_sanitary_registry +#: model:ir.model.fields,field_description:company_sanitary_registry.field_sanitary_registry_warehouse_category__warehouse_id +msgid "Warehouse" +msgstr "Almacén" diff --git a/company_sanitary_registry/migrations/15.0.2.0.1/pre_migration.py b/company_sanitary_registry/migrations/15.0.2.0.1/pre_migration.py new file mode 100644 index 000000000..25f627dcc --- /dev/null +++ b/company_sanitary_registry/migrations/15.0.2.0.1/pre_migration.py @@ -0,0 +1,29 @@ +# Copyright 2025 Tecnativa - Carlos Roca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.logged_query( + env.cr, + """ + CREATE TABLE IF NOT EXISTS sanitary_registry_warehouse_category + ( + id serial primary key, + sanitary_registry_id integer, + categoy_id integer, + warehouse_id integer, + ) + """, + ) + openupgrade.logged_query( + env.cr, + """ + INSERT INTO sanitary_registry_warehouse_category (sanitary_registry_id, category_id) + SELECT sanitary_registry_id, id as category_id + FROM product_category + WHERE sanitary_registry_id IS NOT NULL; + """, + ) diff --git a/company_sanitary_registry/models/__init__.py b/company_sanitary_registry/models/__init__.py index af9301da7..20462f091 100644 --- a/company_sanitary_registry/models/__init__.py +++ b/company_sanitary_registry/models/__init__.py @@ -1,5 +1,5 @@ # Copyright 2023 Tecnativa - Carlos Roca # License AGPL-3 - See https://www.gnu.org/licenses/agpl-3.0.html -from . import product_category from . import res_company from . import sanitary_registry +from . import sanitary_registry_warehouse_category diff --git a/company_sanitary_registry/models/product_category.py b/company_sanitary_registry/models/product_category.py deleted file mode 100644 index 777c78eaa..000000000 --- a/company_sanitary_registry/models/product_category.py +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2025 Tecnativa - Carlos Roca -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl -from odoo import fields, models - - -class ProductCategory(models.Model): - _inherit = "product.category" - - sanitary_registry_id = fields.Many2one("sanitary.registry") - - def get_sanitary_registry(self): - self.ensure_one() - if self.sanitary_registry_id: - return self.sanitary_registry_id - elif self.parent_id: - return self.parent_id.get_sanitary_registry() - return self.sanitary_registry_id diff --git a/company_sanitary_registry/models/sanitary_registry_warehouse_category.py b/company_sanitary_registry/models/sanitary_registry_warehouse_category.py new file mode 100644 index 000000000..0a62c50a8 --- /dev/null +++ b/company_sanitary_registry/models/sanitary_registry_warehouse_category.py @@ -0,0 +1,38 @@ +# Copyright 2023 Tecnativa - Carlos Roca +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl +from odoo import api, fields, models + + +class SanitaryRegistryWarehouseCategory(models.Model): + _name = "sanitary.registry.warehouse.category" + _description = "Sanitary Registry Warehouse Category" + + sanitary_registry_id = fields.Many2one("sanitary.registry", required=True) + category_id = fields.Many2one("product.category") + category_complete_name = fields.Char(related="category_id.complete_name") + warehouse_id = fields.Many2one("stock.warehouse") + + @api.model + def get_active_sanitary_registry(self, category, warehouse): + """Method to get the most specific sanitary registry for a given + product category and warehouse. + """ + category_ids = [category.id] + while category.parent_id: + category = category.parent_id + category_ids.append(category.id) + sanitary_registries = self.search( + [ + "|", + ("category_id", "in", category_ids), + ("category_id", "=", False), + "|", + ("warehouse_id", "=", warehouse.id), + ("warehouse_id", "=", False), + ] + ) + sanitary_registry = sanitary_registries.sorted( + lambda sr: (sr.category_complete_name or "", 1 if sr.warehouse_id else 0), + reverse=True, + )[:1] + return sanitary_registry.sanitary_registry_id diff --git a/company_sanitary_registry/security/ir.model.access.csv b/company_sanitary_registry/security/ir.model.access.csv index f49046434..63a345d5d 100644 --- a/company_sanitary_registry/security/ir.model.access.csv +++ b/company_sanitary_registry/security/ir.model.access.csv @@ -1,3 +1,5 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_sanitary_registry_manager,access_sanitary_registry_manager,model_sanitary_registry,base.group_erp_manager,1,1,1,1 access_sanitary_registry_user,access_sanitary_registry_user,model_sanitary_registry,base.group_user,1,0,0,0 +access_sanitary_registry_warehouse_category_manager,access_sanitary_registry_warehouse_category_manager,model_sanitary_registry_warehouse_category,base.group_erp_manager,1,1,1,1 +access_sanitary_registry_warehouse_category_user,access_sanitary_registry_warehouse_category_user,model_sanitary_registry_warehouse_category,base.group_user,1,0,0,0 diff --git a/company_sanitary_registry/views/product_category_view.xml b/company_sanitary_registry/views/product_category_view.xml deleted file mode 100644 index 0ab9045ab..000000000 --- a/company_sanitary_registry/views/product_category_view.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - product.category - - - - - - - diff --git a/company_sanitary_registry/views/sanitary_registry_warehouse_category_views.xml b/company_sanitary_registry/views/sanitary_registry_warehouse_category_views.xml new file mode 100644 index 000000000..af5f0c142 --- /dev/null +++ b/company_sanitary_registry/views/sanitary_registry_warehouse_category_views.xml @@ -0,0 +1,30 @@ + + + + sanitary.registry.warehouse.category.tree + sanitary.registry.warehouse.category + + + + + + + + + + Sanitary Registry by Category and Warehouse + sanitary.registry.warehouse.category + tree + + + +