-
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[14.0][MIG] l10n_be_cooperator_national_number #69
Changes from 14 commits
dae21b8
6716e31
dbe9d7b
774df4c
26ece8b
d0653c3
6f11e56
78089d8
b32b305
4d63763
0393cae
ec0b451
cfd17fd
d585d9a
10afd2e
69057a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
=================================== | ||
Belgium: Cooperator National Number | ||
=================================== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
||
.. |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/12.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-12-0/cooperative-12-0-l10n_be_cooperator_national_number | ||
:alt: Translate me on Weblate | ||
|
||
|badge1| |badge2| |badge3| |badge4| | ||
|
||
Ask for Belgian National Number in Subscription Request. | ||
|
||
**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 smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/cooperative/issues/new?body=module:%20l10n_be_cooperator_national_number%0Aversion:%2012.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 | ||
|
||
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 <https://github.com/OCA/cooperative/tree/12.0/l10n_be_cooperator_national_number>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2018 Coop IT Easy SC (<http://www.coopiteasy.be>) | ||
# 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": "14.0.1.1.0", | ||
"depends": ["cooperator", "l10n_be_national_number"], | ||
"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": [], | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 "" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# SPDX-FileCopyrightText: 2023 Coop IT Easy SC | ||
# | ||
# SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
from openupgradelib import openupgrade | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
sql = """ | ||
UPDATE res_company | ||
SET display_national_number = true | ||
WHERE require_national_number = true | ||
""" | ||
openupgrade.logged_query(env.cr, sql) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import subscription_request | ||
from . import company |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2019 Coop IT Easy SCRL fs | ||
# Houssine Bakkali <houssine@coopiteasy.be> | ||
# 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(string="Display National Number") | ||
require_national_number = fields.Boolean(string="Require National Number") | ||
|
||
@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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from odoo import _, api, fields, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class SubscriptionRequest(models.Model): | ||
_inherit = "subscription.request" | ||
|
||
national_number = fields.Char(string="National Number") | ||
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_national_number.l10n_be_national_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.")) | ||
super().validate_subscription_request() | ||
|
||
def create_national_number(self, partner): | ||
if not self.is_company: | ||
values = { | ||
"name": self.national_number, | ||
"category_id": self.env.ref( | ||
"l10n_be_national_number.l10n_be_national_number_category" # noqa | ||
).id, | ||
"partner_id": partner.id, | ||
} | ||
self.env["res.partner.id_number"].create(values) | ||
return partner | ||
|
||
def create_coop_partner(self): | ||
partner = super().create_coop_partner() | ||
if self.require_national_number: | ||
self.create_national_number(partner) | ||
return partner | ||
|
||
def get_representative_vals(self): | ||
contact_vals = super().get_representative_vals() | ||
contact_vals["national_number"] = self.national_number | ||
return contact_vals | ||
|
||
def get_partner_vals(self): | ||
contact_vals = super().get_partner_vals() | ||
return contact_vals | ||
|
||
def get_person_info(self, partner): | ||
super().get_person_info(partner) | ||
self.national_number = self.get_national_number_from_partner(partner) | ||
|
||
def update_partner_info(self): | ||
self.create_national_number(self.partner_id) | ||
super().update_partner_info() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Coop IT Easy SC |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Ask for Belgian National Number in Subscription Request. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
Comment on lines
+1
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we be able to display the field and use it without making it mandatory ? If not what's the point in having two toggles ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's what the 'Display' toggle is for. When the 'Display' toggle is disabled, it's as if this module isn't installed. Useful for multi-company. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, it's just that the sentence "In order to expose the functionality of this module, you must enable these toggles for every company that wishes to use it.", seems to mean that you have to enable both toggles for the functionality to work, while actually you can only toggle "display" and the functionality will work (without requirements on the NRN). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, maybe let's write 'one or both of these toggles'? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why putting a condition on "require" and not "display" here ? If the require config is unchecked but display is checked it will not write the national number on the partner ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. I will patch this up, because simply switching to
display
won't suffice.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was surprisingly difficult to fix. Done now. Ready for another review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code and functional review OK