[FIX] account: cash basis taxes: set move lines as tax_exigible=False only when some other line has a payable or receivable account in the move.

Before that, making a misc operation with cash basis taxes always set the move lines as tax_exigible=False (or at least, it was supposed to, see below). This was wrong, as if the move did not contain any payable/receivable account, it would result in no cash basis move being ever created, and so the entry would never affect the tax report.

Additionnally, the tax line was wrongly managed for cash basis taxes on misc entries, as vals.get('tax_ids') returned an ORM command, so a non-False value, even when the tax_ids field was empty. this caused the condition to execute and to reassign taxes to an empty list, which then caused tax_exigible not to be set to False, even when it should.

X-original-commit: https://github.com/odoo/odoo/commit/2437eb0691d07f92094152b84c96a2149c8f4fd8

[FIX] account: make tax exigible correct in cases where the move lines are created separetely from the move.

Additional fix on top of https://github.com/odoo/odoo/commit/02fe997932070cc101a96eb869023702c224318b

Also, add tax_exigible to the form view of account.move.line, as it will not be computed automatically anymore when modifying a single line in draft state through its form view. It now needs to be manually changed in case the user wants to change something having an impact on it through this form (note that this is absolutely not a typical use case).

closes odoo/odoo#58260

X-original-commit: 867797e4983b704599be7943490fc6f071d8c0b7
Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
Signed-off-by: oco-odoo <oco-odoo@users.noreply.github.com>
This commit is contained in:
fw-bot
2020-09-22 16:00:14 +00:00
committed by oco-odoo
parent 33bd1a951a
commit dd2ac143f7
6 changed files with 30 additions and 22 deletions
+21 -14
View File
@@ -704,6 +704,19 @@ class AccountMove(models.Model):
if in_draft_mode:
taxes_map_entry['tax_line'].update(taxes_map_entry['tax_line']._get_fields_onchange_balance())
def update_lines_tax_exigibility(self):
if all(account.user_type_id.type not in {'payable', 'receivable'} for account in self.mapped('line_ids.account_id')):
self.line_ids.write({'tax_exigible': True})
else:
tax_lines_caba = self.line_ids.filtered(lambda x: x.tax_line_id.tax_exigibility == 'on_payment')
base_lines_caba = self.line_ids.filtered(lambda x: any(tax.tax_exigibility == 'on_payment'
or (tax.amount_type == 'group'
and 'on_payment' in tax.mapped('children_tax_ids.tax_exigibility'))
for tax in x.tax_ids))
caba_lines = tax_lines_caba + base_lines_caba
caba_lines.write({'tax_exigible': False})
(self.line_ids - caba_lines).write({'tax_exigible': True})
def _recompute_cash_rounding_lines(self):
''' Handle the cash rounding feature on invoices.
@@ -1755,7 +1768,10 @@ class AccountMove(models.Model):
raise UserError(_('You cannot create a move already in the posted state. Please create a draft move and post it after.'))
vals_list = self._move_autocomplete_invoice_lines_create(vals_list)
return super(AccountMove, self).create(vals_list)
rslt = super(AccountMove, self).create(vals_list)
if 'line_ids' in vals_list:
rslt.update_lines_tax_exigibility()
return rslt
def write(self, vals):
for move in self:
@@ -1801,8 +1817,10 @@ class AccountMove(models.Model):
res |= super(AccountMove, move).write(vals_hashing)
# Ensure the move is still well balanced.
if 'line_ids' in vals and self._context.get('check_move_validity', True):
self._check_balanced()
if 'line_ids' in vals:
if self._context.get('check_move_validity', True):
self._check_balanced()
self.update_lines_tax_exigibility()
self._synchronize_business_models(set(vals.keys()))
@@ -3688,17 +3706,6 @@ class AccountMoveLine(models.Model):
move.date,
))
# Ensure consistency between taxes & tax exigibility fields.
if 'tax_exigible' in vals:
continue
if vals.get('tax_repartition_line_id'):
repartition_line = self.env['account.tax.repartition.line'].browse(vals['tax_repartition_line_id'])
tax = repartition_line.invoice_tax_id or repartition_line.refund_tax_id
vals['tax_exigible'] = tax.tax_exigibility == 'on_invoice'
elif vals.get('tax_ids'):
taxes = self.new({'tax_ids': vals['tax_ids']}).tax_ids.flatten_taxes_hierarchy()
vals['tax_exigible'] = not any(tax.tax_exigibility == 'on_payment' for tax in taxes)
lines = super(AccountMoveLine, self).create(vals_list)
moves = lines.mapped('move_id')
@@ -770,7 +770,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon):
'debit': 64.0,
'credit': 0.0,
'date_maturity': False,
'tax_exigible': True,
'tax_exigible': False,
},
{
'name': child_tax_1.name,
@@ -790,7 +790,7 @@ class TestAccountMoveInInvoiceOnchanges(AccountTestInvoicingCommon):
'debit': 96.0,
'credit': 0.0,
'date_maturity': False,
'tax_exigible': True,
'tax_exigible': False,
},
{
'name': child_tax_2.name,
@@ -481,7 +481,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon):
'debit': 0.0,
'credit': 96.0,
'date_maturity': False,
'tax_exigible': True,
'tax_exigible': False,
},
{
'name': child_tax_1.name,
@@ -501,7 +501,7 @@ class TestAccountMoveInRefundOnchanges(AccountTestInvoicingCommon):
'debit': 0.0,
'credit': 64.0,
'date_maturity': False,
'tax_exigible': True,
'tax_exigible': False,
},
{
'name': child_tax_2.name,
@@ -773,7 +773,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon):
'debit': 0.0,
'credit': 120.0,
'date_maturity': False,
'tax_exigible': True,
'tax_exigible': False,
},
{
'name': child_tax_1.name,
@@ -793,7 +793,7 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon):
'debit': 0.0,
'credit': 80.0,
'date_maturity': False,
'tax_exigible': True,
'tax_exigible': False,
},
{
'name': child_tax_2.name,
@@ -481,7 +481,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon):
'debit': 80.0,
'credit': 0.0,
'date_maturity': False,
'tax_exigible': True,
'tax_exigible': False,
},
{
'name': child_tax_1.name,
@@ -501,7 +501,7 @@ class TestAccountMoveOutRefundOnchanges(AccountTestInvoicingCommon):
'debit': 120.0,
'credit': 0.0,
'date_maturity': False,
'tax_exigible': True,
'tax_exigible': False,
},
{
'name': child_tax_2.name,
@@ -41,6 +41,7 @@
<group string="Taxes" attrs="{'invisible': [('tax_line_id','=',False), ('tax_ids','=',[])]}">
<field name="tax_line_id" readonly="1" attrs="{'invisible': [('tax_line_id','=',False)]}"/>
<field name="tax_ids" widget="many2many_tags" readonly="1" attrs="{'invisible': [('tax_ids','=',[])]}"/>
<field name="tax_exigible" attrs="{'readonly':[('parent_state','=','posted')]}"/>
<field name="tax_audit"/>
</group>
<group string="Matching" attrs="{'invisible':[('matched_debit_ids', '=', []),('matched_credit_ids', '=', [])]}">