[FIX] account: set correct account on cash basis tax line

### Steps to reproduce
* go to Accounting > Settings and activate 'Cash Basis'
* got to Chart of Accounts and create a new  account of type
  `Current Assets`. We'll call it `A`.
* create a new tax, we'll call it `T`, with the following parameters:
  * Tax type: Purchases
  * Tax computation: Percentage of Price
  * Amount: 22%
  * Distribution of invoices:
    * add a line with the following parameters:
      % = 40, Based On = 'of tax' and Account = the tax paid account.
    * add a second line with the following parameters:
      %= 60, Based On = 'of tax'
  * Distribution of Credit Notes: Add the same lines as
    'Distribution of invoices'
  * In the Advanced Options tab, set :
    * Tax Eligibility = 'Based on Payment'
    * Cash Basis Transition Account = `A`
* create a new vendor bill and add a product line to it and set
  Taxes = `T` on that line
* confirm and register payment

Now go to Accounting > Journal Items, group by Journal. Look through the
'Cash Basis Taxes' group and find the entries related to the vendor bill
you just made. One of the debit lines on account `A` is not correct.
Here, the account should be the one specified on the invoice line.

opw-2796727

closes odoo/odoo#105445

X-original-commit: b69fc397aad019cc18bd00975d38dde9ffcc985b
Signed-off-by: Laurent Smet <las@odoo.com>
Signed-off-by: Nshimiyimana Serge Séna (sesn) <sesn@odoo.com>
This commit is contained in:
Nshimiyimana Séna
2022-11-09 15:04:14 +01:00
parent 9d74c8ec4d
commit f1a777903a
2 changed files with 101 additions and 1 deletions
@@ -303,7 +303,7 @@ class AccountPartialReconcile(models.Model):
'tax_repartition_line_id': tax_line.tax_repartition_line_id.id,
'tax_ids': [Command.set(tax_ids.ids)],
'tax_tag_ids': [Command.set(all_tags.ids)],
'account_id': tax_line.tax_repartition_line_id.account_id.id or tax_line.account_id.id,
'account_id': tax_line.tax_repartition_line_id.account_id.id or tax_line.company_id.account_cash_basis_base_account_id.id or tax_line.account_id.id,
'amount_currency': amount_currency,
'currency_id': tax_line.currency_id.id,
'partner_id': tax_line.partner_id.id,
@@ -4014,3 +4014,103 @@ class TestAccountMoveReconcile(AccountTestInvoicingCommon):
{'balance': 1.0, 'tax_line_id': False},
{'balance': -1.0, 'tax_line_id': tax_b.id},
])
def test_cash_basis_taxline_without_account(self):
"""
Make sure that cash basis taxlines that don't have an account are handled properly.
"""
self.env.company.tax_exigibility = True
tax = self.env['account.tax'].create({
'name': 'cash basis 20%',
'type_tax_use': 'purchase',
'amount': 20,
'tax_exigibility': 'on_payment',
'cash_basis_transition_account_id': self.cash_basis_transfer_account.id,
'invoice_repartition_line_ids': [
(0, 0, {
'factor_percent': 100,
'repartition_type': 'base',
}),
(0, 0, {
'factor_percent': 40,
'account_id': self.tax_account_1.id,
'repartition_type': 'tax',
}),
(0, 0, {
'factor_percent': 60,
'repartition_type': 'tax',
}),
],
'refund_repartition_line_ids': [
(0, 0, {
'factor_percent': 100,
'repartition_type': 'base',
}),
(0, 0, {
'factor_percent': 40,
'account_id': self.tax_account_1.id,
'repartition_type': 'tax',
}),
(0, 0, {
'factor_percent': 60,
'repartition_type': 'tax',
}),
],
})
# create invoice
move_form = Form(self.env['account.move'].with_context(
default_move_type='in_invoice'))
move_form.partner_id = self.partner_a
move_form.invoice_date = fields.Date.from_string('2017-01-01')
with move_form.invoice_line_ids.new() as line_form:
line_form.product_id = self.product_a
line_form.tax_ids.clear()
line_form.tax_ids.add(tax)
invoice = move_form.save()
invoice.action_post()
# make payment
self.env['account.payment.register'].with_context(active_model='account.move', active_ids=invoice.ids).create({
'payment_date': invoice.date,
})._create_payments()
# check caba move
partial_rec = invoice.mapped('line_ids.matched_debit_ids')
caba_move = self.env['account.move'].search(
[('tax_cash_basis_rec_id', '=', partial_rec.id)])
expected_values = [
{
'account_id': self.cash_basis_base_account.id,
'debit': 0.0,
'credit': 800.0
},
{
'account_id': self.cash_basis_base_account.id,
'debit': 800.0,
'credit': 0.0
},
{
'account_id': self.cash_basis_transfer_account.id,
'debit': 0.0,
'credit': 64.0
},
{
'account_id': self.tax_account_1.id,
'debit': 64.0,
'credit': 0.0},
{
'account_id': self.cash_basis_transfer_account.id,
'debit': 0.0,
'credit': 96.0
},
{
'account_id': self.cash_basis_base_account.id,
'debit': 96.0,
'credit': 0.0
}
]
self.assertRecordValues(caba_move.line_ids, expected_values)