[IMP] l10n_ec: user-friendly document number

Do not require user to type all digits of the document number
Instead, fill the dash-separated numbers with zeroes, as needed

closes odoo/odoo#90865

X-original-commit: 9ed26751bfbe84444f291835de5f47bbac3f7dde
Signed-off-by: Josse Colpaert <jco@odoo.com>
Signed-off-by: Stanislas Gueniffey (stgu) <stgu@odoo.com>
This commit is contained in:
Stanislas Gueniffey
2022-05-09 14:03:16 +02:00
parent fb6b959fef
commit d111b4b343
@@ -24,13 +24,16 @@ class L10nLatamDocumentType(models.Model):
return super()._format_document_number(document_number)
if not document_number:
return False
if (
not re.match(r"\d{3}-\d{3}-\d{9}$", document_number)
and self.l10n_ec_check_format
and not self.env.context.get("l10n_ec_foreign", False)
):
raise UserError(
_(u"Ecuadorian Document %s must be like 001-001-123456789")
% (self.display_name)
)
if self.l10n_ec_check_format:
document_number = re.sub(r'\s+', "", document_number) # remove any whitespace
num_match = re.match(r'(\d{1,3})-(\d{1,3})-(\d{1,9})', document_number)
if num_match:
# Fill each number group with zeroes (3, 3 and 9 respectively)
document_number = "-".join([n.zfill(3 if i < 2 else 9) for i, n in enumerate(num_match.groups())])
else:
raise UserError(
_(u"Ecuadorian Document %s must be like 001-001-123456789")
% (self.display_name)
)
return document_number