From 1daf8eb12735db5c697e4a0868b43fe44f6b2f6a Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Thu, 20 Feb 2020 13:43:00 +0000 Subject: [FIX] *: set ondelete policy of required Selection fields With this commit, Selection fields with `required=True` which are extended via `selection_add` are given proper ondelete policies to ensure the cleanup of records containing these extended options during uninstall of the extending module. This commit also cleans up leftover uninstall hooks that were being used to handle the same set of problems prior to the ondelete mechanism being implemented for Selection fields. closes odoo/odoo#46325 Related: odoo/enterprise#9117 Signed-off-by: Raphael Collet (rco) --- addons/account_tax_python/__init__.py | 13 ------------- addons/account_tax_python/__manifest__.py | 1 - addons/account_tax_python/models/account_tax.py | 8 ++++++-- 3 files changed, 6 insertions(+), 16 deletions(-) (limited to 'addons/account_tax_python') diff --git a/addons/account_tax_python/__init__.py b/addons/account_tax_python/__init__.py index 3b46f4dba2b..dc5e6b693d1 100644 --- a/addons/account_tax_python/__init__.py +++ b/addons/account_tax_python/__init__.py @@ -2,16 +2,3 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import models - -from odoo import api, SUPERUSER_ID - -import logging -_logger = logging.getLogger(__name__) - -def uninstall_hook(cr, registry): - env = api.Environment(cr, SUPERUSER_ID, {}) - - code_taxes = env['account.tax'].search([('amount_type', '=', 'code')]) - code_taxes.write({'amount_type': 'percent', 'active': False}) - - _logger.warning("The following taxes have been archived following 'account_tax_python' module uninstallation: %s" % code_taxes.ids) diff --git a/addons/account_tax_python/__manifest__.py b/addons/account_tax_python/__manifest__.py index cb0dde674a5..e27facde6aa 100644 --- a/addons/account_tax_python/__manifest__.py +++ b/addons/account_tax_python/__manifest__.py @@ -17,5 +17,4 @@ A tax defined as python code consists of two snippets of python code which are e 'data': [ 'views/account_tax_views.xml', ], - 'uninstall_hook': "uninstall_hook", } diff --git a/addons/account_tax_python/models/account_tax.py b/addons/account_tax_python/models/account_tax.py index dbd143a58b5..435be47fa9c 100644 --- a/addons/account_tax_python/models/account_tax.py +++ b/addons/account_tax_python/models/account_tax.py @@ -8,7 +8,9 @@ from odoo.tools.safe_eval import safe_eval class AccountTaxPython(models.Model): _inherit = "account.tax" - amount_type = fields.Selection(selection_add=[('code', 'Python Code')]) + amount_type = fields.Selection(selection_add=[ + ('code', 'Python Code') + ], ondelete={'code': lambda recs: recs.write({'amount_type': 'percent', 'active': False})}) python_compute = fields.Text(string='Python Code', default="result = price_unit * 0.10", help="Compute the amount of the tax by setting the variable 'result'.\n\n" @@ -54,7 +56,9 @@ class AccountTaxPython(models.Model): class AccountTaxTemplatePython(models.Model): _inherit = 'account.tax.template' - amount_type = fields.Selection(selection_add=[('code', 'Python Code')]) + amount_type = fields.Selection(selection_add=[ + ('code', 'Python Code') + ], ondelete={'code': 'cascade'}) python_compute = fields.Text(string='Python Code', default="result = price_unit * 0.10", help="Compute the amount of the tax by setting the variable 'result'.\n\n" -- cgit v1.2.3