diff --git a/cooperator/models/subscription_request.py b/cooperator/models/subscription_request.py index 143073b26..0330385e6 100644 --- a/cooperator/models/subscription_request.py +++ b/cooperator/models/subscription_request.py @@ -475,7 +475,7 @@ def _compute_subscription_amount(self): _order = "id desc" - def get_person_info(self, partner): + def set_person_info(self, partner): self.firstname = partner.firstname self.name = partner.name self.lastname = partner.lastname @@ -504,10 +504,10 @@ def onchange_partner(self): self.company_email = partner.email self.company_register_number = partner.company_register_number representative = partner.get_representative() - self.get_person_info(representative) + self.set_person_info(representative) self.contact_person_function = representative.function else: - self.get_person_info(partner) + self.set_person_info(partner) # fixme: this is very specific and should not be here. # declare this function in order to be overriden diff --git a/l10n_be_cooperator_national_number/README.rst b/l10n_be_cooperator_national_number/README.rst new file mode 100644 index 000000000..012a5f299 --- /dev/null +++ b/l10n_be_cooperator_national_number/README.rst @@ -0,0 +1,84 @@ +=================================== +Belgium: Cooperator National Number +=================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:630e1017f61be213540b60239befca6d9dc713c41118f2a603254d70f4b9ec7f + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_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_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| + +Ask for Belgian National Number in Subscription Request. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +On the company, two new toggles 'Display National Number' and 'Require National +Number' are added. In order to expose the functionality of this module, you must +enable these toggles for every company that wishes to use it. 'Display' shows +the field and allows it to be filled in. 'Require' makes the field mandatory. + +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 + +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. + +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_national_number/__init__.py b/l10n_be_cooperator_national_number/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/l10n_be_cooperator_national_number/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/l10n_be_cooperator_national_number/__manifest__.py b/l10n_be_cooperator_national_number/__manifest__.py new file mode 100644 index 000000000..a0becdf0b --- /dev/null +++ b/l10n_be_cooperator_national_number/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2018 Coop IT Easy SC () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).# +{ + "name": "Belgium: Cooperator National Number", + "summary": "Ask for Belgian National Number in Cooperative Subscription Request.", + "version": "16.0.1.0.0", + "depends": ["cooperator", "l10n_be_partner_identification"], + "author": "Coop IT Easy SC, Odoo Community Association (OCA)", + "category": "Cooperative management", + "website": "https://github.com/OCA/cooperative", + "license": "AGPL-3", + "data": ["views/subscription_request_view.xml", "views/res_company_view.xml"], + "demo": [], +} diff --git a/l10n_be_cooperator_national_number/i18n/l10n_be_cooperator_national_number.pot b/l10n_be_cooperator_national_number/i18n/l10n_be_cooperator_national_number.pot new file mode 100644 index 000000000..bc0d4df5c --- /dev/null +++ b/l10n_be_cooperator_national_number/i18n/l10n_be_cooperator_national_number.pot @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * l10n_be_cooperator_national_number +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.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: l10n_be_cooperator_national_number +#: model:ir.model,name:l10n_be_cooperator_national_number.model_res_company +msgid "Companies" +msgstr "" + +#. module: l10n_be_cooperator_national_number +#: model:ir.model.fields,field_description:l10n_be_cooperator_national_number.field_subscription_request__display_national_number +msgid "Display National Number" +msgstr "" + +#. module: l10n_be_cooperator_national_number +#: model:ir.model.fields,field_description:l10n_be_cooperator_national_number.field_subscription_request__national_number +msgid "National Number" +msgstr "" + +#. module: l10n_be_cooperator_national_number +#: code:addons/l10n_be_cooperator_national_number/models/subscription_request.py:38 +#, python-format +msgid "National Number is required." +msgstr "" + +#. module: l10n_be_cooperator_national_number +#: model:ir.model.fields,field_description:l10n_be_cooperator_national_number.field_res_company__require_national_number +msgid "Require National Number" +msgstr "" + +#. module: l10n_be_cooperator_national_number +#: model:ir.model,name:l10n_be_cooperator_national_number.model_subscription_request +msgid "Subscription Request" +msgstr "" + diff --git a/l10n_be_cooperator_national_number/models/__init__.py b/l10n_be_cooperator_national_number/models/__init__.py new file mode 100644 index 000000000..40cf510c0 --- /dev/null +++ b/l10n_be_cooperator_national_number/models/__init__.py @@ -0,0 +1,3 @@ +from . import company +from . import subscription_request +from . import res_partner diff --git a/l10n_be_cooperator_national_number/models/company.py b/l10n_be_cooperator_national_number/models/company.py new file mode 100644 index 000000000..6068d57d2 --- /dev/null +++ b/l10n_be_cooperator_national_number/models/company.py @@ -0,0 +1,30 @@ +# Copyright 2019 Coop IT Easy SCRL fs +# Houssine Bakkali +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + + +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class ResCompany(models.Model): + _inherit = "res.company" + + display_national_number = fields.Boolean() + require_national_number = fields.Boolean() + + @api.constrains("display_national_number", "require_national_number") + def _check_national_number(self): + for company in self: + if company.require_national_number and not company.display_national_number: + raise ValidationError( + _( + 'If the "Require National Number" toggle is enabled,' + ' then so must the "Display National Number" toggle.' + ) + ) + + @api.onchange("display_national_number") + def _onchange_display_national_number(self): + if not self.display_national_number: + self.require_national_number = False diff --git a/l10n_be_cooperator_national_number/models/res_partner.py b/l10n_be_cooperator_national_number/models/res_partner.py new file mode 100644 index 000000000..fda7f1225 --- /dev/null +++ b/l10n_be_cooperator_national_number/models/res_partner.py @@ -0,0 +1,36 @@ +# SPDX-FileCopyrightText: 2023 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from odoo import models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + def update_belgian_national_number(self, national_number): + self.ensure_one() + result = None + if national_number: + belgian_cat = self.env.ref( + "l10n_be_partner_identification.l10n_be_national_registry_number_category" + ) + existing = self.env["res.partner.id_number"].search( + [ + ("partner_id", "=", self.id), + ("category_id", "=", belgian_cat.id), + ] + ) + # Update + if existing: + existing.name = national_number + result = existing + # Create new + else: + values = { + "name": national_number, + "category_id": belgian_cat.id, + "partner_id": self.id, + } + result = self.env["res.partner.id_number"].create(values) + return result diff --git a/l10n_be_cooperator_national_number/models/subscription_request.py b/l10n_be_cooperator_national_number/models/subscription_request.py new file mode 100644 index 000000000..83d9adc2c --- /dev/null +++ b/l10n_be_cooperator_national_number/models/subscription_request.py @@ -0,0 +1,50 @@ +from odoo import _, api, fields, models +from odoo.exceptions import UserError + + +class SubscriptionRequest(models.Model): + _inherit = "subscription.request" + + national_number = fields.Char() + display_national_number = fields.Boolean( + compute="_compute_display_national_number", + ) + require_national_number = fields.Boolean( + compute="_compute_require_national_number", + ) + + @api.depends("is_company", "company_id", "company_id.display_national_number") + def _compute_display_national_number(self): + self.display_national_number = ( + self.company_id.display_national_number and not self.is_company + ) + + @api.depends("is_company", "company_id", "company_id.require_national_number") + def _compute_require_national_number(self): + self.require_national_number = ( + self.company_id.require_national_number and not self.is_company + ) + + def get_national_number_from_partner(self, partner): + national_number_id_category = self.env.ref( + "l10n_be_partner_identification.l10n_be_national_registry_number_category" + ).id + national_number = partner.id_numbers.filtered( + lambda rec: rec.category_id.id == national_number_id_category + ) + return national_number.name + + def validate_subscription_request(self): + self.ensure_one() + if self.require_national_number and not self.national_number: + raise UserError(_("National Number is required.")) + invoice = super().validate_subscription_request() + if not self.is_company: + partner = invoice.partner_id + partner.update_belgian_national_number(self.national_number) + return invoice + + def set_person_info(self, partner): + super().set_person_info(partner) + self.national_number = self.get_national_number_from_partner(partner) + return True diff --git a/l10n_be_cooperator_national_number/readme/CONTRIBUTORS.rst b/l10n_be_cooperator_national_number/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..8c568398a --- /dev/null +++ b/l10n_be_cooperator_national_number/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Coop IT Easy SC diff --git a/l10n_be_cooperator_national_number/readme/DESCRIPTION.rst b/l10n_be_cooperator_national_number/readme/DESCRIPTION.rst new file mode 100644 index 000000000..474b53cfb --- /dev/null +++ b/l10n_be_cooperator_national_number/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Ask for Belgian National Number in Subscription Request. diff --git a/l10n_be_cooperator_national_number/readme/USAGE.rst b/l10n_be_cooperator_national_number/readme/USAGE.rst new file mode 100644 index 000000000..bcd2f4655 --- /dev/null +++ b/l10n_be_cooperator_national_number/readme/USAGE.rst @@ -0,0 +1,4 @@ +On the company, two new toggles 'Display National Number' and 'Require National +Number' are added. In order to expose the functionality of this module, you must +enable these toggles for every company that wishes to use it. 'Display' shows +the field and allows it to be filled in. 'Require' makes the field mandatory. diff --git a/l10n_be_cooperator_national_number/static/description/icon.png b/l10n_be_cooperator_national_number/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/l10n_be_cooperator_national_number/static/description/icon.png differ diff --git a/l10n_be_cooperator_national_number/static/description/index.html b/l10n_be_cooperator_national_number/static/description/index.html new file mode 100644 index 000000000..ca0b9e96b --- /dev/null +++ b/l10n_be_cooperator_national_number/static/description/index.html @@ -0,0 +1,429 @@ + + + + + + +Belgium: Cooperator National Number + + + +
+

Belgium: Cooperator National Number

+ + +

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

+

Ask for Belgian National Number in Subscription Request.

+

Table of contents

+ +
+

Usage

+

On the company, two new toggles ‘Display National Number’ and ‘Require National +Number’ are added. In order to expose the functionality of this module, you must +enable these toggles for every company that wishes to use it. ‘Display’ shows +the field and allows it to be filled in. ‘Require’ makes the field mandatory.

+
+
+

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
  • +
+
+
+

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.

+

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_national_number/tests/__init__.py b/l10n_be_cooperator_national_number/tests/__init__.py new file mode 100644 index 000000000..22fec90ed --- /dev/null +++ b/l10n_be_cooperator_national_number/tests/__init__.py @@ -0,0 +1 @@ +from . import test_cooperator_national_number diff --git a/l10n_be_cooperator_national_number/tests/test_cooperator_national_number.py b/l10n_be_cooperator_national_number/tests/test_cooperator_national_number.py new file mode 100644 index 000000000..0ca1d6b07 --- /dev/null +++ b/l10n_be_cooperator_national_number/tests/test_cooperator_national_number.py @@ -0,0 +1,87 @@ +# Copyright 2019 Coop IT Easy SCRL fs +# Robin Keunen +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo.exceptions import UserError, ValidationError +from odoo.tests.common import TransactionCase + +from odoo.addons.cooperator.tests.cooperator_test_mixin import CooperatorTestMixin + +NATIONAL_NUMBER = 90010100123 + + +class TestCooperatorNationalNumber(TransactionCase, CooperatorTestMixin): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.set_up_cooperator_test_data() + + def create_subscription_request(self): + vals = self.get_dummy_subscription_requests_vals() + return self.env["subscription.request"].create(vals) + + def set_national_number_required(self): + self.company.display_national_number = True + self.company.require_national_number = True + + def test_require_without_display(self): + """You cannot require a national number without also displaying it.""" + self.company.write( + { + "display_national_number": False, + "require_national_number": False, + } + ) + with self.assertRaises(ValidationError): + self.company.require_national_number = True + self.set_national_number_required() + with self.assertRaises(ValidationError): + self.company.display_national_number = False + + def test_company_not_required(self): + """Subscription requests for companies do not require a national number.""" + self.set_national_number_required() + vals = self.get_dummy_company_subscription_requests_vals() + subscription_request = self.env["subscription.request"].create(vals) + subscription_request.validate_subscription_request() + self.assertFalse(subscription_request.display_national_number) + self.assertFalse(subscription_request.require_national_number) + + def test_national_number_applied_to_partner(self): + self.set_national_number_required() + subscription_request = self.create_subscription_request() + subscription_request.national_number = NATIONAL_NUMBER + subscription_request.validate_subscription_request() + partner = subscription_request.partner_id + created_id_number = self.env["res.partner.id_number"].search( + [("name", "=", NATIONAL_NUMBER)] + ) + self.assertTrue(created_id_number) + self.assertEqual(created_id_number.partner_id, partner) + + def test_error_if_missing_and_required(self): + self.set_national_number_required() + subscription_request = self.create_subscription_request() + with self.assertRaises(UserError): + subscription_request.validate_subscription_request() + + def test_no_national_number_provided(self): + """Expect an error if no national number is given, but one is required.""" + self.set_national_number_required() + vals = self.get_dummy_subscription_requests_vals() + subscription_request = self.env["subscription.request"].create(vals) + with self.assertRaises(UserError): + subscription_request.validate_subscription_request() + + def test_national_number_provided_not_required(self): + """Expect no error when a number is given but not required.""" + vals = self.get_dummy_subscription_requests_vals() + subscription_request = self.env["subscription.request"].create(vals) + subscription_request.national_number = NATIONAL_NUMBER + subscription_request.validate_subscription_request() + + def test_no_national_number_provided_not_required(self): + """Expect no error when no number is given nor required.""" + vals = self.get_dummy_subscription_requests_vals() + subscription_request = self.env["subscription.request"].create(vals) + subscription_request.validate_subscription_request() diff --git a/l10n_be_cooperator_national_number/views/res_company_view.xml b/l10n_be_cooperator_national_number/views/res_company_view.xml new file mode 100644 index 000000000..6f223c666 --- /dev/null +++ b/l10n_be_cooperator_national_number/views/res_company_view.xml @@ -0,0 +1,17 @@ + + + + res.company.form.easymy.coop + + res.company + + + + + + + + diff --git a/l10n_be_cooperator_national_number/views/subscription_request_view.xml b/l10n_be_cooperator_national_number/views/subscription_request_view.xml new file mode 100644 index 000000000..8aafa4b98 --- /dev/null +++ b/l10n_be_cooperator_national_number/views/subscription_request_view.xml @@ -0,0 +1,21 @@ + + + + + + subscription.request.view.form + subscription.request + + + + + + + + + + diff --git a/setup/l10n_be_cooperator_national_number/odoo/addons/l10n_be_cooperator_national_number b/setup/l10n_be_cooperator_national_number/odoo/addons/l10n_be_cooperator_national_number new file mode 120000 index 000000000..92ca75108 --- /dev/null +++ b/setup/l10n_be_cooperator_national_number/odoo/addons/l10n_be_cooperator_national_number @@ -0,0 +1 @@ +../../../../l10n_be_cooperator_national_number \ No newline at end of file diff --git a/setup/l10n_be_cooperator_national_number/setup.py b/setup/l10n_be_cooperator_national_number/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/l10n_be_cooperator_national_number/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)