[REM] core: remove useless view_init

The method view_init() is a hook called from default_get(). We can get
the same result by overriding default_get directly.

Part-of: odoo/odoo#79563
This commit is contained in:
Rémy Voet (ryv)
2021-12-24 14:56:56 +00:00
committed by Raphael Collet
parent c33f827957
commit 3346008c43
4 changed files with 32 additions and 20 deletions
+5 -10
View File
@@ -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()
+1
View File
@@ -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
@@ -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)
-10
View File
@@ -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)