[FIX] account: fixed tax name unique constraint error
due to the absence of IR model data entries for certain account taxes, but with identical tax names, tax types, and scopes, attempts to create standard taxes with the same names alongside IR model data result in a constraint violation, specifically, "tax name must be unique." To address this constraint, we append "old" to the tax name for existing taxes lacking IR model data entries. see: https://github.com/odoo/odoo/blob/740fb9ac8c8e121820feeac0e1f25a304e47da9d/addons/account/models/account_tax.py#L202 ``` File "/home/odoo/src/odoo/17.0/odoo/models.py", line 4864, in _create records._validate_fields(name for data in data_list for name in data['stored']) File "/home/odoo/src/odoo/17.0/odoo/models.py", line 1456, in _validate_fields check(self) File "/home/odoo/src/odoo/17.0/addons/account/models/account_tax.py", line 201, in _constrains_name raise ValidationError( odoo.exceptions.ValidationError: Tax names must be unique! ``` closes odoo/odoo#161146 X-original-commit: 87e13a0f29ace57f1fd591d7180a64bb085a3bca Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
@@ -316,8 +316,14 @@ class AccountChartTemplate(models.AbstractModel):
|
||||
if xmlid in xmlid2tax:
|
||||
obsolete_xmlid.add(xmlid)
|
||||
oldtax = xmlid2tax[xmlid]
|
||||
if unique_tax_name_key(oldtax) in unique_tax_name_keys:
|
||||
oldtax.name = f"[old] {oldtax.name}"
|
||||
else:
|
||||
oldtax = current_taxes.filtered(
|
||||
lambda t: t.name == values.get('name')\
|
||||
and t.type_tax_use == values.get('type_tax_use')\
|
||||
and t.tax_scope == values.get('tax_scope', False)
|
||||
)
|
||||
if unique_tax_name_key(oldtax) in unique_tax_name_keys:
|
||||
oldtax.name = f"[old] {oldtax.name}"
|
||||
else:
|
||||
repartition_lines = values.get('repartition_line_ids')
|
||||
values.clear()
|
||||
|
||||
Reference in New Issue
Block a user