Skip to content

Commit

Permalink
[IMP] l10n_ec: user-friendly document number
Browse files Browse the repository at this point in the history
Do not require user to type all digits of the document number
Instead, fill the dash-separated numbers with zeroes, as needed

closes odoo#89924

Signed-off-by: Josse Colpaert <[email protected]>
  • Loading branch information
odoostan committed May 6, 2022
1 parent 00360b4 commit 9ed2675
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions addons/l10n_ec/models/l10n_latam_document_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ def _format_document_number(self, document_number):
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

0 comments on commit 9ed2675

Please sign in to comment.