details: https://code.tryton.org/tryton/commit/8099f9ce2cc7
branch: 7.8
user: Cédric Krier <[email protected]>
date: Wed Sep 30 18:30:11 2026 +0200
description:
Validate stdnum code before compacting and formatting it
Closes #15017
(grafted from 7d7d0ccfb5ab052e3a83b8d33c581d41dcf9eb38)
diffstat:
modules/party/party.py | 21 +++++++++++++--------
1 files changed, 13 insertions(+), 8 deletions(-)
diffs (40 lines):
diff -r fcfd1fe3255c -r 8099f9ce2cc7 modules/party/party.py
--- a/modules/party/party.py Thu Oct 01 09:54:29 2026 +0200
+++ b/modules/party/party.py Wed Sep 30 18:30:11 2026 +0200
@@ -393,12 +393,15 @@
else:
for country in eu_vat.guess_country(text):
if 'eu_vat' in identifier_types:
- code = eu_vat.compact(country + text)
- add('eu_vat', code)
+ code = country + text
+ if eu_vat.is_valid(code):
+ code = eu_vat.compact(code)
+ add('eu_vat', code)
elif f'{country}_vat' in identifier_types:
vat = get_cc_module(country, 'vat')
- code = vat.compact(text)
- add(f'{country}_vat', code)
+ if vat.is_valid(text):
+ code = vat.compact(text)
+ add(f'{country}_vat', code)
return result
@classmethod
@@ -887,10 +890,12 @@
if self.type and '_' in self.type:
module = get_cc_module(*self.type.split('_', 1))
if module:
- try:
- return module.compact(self.code)
- except stdnum.exceptions.ValidationError:
- pass
+ if (hasattr(module, 'is_valid')
+ and module.is_valid(self.code)):
+ try:
+ return module.compact(self.code)
+ except stdnum.exceptions.ValidationError:
+ pass
return self.code
def pre_validate(self):