Skip to content
Snippets Groups Projects
Commit 7c4d3cd4 authored by Guillaume (guva)'s avatar Guillaume (guva)
Browse files

[REV][FIX] account_check_printing: allow multiple payments


revert of 135f3d7b373d07fb1f0a27145df3d3cd9fc28337
We don't want to consume a sequence in a compute.

closes odoo/odoo#90847

Signed-off-by: default avatarWilliam André (wan) <wan@odoo.com>
parent f0125959
No related branches found
No related tags found
No related merge requests found
......@@ -36,7 +36,7 @@ class AccountJournal(models.Model):
for journal in self:
sequence = journal.check_sequence_id
if sequence:
journal.check_next_number = sequence.next_by_id()
journal.check_next_number = sequence.get_next_char(sequence.number_next_actual)
else:
journal.check_next_number = 1
......
......@@ -85,12 +85,14 @@ class AccountPayment(models.Model):
else:
pay.check_amount_in_words = False
@api.depends('journal_id', 'payment_method_code', 'state')
@api.depends('journal_id', 'payment_method_code')
def _compute_check_number(self):
for pay in self.filtered(lambda p: p.state == 'posted'):
if pay.journal_id.check_manual_sequencing and pay.payment_method_code == 'check_printing' and not pay.check_number:
for pay in self:
if pay.journal_id.check_manual_sequencing and pay.payment_method_code == 'check_printing':
sequence = pay.journal_id.check_sequence_id
pay.check_number = sequence.next_by_id()
pay.check_number = sequence.get_next_char(sequence.number_next_actual)
else:
pay.check_number = False
def _inverse_check_number(self):
for payment in self:
......@@ -106,6 +108,14 @@ class AccountPayment(models.Model):
if record.payment_type == 'outbound' and preferred in record.journal_id.outbound_payment_method_ids:
record.payment_method_id = preferred
def action_post(self):
res = super(AccountPayment, self).action_post()
payment_method_check = self.env.ref('account_check_printing.account_payment_method_check')
for payment in self.filtered(lambda p: p.payment_method_id == payment_method_check and p.check_manual_sequencing):
sequence = payment.journal_id.check_sequence_id
payment.check_number = sequence.next_by_id()
return res
def print_checks(self):
""" Check that the recordset is valid, set the payments state to sent and call print_checks() """
# Since this method can be called via a client_action_multi, we need to make sure the received records are what we expect
......
......@@ -134,30 +134,3 @@ class TestPrintCheck(AccountTestInvoicingCommon):
'amount_paid': f'150.000{NON_BREAKING_SPACE}',
'currency': invoice.currency_id,
}]])
def test_in_invoice_check_manual_sequencing_with_multiple_payments(self):
"""
Test the check generation for vendor bills with multiple payments.
"""
nb_invoices_to_test = INV_LINES_PER_STUB + 1
self.company_data['default_journal_bank'].write({
'check_manual_sequencing': True,
'check_next_number': '11111',
})
in_invoices = self.env['account.move'].create([{
'move_type': 'in_invoice',
'partner_id': self.partner_a.id,
'date': '2017-01-01',
'invoice_date': '2017-01-01',
'invoice_line_ids': [(0, 0, {'product_id': self.product_a.id, 'price_unit': 100.0})]
} for i in range(nb_invoices_to_test)])
in_invoices.action_post()
payments = self.env['account.payment.register'].with_context(active_model='account.move', active_ids=in_invoices.ids).create({
'group_payment': False,
'payment_method_id': self.payment_method_check.id,
})._create_payments()
self.assertEqual(set(payments.mapped('check_number')), {str(x) for x in range(11111, 11121)})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment