From 9d1aa41bfbafce072bae672b3a329da99fca712f Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Fri, 30 Nov 2018 15:39:30 +0000 Subject: [PATCH] [FIX] account: randomize invoice reference if no match Take explanation of commit d94e8a0 but this time, have a suffix with a flavor of %(year)s Before this commit, validating the invoice crashes After this commit it doesn't. OPW 1912954 closes odoo/odoo#29160 --- addons/account/models/account_invoice.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 58fab13d628..a16dfcb83f5 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -397,7 +397,12 @@ class AccountInvoice(models.Model): if self.company_id.invoice_reference_type == 'invoice_number': seq_suffix = self.journal_id.sequence_id.suffix or '' regex_number = '.*?([0-9]+)%s$' % seq_suffix - identification_number = int(re.match(regex_number, self.number).group(1)) + exact_match = re.match(regex_number, self.number) + if exact_match: + identification_number = int(exact_match.group(1)) + else: + ran_num = str(uuid.uuid4().int) + identification_number = int(ran_num[:5] + ran_num[-5:]) prefix = self.number else: #self.company_id.invoice_reference_type == 'partner'