[FIX] board: don't use ir_values to get dashboard action id
Former implementation used ir_values to retrieve the dashboard action id from
its menu id. Using ir_values to do that doesn't work anymore since the
cleaning up of rev. e7e452f.
We now retrieve the action id from its xmlid directly in the controller.
This commit is contained in:
@@ -13,29 +13,6 @@ class board_board(osv.osv):
|
||||
_auto = False
|
||||
_columns = {}
|
||||
|
||||
@tools.cache()
|
||||
def list(self, cr, uid, context=None):
|
||||
Actions = self.pool.get('ir.actions.act_window')
|
||||
Menus = self.pool.get('ir.ui.menu')
|
||||
IrValues = self.pool.get('ir.values')
|
||||
|
||||
act_ids = Actions.search(cr, uid, [('res_model', '=', self._name)], context=context)
|
||||
refs = ['%s,%s' % (Actions._name, act_id) for act_id in act_ids]
|
||||
|
||||
# cannot search "action" field on menu (non stored function field without search_fnct)
|
||||
irv_ids = IrValues.search(cr, uid, [
|
||||
('model', '=', 'ir.ui.menu'),
|
||||
('key', '=', 'action'),
|
||||
('key2', '=', 'tree_but_open'),
|
||||
('value', 'in', refs),
|
||||
], context=context)
|
||||
menu_ids = map(itemgetter('res_id'), IrValues.read(cr, uid, irv_ids, ['res_id'], context=context))
|
||||
menu_names = Menus.name_get(cr, uid, menu_ids, context=context)
|
||||
return [dict(id=m[0], name=m[1]) for m in menu_names]
|
||||
|
||||
def _clear_list_cache(self):
|
||||
self.list.clear_cache(self)
|
||||
|
||||
def create(self, cr, user, vals, context=None):
|
||||
return 0
|
||||
|
||||
|
||||
+32
-31
@@ -1,39 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from xml.etree import ElementTree
|
||||
|
||||
from openerp.addons.web.controllers.main import load_actions_from_ir_values
|
||||
from openerp.http import Controller, route, request
|
||||
|
||||
class Board(Controller):
|
||||
@route('/board/add_to_dashboard', type='json', auth='user')
|
||||
def add_to_dashboard(self, menu_id, action_id, context_to_save, domain, view_mode, name=''):
|
||||
# FIXME move this method to board.board model
|
||||
dashboard_action = load_actions_from_ir_values('action', 'tree_but_open',
|
||||
[('ir.ui.menu', menu_id)], False)
|
||||
|
||||
if dashboard_action:
|
||||
action = dashboard_action[0][2]
|
||||
if action['res_model'] == 'board.board' and action['views'][0][1] == 'form':
|
||||
# Maybe should check the content instead of model board.board ?
|
||||
view_id = action['views'][0][0]
|
||||
board = request.session.model(action['res_model']).fields_view_get(view_id, 'form')
|
||||
if board and 'arch' in board:
|
||||
xml = ElementTree.fromstring(board['arch'])
|
||||
column = xml.find('./board/column')
|
||||
if column is not None:
|
||||
new_action = ElementTree.Element('action', {
|
||||
'name': str(action_id),
|
||||
'string': name,
|
||||
'view_mode': view_mode,
|
||||
'context': str(context_to_save),
|
||||
'domain': str(domain)
|
||||
})
|
||||
column.insert(0, new_action)
|
||||
arch = ElementTree.tostring(xml, 'utf-8')
|
||||
return request.session.model('ir.ui.view.custom').create({
|
||||
'user_id': request.session.uid,
|
||||
'ref_id': view_id,
|
||||
'arch': arch
|
||||
}, request.context)
|
||||
class Board(Controller):
|
||||
|
||||
@route('/board/add_to_dashboard', type='json', auth='user')
|
||||
def add_to_dashboard(self, action_id, context_to_save, domain, view_mode, name=''):
|
||||
# Retrieve the 'My Dashboard' action from its xmlid
|
||||
action = request.env['ir.model.data'].get_object('board', 'open_board_my_dash_action')
|
||||
|
||||
if action and action['res_model'] == 'board.board' and action['views'][0][1] == 'form':
|
||||
# Maybe should check the content instead of model board.board ?
|
||||
view_id = action['views'][0][0]
|
||||
board = request.env[action['res_model']].fields_view_get(view_id, 'form')
|
||||
if board and 'arch' in board:
|
||||
xml = ElementTree.fromstring(board['arch'])
|
||||
column = xml.find('./board/column')
|
||||
if column is not None:
|
||||
new_action = ElementTree.Element('action', {
|
||||
'name': str(action_id),
|
||||
'string': name,
|
||||
'view_mode': view_mode,
|
||||
'context': str(context_to_save),
|
||||
'domain': str(domain)
|
||||
})
|
||||
column.insert(0, new_action)
|
||||
arch = ElementTree.tostring(xml, 'utf-8')
|
||||
request.env['ir.ui.view.custom'].create({
|
||||
'user_id': request.session.uid,
|
||||
'ref_id': view_id,
|
||||
'arch': arch
|
||||
})
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
@@ -395,23 +395,19 @@ FavoriteMenu.include({
|
||||
board = new Model('board.board'),
|
||||
name = self.$add_dashboard_input.val();
|
||||
|
||||
board.call('list', [board.context()])
|
||||
.then(function (board_list) {
|
||||
return self.rpc('/board/add_to_dashboard', {
|
||||
menu_id: board_list[0].id,
|
||||
action_id: self.action_id,
|
||||
context_to_save: c,
|
||||
domain: d,
|
||||
view_mode: self.view_manager.active_view.type,
|
||||
name: name,
|
||||
});
|
||||
}).then(function (r) {
|
||||
if (r) {
|
||||
self.do_notify(_.str.sprintf(_t("'%s' added to dashboard"), name), '');
|
||||
} else {
|
||||
self.do_warn(_t("Could not add filter to dashboard"));
|
||||
}
|
||||
});
|
||||
return self.rpc('/board/add_to_dashboard', {
|
||||
action_id: self.action_id,
|
||||
context_to_save: c,
|
||||
domain: d,
|
||||
view_mode: self.view_manager.active_view.type,
|
||||
name: name,
|
||||
}).then(function (r) {
|
||||
if (r) {
|
||||
self.do_notify(_.str.sprintf(_t("'%s' added to dashboard"), name), '');
|
||||
} else {
|
||||
self.do_warn(_t("Could not add filter to dashboard"));
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user