[FIX] account: reconcile in liquidity accounts.
Make one Payment Reverse the entry of this payment. Before this commit, only the lines in the receivable were reconciled. The lines in the liquidity were'nt, leaving the two entries appearing in some reports After this commit, the four lines are reconciled two by two, even in the liquidity account OPW 1816641 closes #25026
This commit is contained in:
@@ -222,7 +222,8 @@ class AccountMove(models.Model):
|
||||
# Do not forward port in >= saas-14
|
||||
def _reconcile_reversed_pair(self, move, reversed_move):
|
||||
amls_to_reconcile = (move.line_ids + reversed_move.line_ids).filtered(lambda l: not l.reconciled)
|
||||
accounts_reconcilable = amls_to_reconcile.mapped('account_id').filtered(lambda a: a.reconcile)
|
||||
# Do not forward port changes in this file in >= saas-14
|
||||
accounts_reconcilable = amls_to_reconcile.mapped('account_id').filtered(lambda a: a.reconcile or a.internal_type == 'liquidity')
|
||||
for account in accounts_reconcilable:
|
||||
amls_for_account = amls_to_reconcile.filtered(lambda l: l.account_id.id == account.id)
|
||||
amls_for_account.reconcile()
|
||||
@@ -804,6 +805,9 @@ class AccountMoveLine(models.Model):
|
||||
def _get_pair_to_reconcile(self):
|
||||
#field is either 'amount_residual' or 'amount_residual_currency' (if the reconciled account has a secondary currency set)
|
||||
field = self[0].account_id.currency_id and 'amount_residual_currency' or 'amount_residual'
|
||||
if not self[0].account_id.reconcile and self[0].account_id.internal_type == 'liquidity':
|
||||
field = 'balance'
|
||||
|
||||
rounding = self[0].company_id.currency_id.rounding
|
||||
if self[0].currency_id and all([x.amount_currency and x.currency_id == self[0].currency_id for x in self]):
|
||||
#or if all lines share the same currency
|
||||
@@ -904,7 +908,7 @@ class AccountMoveLine(models.Model):
|
||||
raise UserError(_('To reconcile the entries company should be the same for all entries!'))
|
||||
if len(set(all_accounts)) > 1:
|
||||
raise UserError(_('Entries are not of the same account!'))
|
||||
if not all_accounts[0].reconcile:
|
||||
if not (all_accounts[0].reconcile or all_accounts[0].internal_type == 'liquidity'):
|
||||
raise UserError(_('The account %s (%s) is not marked as reconciliable !') % (all_accounts[0].name, all_accounts[0].code))
|
||||
|
||||
#reconcile everything that can be
|
||||
|
||||
@@ -39,6 +39,12 @@ class TestReconciliation(AccountingTestCase):
|
||||
self.diff_income_account = self.env['res.users'].browse(self.env.uid).company_id.income_currency_exchange_account_id
|
||||
self.diff_expense_account = self.env['res.users'].browse(self.env.uid).company_id.expense_currency_exchange_account_id
|
||||
|
||||
self.inbound_payment_method = self.env['account.payment.method'].create({
|
||||
'name': 'inbound',
|
||||
'code': 'IN',
|
||||
'payment_type': 'inbound',
|
||||
})
|
||||
|
||||
def create_invoice(self, type='out_invoice', invoice_amount=50, currency_id=None):
|
||||
#we create an invoice in given currency
|
||||
invoice = self.account_invoice_model.create({'partner_id': self.partner_agrolait_id,
|
||||
@@ -704,3 +710,47 @@ class TestReconciliation(AccountingTestCase):
|
||||
# Unreconcile invoice and check residual
|
||||
credit_aml.with_context(invoice_id=inv.id).remove_move_reconcile()
|
||||
self.assertAlmostEquals(inv.residual, 111)
|
||||
|
||||
# Please do forward port all the way up
|
||||
def test_revert_payment_and_reconcile(self):
|
||||
payment = self.env['account.payment'].create({
|
||||
'payment_method_id': self.inbound_payment_method.id,
|
||||
'payment_type': 'inbound',
|
||||
'partner_type': 'customer',
|
||||
'partner_id': self.partner_agrolait_id,
|
||||
'journal_id': self.bank_journal_usd.id,
|
||||
'payment_date': '2018-06-04',
|
||||
'amount': 666,
|
||||
})
|
||||
payment.post()
|
||||
|
||||
self.assertEqual(len(payment.move_line_ids), 2)
|
||||
|
||||
bank_line = payment.move_line_ids.filtered(lambda l: l.account_id.id == self.bank_journal_usd.default_debit_account_id.id)
|
||||
customer_line = payment.move_line_ids - bank_line
|
||||
|
||||
self.assertEqual(len(bank_line), 1)
|
||||
self.assertEqual(len(customer_line), 1)
|
||||
self.assertNotEqual(bank_line.id, customer_line.id)
|
||||
|
||||
self.assertEqual(bank_line.move_id.id, customer_line.move_id.id)
|
||||
move = bank_line.move_id
|
||||
|
||||
# Reversing the payment's move
|
||||
reversed_move_list = move.reverse_moves('2018-06-04')
|
||||
self.assertEqual(len(reversed_move_list), 1)
|
||||
reversed_move = self.env['account.move'].browse(reversed_move_list[0])
|
||||
|
||||
self.assertEqual(len(reversed_move.line_ids), 2)
|
||||
|
||||
# Testing the reconciliation matching between the move lines and their reversed counterparts
|
||||
reversed_bank_line = reversed_move.line_ids.filtered(lambda l: l.account_id.id == self.bank_journal_usd.default_debit_account_id.id)
|
||||
reversed_customer_line = reversed_move.line_ids - reversed_bank_line
|
||||
|
||||
self.assertEqual(len(reversed_bank_line), 1)
|
||||
self.assertEqual(len(reversed_customer_line), 1)
|
||||
self.assertNotEqual(reversed_bank_line.id, reversed_customer_line.id)
|
||||
self.assertEqual(reversed_bank_line.move_id.id, reversed_customer_line.move_id.id)
|
||||
|
||||
self.assertEqual(reversed_bank_line.full_reconcile_id.id, bank_line.full_reconcile_id.id)
|
||||
self.assertEqual(reversed_customer_line.full_reconcile_id.id, customer_line.full_reconcile_id.id)
|
||||
|
||||
Reference in New Issue
Block a user