Skip to content

Commit

Permalink
Merge PR #3592 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by sergiocorato
  • Loading branch information
OCA-git-bot committed Feb 28, 2024
2 parents 5d67e82 + 894de6c commit 2a6376f
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions l10n_it_website_sale_fiscalcode/controllers/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2017 Nicola Malcontenti - Agile Business Group

from odoo import _
from odoo.exceptions import ValidationError
from odoo.http import request

from odoo.addons.website_sale.controllers.main import WebsiteSale
Expand All @@ -22,15 +22,29 @@ def checkout_form_validate(self, mode, all_form_values, data):
error, error_message = super().checkout_form_validate(
mode, all_form_values, data
)
partner_sudo = request.env.user.partner_id.sudo()
# Check fiscalcode
partner = request.env.user.partner_id
# company_type does not come from page form
company_type = partner.company_type
company_name = False
if "company_name" in data:
company_name = data.get("company_name")
else:
# when company_name is not posted (readonly)
if partner.company_name:
company_name = partner.company_name
elif partner.company_type == "company":
company_name = partner.name
dummy_partner = request.env["res.partner"].new(
{
"fiscalcode": data.get("fiscalcode"),
"is_company": partner_sudo.is_company,
"company_name": company_name,
"company_type": company_type,
}
)
if dummy_partner.fiscalcode:
if len(dummy_partner.fiscalcode) != 16:
error["fiscalcode"] = "error"
error_message.append(_("Fiscal Code not valid"))
try:
dummy_partner.check_fiscalcode()
except ValidationError as e:
error["fiscalcode"] = "error"
error_message.append(e)
return error, error_message

0 comments on commit 2a6376f

Please sign in to comment.