|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 | from odoo.addons.account.tests.common import AccountTestInvoicingCommon
|
3 | 3 | from odoo.tests import tagged
|
| 4 | +from odoo.tests.common import Form |
| 5 | +from odoo import fields |
4 | 6 |
|
5 | 7 |
|
6 | 8 | @tagged('post_install', '-at_install')
|
@@ -2076,6 +2078,56 @@ def test_caba_mix_reconciliation(self):
|
2076 | 2078 | # Check full reconciliation
|
2077 | 2079 | self.assertTrue(all(line.full_reconcile_id for line in lines_to_reconcile), "All tax lines should be fully reconciled")
|
2078 | 2080 |
|
| 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 | + |
2079 | 2131 | def test_caba_dest_acc_reconciliation_partial_pmt(self):
|
2080 | 2132 | """ Test the reconciliation of tax lines (when using a reconcilable tax account)
|
2081 | 2133 | for partially paid invoices with cash basis taxes.
|
|
0 commit comments