[FIX] account: bank reconciliation: don't force partner when mixing payments with and without partner

Steps to reproduce :

- Create an invoice for a customer (ex $100)
- Create a payment for the invoice (ex $100)
- create a bank statement with a line item for $200
- In reconciliation, add either another journal entry or a manual operation without partner to reconcile the remaining $100

Issue:

All lines receive the partner from the invoice

opw-2691196

closes odoo/odoo#82517

X-original-commit: 6cda0780fdccf666f5a3fb0f39db59fcb0bd45c8
Signed-off-by: Guillaume Vanleynseele <guva@odoo.com>
Signed-off-by: Olivier Colson <oco@odoo.com>
This commit is contained in:
Guillaume (guva)
2022-01-11 08:36:51 +00:00
parent 386e54c9e2
commit e666487446
2 changed files with 85 additions and 2 deletions
@@ -1236,8 +1236,8 @@ class AccountBankStatementLine(models.Model):
if not self.partner_id:
rec_overview_partners = set(overview['counterpart_line'].partner_id.id
for overview in reconciliation_overview
if overview.get('counterpart_line') and overview['counterpart_line'].partner_id)
if len(rec_overview_partners) == 1:
if overview.get('counterpart_line'))
if len(rec_overview_partners) == 1 and rec_overview_partners != {False}:
self.line_ids.write({'partner_id': rec_overview_partners.pop()})
# Refresh analytic lines.
@@ -1464,3 +1464,86 @@ class TestAccountBankStatementLine(TestAccountBankStatementCommon):
self.assertRecordValues(statement_line.line_ids.analytic_line_ids, [
{'amount': 100.0, 'account_id': analytic_account.id},
])
def test_reconciliation_line_with_no_partner(self):
"""
Ensure that entry lines and statement line have no partner when reconciling
lines without partner with others with partner
"""
statement = self.env['account.bank.statement'].create({
'name': 'test_statement',
'date': '2019-01-01',
'journal_id': self.bank_journal_1.id,
'line_ids': [
(0, 0, {
'date': '2022-01-01',
'payment_ref': "Happy new year",
'amount': 200.0,
}),
],
})
statement.button_post()
partner = self.env['res.partner'].create({'name': 'test'})
receivable_account = self.company_data['default_account_receivable']
outstanding_account = self.env['account.account'].search([('code', '=', '101402'), ('company_id', '=', self.env.company.id)])
payments = self.env['account.payment'].create([
{
'name': 'Payment without partner',
'date': fields.Date.from_string('2022-01-01'),
'is_internal_transfer': False,
'amount': 100.0,
'payment_type': 'inbound',
'partner_type': 'customer',
'destination_account_id': receivable_account.id,
'journal_id': self.bank_journal_1.id,
},
{
'name': 'Payment with partner',
'date': fields.Date.from_string('2022-01-01'),
'is_internal_transfer': False,
'amount': 100.0,
'payment_type': 'inbound',
'partner_type': 'customer',
'partner_id': partner.id,
'destination_account_id': receivable_account.id,
'journal_id': self.bank_journal_1.id,
},
])
payments.action_post()
statement_line = statement.line_ids
statement_line.reconcile([
{'id': payments[0].move_id.line_ids.filtered(lambda line: line.account_id == outstanding_account).id},
{'id': payments[1].move_id.line_ids.filtered(lambda line: line.account_id == outstanding_account).id},
])
self.assertRecordValues(
statement.line_ids.move_id.line_ids,
[
{
'debit': 200.0,
'credit': 0.0,
'partner_id': False,
'account_id': self.bank_journal_1.default_account_id.id
},
{
'debit': 0.0,
'credit': 100.0,
'partner_id': False,
'account_id': outstanding_account.id
},
{
'debit': 0.0,
'credit': 100.0,
'partner_id': partner.id,
'account_id': outstanding_account.id
},
])
self.assertRecordValues(statement.line_ids, [{
'partner_id': False,
}])