From c8e862249eba4b5f6cc9c3ac89167aec494c44f4 Mon Sep 17 00:00:00 2001 From: "Andrea Grazioso (agr-odoo)" Date: Tue, 10 Dec 2019 15:35:21 +0000 Subject: [PATCH] [IMP] account_check_printing: store check number also as int Go to Accounting > Vendor Bill, pay via check, view the invoice and click on 'Print Check'. The widget will popup but as the 'next check number' will always display 1. This append because the model of account_payment has changed https://github.com/odoo/odoo/blob/13.0/addons/account_check_printing/models/account_payment.py#L28 and now check_number is a char so it will not sorted correcly by the database. To avoid doing a lot of strings manipulation it is convenient to store the check number as integer, with proper default case Followup of opw 2151242 closes odoo/odoo#41659 Signed-off-by: Nicolas Martinelli (nim) --- .../models/account_payment.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/addons/account_check_printing/models/account_payment.py b/addons/account_check_printing/models/account_payment.py index 85b01c5491e..79b6468b143 100644 --- a/addons/account_check_printing/models/account_payment.py +++ b/addons/account_check_printing/models/account_payment.py @@ -28,6 +28,19 @@ class AccountPayment(models.Model): check_number = fields.Char(string="Check Number", readonly=True, copy=False, help="The selected journal is configured to print check numbers. If your pre-printed check paper already has numbers " "or if the current numbering is wrong, you can change it in the journal configuration page.") + check_number_int = fields.Integer(string="Check Number Integer", store=True, compute='_compute_check_number') + + @api.depends('check_number') + def _compute_check_number(self): + # store check number as int to avoid doing a lot of checks and transformations + # when calculating next_check_number + for record in self: + number = record.check_number + try: + number = int(number) + except Exception as e: + number = 0 + record.check_number_int = number @api.onchange('amount', 'currency_id') def _onchange_amount(self): @@ -74,8 +87,8 @@ class AccountPayment(models.Model): # so payments are attributed the number of the check the'll be printed on. last_printed_check = self.search([ ('journal_id', '=', self[0].journal_id.id), - ('check_number', '!=', "0")], order="check_number desc", limit=1) - next_check_number = last_printed_check and int(last_printed_check.check_number) + 1 or 1 + ('check_number_int', '!=', 0)], order="check_number_int desc", limit=1) + next_check_number = last_printed_check and last_printed_check.check_number_int + 1 or 1 return { 'name': _('Print Pre-numbered Checks'),