[FIX] account: write off with same account as the move lines

Having two move lines to reconcile.
The debit one with a past date.
The credit one with a future date.
Have a write-off in the same account as the move lines.

Before this commit, the function that creates the write-off move lines
(_create_writeoff) returns two move lines (the write-off move line itself
and the balance move line) normally only the balance move line should be
returned. Because of this, the reconciliation is not done correctly:
the credit move line is reconciled with the write-off and the balance
line. And the debit move line is not reconciled.

Now, the function _create_writeoff returns only the balance line so the
debit move line, the credit move line and the balance line are totally
reconciled.

opw-1924973

closes odoo/odoo#32055

Signed-off-by: Cedric Snauwaert (csn) <csn@openerp.com>
This commit is contained in:
Jorge Pinna Puissant
2019-03-25 08:49:07 +00:00
parent b1ed7b4637
commit 9a8859cc92
2 changed files with 62 additions and 1 deletions
+1 -1
View File
@@ -1039,7 +1039,7 @@ class AccountMoveLine(models.Model):
writeoff_moves += writeoff_move
# writeoff_move.post()
line_to_reconcile += writeoff_move.line_ids.filtered(lambda r: r.account_id == self[0].account_id)
line_to_reconcile += writeoff_move.line_ids.filtered(lambda r: r.account_id == self[0].account_id).sorted(key='id')[-1:]
if writeoff_moves:
writeoff_moves.post()
# Return the writeoff move.line which is to be reconciled
@@ -470,6 +470,67 @@ class TestReconciliation(AccountingTestCase):
self.assertEquals(aml.amount_residual, 0, 'The journal item should be totally reconciled')
self.assertEquals(aml.amount_residual_currency, 0, 'The journal item should be totally reconciled')
def test_manual_reconcile_wizard_same_account(self):
move_ids = self.env['account.move']
debit_line_vals = {
'name': '1',
'debit': 728.35,
'credit': 0.0,
'account_id': self.account_rcv.id,
'amount_currency': 795.05,
'currency_id': self.currency_swiss_id,
}
credit_line_vals = {
'name': '1',
'debit': 0.0,
'credit': 728.35,
'account_id': self.account_rsa.id,
'amount_currency': -795.05,
'currency_id': self.currency_swiss_id,
}
vals = {
'journal_id': self.bank_journal_euro.id,
'date': time.strftime('%Y') + '-02-15',
'line_ids': [(0,0, debit_line_vals), (0, 0, credit_line_vals)]
}
move_ids += self.env['account.move'].create(vals)
debit_line_vals = {
'name': '2',
'debit': 0.0,
'credit': 737.10,
'account_id': self.account_rcv.id,
'amount_currency': -811.25,
'currency_id': self.currency_swiss_id,
}
credit_line_vals = {
'name': '2',
'debit': 737.10,
'credit': 0.0,
'account_id': self.account_rsa.id,
'amount_currency': 811.25,
'currency_id': self.currency_swiss_id,
}
vals = {
'journal_id': self.bank_journal_euro.id,
'date': time.strftime('%Y') + '-07-15',
'line_ids': [(0,0, debit_line_vals), (0, 0, credit_line_vals)]
}
move_ids += self.env['account.move'].create(vals)
account_move_line = move_ids.mapped('line_ids').filtered(lambda l: l.account_id == self.account_rcv)
writeoff_vals = [{
'account_id': self.account_rcv.id,
'journal_id': self.bank_journal_euro.id,
'date': time.strftime('%Y') + '-04-15',
'debit': 8.75,
'credit': 0.0
}]
writeoff_line = account_move_line._create_writeoff(writeoff_vals)
(account_move_line + writeoff_line).reconcile()
self.assertEquals(len(writeoff_line), 1, "The writeoff_line (balance_line) should have only one moves line")
self.assertTrue(all(l.reconciled for l in writeoff_line), 'The balance lines should be totally reconciled')
self.assertTrue(all(l.reconciled for l in account_move_line), 'The move lines should be totally reconciled')
def test_reconcile_bank_statement_with_payment_and_writeoff(self):
# Use case:
# Company is in EUR, create a bill for 80 USD and register payment of 80 USD.