diff --git a/addons/crm/wizard/crm_lead_to_opportunity.py b/addons/crm/wizard/crm_lead_to_opportunity.py index b24314c75af..3e7f44f5573 100644 --- a/addons/crm/wizard/crm_lead_to_opportunity.py +++ b/addons/crm/wizard/crm_lead_to_opportunity.py @@ -12,13 +12,17 @@ class Lead2OpportunityPartner(models.TransientModel): @api.model def default_get(self, fields): - """ Allow support of active_id / active_model instead of jut default_lead_id to ease window action definitions, and be backward compatible. """ result = super(Lead2OpportunityPartner, self).default_get(fields) if not result.get('lead_id') and self.env.context.get('active_id'): result['lead_id'] = self.env.context.get('active_id') + + if result.get('lead_id'): + if self.env['crm.lead'].browse(result['lead_id']).probability == 100: + raise UserError(_("Closed/Dead leads cannot be converted into opportunities.")) + return result name = fields.Selection([ @@ -105,15 +109,6 @@ class Lead2OpportunityPartner(models.TransientModel): team = self.env['crm.team']._get_default_team_id(user_id=user.id, domain=None) convert.team_id = team.id - @api.model - def view_init(self, fields): - # JEM TDE FIXME: clean that brol - """ Check some preconditions before the wizard executes. """ - for lead in self.env['crm.lead'].browse(self._context.get('active_ids', [])): - if lead.probability == 100: - raise UserError(_("Closed/Dead leads cannot be converted into opportunities.")) - return False - def action_apply(self): if self.name == 'merge': result_opportunity = self._action_merge() diff --git a/odoo/addons/base/tests/__init__.py b/odoo/addons/base/tests/__init__.py index 05ba4548bde..5aec91b00e7 100644 --- a/odoo/addons/base/tests/__init__.py +++ b/odoo/addons/base/tests/__init__.py @@ -7,6 +7,7 @@ from . import test_api from . import test_base from . import test_basecase from . import test_cache +from . import test_deprecation from . import test_db_cursor from . import test_expression from . import test_float diff --git a/odoo/addons/base/tests/test_deprecation.py b/odoo/addons/base/tests/test_deprecation.py new file mode 100644 index 00000000000..9e74e4a5263 --- /dev/null +++ b/odoo/addons/base/tests/test_deprecation.py @@ -0,0 +1,26 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import inspect + +from odoo.tests.common import TransactionCase, tagged + +DEPRECATED_MODEL_ATTRIBUTES = [ + 'view_init', +] + + +@tagged('-at_install', 'post_install', 'deprecation') +class TestModelDeprecations(TransactionCase): + + def test_model_attributes(self): + for model_name, Model in self.registry.items(): + for attr in DEPRECATED_MODEL_ATTRIBUTES: + with self.subTest(model=model_name, attr=attr): + value = getattr(Model, attr, None) + if value is None: + continue + msg = f"Deprecated method/attribute {model_name}.{attr}" + module = inspect.getmodule(value) + if module: + msg += f" in {module}" + self.fail(msg) diff --git a/odoo/models.py b/odoo/models.py index aab48dab9f5..f070b3937ba 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -538,13 +538,6 @@ class BaseModel(metaclass=MetaModel): CONCURRENCY_CHECK_FIELD = '__last_update' - @api.model - def view_init(self, fields_list): - """ Override this method to do specific things when a form view is - opened. This method is invoked by :meth:`~default_get`. - """ - pass - def _valid_field_parameter(self, field, name): """ Return whether the given parameter name is valid for the field. """ return name == 'related_sudo' @@ -1389,9 +1382,6 @@ class BaseModel(metaclass=MetaModel): Unrequested defaults won't be considered, there is no need to return a value for fields whose names are not in `fields_list`. """ - # trigger view init hook - self.view_init(fields_list) - defaults = {} parent_fields = defaultdict(list) ir_defaults = self.env['ir.default'].get_model_defaults(self._name)