[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) <nim@odoo.com>
This commit is contained in:
Andrea Grazioso (agr-odoo)
2019-12-12 09:00:18 +00:00
parent 513f8e134e
commit c8e862249e
@@ -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'),