diff --git a/l10n_be_cooperator_portal_national_number/README.rst b/l10n_be_cooperator_portal_national_number/README.rst new file mode 100644 index 000000000..e8998b010 --- /dev/null +++ b/l10n_be_cooperator_portal_national_number/README.rst @@ -0,0 +1,86 @@ +========================================== +Belgium: Cooperator Portal National Number +========================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:edd0ec10bd9936397267e9ce09d6d46850863b5f8a89c63ac389fd0239fd0b22 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fcooperative-lightgray.png?logo=github + :target: https://github.com/OCA/cooperative/tree/16.0/l10n_be_cooperator_portal_national_number + :alt: OCA/cooperative +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/cooperative-16-0/cooperative-16-0-l10n_be_cooperator_portal_national_number + :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/cooperative&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Add the ability to change national number on the account portal. + +**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 +~~~~~~~ + +* Coop IT Easy SC + +Contributors +~~~~~~~~~~~~ + +* `Coop IT Easy SC `_: + + * Carmen Bianca BAKKER + +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-carmenbianca| image:: https://github.com/carmenbianca.png?size=40px + :target: https://github.com/carmenbianca + :alt: carmenbianca + +Current `maintainer `__: + +|maintainer-carmenbianca| + +This module is part of the `OCA/cooperative `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/l10n_be_cooperator_portal_national_number/__init__.py b/l10n_be_cooperator_portal_national_number/__init__.py new file mode 100644 index 000000000..c6177db79 --- /dev/null +++ b/l10n_be_cooperator_portal_national_number/__init__.py @@ -0,0 +1,6 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from . import controllers +from . import models diff --git a/l10n_be_cooperator_portal_national_number/__manifest__.py b/l10n_be_cooperator_portal_national_number/__manifest__.py new file mode 100644 index 000000000..c61d69ac6 --- /dev/null +++ b/l10n_be_cooperator_portal_national_number/__manifest__.py @@ -0,0 +1,22 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +{ + "name": "Belgium: Cooperator Portal National Number", + "summary": """ + Add the ability to change national number on the account portal.""", + "version": "16.0.1.0.0", + "category": "Cooperative management", + "website": "https://github.com/OCA/cooperative", + "author": "Coop IT Easy SC, Odoo Community Association (OCA)", + "maintainers": ["carmenbianca"], + "license": "AGPL-3", + "application": False, + "depends": [ + "cooperator_portal", + "l10n_be_cooperator_national_number", + ], + "auto_install": True, + "data": ["views/portal_templates.xml"], +} diff --git a/l10n_be_cooperator_portal_national_number/controllers/__init__.py b/l10n_be_cooperator_portal_national_number/controllers/__init__.py new file mode 100644 index 000000000..9a42f94f3 --- /dev/null +++ b/l10n_be_cooperator_portal_national_number/controllers/__init__.py @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from . import portal diff --git a/l10n_be_cooperator_portal_national_number/controllers/portal.py b/l10n_be_cooperator_portal_national_number/controllers/portal.py new file mode 100644 index 000000000..07e29b71a --- /dev/null +++ b/l10n_be_cooperator_portal_national_number/controllers/portal.py @@ -0,0 +1,59 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + + +from odoo import _ +from odoo.http import request, route + +from odoo.addons.account.controllers.portal import PortalAccount + + +class CooperatorPortal(PortalAccount): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + # See cooportal_portal/controllers/portal.py for why this code is the + # way it is. + if "OPTIONAL_BILLING_FIELDS" not in vars(self): + self.OPTIONAL_BILLING_FIELDS = PortalAccount.OPTIONAL_BILLING_FIELDS.copy() + self.OPTIONAL_BILLING_FIELDS.extend(["national_number"]) + + def _prepare_portal_layout_values(self): + values = super()._prepare_portal_layout_values() + values[ + "display_national_number" + ] = request.env.company.get_display_national_number( + request.env.user.partner_id.is_company + ) + national_number = request.env.user.partner_id.get_be_national_register_number() + values["national_number"] = national_number + return values + + def details_form_validate(self, data): + error, error_message = super().details_form_validate(data) + national_number = data.get("national_number") + if national_number: + valid = request.env["res.partner"].validate_be_national_register_number( + national_number + ) + if not valid: + error["national_number"] = "error" + error_message.append(_("The national number is not valid.")) + # Normally this should be in MANDATORY_BILLING_FIELDS, but national + # number is conditionally required, which is tricky. + if not national_number and request.env.company.get_require_national_number( + request.env.user.partner_id.is_company + ): + error["national_number"] = "error" + error_message.append(_("The national number is required.")) + return error, error_message + + @route(["/my/account"], type="http", auth="user", website=True) + def account(self, redirect=None, **post): + res = super().account(redirect, **post) + if not res.qcontext.get("error"): + national_number = post.get("national_number") + request.env.user.partner_id.sudo().update_be_national_register_number( + national_number + ) + return res diff --git a/l10n_be_cooperator_portal_national_number/models/__init__.py b/l10n_be_cooperator_portal_national_number/models/__init__.py new file mode 100644 index 000000000..d2b367253 --- /dev/null +++ b/l10n_be_cooperator_portal_national_number/models/__init__.py @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2022 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from . import res_partner diff --git a/l10n_be_cooperator_portal_national_number/models/res_partner.py b/l10n_be_cooperator_portal_national_number/models/res_partner.py new file mode 100644 index 000000000..1c822c2db --- /dev/null +++ b/l10n_be_cooperator_portal_national_number/models/res_partner.py @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: 2022 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from odoo import models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + def write(self, vals): + # For an explanation, see res_partner of cooperator_portal. + if "national_number" in vals: + del vals["national_number"] + return super().write(vals) diff --git a/l10n_be_cooperator_portal_national_number/readme/CONTRIBUTORS.rst b/l10n_be_cooperator_portal_national_number/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..55fb3ceb8 --- /dev/null +++ b/l10n_be_cooperator_portal_national_number/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Coop IT Easy SC `_: + + * Carmen Bianca BAKKER diff --git a/l10n_be_cooperator_portal_national_number/readme/DESCRIPTION.rst b/l10n_be_cooperator_portal_national_number/readme/DESCRIPTION.rst new file mode 100644 index 000000000..fc4b524de --- /dev/null +++ b/l10n_be_cooperator_portal_national_number/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Add the ability to change national number on the account portal. diff --git a/l10n_be_cooperator_portal_national_number/static/description/index.html b/l10n_be_cooperator_portal_national_number/static/description/index.html new file mode 100644 index 000000000..5799b5fb1 --- /dev/null +++ b/l10n_be_cooperator_portal_national_number/static/description/index.html @@ -0,0 +1,425 @@ + + + + + +Belgium: Cooperator Portal National Number + + + +
+

Belgium: Cooperator Portal National Number

+ + +

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

+

Add the ability to change national number on the account portal.

+

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

+
    +
  • Coop IT Easy SC
  • +
+
+
+

Contributors

+ +
+
+

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:

+

carmenbianca

+

This module is part of the OCA/cooperative project on GitHub.

+

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

+
+
+
+ + diff --git a/l10n_be_cooperator_portal_national_number/views/portal_templates.xml b/l10n_be_cooperator_portal_national_number/views/portal_templates.xml new file mode 100644 index 000000000..1d1ce1f6f --- /dev/null +++ b/l10n_be_cooperator_portal_national_number/views/portal_templates.xml @@ -0,0 +1,34 @@ + + + + + + + diff --git a/setup/l10n_be_cooperator_portal_national_number/odoo/addons/l10n_be_cooperator_portal_national_number b/setup/l10n_be_cooperator_portal_national_number/odoo/addons/l10n_be_cooperator_portal_national_number new file mode 120000 index 000000000..29c152557 --- /dev/null +++ b/setup/l10n_be_cooperator_portal_national_number/odoo/addons/l10n_be_cooperator_portal_national_number @@ -0,0 +1 @@ +../../../../l10n_be_cooperator_portal_national_number \ No newline at end of file diff --git a/setup/l10n_be_cooperator_portal_national_number/setup.py b/setup/l10n_be_cooperator_portal_national_number/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/l10n_be_cooperator_portal_national_number/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)