From 5801ec664dd2fc618b2f6fbab508abda76952b78 Mon Sep 17 00:00:00 2001 From: "Dylan Kiss (dyki)" Date: Mon, 2 Oct 2023 16:34:56 +0200 Subject: [PATCH] [IMP] account{_peppol}: allow install via settings Currently it is not easily discoverable that users can install the PEPPOL module. They have to go to the Apps list and search for PEPPOL there. In order to make the installation easy and discoverable, we added a checkbox to the Invoicing/Accounting settings to install the module and afterwards show the checkbox to enable PEPPOL per company. The install checkbox is only shown when editing the settings of a company that is eligible for PEPPOL to avoid confusion. In order to do that, we created a `PEPPOL_LIST` variable in `account` containing all countries currently allowed to use PEPPOL. The code in `account_peppol` formerly using the `EAS_MAPPING` variable of the `account_edi_ubl_cii` module is now also using this new list. task-3519564 closes odoo/odoo#137287 Signed-off-by: Laurent Smet (las) --- addons/account/models/company.py | 6 + addons/account/models/res_config_settings.py | 18 +- .../views/res_config_settings_views.xml | 15 + addons/account_peppol/i18n/account_peppol.pot | 10 - addons/account_peppol/models/res_company.py | 6 +- .../models/res_config_settings.py | 31 +- .../views/res_config_settings_views.xml | 284 +++++++++--------- 7 files changed, 193 insertions(+), 177 deletions(-) diff --git a/addons/account/models/company.py b/addons/account/models/company.py index e6d282976b3..961d05e9185 100644 --- a/addons/account/models/company.py +++ b/addons/account/models/company.py @@ -26,6 +26,12 @@ MONTH_SELECTION = [ ('12', 'December'), ] +PEPPOL_LIST = [ + 'AD', 'AL', 'AT', 'BA', 'BE', 'BG', 'CH', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', + 'FR', 'GB', 'GR', 'HR', 'HU', 'IE', 'IS', 'IT', 'LI', 'LT', 'LU', 'LV', 'MC', 'ME', + 'MK', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'RS', 'SE', 'SI', 'SK', 'SM', 'TR', 'VA', +] + class ResCompany(models.Model): _name = "res.company" _inherit = ["res.company", "mail.thread"] diff --git a/addons/account/models/res_config_settings.py b/addons/account/models/res_config_settings.py index 36be090c539..01f7d3f8dc7 100644 --- a/addons/account/models/res_config_settings.py +++ b/addons/account/models/res_config_settings.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import api, fields, models, _ +from odoo import _, api, fields, models + +from odoo.addons.account.models.company import PEPPOL_LIST class ResConfigSettings(models.TransientModel): @@ -117,6 +119,7 @@ class ResConfigSettings(models.TransientModel): module_account_avatax = fields.Boolean(string="Account Avatax") module_account_invoice_extract = fields.Boolean(string="Document Digitization") module_snailmail_account = fields.Boolean(string="Snailmail") + module_account_peppol = fields.Boolean(string='PEPPOL Invoicing') tax_exigibility = fields.Boolean(string='Cash Basis', related='company_id.tax_exigibility', readonly=False) tax_cash_basis_journal_id = fields.Many2one( 'account.journal', @@ -208,6 +211,19 @@ class ResConfigSettings(models.TransientModel): domain="[('account_type', 'in', ('income', 'expense'))]", ) + # PEPPOL + is_account_peppol_eligible = fields.Boolean( + string='PEPPOL eligible', + compute='_compute_is_account_peppol_eligible', + ) # technical field used for showing the Peppol settings conditionally + + @api.depends('country_code') + def _compute_is_account_peppol_eligible(self): + # we want to show Peppol settings only to customers that are eligible for Peppol, + # except countries that are not in Europe + for config in self: + config.is_account_peppol_eligible = config.country_code in PEPPOL_LIST + def set_values(self): super().set_values() # install a chart of accounts for the given company (if required) diff --git a/addons/account/views/res_config_settings_views.xml b/addons/account/views/res_config_settings_views.xml index 8c6dbe3acf4..dadc31dc9a1 100644 --- a/addons/account/views/res_config_settings_views.xml +++ b/addons/account/views/res_config_settings_views.xml @@ -348,6 +348,21 @@ + + +
+
+ +
+
+
+ diff --git a/addons/account_peppol/i18n/account_peppol.pot b/addons/account_peppol/i18n/account_peppol.pot index 4e9023a6e53..68d1526a466 100644 --- a/addons/account_peppol/i18n/account_peppol.pot +++ b/addons/account_peppol/i18n/account_peppol.pot @@ -212,11 +212,6 @@ msgstr "" msgid "PEPPOL" msgstr "" -#. module: account_peppol -#: model_terms:ir.ui.view,arch_db:account_peppol.res_config_settings_view_form -msgid "PEPPOL Electronic Document Invoicing" -msgstr "" - #. module: account_peppol #: model:ir.model.fields,field_description:account_peppol.field_res_company__is_account_peppol_participant msgid "PEPPOL Participant" @@ -228,11 +223,6 @@ msgstr "" msgid "PEPPOL Purchase Journal" msgstr "" -#. module: account_peppol -#: model:ir.model.fields,field_description:account_peppol.field_res_config_settings__is_account_peppol_eligible -msgid "PEPPOL eligible" -msgstr "" - #. module: account_peppol #: model:ir.model.fields,field_description:account_peppol.field_res_partner__account_peppol_is_endpoint_valid #: model:ir.model.fields,field_description:account_peppol.field_res_users__account_peppol_is_endpoint_valid diff --git a/addons/account_peppol/models/res_company.py b/addons/account_peppol/models/res_company.py index a7372ac2556..7d4ce931ef6 100644 --- a/addons/account_peppol/models/res_company.py +++ b/addons/account_peppol/models/res_company.py @@ -6,15 +6,13 @@ from stdnum import get_cc_module, ean from odoo import _, api, fields, models from odoo.exceptions import ValidationError -from odoo.addons.account_edi_ubl_cii.models.account_edi_common import EAS_MAPPING +from odoo.addons.account.models.company import PEPPOL_LIST try: import phonenumbers except ImportError: phonenumbers = None -# at the moment, only phone numbers in European countries are accepted -PHONE_ALLOWED_COUNTRIES = set(EAS_MAPPING.keys()) - {'AU', 'SG', 'NZ'} PEPPOL_ENDPOINT_RULES = { '0007': ['se', 'orgnr'], @@ -95,7 +93,7 @@ class ResCompany(models.Model): raise ValidationError(error_message) country_code = phonenumbers.phonenumberutil.region_code_for_number(phone_nbr) - if country_code not in PHONE_ALLOWED_COUNTRIES or not phonenumbers.is_valid_number(phone_nbr): + if country_code not in PEPPOL_LIST or not phonenumbers.is_valid_number(phone_nbr): raise ValidationError(error_message) def _check_peppol_endpoint_number(self, warning=False): diff --git a/addons/account_peppol/models/res_config_settings.py b/addons/account_peppol/models/res_config_settings.py index f47e7a68f56..b3691641ece 100644 --- a/addons/account_peppol/models/res_config_settings.py +++ b/addons/account_peppol/models/res_config_settings.py @@ -5,10 +5,6 @@ from odoo import _, api, fields, models, modules, tools from odoo.exceptions import UserError, ValidationError from odoo.addons.account_edi_proxy_client.models.account_edi_proxy_user import AccountEdiProxyError -from odoo.addons.account_edi_ubl_cii.models.account_edi_common import EAS_MAPPING - -# at the moment, only European countries are accepted -ALLOWED_COUNTRIES = set(EAS_MAPPING.keys()) - {'AU', 'SG', 'NZ'} class ResConfigSettings(models.TransientModel): @@ -32,15 +28,14 @@ class ResConfigSettings(models.TransientModel): account_peppol_proxy_state = fields.Selection(related='company_id.account_peppol_proxy_state', readonly=False) account_peppol_purchase_journal_id = fields.Many2one(related='company_id.peppol_purchase_journal_id', readonly=False) account_peppol_verification_code = fields.Char(related='account_peppol_edi_user.peppol_verification_code', readonly=False) - is_account_peppol_eligible = fields.Boolean( - string='PEPPOL eligible', - compute='_compute_is_account_peppol_eligible', - ) # technical field used for showing the Peppol settings conditionally is_account_peppol_participant = fields.Boolean( string='Use PEPPOL', related='company_id.is_account_peppol_participant', readonly=False, help='Register as a PEPPOL user', ) + has_peppol_participant = fields.Boolean( + compute='_compute_has_peppol_participant' + ) # ------------------------------------------------------------------------- # HELPER METHODS @@ -67,18 +62,6 @@ class ResConfigSettings(models.TransientModel): # COMPUTE METHODS # ------------------------------------------------------------------------- - @api.depends("company_id.country_id") - def _compute_is_account_peppol_eligible(self): - # we want to show Peppol settings only to customers that are eligible for Peppol, - # except countries that are not in Europe - # but keeping an option to see them for testing purposes using a config param - for config in self: - peppol_param = config.env['ir.config_parameter'].sudo().get_param( - 'account_peppol.edi.mode', False - ) - config.is_account_peppol_eligible = config.company_id.country_id.code in ALLOWED_COUNTRIES \ - or peppol_param == 'test' - @api.depends("company_id.account_edi_proxy_client_ids") def _compute_account_peppol_edi_user(self): for config in self: @@ -97,6 +80,14 @@ class ResConfigSettings(models.TransientModel): config.account_peppol_endpoint_warning = _("The endpoint number might not be correct. " "Please check if you entered the right identification number.") + @api.depends('company_id.is_account_peppol_participant') + def _compute_has_peppol_participant(self): + number_of_peppol_participants = len(self.env['res.company'].sudo().search([ + ('is_account_peppol_participant', '=', True) + ])) + for config in self: + config.has_peppol_participant = number_of_peppol_participants > 0 + # ------------------------------------------------------------------------- # BUSINESS ACTIONS # ------------------------------------------------------------------------- diff --git a/addons/account_peppol/views/res_config_settings_views.xml b/addons/account_peppol/views/res_config_settings_views.xml index d6bd89e8db7..628e6122688 100644 --- a/addons/account_peppol/views/res_config_settings_views.xml +++ b/addons/account_peppol/views/res_config_settings_views.xml @@ -5,164 +5,164 @@ res.config.settings - - - -
-
-
- -
- -
-
-
-