Skip to content

Commit

Permalink
[14.0][FIX] l10n_it_website_sale_fiscalcode: fix fiscalcode check
Browse files Browse the repository at this point in the history
Implement

- #3588
- #3591

This commit restores the call to the constrains `check_fiscalcode()`
in `checkout_form_validate()` method of `WebsiteSale` controller (#3558).
The `company_name` will also be added to the dummy partned so the field
value will be correctly evaluated on the constrains (#3591).
  • Loading branch information
FrancescoBallerini authored and OCA-git-bot committed Feb 27, 2024
1 parent 026442c commit 894de6c
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

Check warning on line 26 in l10n_it_website_sale_fiscalcode/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_website_sale_fiscalcode/controllers/main.py#L26

Added line #L26 was not covered by tests
# company_type does not come from page form
company_type = partner.company_type
company_name = False

Check warning on line 29 in l10n_it_website_sale_fiscalcode/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_website_sale_fiscalcode/controllers/main.py#L28-L29

Added lines #L28 - L29 were not covered by tests
if "company_name" in data:
company_name = data.get("company_name")

Check warning on line 31 in l10n_it_website_sale_fiscalcode/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_website_sale_fiscalcode/controllers/main.py#L31

Added line #L31 was not covered by tests
else:
# when company_name is not posted (readonly)
if partner.company_name:
company_name = partner.company_name

Check warning on line 35 in l10n_it_website_sale_fiscalcode/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_website_sale_fiscalcode/controllers/main.py#L35

Added line #L35 was not covered by tests
elif partner.company_type == "company":
company_name = partner.name

Check warning on line 37 in l10n_it_website_sale_fiscalcode/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_website_sale_fiscalcode/controllers/main.py#L37

Added line #L37 was not covered by tests
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)

Check warning on line 49 in l10n_it_website_sale_fiscalcode/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_website_sale_fiscalcode/controllers/main.py#L45-L49

Added lines #L45 - L49 were not covered by tests
return error, error_message

0 comments on commit 894de6c

Please sign in to comment.