diff --git a/base_portal_type/README.rst b/base_portal_type/README.rst new file mode 100644 index 000000000..e383e9c06 --- /dev/null +++ b/base_portal_type/README.rst @@ -0,0 +1,113 @@ +============ +Portal types +============ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:f6552e1fb54368304e258e85090d45598992675542c1fef6b16f439950226f68 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |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%2Fserver--backend-lightgray.png?logo=github + :target: https://github.com/OCA/server-backend/tree/18.0/base_portal_type + :alt: OCA/server-backend +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-backend-18-0/server-backend-18-0-base_portal_type + :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/server-backend&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows administrator to configure groups for portal users, +which is not possible with standard Odoo. + +That's useful for having different types of portal users (think +differentiate vendors from customers) and leveraging Odoo's group +mechanism for ie views instead having to cook up custom solutions. + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +1. create a group of category ``base_portal_type.category_portal_type`` +2. observe the group shows up on a user form for users of type Portal +3. now you can use this group in your frontend templates and code to + make some features accessible to this group + +Known issues / Roadmap +====================== + +- allowing to chose portal groups in the portal wizard would be nice + +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 +------- + +* Hunki Enterprises BV + +Contributors +------------ + +- Holger Brunn + (https://hunki-enterprises.com) +- `Heliconia Solutions Pvt. Ltd. `__ + + - Bhavesh Heliconia + +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-hbrunn| image:: https://github.com/hbrunn.png?size=40px + :target: https://github.com/hbrunn + :alt: hbrunn + +Current `maintainer `__: + +|maintainer-hbrunn| + +This module is part of the `OCA/server-backend `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_portal_type/__init__.py b/base_portal_type/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/base_portal_type/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/base_portal_type/__manifest__.py b/base_portal_type/__manifest__.py new file mode 100644 index 000000000..33858100d --- /dev/null +++ b/base_portal_type/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2023 Hunki Enterprises BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + +{ + "name": "Portal types", + "summary": "Base module to allow different types of portals", + "version": "18.0.1.0.0", + "development_status": "Alpha", + "category": "Technical", + "website": "https://github.com/OCA/server-backend", + "author": "Hunki Enterprises BV, Odoo Community Association (OCA)", + "maintainers": ["hbrunn"], + "license": "AGPL-3", + "depends": [ + "portal", + ], + "data": [ + "data/ir_module_category.xml", + ], + "demo": [ + "demo/res_groups.xml", + ], +} diff --git a/base_portal_type/data/ir_module_category.xml b/base_portal_type/data/ir_module_category.xml new file mode 100644 index 000000000..09683132b --- /dev/null +++ b/base_portal_type/data/ir_module_category.xml @@ -0,0 +1,8 @@ + + + + + Portal type + + diff --git a/base_portal_type/demo/res_groups.xml b/base_portal_type/demo/res_groups.xml new file mode 100644 index 000000000..3b375dc1b --- /dev/null +++ b/base_portal_type/demo/res_groups.xml @@ -0,0 +1,9 @@ + + + + + A portal type + + + diff --git a/base_portal_type/i18n/base_portal_type.pot b/base_portal_type/i18n/base_portal_type.pot new file mode 100644 index 000000000..b4d1d60d0 --- /dev/null +++ b/base_portal_type/i18n/base_portal_type.pot @@ -0,0 +1,29 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_portal_type +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \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: base_portal_type +#: model:res.groups,name:base_portal_type.group_portal_type +msgid "A portal type" +msgstr "" + +#. module: base_portal_type +#: model:ir.model,name:base_portal_type.model_res_groups +msgid "Access Groups" +msgstr "" + +#. module: base_portal_type +#: model:ir.module.category,name:base_portal_type.category_portal_type +msgid "Portal type" +msgstr "" diff --git a/base_portal_type/i18n/it.po b/base_portal_type/i18n/it.po new file mode 100644 index 000000000..cbe86b476 --- /dev/null +++ b/base_portal_type/i18n/it.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_portal_type +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-01-03 14:34+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: base_portal_type +#: model:res.groups,name:base_portal_type.group_portal_type +msgid "A portal type" +msgstr "Un tipo portale" + +#. module: base_portal_type +#: model:ir.model,name:base_portal_type.model_res_groups +msgid "Access Groups" +msgstr "Gruppi di accesso" + +#. module: base_portal_type +#: model:ir.module.category,name:base_portal_type.category_portal_type +msgid "Portal type" +msgstr "Tipo portale" diff --git a/base_portal_type/models/__init__.py b/base_portal_type/models/__init__.py new file mode 100644 index 000000000..9a3f975b7 --- /dev/null +++ b/base_portal_type/models/__init__.py @@ -0,0 +1 @@ +from . import res_groups diff --git a/base_portal_type/models/res_groups.py b/base_portal_type/models/res_groups.py new file mode 100644 index 000000000..30728b992 --- /dev/null +++ b/base_portal_type/models/res_groups.py @@ -0,0 +1,79 @@ +# Copyright 2023 Hunki Enterprises BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + + +from lxml import etree + +from odoo import api, models + +from odoo.addons.base.models.res_users import name_boolean_group, name_selection_groups + + +class ResGroups(models.Model): + _inherit = "res.groups" + + @api.model + def _update_user_groups_view(self): + result = super()._update_user_groups_view() + view = self.env.ref("base.user_groups_view") + arch = etree.fromstring(view.arch) + user_type_groups = [ + groups + for app, kind, groups, category in self.get_groups_by_application() + if app.xml_id == "base.module_category_user_type" + ][0] + portal_group = self.env.ref("base.group_portal") + internal_group = self.env.ref("base.group_user") + portal_groups = ( + self.env["res.groups"] + .with_context(lang=None) + .search( + [ + ( + "category_id", + "=", + self.env.ref("base_portal_type.category_portal_type").id, + ), + ] + ) + ) + user_type_field = name_selection_groups(user_type_groups.ids) + for node in arch.xpath(f"//group/field[@name='{user_type_field}']"): + for group in portal_groups: + field_name = name_boolean_group(group.id) + for field_node in arch.xpath(f"//field[@name='{field_name}']"): + field_node.attrib["readonly"] = ( + f"{user_type_field} not in " + f"{(portal_group + internal_group).ids}" + ) + node.addnext( + etree.Element( + "field", + { + "name": field_name, + "on_change": "1", + "invisible": f"{user_type_field} != {portal_group.id}", + }, + ) + ) + view_context = dict(self.env.context, lang=None) + view_context.pop("install_filename", None) + # pylint: disable=context-overridden + view.with_context(view_context).write( + {"arch": etree.tostring(arch, pretty_print=True, encoding="unicode")} + ) + return result + + @api.model + def get_groups_by_application(self): + return [ + ( + app, + kind + if app.xml_id != "base_portal_type.category_portal_type" + else "boolean", + groups, + category, + ) + for app, kind, groups, category in super().get_groups_by_application() + ] diff --git a/base_portal_type/pyproject.toml b/base_portal_type/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/base_portal_type/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/base_portal_type/readme/CONTRIBUTORS.md b/base_portal_type/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..6bce0da10 --- /dev/null +++ b/base_portal_type/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- Holger Brunn \ + () +- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) + - Bhavesh Heliconia diff --git a/base_portal_type/readme/DESCRIPTION.md b/base_portal_type/readme/DESCRIPTION.md new file mode 100644 index 000000000..464393153 --- /dev/null +++ b/base_portal_type/readme/DESCRIPTION.md @@ -0,0 +1,6 @@ +This module allows administrator to configure groups for portal users, +which is not possible with standard Odoo. + +That's useful for having different types of portal users (think +differentiate vendors from customers) and leveraging Odoo's group +mechanism for ie views instead having to cook up custom solutions. diff --git a/base_portal_type/readme/ROADMAP.md b/base_portal_type/readme/ROADMAP.md new file mode 100644 index 000000000..04bcdd8e0 --- /dev/null +++ b/base_portal_type/readme/ROADMAP.md @@ -0,0 +1 @@ +- allowing to chose portal groups in the portal wizard would be nice diff --git a/base_portal_type/readme/USAGE.md b/base_portal_type/readme/USAGE.md new file mode 100644 index 000000000..7e346460a --- /dev/null +++ b/base_portal_type/readme/USAGE.md @@ -0,0 +1,6 @@ +To use this module, you need to: + +1. create a group of category `base_portal_type.category_portal_type` +2. observe the group shows up on a user form for users of type Portal +3. now you can use this group in your frontend templates and code to + make some features accessible to this group diff --git a/base_portal_type/static/description/icon.png b/base_portal_type/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/base_portal_type/static/description/icon.png differ diff --git a/base_portal_type/static/description/index.html b/base_portal_type/static/description/index.html new file mode 100644 index 000000000..45ab01b10 --- /dev/null +++ b/base_portal_type/static/description/index.html @@ -0,0 +1,458 @@ + + + + + +Portal types + + + +
+

Portal types

+ + +

Alpha License: AGPL-3 OCA/server-backend Translate me on Weblate Try me on Runboat

+

This module allows administrator to configure groups for portal users, +which is not possible with standard Odoo.

+

That’s useful for having different types of portal users (think +differentiate vendors from customers) and leveraging Odoo’s group +mechanism for ie views instead having to cook up custom solutions.

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. create a group of category base_portal_type.category_portal_type
  2. +
  3. observe the group shows up on a user form for users of type Portal
  4. +
  5. now you can use this group in your frontend templates and code to +make some features accessible to this group
  6. +
+
+
+

Known issues / Roadmap

+
    +
  • allowing to chose portal groups in the portal wizard would be nice
  • +
+
+
+

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

+
    +
  • Hunki Enterprises BV
  • +
+
+ +
+

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:

+

hbrunn

+

This module is part of the OCA/server-backend project on GitHub.

+

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

+
+
+
+ + diff --git a/base_portal_type/tests/__init__.py b/base_portal_type/tests/__init__.py new file mode 100644 index 000000000..e34149cc7 --- /dev/null +++ b/base_portal_type/tests/__init__.py @@ -0,0 +1 @@ +from . import test_base_portal_type diff --git a/base_portal_type/tests/test_base_portal_type.py b/base_portal_type/tests/test_base_portal_type.py new file mode 100644 index 000000000..c61d2ce1c --- /dev/null +++ b/base_portal_type/tests/test_base_portal_type.py @@ -0,0 +1,20 @@ +# Copyright 2023 Hunki Enterprises BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) + + +from lxml import etree + +from odoo.tests.common import TransactionCase + +from odoo.addons.base.models.res_users import name_boolean_group + + +class TestBasePortalGroup(TransactionCase): + def test_portal_group_view(self): + """Test that our group is added to the users form twice""" + group = self.env.ref("base_portal_type.group_portal_type").copy() + group_field_name = name_boolean_group(group.id) + groups_view = etree.fromstring(self.env.ref("base.user_groups_view").arch) + self.assertEqual( + len(groups_view.xpath(f"//field[@name='{group_field_name}']")), 3 + )