Skip to content

Commit

Permalink
[ADD] l10n_be_cooperator_portal_national_number
Browse files Browse the repository at this point in the history
Signed-off-by: Carmen Bianca BAKKER <[email protected]>
  • Loading branch information
carmenbianca committed Jun 13, 2024
1 parent a05eb10 commit ff523dc
Show file tree
Hide file tree
Showing 13 changed files with 668 additions and 0 deletions.
86 changes: 86 additions & 0 deletions l10n_be_cooperator_portal_national_number/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/OCA/cooperative/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 <https://github.com/OCA/cooperative/issues/new?body=module:%20l10n_be_cooperator_portal_national_number%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* Coop IT Easy SC

Contributors
~~~~~~~~~~~~

* `Coop IT Easy SC <https://github.com/OCA/cooperative>`_:

* 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 <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-carmenbianca|

This module is part of the `OCA/cooperative <https://github.com/OCA/cooperative/tree/16.0/l10n_be_cooperator_portal_national_number>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
6 changes: 6 additions & 0 deletions l10n_be_cooperator_portal_national_number/__init__.py
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions l10n_be_cooperator_portal_national_number/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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"],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later

from . import portal
59 changes: 59 additions & 0 deletions l10n_be_cooperator_portal_national_number/controllers/portal.py
Original file line number Diff line number Diff line change
@@ -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)

Check warning on line 14 in l10n_be_cooperator_portal_national_number/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

l10n_be_cooperator_portal_national_number/controllers/portal.py#L14

Added line #L14 was not covered by tests
# 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"])

Check warning on line 19 in l10n_be_cooperator_portal_national_number/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

l10n_be_cooperator_portal_national_number/controllers/portal.py#L18-L19

Added lines #L18 - L19 were not covered by tests

def _prepare_portal_layout_values(self):
values = super()._prepare_portal_layout_values()
values[

Check warning on line 23 in l10n_be_cooperator_portal_national_number/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

l10n_be_cooperator_portal_national_number/controllers/portal.py#L22-L23

Added lines #L22 - L23 were not covered by tests
"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

Check warning on line 30 in l10n_be_cooperator_portal_national_number/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

l10n_be_cooperator_portal_national_number/controllers/portal.py#L28-L30

Added lines #L28 - L30 were not covered by tests

def details_form_validate(self, data):
error, error_message = super().details_form_validate(data)
national_number = data.get("national_number")

Check warning on line 34 in l10n_be_cooperator_portal_national_number/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

l10n_be_cooperator_portal_national_number/controllers/portal.py#L33-L34

Added lines #L33 - L34 were not covered by tests
if national_number:
failed = request.env["res.partner"].check_be_national_register_number(

Check warning on line 36 in l10n_be_cooperator_portal_national_number/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

l10n_be_cooperator_portal_national_number/controllers/portal.py#L36

Added line #L36 was not covered by tests
national_number
)
if failed:
error["national_number"] = "error"
error_message.append(_("The national number is not valid."))

Check warning on line 41 in l10n_be_cooperator_portal_national_number/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

l10n_be_cooperator_portal_national_number/controllers/portal.py#L40-L41

Added lines #L40 - L41 were not covered by tests
# 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

Check warning on line 49 in l10n_be_cooperator_portal_national_number/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

l10n_be_cooperator_portal_national_number/controllers/portal.py#L47-L49

Added lines #L47 - L49 were not covered by tests

@route(["/my/account"], type="http", auth="user", website=True)
def account(self, redirect=None, **post):
res = super().account(redirect, **post)

Check warning on line 53 in l10n_be_cooperator_portal_national_number/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

l10n_be_cooperator_portal_national_number/controllers/portal.py#L53

Added line #L53 was not covered by tests
if not res.qcontext.get("error"):
national_number = post.get("national_number")
request.env.user.partner_id.update_be_national_register_number(

Check warning on line 56 in l10n_be_cooperator_portal_national_number/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

l10n_be_cooperator_portal_national_number/controllers/portal.py#L55-L56

Added lines #L55 - L56 were not covered by tests
national_number
)
return res

Check warning on line 59 in l10n_be_cooperator_portal_national_number/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

l10n_be_cooperator_portal_national_number/controllers/portal.py#L59

Added line #L59 was not covered by tests
5 changes: 5 additions & 0 deletions l10n_be_cooperator_portal_national_number/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2022 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later

from . import res_partner
15 changes: 15 additions & 0 deletions l10n_be_cooperator_portal_national_number/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -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)

Check warning on line 15 in l10n_be_cooperator_portal_national_number/models/res_partner.py

View check run for this annotation

Codecov / codecov/patch

l10n_be_cooperator_portal_national_number/models/res_partner.py#L14-L15

Added lines #L14 - L15 were not covered by tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Coop IT Easy SC <https://github.com/OCA/cooperative>`_:

* Carmen Bianca BAKKER
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add the ability to change national number on the account portal.
Loading

0 comments on commit ff523dc

Please sign in to comment.