Skip to content

Commit 66efdb2

Browse files
committed
[ADD] l10n_uy_website_sale: add Ecommerce module for Uruguay
This commit add Ecommerce related bridge module for Uruguay country to add Uruguay related field in address checkout form and `my/account` page. Also set DNI as default `ID type` for peru address. task-4404637 closes odoo#218920 X-original-commit: 42c43db Signed-off-by: Laurent Smet (las) <las@odoo.com> Signed-off-by: Kartik Chavda (kcv) <kcv@odoo.com>
1 parent f40854b commit 66efdb2

14 files changed

Lines changed: 259 additions & 1 deletion

File tree

addons/l10n_pe_website_sale/controllers/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def _prepare_address_form_values(self, order_sudo, partner_sudo, address_type, *
4141
can_edit_vat = rendering_values['can_edit_vat']
4242
LatamIdentificationType = request.env['l10n_latam.identification.type'].sudo()
4343
rendering_values.update({
44+
"identification": partner_sudo.l10n_latam_identification_type_id or request.env.ref('l10n_pe.it_DNI').id,
4445
'identification_types': LatamIdentificationType.search([
4546
'|', ('country_id', '=', False), ('country_id.code', '=', 'PE')
4647
]) if can_edit_vat else LatamIdentificationType,

addons/l10n_pe_website_sale/views/templates.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
<option value="">Identification Type...</option>
1010
<t t-foreach="identification_types" t-as="id_type">
1111
<option t-att-value="id_type.id"
12-
t-att-selected="id_type.id == partner_sudo.l10n_latam_identification_type_id.id">
12+
t-att-selected="id_type.id == int(identification or 0)"
13+
>
1314
<t t-out="id_type.name"/>
1415
</option>
1516
</t>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
2+
3+
from . import controllers
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
2+
{
3+
'name': 'Uruguay Website',
4+
'version': '1.0',
5+
'category': 'Accounting/Localizations/Website',
6+
'description': """ Add address Uruguay localisation fields in address page. """,
7+
'depends': [
8+
'l10n_uy',
9+
'website_sale',
10+
],
11+
'data': [
12+
'data/ir_model_fields.xml',
13+
'views/website_sales_templates.xml',
14+
],
15+
'assets': {
16+
'web.assets_tests': [
17+
'l10n_uy_website_sale/static/tests/tours/*.js',
18+
],
19+
},
20+
'installable': True,
21+
'auto_install': True,
22+
'license': 'LGPL-3',
23+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
2+
3+
from . import main
4+
from . import portal
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
2+
3+
from odoo.addons.website_sale.controllers.main import WebsiteSale
4+
from odoo.http import request
5+
6+
7+
class L10nUYWebsiteSale(WebsiteSale):
8+
9+
def _get_mandatory_billing_address_fields(self, country_sudo):
10+
""" Extend mandatory fields to add new identification and responsibility fields when company is Uruguay. """
11+
mandatory_fields = super()._get_mandatory_billing_address_fields(country_sudo)
12+
if request.website.sudo().company_id.country_id.code == 'UY':
13+
mandatory_fields |= {'l10n_latam_identification_type_id', 'vat'}
14+
return mandatory_fields
15+
16+
def _prepare_address_form_values(self, order_sudo, partner_sudo, address_type, **kwargs):
17+
rendering_values = super()._prepare_address_form_values(
18+
order_sudo, partner_sudo, address_type=address_type, **kwargs
19+
)
20+
if request.website.sudo().company_id.country_id.code != 'UY':
21+
return rendering_values
22+
23+
if kwargs.get('use_delivery_as_billing') and address_type == 'delivery' or address_type == 'billing':
24+
can_edit_vat = rendering_values['can_edit_vat']
25+
LatamIdentificationType = request.env['l10n_latam.identification.type'].sudo()
26+
rendering_values.update({
27+
'identification': partner_sudo.l10n_latam_identification_type_id or request.env.ref('l10n_uy.it_ci').id,
28+
'identification_types': LatamIdentificationType.search([
29+
'|', ('country_id', '=', False), ('country_id.code', '=', 'PE')
30+
]) if can_edit_vat else LatamIdentificationType,
31+
'vat_label': request.env._("Identification Number"),
32+
})
33+
34+
return rendering_values
35+
36+
def _get_vat_validation_fields(self):
37+
fnames = super()._get_vat_validation_fields()
38+
if request.website.sudo().company_id.account_fiscal_country_id.code == 'UY':
39+
fnames.add('l10n_latam_identification_type_id')
40+
fnames.add('name')
41+
return fnames
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
2+
3+
from odoo.addons.portal.controllers.portal import CustomerPortal
4+
from odoo.http import request
5+
6+
7+
class CustomerPortalUruguay(CustomerPortal):
8+
9+
def _is_uruguay_company(self):
10+
return request.env.company.country_code == 'UY'
11+
12+
def _get_mandatory_fields(self):
13+
# EXTEND 'portal'
14+
mandatory_fields = super()._get_mandatory_fields()
15+
16+
if self._is_uruguay_company():
17+
mandatory_fields.extend(('l10n_latam_identification_type_id', 'vat'))
18+
19+
return mandatory_fields
20+
21+
def _prepare_portal_layout_values(self):
22+
# EXTEND 'portal'
23+
portal_layout_values = super()._prepare_portal_layout_values()
24+
25+
if self._is_uruguay_company():
26+
partner = request.env.user.partner_id
27+
portal_layout_values.update({
28+
# Select CI identification type by default
29+
'identification': partner.l10n_latam_identification_type_id or request.env.ref('l10n_uy.it_ci').id,
30+
'identification_types': request.env['l10n_latam.identification.type'].search(
31+
['|', ('country_id', '=', False), ('country_id.code', '=', 'UY')]),
32+
})
33+
34+
return portal_layout_values
35+
36+
def details_form_validate(self, data, partner_creation=False):
37+
# EXTEND 'portal'
38+
error, error_message = super().details_form_validate(data, partner_creation)
39+
40+
# sanitize identification value to make sure it's correctly written on the partner
41+
if self._is_uruguay_company() and data.get('l10n_latam_identification_type_id'):
42+
data['l10n_latam_identification_type_id'] = int(data['l10n_latam_identification_type_id'])
43+
44+
return error, error_message
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<odoo>
3+
4+
<function model="ir.model.fields" name="formbuilder_whitelist">
5+
<value>res.partner</value>
6+
<value eval="['l10n_latam_identification_type_id']"/>
7+
</function>
8+
9+
</odoo>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
2+
3+
from . import website
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
2+
3+
from odoo import models
4+
5+
6+
class Website(models.Model):
7+
_inherit = 'website'
8+
9+
def _display_partner_b2b_fields(self):
10+
""" Uruguay localization must always display b2b fields. """
11+
return self.company_id.country_id.code == 'UY' or super()._display_partner_b2b_fields()

0 commit comments

Comments
 (0)