[FIX] account: payment method for different payment types

This commit fix a bug noticed when fixing this other
one in v15 https://github.com/odoo/odoo/pull/93943.

We notice that, in addition to not set correctly
the payment type, the payment method was wrong too.

With this commit, when creating payments from batch,
we check for each payment if its type is the same
as the one set on the wizard. If not (which means
that there are payments of differents types), we set
the payment method regarding the payment type.

opw-2852186

closes odoo/odoo#98153

X-original-commit: af1fab8dab141c49d98b431a40a5ce98f2f3249c
Signed-off-by: Laurent Smet <las@odoo.com>
Signed-off-by: Guillaume Vanleynseele (guva) <guva@odoo.com>
This commit is contained in:
Guillaume (guva)
2022-08-17 11:21:34 +02:00
parent a41bec89e9
commit 62520fbefe
2 changed files with 78 additions and 2 deletions
@@ -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,
},
])
@@ -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
}