Skip to content

Commit fdaf42a

Browse files
committed
[IMP] account_ux: prevent tax changes when used in accounting entries
Prevent changes to critical tax fields such as amount, amount type, and base configuration once the tax has been used in accounting entries (account.move.line). Modifying these fields after the tax has already been applied could lead to inconsistent financial data or miscalculations. To ensure data integrity, a constraint was added to block changes to the following fields: - amount_type - price_include_override - include_base_amount - is_base_affected - amount If the tax is found in any existing move line, a ValidationError is raised to prevent the update. closes #734 Signed-off-by: Filoquin adhoc <maq@adhoc.com.ar>
1 parent d9d6037 commit fdaf42a

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

account_ux/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
from . import account_move
1313
from . import account_chart_template
1414
from . import account_payment
15+
from . import account_tax

account_ux/models/account_tax.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from odoo import api, models
2+
from odoo.exceptions import ValidationError
3+
4+
5+
class AccountTax(models.Model):
6+
_inherit = "account.tax"
7+
8+
@api.constrains("amount_type", "price_include_override", "include_base_amount", "is_base_affected", "amount")
9+
def _check_company_matches_active_company(self):
10+
for tax in self:
11+
has_move_lines = self.env["account.move.line"].sudo().search([("tax_ids", "in", tax.ids)], limit=1)
12+
if has_move_lines:
13+
raise ValidationError(
14+
"The tax computation fields cannot be modified because there are accounting entries linked to this tax. "
15+
"We recommend creating a new tax and archiving this one if necessary."
16+
)

0 commit comments

Comments
 (0)