[REM] core,base,*: deprecated some methods to be remove correctly later

- Deprecated `norecompute` (on Environment class) because it is useless
and do nothing.
- Deprecated `cache_restart` (`res.company`) because `clear_caches` do
the stuff.
- Deprecated `write_company_and_print_report` (`res.company`) because
since https://github.com/odoo/odoo/pull/33863/, it is unused
- Deprecated `open_company_edit_report` (`res.company`) because since
25f7040998, it is unused.

Part-of: odoo/odoo#99550
This commit is contained in:
Rémy Voet (ryv)
2022-11-02 15:34:30 +01:00
parent 5a8df8e304
commit 3353dfdb29
5 changed files with 35 additions and 35 deletions
+7 -8
View File
@@ -100,14 +100,13 @@ class RatingMixin(models.AbstractModel):
def write(self, values):
""" If the rated ressource name is modified, we should update the rating res_name too.
If the rated ressource parent is changed we should update the parent_res_id too"""
with self.env.norecompute():
result = super(RatingMixin, self).write(values)
for record in self:
if record._rec_name in values: # set the res_name of ratings to be recomputed
res_name_field = self.env['rating.rating']._fields['res_name']
self.env.add_to_compute(res_name_field, record.rating_ids)
if record._rating_get_parent_field_name() in values:
record.rating_ids.sudo().write({'parent_res_id': record[record._rating_get_parent_field_name()].id})
result = super(RatingMixin, self).write(values)
for record in self:
if record._rec_name in values: # set the res_name of ratings to be recomputed
res_name_field = self.env['rating.rating']._fields['res_name']
self.env.add_to_compute(res_name_field, record.rating_ids)
if record._rating_get_parent_field_name() in values:
record.rating_ids.sudo().write({'parent_res_id': record[record._rating_get_parent_field_name()].id})
return result
+4 -2
View File
@@ -5,7 +5,7 @@ import base64
import io
import logging
import os
import re
import warnings
from odoo import api, fields, models, tools, _, Command
from odoo.exceptions import ValidationError, UserError
@@ -191,8 +191,8 @@ class Company(models.Model):
_logger.warning("The method '_company_default_get' on res.company is deprecated and shouldn't be used anymore")
return self.env.company
# deprecated, use clear_caches() instead
def cache_restart(self):
warnings.warn("Since 17.0, deprecated method, use `clear_caches` instead", DeprecationWarning, 2)
self.clear_caches()
@api.model_create_multi
@@ -281,10 +281,12 @@ class Company(models.Model):
raise ValidationError(_('You cannot create recursive companies.'))
def open_company_edit_report(self):
warnings.warn("Since 17.0.", DeprecationWarning, 2)
self.ensure_one()
return self.env['res.config.settings'].open_company()
def write_company_and_print_report(self):
warnings.warn("Since 17.0.", DeprecationWarning, 2)
context = self.env.context
report_name = context.get('default_report_name')
active_ids = context.get('active_ids')
+9 -10
View File
@@ -562,16 +562,15 @@ class ResConfigSettings(models.TransientModel, ResConfigModuleInstallationMixin)
IrDefault.set(model, field, value)
# group fields: modify group / implied groups
with self.env.norecompute():
for name, groups, implied_group in sorted(classified['group'], key=lambda k: self[k[0]]):
groups = groups.sudo()
implied_group = implied_group.sudo()
if self[name] == current_settings[name]:
continue
if int(self[name]):
groups._apply_group(implied_group)
else:
groups._remove_group(implied_group)
for name, groups, implied_group in sorted(classified['group'], key=lambda k: self[k[0]]):
groups = groups.sudo()
implied_group = implied_group.sudo()
if self[name] == current_settings[name]:
continue
if int(self[name]):
groups._apply_group(implied_group)
else:
groups._remove_group(implied_group)
# config fields: store ir.config_parameters
IrConfigParameter = self.env['ir.config_parameter'].sudo()
+2 -1
View File
@@ -780,7 +780,8 @@ class Environment(Mapping):
@contextmanager
def norecompute(self):
""" Delay recomputations (deprecated: this is not the default behavior). """
""" Deprecated: It does nothing, recomputation is delayed by default. """
warnings.warn("`norecompute` is useless. Deprecated since 17.0.", DeprecationWarning, 2)
yield
def cache_key(self, field):
+13 -14
View File
@@ -2338,20 +2338,19 @@ class Binary(Field):
return
# create the attachments that store the values
env = record_values[0][0].env
with env.norecompute():
env['ir.attachment'].sudo().with_context(
binary_field_real_user=env.user,
).create([{
'name': self.name,
'res_model': self.model_name,
'res_field': self.name,
'res_id': record.id,
'type': 'binary',
'datas': value,
}
for record, value in record_values
if value
])
env['ir.attachment'].sudo().with_context(
binary_field_real_user=env.user,
).create([{
'name': self.name,
'res_model': self.model_name,
'res_field': self.name,
'res_id': record.id,
'type': 'binary',
'datas': value,
}
for record, value in record_values
if value
])
def write(self, records, value):
if not self.attachment: