2012-08-09 15:30:27 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from xml.etree import ElementTree
|
|
|
|
|
2012-10-10 20:46:17 +00:00
|
|
|
from openerp.addons.web.controllers.main import load_actions_from_ir_values
|
2014-07-06 14:44:26 +00:00
|
|
|
from openerp.http import Controller, route, request
|
2012-08-09 15:30:27 +00:00
|
|
|
|
2013-10-22 13:10:49 +00:00
|
|
|
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=''):
|
2012-08-09 15:30:27 +00:00
|
|
|
# FIXME move this method to board.board model
|
2013-10-22 13:10:49 +00:00
|
|
|
dashboard_action = load_actions_from_ir_values('action', 'tree_but_open',
|
|
|
|
[('ir.ui.menu', menu_id)], False)
|
2012-08-09 15:30:27 +00:00
|
|
|
|
|
|
|
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]
|
2013-10-22 13:10:49 +00:00
|
|
|
board = request.session.model(action['res_model']).fields_view_get(view_id, 'form')
|
2012-08-09 15:30:27 +00:00
|
|
|
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,
|
2012-11-26 14:04:23 +00:00
|
|
|
'context': str(context_to_save),
|
2012-08-09 15:30:27 +00:00
|
|
|
'domain': str(domain)
|
|
|
|
})
|
|
|
|
column.insert(0, new_action)
|
|
|
|
arch = ElementTree.tostring(xml, 'utf-8')
|
2013-10-22 13:10:49 +00:00
|
|
|
return request.session.model('ir.ui.view.custom').create({
|
|
|
|
'user_id': request.session.uid,
|
2012-08-09 15:30:27 +00:00
|
|
|
'ref_id': view_id,
|
|
|
|
'arch': arch
|
2013-10-22 13:10:49 +00:00
|
|
|
}, request.context)
|
2012-08-09 15:30:27 +00:00
|
|
|
|
|
|
|
return False
|