Skip to content

Commit 2a8f777

Browse files
agr-odoooco-odoo
authored andcommitted
[FIX] account: process duplicate tax lines when creating CABA entries
- Enable cash basis (Accounting>Settings>Taxes) - Enable analytic accounting (Accounting>Settings>Analytics) - Have a sale tax: - Based on payment (Account 10100 Current Assets) - Included in Analytic Cost - Create a [DEMO] product with such tax - Create an invoice with 2 lines: - One line with product DEMO and whatever analytic account - One line with product DEMO but no analytic account -Confirm and receive payment CABA entry will consider only 1 tax line, because the 2 entries are equal beside the analytic account which is not considered in the grouping keys opw-2507417 closes odoo#70884 Signed-off-by: oco-odoo <[email protected]>
1 parent 9b64e52 commit 2a8f777

File tree

3 files changed

+87
-26
lines changed

3 files changed

+87
-26
lines changed

addons/account/models/account_move.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4418,12 +4418,19 @@ def _add_cash_basis_lines_to_exchange_difference_vals(lines, exchange_diff_move_
44184418
if line.tax_repartition_line_id:
44194419
# Tax line.
44204420
grouping_key = self.env['account.partial.reconcile']._get_cash_basis_tax_line_grouping_key_from_record(line)
4421-
account_vals_to_fix[grouping_key] = {
4422-
**vals,
4423-
'account_id': line.account_id.id,
4424-
'tax_base_amount': line.tax_base_amount,
4425-
'tax_repartition_line_id': line.tax_repartition_line_id.id,
4426-
}
4421+
if grouping_key in account_vals_to_fix:
4422+
account_vals_to_fix[grouping_key].update({
4423+
'debit': account_vals_to_fix[grouping_key]['debit'] + vals['debit'],
4424+
'credit': account_vals_to_fix[grouping_key]['credit'] + vals['credit'],
4425+
'tax_base_amount': account_vals_to_fix[grouping_key]['tax_base_amount'] + line.tax_base_amount,
4426+
})
4427+
else:
4428+
account_vals_to_fix[grouping_key] = {
4429+
**vals,
4430+
'account_id': line.account_id.id,
4431+
'tax_base_amount': line.tax_base_amount,
4432+
'tax_repartition_line_id': line.tax_repartition_line_id.id,
4433+
}
44274434
elif line.tax_ids:
44284435
# Base line.
44294436
account_to_fix = line.company_id.account_cash_basis_base_account_id

addons/account/models/account_partial_reconcile.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -522,33 +522,35 @@ def _create_tax_cash_basis_moves(self):
522522
if line.tax_repartition_line_id:
523523
# Tax line.
524524

525-
cb_tax_line_vals = self._prepare_cash_basis_tax_line_vals(line, balance, amount_currency)
526-
grouping_key = self._get_cash_basis_tax_line_grouping_key_from_vals(cb_tax_line_vals)
527-
partial_lines_to_create[grouping_key] = {
528-
'tax_line': line,
529-
'vals': cb_tax_line_vals,
530-
}
531-
525+
cb_line_vals = self._prepare_cash_basis_tax_line_vals(line, balance, amount_currency)
526+
grouping_key = self._get_cash_basis_tax_line_grouping_key_from_vals(cb_line_vals)
532527
elif line.tax_ids:
533528
# Base line.
534529

535-
cb_base_line_vals = self._prepare_cash_basis_base_line_vals(line, balance, amount_currency)
536-
grouping_key = self._get_cash_basis_base_line_grouping_key_from_vals(cb_base_line_vals)
530+
cb_line_vals = self._prepare_cash_basis_base_line_vals(line, balance, amount_currency)
531+
grouping_key = self._get_cash_basis_base_line_grouping_key_from_vals(cb_line_vals)
537532

538-
if grouping_key in partial_lines_to_create:
539-
aggregated_vals = partial_lines_to_create[grouping_key]['vals']
540-
balance = aggregated_vals['debit'] - aggregated_vals['credit']
541-
balance += cb_base_line_vals['debit'] - cb_base_line_vals['credit']
533+
if grouping_key in partial_lines_to_create:
534+
aggregated_vals = partial_lines_to_create[grouping_key]['vals']
542535

536+
aggregated_vals.update({
537+
'debit': aggregated_vals['debit'] + cb_line_vals['debit'],
538+
'credit': aggregated_vals['credit'] + cb_line_vals['credit'],
539+
'amount_currency': aggregated_vals['amount_currency'] + cb_line_vals['amount_currency'],
540+
})
541+
if line.tax_repartition_line_id:
543542
aggregated_vals.update({
544-
'debit': balance if balance > 0.0 else 0.0,
545-
'credit': -balance if balance < 0.0 else 0.0,
543+
'tax_base_amount': aggregated_vals['tax_base_amount'] + cb_line_vals['tax_base_amount'],
544+
})
545+
partial_lines_to_create[grouping_key]['tax_line'] += line
546+
else:
547+
partial_lines_to_create[grouping_key] = {
548+
'vals': cb_line_vals,
549+
}
550+
if line.tax_repartition_line_id:
551+
partial_lines_to_create[grouping_key].update({
552+
'tax_line': line,
546553
})
547-
aggregated_vals['amount_currency'] += cb_base_line_vals['amount_currency']
548-
else:
549-
partial_lines_to_create[grouping_key] = {
550-
'vals': cb_base_line_vals,
551-
}
552554

553555
# ==========================================================================
554556
# Create the counterpart journal items.

addons/account/tests/test_account_move_reconcile.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# -*- coding: utf-8 -*-
22
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
33
from odoo.tests import tagged
4+
from odoo.tests.common import Form
5+
from odoo import fields
46

57

68
@tagged('post_install', '-at_install')
@@ -2076,6 +2078,56 @@ def test_caba_mix_reconciliation(self):
20762078
# Check full reconciliation
20772079
self.assertTrue(all(line.full_reconcile_id for line in lines_to_reconcile), "All tax lines should be fully reconciled")
20782080

2081+
def test_caba_double_tax(self):
2082+
""" Test the CABA entries generated from an invoice with almost
2083+
equal lines, different only on analytic accounting
2084+
"""
2085+
# Make the tax account reconcilable
2086+
self.tax_account_1.reconcile = True
2087+
2088+
# Create an invoice with a CABA tax using 'Include in analytic cost'
2089+
move_form = Form(self.env['account.move'].with_context(default_move_type='in_invoice', account_predictive_bills_disable_prediction=True))
2090+
move_form.invoice_date = fields.Date.from_string('2019-01-01')
2091+
move_form.partner_id = self.partner_a
2092+
self.cash_basis_tax_a_third_amount.analytic = True
2093+
test_analytic_account = self.env['account.analytic.account'].create({'name': 'test_analytic_account'})
2094+
2095+
tax = self.cash_basis_tax_a_third_amount
2096+
2097+
# line with analytic account, will generate 2 lines in CABA move
2098+
with move_form.invoice_line_ids.new() as line_form:
2099+
line_form.name = "test line with analytic account"
2100+
line_form.product_id = self.product_a
2101+
line_form.tax_ids.clear()
2102+
line_form.tax_ids.add(tax)
2103+
line_form.analytic_account_id = test_analytic_account
2104+
line_form.price_unit = 100
2105+
2106+
# line with analytic account, will generate other 2 lines in CABA move
2107+
# even if the tax is the same
2108+
with move_form.invoice_line_ids.new() as line_form:
2109+
line_form.name = "test line"
2110+
line_form.product_id = self.product_a
2111+
line_form.tax_ids.clear()
2112+
line_form.tax_ids.add(tax)
2113+
line_form.price_unit = 100
2114+
2115+
rslt = move_form.save()
2116+
rslt.action_post()
2117+
2118+
pmt_wizard = self.env['account.payment.register'].with_context(active_model='account.move', active_ids=rslt.ids).create({
2119+
'amount': rslt.amount_total,
2120+
'payment_date': rslt.date,
2121+
'journal_id': self.company_data['default_journal_bank'].id,
2122+
'payment_method_id': self.env.ref('account.account_payment_method_manual_in').id,
2123+
})
2124+
pmt_wizard._create_payments()
2125+
2126+
partial_rec = rslt.mapped('line_ids.matched_debit_ids')
2127+
caba_move = self.env['account.move'].search([('tax_cash_basis_rec_id', '=', partial_rec.id)])
2128+
self.assertEqual(len(caba_move.line_ids), 4, "All lines should be there")
2129+
self.assertEqual(caba_move.line_ids.filtered(lambda x: x.tax_line_id).balance, 66.66, "Tax amount should take into account both lines")
2130+
20792131
def test_caba_dest_acc_reconciliation_partial_pmt(self):
20802132
""" Test the reconciliation of tax lines (when using a reconcilable tax account)
20812133
for partially paid invoices with cash basis taxes.

0 commit comments

Comments
 (0)