[ADD] l10n_it_edi_website_sale: Add 'Codice Fiscale' in checkout form

Implemented 'Codice Fiscale' field in checkout address form, addressing
a key need for our Italian customers.

This enhancement:

- Adds an optional 'Codice Fiscale' field, available for both
individuals and companies.
- Ensures compliance with Italian e-invoice requirements.

This update is a step towards better adapting our system to specific
localization requirements, enhancing user experience in italy.

task-3623622

closes odoo/odoo#151484

X-original-commit: 79157cdc9396b1a84f70d455f211febbc505c66c
Signed-off-by: Josse Colpaert <jco@odoo.com>
Signed-off-by: Mohamed Erradi (moer) <moer@odoo.com>
This commit is contained in:
moerradi
2024-01-29 02:16:51 +00:00
parent 625dac5a10
commit 586f75687d
9 changed files with 159 additions and 0 deletions
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import controllers
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': "Italy eCommerce eInvoicing",
'version': "1.0",
'category': 'Accounting/Localizations/Website',
'summary': "Features for Italian eCommerce eInvoicing",
'description': """
Contains features for Italian eCommerce eInvoicing
""",
'depends': ['l10n_it_edi', 'website_sale'],
'data': [
'views/templates.xml',
'data/data.xml'
],
'installable': True,
'auto_install': True,
'license': 'OEEL-1',
'assets': {
'web.assets_tests': [
'l10n_it_edi_website_sale/static/tests/**/*',
],
},
}
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import main
@@ -0,0 +1,26 @@
# -*- coding:utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.website_sale.controllers.main import WebsiteSale
from odoo.http import request
from odoo.exceptions import UserError
from odoo import _
class ItalyWebsiteSaleForm(WebsiteSale):
def checkout_form_validate(self, mode, all_form_values, data):
error, error_message = super().checkout_form_validate(mode, all_form_values, data)
Partner = request.env['res.partner']
if data.get('l10n_it_codice_fiscale'):
partner_dummy = Partner.new({
'l10n_it_codice_fiscale': data.get('l10n_it_codice_fiscale')
})
try:
partner_dummy.validate_codice_fiscale()
except UserError as e:
error['l10n_it_codice_fiscale'] = 'error'
error_message.append(e.name)
pa_index = data.get('l10n_it_pa_index')
if pa_index:
if len(pa_index) < 6 or len(pa_index) > 7:
error['l10n_it_pa_index'] = 'error'
error_message.append(_('PA index must have between 6 and 7 characters'))
return error, error_message
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<function model="ir.model.fields" name="formbuilder_whitelist">
<value>res.partner</value>
<value eval="[
'l10n_it_codice_fiscale',
'l10n_it_pa_index',
]"/>
</function>
</data>
</odoo>
@@ -0,0 +1,45 @@
/** @odoo-module alias=l10n_it_edi_website_sale.tour **/
import { registry } from "@web/core/registry";
import tourUtils from "@website_sale/js/tours/tour_utils";
registry.category("web_tour.tours").add('shop_checkout_address', {
test: true,
url: '/shop',
steps: () => [
{
content: "search Storage Box",
trigger: 'form input[name="search"]',
run: "text Storage Box",
},
{
content: "search Storage Box",
trigger: 'form:has(input[name="search"]) .oe_search_button',
},
{
content: "select Storage Box",
trigger: '.oe_product_cart:first a:contains("Storage Box")',
},
{
id: 'add_cart_step',
content: "click on add to cart",
trigger: '#product_detail form[action^="/shop/cart/update"] #add_to_cart',
},
tourUtils.goToCart(),
{
content: "go to address form",
trigger: 'a[href="/shop/checkout?express=1"]',
},
// check if the fields Codice Fiscale and PA index are present
{
content: "check if the fields Codice Destinatario is present",
trigger: 'input[name="l10n_it_pa_index"]',
run: "text 1234567890123456789012345",
},
{
content: "check if the fields Codice Fiscale is present",
trigger: 'input[name="l10n_it_codice_fiscale"]',
run: "text 12345678901",
},
]
});
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import test_l10n_it_edi_website_sale
@@ -0,0 +1,19 @@
from odoo.tests.common import HttpCase, tagged
@tagged('post_install_l10n', 'post_install', '-at_install')
class TestUi(HttpCase):
def setUp(self):
super(TestUi, self).setUp()
self.env['product.product'].create({
'name': 'Storage Box',
'standard_price': 70.0,
'list_price': 79.0,
'website_published': True,
})
def test_checkout_address(self):
# set current company's fiscal country to italy
website = self.env['website'].get_current_website()
website.company_id.account_fiscal_country_id = website.company_id.country_id = self.env.ref('base.it')
self.start_tour("/", 'shop_checkout_address')
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="address" inherit_id="website_sale.address" name="Show l10n_it fields" customize_show="True">
<xpath expr="//div[contains(@t-attf-class, 'div_vat')]" position="after">
<t t-if="res_company.account_fiscal_country_id.code == 'IT'">
<div class="w-100"/>
<div t-attf-class="mb-3 #{error.get('vat') and 'o_has_error' or ''} col-lg-6 div_l10n_it_codice_fiscale mb-0" id="div_l10n_it_codice_fiscale">
<label class="col-form-label fw-normal label-optional" for="l10n_it_codice_fiscale">Codice Fiscale </label>
<input type="text" name="l10n_it_codice_fiscale" t-attf-class="form-control #{error.get('l10n_it_codice_fiscale') and 'is-invalid' or ''}" t-att-value="'l10n_it_codice_fiscale' in checkout and checkout['l10n_it_codice_fiscale']"/>
</div>
<div t-attf-class="mb-3 #{error.get('vat') and 'o_has_error' or ''} col-lg-6 div_l10n_it_pa_index mb-0" id="div_l10n_it_pa_index">
<label class="col-form-label fw-normal label-optional" for="l10n_it_pa_index">PA index </label>
<input type="text" name="l10n_it_pa_index" t-attf-class="form-control #{error.get('l10n_it_pa_index') and 'is-invalid' or ''}" t-att-value="'l10n_it_codice_fiscale' in checkout and checkout['l10n_it_codice_fiscale']"/>
</div>
</t>
</xpath>
</template>
</data>
</odoo>