[FIX] orm: "relate" binding type on actions

When ir.values was removed and the "action" ir.values were merged
directly into the actions themselves, "client_action_relate" was
discarded as unused (and possibly too similar to
client_action_multi?). *However*:

* it was actually used implicitly as "relate" was the default key2 of
  the <act_window> XML tag
* and it had a crucial difference from client_action_multi:
  client_action_multi is shown on both form and list views by default
  and only on list if multi=True, whereas relate is shown on *either*
  the form or list view (tree if multi else form)

This means without relate the actions which should be only visible on
the form view are now on both list and tree, which leads to
overpopulated `Action` menus and odd behaviours (e.g. actions relying
active_id on lists, which id do they get and why?)

=> reintroduce relate as "action_form_only" for the specific case of
multi=False and either no key2 or a key2 of client_action_relate. If
multi=True then binding_type=action.

Fixes #20124

Followup: Task 1843603 to remove #multi and redundancy
This commit is contained in:
xmo-odoo
2018-05-09 09:45:29 +02:00
committed by GitHub
parent f2e105eeca
commit 020906659e
3 changed files with 10 additions and 2 deletions
+1
View File
@@ -34,6 +34,7 @@ class IrActions(models.Model):
binding_model_id = fields.Many2one('ir.model', ondelete='cascade',
help="Setting a value makes this action available in the sidebar for the given model.")
binding_type = fields.Selection([('action', 'Action'),
('action_form_only', "Form-only"),
('report', 'Report')],
required=True, default='action')
+4
View File
@@ -1391,6 +1391,9 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
resaction = [action
for action in bindings['action']
if view_type == 'tree' or not action.get('multi')]
resrelate = []
if view_type == 'form':
resrelate = bindings['action_form_only']
for res in itertools.chain(resreport, resaction):
res['string'] = res['name']
@@ -1398,6 +1401,7 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
result['toolbar'] = {
'print': resreport,
'action': resaction,
'relate': resrelate,
}
return result
+5 -2
View File
@@ -427,11 +427,14 @@ form: module.record_id""" % (xml_id,)
if rec.get('target'):
res['target'] = rec.get('target','')
if rec.get('multi'):
res['multi'] = safe_eval(rec.get('multi', 'False'))
if src_model:
res['binding_model_id'] = self.env['ir.model']._get(src_model).id
res['binding_type'] = 'report' if rec.get('key2') == 'client_print_multi' else 'action'
if rec.get('multi'):
res['multi'] = safe_eval(rec.get('multi', 'False'))
if rec.get('key2') in (None, 'client_action_relate'):
if not res.get('multi'):
res['binding_type'] = 'action_form_only'
id = self.env['ir.model.data']._update('ir.actions.act_window', self.module, res, xml_id, noupdate=self.isnoupdate(data_node), mode=self.mode)
self.idref[xml_id] = int(id)