[REM] core: support for the deprecated <report> and <act_window> tags
Part-of: odoo/odoo#98138
This commit is contained in:
@@ -272,160 +272,12 @@ form: module.record_id""" % (xml_id,)
|
||||
if records:
|
||||
records.unlink()
|
||||
|
||||
def _tag_report(self, rec):
|
||||
res = {}
|
||||
for dest,f in (('name','string'),('model','model'),('report_name','name')):
|
||||
res[dest] = rec.get(f)
|
||||
assert res[dest], "Attribute %s of report is empty !" % (f,)
|
||||
for field, dest in (('attachment', 'attachment'),
|
||||
('attachment_use', 'attachment_use'),
|
||||
('usage', 'usage'),
|
||||
('file', 'report_file'),
|
||||
('report_type', 'report_type'),
|
||||
('parser', 'parser'),
|
||||
('print_report_name', 'print_report_name'),
|
||||
):
|
||||
if rec.get(field):
|
||||
res[dest] = rec.get(field)
|
||||
if rec.get('auto'):
|
||||
res['auto'] = safe_eval(rec.get('auto','False'))
|
||||
if rec.get('header'):
|
||||
res['header'] = safe_eval(rec.get('header','False'))
|
||||
|
||||
res['multi'] = rec.get('multi') and safe_eval(rec.get('multi','False'))
|
||||
|
||||
xml_id = rec.get('id','')
|
||||
self._test_xml_id(xml_id)
|
||||
warnings.warn(f"The <report> tag is deprecated, use a <record> tag for {xml_id!r}.", DeprecationWarning)
|
||||
|
||||
if rec.get('groups'):
|
||||
g_names = rec.get('groups','').split(',')
|
||||
groups_value = []
|
||||
for group in g_names:
|
||||
if group.startswith('-'):
|
||||
group_id = self.id_get(group[1:])
|
||||
groups_value.append(odoo.Command.unlink(group_id))
|
||||
else:
|
||||
group_id = self.id_get(group)
|
||||
groups_value.append(odoo.Command.link(group_id))
|
||||
res['groups_id'] = groups_value
|
||||
if rec.get('paperformat'):
|
||||
pf_name = rec.get('paperformat')
|
||||
pf_id = self.id_get(pf_name)
|
||||
res['paperformat_id'] = pf_id
|
||||
|
||||
xid = self.make_xml_id(xml_id)
|
||||
data = dict(xml_id=xid, values=res, noupdate=self.noupdate)
|
||||
report = self.env['ir.actions.report']._load_records([data], self.mode == 'update')
|
||||
self.idref[xml_id] = report.id
|
||||
|
||||
if not rec.get('menu') or safe_eval(rec.get('menu','False')):
|
||||
report.create_action()
|
||||
elif self.mode=='update' and safe_eval(rec.get('menu','False'))==False:
|
||||
# Special check for report having attribute menu=False on update
|
||||
report.unlink_action()
|
||||
return report.id
|
||||
|
||||
def _tag_function(self, rec):
|
||||
if self.noupdate and self.mode != 'init':
|
||||
return
|
||||
env = self.get_env(rec)
|
||||
_eval_xml(self, rec, env)
|
||||
|
||||
def _tag_act_window(self, rec):
|
||||
name = rec.get('name')
|
||||
xml_id = rec.get('id','')
|
||||
self._test_xml_id(xml_id)
|
||||
warnings.warn(f"The <act_window> tag is deprecated, use a <record> for {xml_id!r}.", DeprecationWarning)
|
||||
view_id = False
|
||||
if rec.get('view_id'):
|
||||
view_id = self.id_get(rec.get('view_id'))
|
||||
domain = rec.get('domain') or '[]'
|
||||
res_model = rec.get('res_model')
|
||||
binding_model = rec.get('binding_model')
|
||||
view_mode = rec.get('view_mode') or 'tree,form'
|
||||
usage = rec.get('usage')
|
||||
limit = rec.get('limit')
|
||||
uid = self.env.user.id
|
||||
|
||||
# Act_window's 'domain' and 'context' contain mostly literals
|
||||
# but they can also refer to the variables provided below
|
||||
# in eval_context, so we need to eval() them before storing.
|
||||
# Among the context variables, 'active_id' refers to
|
||||
# the currently selected items in a list view, and only
|
||||
# takes meaning at runtime on the client side. For this
|
||||
# reason it must remain a bare variable in domain and context,
|
||||
# even after eval() at server-side. We use the special 'unquote'
|
||||
# class to achieve this effect: a string which has itself, unquoted,
|
||||
# as representation.
|
||||
active_id = unquote("active_id")
|
||||
active_ids = unquote("active_ids")
|
||||
active_model = unquote("active_model")
|
||||
|
||||
# Include all locals() in eval_context, for backwards compatibility
|
||||
eval_context = {
|
||||
'name': name,
|
||||
'xml_id': xml_id,
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_id': view_id,
|
||||
'domain': domain,
|
||||
'res_model': res_model,
|
||||
'src_model': binding_model,
|
||||
'view_mode': view_mode,
|
||||
'usage': usage,
|
||||
'limit': limit,
|
||||
'uid': uid,
|
||||
'active_id': active_id,
|
||||
'active_ids': active_ids,
|
||||
'active_model': active_model,
|
||||
}
|
||||
context = self.get_env(rec, eval_context).context
|
||||
|
||||
try:
|
||||
domain = safe_eval(domain, eval_context)
|
||||
except (ValueError, NameError):
|
||||
# Some domains contain references that are only valid at runtime at
|
||||
# client-side, so in that case we keep the original domain string
|
||||
# as it is. We also log it, just in case.
|
||||
_logger.debug('Domain value (%s) for element with id "%s" does not parse '\
|
||||
'at server-side, keeping original string, in case it\'s meant for client side only',
|
||||
domain, xml_id or 'n/a', exc_info=True)
|
||||
res = {
|
||||
'name': name,
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_id': view_id,
|
||||
'domain': domain,
|
||||
'context': context,
|
||||
'res_model': res_model,
|
||||
'view_mode': view_mode,
|
||||
'usage': usage,
|
||||
'limit': limit,
|
||||
}
|
||||
|
||||
if rec.get('groups'):
|
||||
g_names = rec.get('groups','').split(',')
|
||||
groups_value = []
|
||||
for group in g_names:
|
||||
if group.startswith('-'):
|
||||
group_id = self.id_get(group[1:])
|
||||
groups_value.append(odoo.Command.unlink(group_id))
|
||||
else:
|
||||
group_id = self.id_get(group)
|
||||
groups_value.append(odoo.Command.link(group_id))
|
||||
res['groups_id'] = groups_value
|
||||
|
||||
if rec.get('target'):
|
||||
res['target'] = rec.get('target','')
|
||||
if binding_model:
|
||||
res['binding_model_id'] = self.env['ir.model']._get(binding_model).id
|
||||
res['binding_type'] = rec.get('binding_type') or 'action'
|
||||
views = rec.get('binding_views')
|
||||
if views is not None:
|
||||
res['binding_view_types'] = views
|
||||
xid = self.make_xml_id(xml_id)
|
||||
data = dict(xml_id=xid, values=res, noupdate=self.noupdate)
|
||||
self.env['ir.actions.act_window']._load_records([data], self.mode == 'update')
|
||||
|
||||
def _tag_menuitem(self, rec, parent=None):
|
||||
rec_id = rec.attrib["id"]
|
||||
self._test_xml_id(rec_id)
|
||||
@@ -735,8 +587,6 @@ form: module.record_id""" % (xml_id,)
|
||||
'function': self._tag_function,
|
||||
'menuitem': self._tag_menuitem,
|
||||
'template': self._tag_template,
|
||||
'report': self._tag_report,
|
||||
'act_window': self._tag_act_window,
|
||||
|
||||
**dict.fromkeys(self.DATA_ROOTS, self._tag_root)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user