diff --git a/addons/account/tests/test_account_payment_register.py b/addons/account/tests/test_account_payment_register.py index de9d4b66459..59d900285cc 100644 --- a/addons/account/tests/test_account_payment_register.py +++ b/addons/account/tests/test_account_payment_register.py @@ -537,7 +537,7 @@ class TestAccountPaymentRegister(AccountTestInvoicingCommon): }, { 'ref': 'RBILL/2017/01/0001', - 'payment_method_line_id': self.outbound_payment_method_line.id, + 'payment_method_line_id': self.inbound_payment_method_line.id, }, ]) self.assertRecordValues(payments[0].line_ids.sorted('balance') + payments[1].line_ids.sorted('balance') + payments[2].line_ids.sorted('balance'), [ @@ -1159,3 +1159,74 @@ class TestAccountPaymentRegister(AccountTestInvoicingCommon): {'amount_residual': 0.0, 'amount_residual_currency': 0.0, 'currency_id': self.company_data['currency'].id, 'reconciled': True}, {'amount_residual': 0.0, 'amount_residual_currency': 0.0, 'currency_id': self.currency_data['currency'].id, 'reconciled': True}, ]) + + def test_payment_method_different_type_single_batch_not_grouped(self): + """ Test payment methods when paying a bill and a refund with separated payments (1000 + -2000).""" + in_refund = self.env['account.move'].create({ + 'move_type': 'in_refund', + 'date': '2017-01-01', + 'invoice_date': '2017-01-01', + 'partner_id': self.partner_a.id, + 'invoice_line_ids': [(0, 0, {'product_id': self.product_a.id, 'price_unit': 1600.0, 'tax_ids': False})], + }) + in_refund.action_post() + + active_ids = (self.in_invoice_1 + in_refund).ids + payments = self.env['account.payment.register'].with_context(active_model='account.move', active_ids=active_ids).create({ + 'group_payment': False, + })._create_payments() + + self.assertRecordValues(payments[0], [ + { + 'ref': 'BILL/2017/01/0001', + 'payment_method_line_id': self.bank_journal_1.outbound_payment_method_line_ids[0].id, + 'payment_type': 'outbound', + } + ]) + + self.assertRecordValues(payments[1], [ + { + 'ref': 'RBILL/2017/01/0002', + 'payment_method_line_id': self.bank_journal_1.inbound_payment_method_line_ids[0].id, + 'payment_type': 'inbound', + }, + ]) + + self.assertRecordValues(payments[0].line_ids.sorted('balance'), [ + # == Payment 1: to pay in_invoice_1 == + # Liquidity line: + { + 'debit': 0.0, + 'credit': 1000.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': -1000.0, + 'reconciled': False, + }, + # Payable line: + { + 'debit': 1000.0, + 'credit': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': 1000.0, + 'reconciled': True, + }, + ]) + self.assertRecordValues(payments[1].line_ids.sorted('balance'), [ + # == Payment 2: to pay in_refund_1 == + # Payable line: + { + 'debit': 0.0, + 'credit': 1600.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': -1600.0, + 'reconciled': True, + }, + # Liquidity line: + { + 'debit': 1600.0, + 'credit': 0.0, + 'currency_id': self.company_data['currency'].id, + 'amount_currency': 1600.0, + 'reconciled': False, + }, + ]) diff --git a/addons/account/wizard/account_payment_register.py b/addons/account/wizard/account_payment_register.py index 81feee97191..d515c8a533c 100644 --- a/addons/account/wizard/account_payment_register.py +++ b/addons/account/wizard/account_payment_register.py @@ -595,6 +595,11 @@ class AccountPaymentRegister(models.TransientModel): else: partner_bank_id = batch_result['payment_values']['partner_bank_id'] + payment_method_line = self.payment_method_line_id + + if batch_values['payment_type'] != payment_method_line.payment_type: + payment_method_line = self.journal_id._get_available_payment_method_lines(batch_values['payment_type'])[:1] + return { 'date': self.payment_date, 'amount': batch_values['source_amount_currency'], @@ -605,7 +610,7 @@ class AccountPaymentRegister(models.TransientModel): 'currency_id': batch_values['source_currency_id'], 'partner_id': batch_values['partner_id'], 'partner_bank_id': partner_bank_id, - 'payment_method_line_id': self.payment_method_line_id.id, + 'payment_method_line_id': payment_method_line.id, 'destination_account_id': batch_result['lines'][0].account_id.id }