Allow to remove account and tax templates?

Currently, models account.account or have a m2o field to its template. That means that if we remove an account or tax from the template file (account_es, account_fr, etc), accounts cannot be removed from account.template (or tables.

That sounds a bit strange to me, as the idea of separating account.template and account.account should be precisely that templates keep changing over time, but not the accounts.

So, do you think adding a “SET NULL” to cascade’s of m2o field be appropriate?

template = fields.Many2One(‘account.template’, ‘Template’, cascade=‘SET NULL’)

Are you sure that accounts can not be removed?

Set null is the default value for Many2One fields, so what you propose is the current behaviour.

Traceback about can’t delete because is referenced to

trytond.model.modelsql.ForeignKeyError: ('UserError', ('Los registros no pueden eliminarse porque se utilizan en el campo "Plantilla" de "Impuesto contable".', ''))
2144 139941849138944 [2019-06-15 14:27:54,864] ERROR trytond.convert Could not delete id: 164 of model
There should be some relation that points to this resource
You should manually fix this and restart --update=module
Traceback (most recent call last):
 File "/home/administrator/calfruitos_next/trytond/trytond/", line 814, in post_import
 File "/home/administrator/calfruitos_next/trytond/trytond/model/", line 159, in wrapper
   return func(cls, *args, **kwargs)
 File "/home/administrator/calfruitos_next/trytond/trytond/model/", line 1127, in delete

Moreover, removing a template is in most of the case not the right thing. If the template was there, it means it was useful during a period. So it is better to fill an end_date.

It is on purpose Issue 7718: Improve tax update from template - Tryton issue tracker
Also I think RESTRICT should also be set on template of account as we have active period.

Raimon, my friend, taxes are not accounts :wink:

the topic is “Allow to remove account and tax templates?” The traceback show can’t remove a tax.template that is not more defined in XML account module. :wink:

“end_date” is not valid option in our case. We need to remove (deprecated taxes because the definition theaccount chart in 3.x and 5.x are changed).

Precisely, it has CHANGED so it has an end date.

IIRC there where some taxes on the trytonspains’ account_es fwhere the end_date it was already set.
Those taxes where removed when the account_es was included as oficial module.

If you are in this case, the migration is not supported out of the box and you should update the data on the database. Feel free to ping me if you have any issues.

It will be great to publish a migration script so others can benefit also.

There is available in NaN-TIC upgrades project with other scripts o queries (in bitbucket) because account module don’t support the feature that in case the XML changed, remove deprecated taxes (because try to remove in and can’t).

Could you provide a link?

Hope it helps more people: