From a4baafa76114cd5d742a019a7cdd4b1e16dbe235 Mon Sep 17 00:00:00 2001 From: qdp-odoo Date: Mon, 12 Jun 2023 15:33:28 +0000 Subject: [PATCH] [IMP] account: prevent the deletion of tag when set on tax/account MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because if a tag is still linked to a tax or an account, then it's probably also still referenced in a report line, and it makes no sense allowing to delete such a tag. closes odoo/odoo#125843 X-original-commit: 3b71689954a941b12d8eda1d08c3ad58aca320d8 Signed-off-by: Quentin De Paoli Signed-off-by: William André (wan) --- addons/account/models/account_account.py | 2 +- addons/account/models/account_tax.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_account.py b/addons/account/models/account_account.py index c2ba19ed75a..4638b9da74d 100644 --- a/addons/account/models/account_account.py +++ b/addons/account/models/account_account.py @@ -94,7 +94,7 @@ class AccountAccount(models.Model): note = fields.Text('Internal Notes', tracking=True) company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, default=lambda self: self.env.company) - tag_ids = fields.Many2many('account.account.tag', 'account_account_account_tag', string='Tags', help="Optional tags you may want to assign for custom reporting") + tag_ids = fields.Many2many('account.account.tag', 'account_account_account_tag', string='Tags', help="Optional tags you may want to assign for custom reporting", ondelete='restrict') group_id = fields.Many2one('account.group', compute='_compute_account_group', store=True, readonly=True, help="Account prefixes can determine account groups.") root_id = fields.Many2one('account.root', compute='_compute_account_root', store=True, precompute=True) diff --git a/addons/account/models/account_tax.py b/addons/account/models/account_tax.py index 32b7ce4d665..487ff06810a 100644 --- a/addons/account/models/account_tax.py +++ b/addons/account/models/account_tax.py @@ -1356,7 +1356,7 @@ class AccountTaxRepartitionLine(models.Model): domain="[('deprecated', '=', False), ('company_id', '=', company_id), ('account_type', 'not in', ('asset_receivable', 'liability_payable'))]", check_company=True, help="Account on which to post the tax amount") - tag_ids = fields.Many2many(string="Tax Grids", comodel_name='account.account.tag', domain=[('applicability', '=', 'taxes')], copy=True) + tag_ids = fields.Many2many(string="Tax Grids", comodel_name='account.account.tag', domain=[('applicability', '=', 'taxes')], copy=True, ondelete='restrict') tax_id = fields.Many2one(comodel_name='account.tax', ondelete='cascade', check_company=True) company_id = fields.Many2one(string="Company", comodel_name='res.company', related="tax_id.company_id", store=True, help="The company this distribution line belongs to.") sequence = fields.Integer(string="Sequence", default=1,