Skip to content

Commit

Permalink
[FIX] account: payment method for different payment types
Browse files Browse the repository at this point in the history
This commit fix a bug noticed when fixing this other
one in v15 odoo#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#97943

X-original-commit: e66663b
Signed-off-by: Laurent Smet <las@odoo.com>
Signed-off-by: Guillaume Vanleynseele (guva) <guva@odoo.com>
  • Loading branch information
guva-odoo committed Aug 11, 2022
1 parent 09e4b2f commit 7ed533d
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
73 changes: 72 additions & 1 deletion addons/account/tests/test_account_payment_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def test_register_payment_multiple_batch_grouped_with_credit_note(self):
},
{
'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'), [
Expand Down Expand Up @@ -1066,3 +1066,74 @@ def test_register_payment_inbound_multiple_bank_account(self):
'partner_bank_id': self.comp_bank_account2.id,
},
])

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})],
})
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,
},
])
7 changes: 6 additions & 1 deletion addons/account/wizard/account_payment_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,11 @@ def _create_payment_vals_from_batch(self, batch_result):
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'],
Expand All @@ -534,7 +539,7 @@ def _create_payment_vals_from_batch(self, batch_result):
'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
}

Expand Down

0 comments on commit 7ed533d

Please sign in to comment.