diff options
| author | Adrian Torres <adt@odoo.com> | 2020-02-20 13:43:00 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2020-03-30 13:42:04 +0000 |
| commit | 1daf8eb12735db5c697e4a0868b43fe44f6b2f6a (patch) | |
| tree | b02820d3679615e7e92a6258a6cc1d428db4c526 /addons/account_tax_python | |
| parent | f0481392c6501cae2c38359f526da1eefa451337 (diff) | |
[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) <rco@openerp.com>
Diffstat (limited to 'addons/account_tax_python')
| -rw-r--r-- | addons/account_tax_python/__init__.py | 13 | ||||
| -rw-r--r-- | addons/account_tax_python/__manifest__.py | 1 | ||||
| -rw-r--r-- | addons/account_tax_python/models/account_tax.py | 8 |
3 files changed, 6 insertions, 16 deletions
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" |
