diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py
index 71bc0b682e7..2905ff4764d 100644
--- a/addons/account/models/account_move.py
+++ b/addons/account/models/account_move.py
@@ -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')
diff --git a/addons/account/tests/test_account_move_in_invoice.py b/addons/account/tests/test_account_move_in_invoice.py
index 278260d40c5..c9df200825c 100644
--- a/addons/account/tests/test_account_move_in_invoice.py
+++ b/addons/account/tests/test_account_move_in_invoice.py
@@ -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,
diff --git a/addons/account/tests/test_account_move_in_refund.py b/addons/account/tests/test_account_move_in_refund.py
index 262a1a82513..593cdde3a41 100644
--- a/addons/account/tests/test_account_move_in_refund.py
+++ b/addons/account/tests/test_account_move_in_refund.py
@@ -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,
diff --git a/addons/account/tests/test_account_move_out_invoice.py b/addons/account/tests/test_account_move_out_invoice.py
index 0d31b231ede..e50a62b5689 100644
--- a/addons/account/tests/test_account_move_out_invoice.py
+++ b/addons/account/tests/test_account_move_out_invoice.py
@@ -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,
diff --git a/addons/account/tests/test_account_move_out_refund.py b/addons/account/tests/test_account_move_out_refund.py
index c1720dd2ba8..967eb2326a6 100644
--- a/addons/account/tests/test_account_move_out_refund.py
+++ b/addons/account/tests/test_account_move_out_refund.py
@@ -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,
diff --git a/addons/account/views/account_move_views.xml b/addons/account/views/account_move_views.xml
index 27381a5e04f..66d6b010264 100644
--- a/addons/account/views/account_move_views.xml
+++ b/addons/account/views/account_move_views.xml
@@ -41,6 +41,7 @@
+