[FIX] account: Fix unbalanced journal entry when editing payment
Steps to reproduce: - On bank journal set the outstanding payments accounts and the outstanding receipts accounts, respectively to 101403 and 101402 - In Accounting > Configuration > Settings > Default Accounts, let the two outstanding accounts empty. - Customer > payment > create a payment : payment type "Receive", amount 5 for example. Save it. - Edit the payment and change the payment type to "Send". - Click on Save. Issue Got an UserError "Cannot create unbalanced journal entry" Since the payment_type has changed, the computed outstanding_account_id on the payment is recomputed. When splitting journal items using the _seek_for_lines() method, odoo is not able to retrieve the liquidity lines since outstanding_account_id has changed. opw-2620046 closes odoo/odoo#78866 X-original-commit: 865c5d7741ca1bf003b4181d06484cc4ecaf8fcb Signed-off-by: Laurent Smet <smetl@users.noreply.github.com> Signed-off-by: guva-odoo <guva-odoo@users.noreply.github.com>
This commit is contained in:
@@ -194,6 +194,8 @@ class AccountPayment(models.Model):
|
||||
self.payment_method_line_id.payment_account_id,
|
||||
self.journal_id.company_id.account_journal_payment_debit_account_id,
|
||||
self.journal_id.company_id.account_journal_payment_credit_account_id,
|
||||
self.journal_id.inbound_payment_method_line_ids.payment_account_id,
|
||||
self.journal_id.outbound_payment_method_line_ids.payment_account_id,
|
||||
)
|
||||
|
||||
def _prepare_move_line_default_vals(self, write_off_line_vals=None):
|
||||
|
||||
@@ -769,3 +769,47 @@ class TestAccountPayment(AccountTestInvoicingCommon):
|
||||
self.assertEqual(payment.name, '/')
|
||||
payment.action_post()
|
||||
self.assertRegex(payment.name, r'BNK1/\d{4}/\d{2}/0002')
|
||||
|
||||
def test_payment_without_default_company_account(self):
|
||||
""" The purpose of this test is to check the specific behavior when duplicating an inbound payment, then change
|
||||
the copy to an outbound payment when we set the outstanding accounts (payments and receipts) on a journal but
|
||||
not on the company level.
|
||||
"""
|
||||
company = self.company_data['company']
|
||||
bank_journal = self.company_data['default_journal_bank']
|
||||
|
||||
bank_journal.outbound_payment_method_line_ids.payment_account_id = company.account_journal_payment_credit_account_id
|
||||
bank_journal.inbound_payment_method_line_ids.payment_account_id = company.account_journal_payment_debit_account_id
|
||||
company.account_journal_payment_debit_account_id = False
|
||||
company.account_journal_payment_credit_account_id = False
|
||||
|
||||
payment = self.env['account.payment'].create({
|
||||
'amount': 5.0,
|
||||
'payment_type': 'inbound',
|
||||
'partner_type': 'customer',
|
||||
'journal_id': bank_journal.id,
|
||||
})
|
||||
self.assertRecordValues(payment, [{
|
||||
'amount': 5.0,
|
||||
'payment_type': 'inbound',
|
||||
'partner_type': 'customer',
|
||||
'payment_reference': False,
|
||||
'is_reconciled': False,
|
||||
'currency_id': self.company_data['currency'].id,
|
||||
'partner_id': False,
|
||||
'payment_method_line_id': self.inbound_payment_method_line.id,
|
||||
'partner_bank_id': False,
|
||||
}])
|
||||
|
||||
payment.payment_type = 'outbound'
|
||||
self.assertRecordValues(payment, [{
|
||||
'amount': 5.0,
|
||||
'payment_type': 'outbound',
|
||||
'partner_type': 'customer',
|
||||
'payment_reference': False,
|
||||
'is_reconciled': False,
|
||||
'currency_id': self.company_data['currency'].id,
|
||||
'partner_id': False,
|
||||
'payment_method_line_id': self.outbound_payment_method_line.id,
|
||||
'partner_bank_id': False,
|
||||
}])
|
||||
|
||||
Reference in New Issue
Block a user