From 1bb1a95ab85624d54625c788ff0f1caee566b5ca Mon Sep 17 00:00:00 2001 From: Yosua Nicolaus Date: Tue, 30 Jan 2024 15:17:21 +0100 Subject: [PATCH] [IMP] l10n_ec_website_sale: portal contact information Currently, if a customer wants to edit his/her information from the Portal access, they cannot modify the information linked to EC. This commit aims to support Ecuadorian companies needed information when editing the portal contact information: - added "Identification Type" field - renamed "VAT" to "Identification Number" - make those 2 fields required closes odoo/odoo#142730 Task-id: 3620196 Signed-off-by: Josse Colpaert --- .../controllers/__init__.py | 1 + .../controllers/portal.py | 43 +++++++++++++++++++ .../views/website_sales_templates.xml | 18 ++++++++ 3 files changed, 62 insertions(+) create mode 100644 addons/l10n_ec_website_sale/controllers/portal.py diff --git a/addons/l10n_ec_website_sale/controllers/__init__.py b/addons/l10n_ec_website_sale/controllers/__init__.py index 80ee4da1c5e..8739d256707 100644 --- a/addons/l10n_ec_website_sale/controllers/__init__.py +++ b/addons/l10n_ec_website_sale/controllers/__init__.py @@ -1,3 +1,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import main +from . import portal diff --git a/addons/l10n_ec_website_sale/controllers/portal.py b/addons/l10n_ec_website_sale/controllers/portal.py new file mode 100644 index 00000000000..11313c6cb73 --- /dev/null +++ b/addons/l10n_ec_website_sale/controllers/portal.py @@ -0,0 +1,43 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.addons.portal.controllers.portal import CustomerPortal +from odoo.http import request + + +class CustomerPortalEcuador(CustomerPortal): + + def _is_ecuador_company(self): + return request.env.company.country_code == 'EC' + + def _get_mandatory_fields(self): + # EXTEND 'portal' + mandatory_fields = super()._get_mandatory_fields() + + if self._is_ecuador_company(): + mandatory_fields.extend(('l10n_latam_identification_type_id', 'vat')) + + return mandatory_fields + + def _prepare_portal_layout_values(self): + # EXTEND 'portal' + portal_layout_values = super()._prepare_portal_layout_values() + + if self._is_ecuador_company(): + partner = request.env.user.partner_id + portal_layout_values.update({ + 'identification': partner.l10n_latam_identification_type_id, + 'identification_types': request.env['l10n_latam.identification.type'].search( + ['|', ('country_id', '=', False), ('country_id.code', '=', 'EC')]), + }) + + return portal_layout_values + + def details_form_validate(self, data, partner_creation=False): + # EXTEND 'portal' + error, error_message = super().details_form_validate(data, partner_creation) + + # sanitize identification value to make sure it's correctly written on the partner + if self._is_ecuador_company() and data.get('l10n_latam_identification_type_id'): + data['l10n_latam_identification_type_id'] = int(data['l10n_latam_identification_type_id']) + + return error, error_message diff --git a/addons/l10n_ec_website_sale/views/website_sales_templates.xml b/addons/l10n_ec_website_sale/views/website_sales_templates.xml index 6cd854926e0..99807f5e13c 100644 --- a/addons/l10n_ec_website_sale/views/website_sales_templates.xml +++ b/addons/l10n_ec_website_sale/views/website_sales_templates.xml @@ -45,4 +45,22 @@ + +