From 3f16aa4aee2cefe77e46a43095e1472ffeaee79e Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Thu, 7 Nov 2024 11:43:36 +0100 Subject: [PATCH] [ADD] web_select_only_child_company --- .../odoo/addons/web_select_only_child_company | 1 + setup/web_select_only_child_company/setup.py | 6 + web_select_only_child_company/README.rst | 94 ++++ web_select_only_child_company/__init__.py | 1 + web_select_only_child_company/__manifest__.py | 24 + .../demo/res_company.xml | 29 ++ web_select_only_child_company/i18n/fr.po | 0 .../models/__init__.py | 2 + .../models/ir_http.py | 18 + .../models/res_company.py | 20 + .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 11 + .../readme/INSTALL.rst | 3 + .../static/description/index.html | 433 ++++++++++++++++++ .../static/src/js/switch_company_menu.esm.js | 29 ++ .../static/src/xml/switch_company_menu.xml | 29 ++ 16 files changed, 701 insertions(+) create mode 120000 setup/web_select_only_child_company/odoo/addons/web_select_only_child_company create mode 100644 setup/web_select_only_child_company/setup.py create mode 100644 web_select_only_child_company/README.rst create mode 100644 web_select_only_child_company/__init__.py create mode 100644 web_select_only_child_company/__manifest__.py create mode 100644 web_select_only_child_company/demo/res_company.xml create mode 100644 web_select_only_child_company/i18n/fr.po create mode 100644 web_select_only_child_company/models/__init__.py create mode 100644 web_select_only_child_company/models/ir_http.py create mode 100644 web_select_only_child_company/models/res_company.py create mode 100644 web_select_only_child_company/readme/CONTRIBUTORS.rst create mode 100644 web_select_only_child_company/readme/DESCRIPTION.rst create mode 100644 web_select_only_child_company/readme/INSTALL.rst create mode 100644 web_select_only_child_company/static/description/index.html create mode 100644 web_select_only_child_company/static/src/js/switch_company_menu.esm.js create mode 100644 web_select_only_child_company/static/src/xml/switch_company_menu.xml diff --git a/setup/web_select_only_child_company/odoo/addons/web_select_only_child_company b/setup/web_select_only_child_company/odoo/addons/web_select_only_child_company new file mode 120000 index 00000000..307dbbc1 --- /dev/null +++ b/setup/web_select_only_child_company/odoo/addons/web_select_only_child_company @@ -0,0 +1 @@ +../../../../web_select_only_child_company \ No newline at end of file diff --git a/setup/web_select_only_child_company/setup.py b/setup/web_select_only_child_company/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/web_select_only_child_company/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_select_only_child_company/README.rst b/web_select_only_child_company/README.rst new file mode 100644 index 00000000..d05ceee7 --- /dev/null +++ b/web_select_only_child_company/README.rst @@ -0,0 +1,94 @@ +======================= +Companies - Only Childs +======================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:c2242a93fd226bb64ee5d53346547d2491df28560f206b885f5df0c95804ad2b + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmulti--company-lightgray.png?logo=github + :target: https://github.com/OCA/multi-company/tree/16.0/res_company_select_only_childs + :alt: OCA/multi-company +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/multi-company-16-0/multi-company-16-0-res_company_select_only_childs + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/multi-company&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module is usefull in a multi-company context with hierarchy. +(with parent and child companies) + +Once installed, if a user select a company in the UI, +it will select all the child companies, and remove all the companies +that doesn't belong to the selected one. + +this module is usefull when you have a structure of companies +with parent and childs, and if it makes no sense to display parent information +without childs information. In that case, the users will save a lot of time +to select companies. + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* GRAP + +Contributors +~~~~~~~~~~~~ + +* Sylvain LE GAL + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-legalsylvain| image:: https://github.com/legalsylvain.png?size=40px + :target: https://github.com/legalsylvain + :alt: legalsylvain + +Current `maintainer `__: + +|maintainer-legalsylvain| + +This module is part of the `OCA/multi-company `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_select_only_child_company/__init__.py b/web_select_only_child_company/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/web_select_only_child_company/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/web_select_only_child_company/__manifest__.py b/web_select_only_child_company/__manifest__.py new file mode 100644 index 00000000..01cc0c1b --- /dev/null +++ b/web_select_only_child_company/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Companies - Only Childs", + "summary": "When selecting a company," + " automatically select all the child companies.", + "version": "16.0.1.0.0", + "category": "Tools", + "author": "GRAP, Odoo Community Association (OCA)", + "maintainers": ["legalsylvain"], + "website": "https://github.com/grap/grap-odoo-incubator", + "license": "AGPL-3", + "depends": ["web"], + "assets": { + "web.assets_backend": [ + "web_select_only_child_company/static/src/xml/switch_company_menu.xml", + "web_select_only_child_company/static/src/js/switch_company_menu.esm.js", + ], + }, + "demo": ["demo/res_company.xml"], + "installable": True, +} diff --git a/web_select_only_child_company/demo/res_company.xml b/web_select_only_child_company/demo/res_company.xml new file mode 100644 index 00000000..f8c63c40 --- /dev/null +++ b/web_select_only_child_company/demo/res_company.xml @@ -0,0 +1,29 @@ + + + + + Parent Company (Demo data Only Child) + + + + Child Company (Demo data Only Child) + + + + diff --git a/web_select_only_child_company/i18n/fr.po b/web_select_only_child_company/i18n/fr.po new file mode 100644 index 00000000..e69de29b diff --git a/web_select_only_child_company/models/__init__.py b/web_select_only_child_company/models/__init__.py new file mode 100644 index 00000000..ebe984e7 --- /dev/null +++ b/web_select_only_child_company/models/__init__.py @@ -0,0 +1,2 @@ +from . import ir_http +from . import res_company diff --git a/web_select_only_child_company/models/ir_http.py b/web_select_only_child_company/models/ir_http.py new file mode 100644 index 00000000..acd4311e --- /dev/null +++ b/web_select_only_child_company/models/ir_http.py @@ -0,0 +1,18 @@ +# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop) +# @author Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models + + +class Http(models.AbstractModel): + _inherit = "ir.http" + + def session_info(self): + result = super().session_info() + if self.env.user.has_group("base.group_user"): + for company in self.env.user.company_ids: + result["user_companies"]["allowed_companies"][company.id][ + "all_child_ids" + ] = company.all_child_ids.ids + return result diff --git a/web_select_only_child_company/models/res_company.py b/web_select_only_child_company/models/res_company.py new file mode 100644 index 00000000..17faa9d7 --- /dev/null +++ b/web_select_only_child_company/models/res_company.py @@ -0,0 +1,20 @@ +# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop) +# @author Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + all_child_ids = fields.One2many( + comodel_name="res.company", compute="_compute_all_child_ids", recursive=True + ) + + @api.depends("child_ids.all_child_ids") + def _compute_all_child_ids(self): + for company in self: + company.all_child_ids = company.mapped("child_ids") | company.mapped( + "child_ids.all_child_ids" + ) diff --git a/web_select_only_child_company/readme/CONTRIBUTORS.rst b/web_select_only_child_company/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..9f76a75b --- /dev/null +++ b/web_select_only_child_company/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Sylvain LE GAL diff --git a/web_select_only_child_company/readme/DESCRIPTION.rst b/web_select_only_child_company/readme/DESCRIPTION.rst new file mode 100644 index 00000000..3d2342a8 --- /dev/null +++ b/web_select_only_child_company/readme/DESCRIPTION.rst @@ -0,0 +1,11 @@ +This module is usefull in a multi-company context with hierarchy. +(with parent and child companies) + +Once installed, if a user select a company in the UI, +it will select all the child companies, and remove all the companies +that doesn't belong to the selected one. + +this module is usefull when you have a structure of companies +with parent and childs, and if it makes no sense to display parent information +without childs information. In that case, the users will save a lot of time +to select companies. diff --git a/web_select_only_child_company/readme/INSTALL.rst b/web_select_only_child_company/readme/INSTALL.rst new file mode 100644 index 00000000..1d4f2333 --- /dev/null +++ b/web_select_only_child_company/readme/INSTALL.rst @@ -0,0 +1,3 @@ +This module requires a patch in the core of odoo, available here. + +https://github.com/odoo/odoo/pull/186621 diff --git a/web_select_only_child_company/static/description/index.html b/web_select_only_child_company/static/description/index.html new file mode 100644 index 00000000..d23b4a7c --- /dev/null +++ b/web_select_only_child_company/static/description/index.html @@ -0,0 +1,433 @@ + + + + + +Companies - Only Childs + + + +
+

Companies - Only Childs

+ + +

Beta License: AGPL-3 OCA/multi-company Translate me on Weblate Try me on Runboat

+

This module is usefull in a multi-company context with hierarchy. +(with parent and child companies)

+

Once installed, if a user select a company in the UI, +it will select all the child companies, and remove all the companies +that doesn’t belong to the selected one.

+

this module is usefull when you have a structure of companies +with parent and childs, and if it makes no sense to display parent information +without childs information. In that case, the users will save a lot of time +to select companies.

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • GRAP
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

legalsylvain

+

This module is part of the OCA/multi-company project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/web_select_only_child_company/static/src/js/switch_company_menu.esm.js b/web_select_only_child_company/static/src/js/switch_company_menu.esm.js new file mode 100644 index 00000000..cc319be4 --- /dev/null +++ b/web_select_only_child_company/static/src/js/switch_company_menu.esm.js @@ -0,0 +1,29 @@ +/** @odoo-module **/ +/* +Copyright (C) 2024 - Today: GRAP (http://www.grap.coop) +# @author Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +*/ + +import { SwitchCompanyMenu } from "@web/webclient/switch_company_menu/switch_company_menu"; +import { browser } from "@web/core/browser/browser"; +import { patch } from "@web/core/utils/patch"; +import { session } from "@web/session"; +import { symmetricalDifference } from "@web/core/utils/arrays"; + +patch( + SwitchCompanyMenu.prototype, + "web_select_only_child_company.SwitchCompanyMenu", + { + logIntoCompany(companyId) { + browser.clearTimeout(this.toggleTimer); + var newCompanyIds = [companyId].concat(session.user_companies.allowed_companies[companyId].all_child_ids); + var companiesToToggle = symmetricalDifference(this.companyService.allowedCompanyIds, newCompanyIds); + if (companiesToToggle.length !== 0) { + this.companyService.setCompanies("switch", ...newCompanyIds); + } + }, + } +); + +export default SwitchCompanyMenu; diff --git a/web_select_only_child_company/static/src/xml/switch_company_menu.xml b/web_select_only_child_company/static/src/xml/switch_company_menu.xml new file mode 100644 index 00000000..2e352ba9 --- /dev/null +++ b/web_select_only_child_company/static/src/xml/switch_company_menu.xml @@ -0,0 +1,29 @@ + + + + + + + () => this.logIntoCompany(company.id) + + + + + + + () => this.logIntoCompany(company.id) + + +