Skip to content

Commit b256b27

Browse files
[FIX] intrastat_product: no longer use is_valid from stdnum.vatin lib and use Odoo's validation
1 parent f172138 commit b256b27

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

intrastat_product/models/intrastat_product_declaration.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from datetime import date
99

1010
from dateutil.relativedelta import relativedelta
11-
from stdnum.vatin import is_valid
1211

1312
from odoo import Command, _, api, fields, models
1413
from odoo.exceptions import RedirectWarning, UserError, ValidationError
@@ -1129,8 +1128,17 @@ def _compute_product_origin_country_code(self):
11291128
@api.constrains("vat")
11301129
def _check_vat(self):
11311130
for this in self:
1132-
if this.vat and not is_valid(this.vat):
1133-
raise ValidationError(_("The VAT number '%s' is invalid.") % this.vat)
1131+
if not this.vat:
1132+
continue
1133+
country = this.partner_id.commercial_partner_id.country_id
1134+
partner_obj = self.env["res.partner"]
1135+
if not partner_obj._run_vat_test(this.vat, country):
1136+
msg = partner_obj._build_vat_error_message(
1137+
country and country.code.lower() or None,
1138+
this.vat,
1139+
_("partner [%s]") % this.partner_id.name,
1140+
)
1141+
raise ValidationError(msg)
11341142

11351143
@api.depends("partner_id")
11361144
def _compute_vat(self):

0 commit comments

Comments
 (0)