use new API

This commit is contained in:
Giorgio Borelli
2014-11-11 16:11:42 +01:00
parent 910179599d
commit fc55bca7aa
4 changed files with 74 additions and 71 deletions

View File

@@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, fields
from openerp import models, fields, api
from openerp import SUPERUSER_ID
@@ -38,35 +38,30 @@ class document_page_create_menu(models.TransientModel):
required=True
)
def default_get(self, cr, uid, fields, context=None):
if context is None:
context = {}
res = super(document_page_create_menu, self).default_get(
cr, uid,
fields,
context=context
)
page_id = context.get('active_id')
obj_page = self.pool.get('document.page')
page = obj_page.browse(cr, uid, page_id, context=context)
@api.model
def default_get(self, fields_list):
res = super(document_page_create_menu, self).default_get(fields_list)
page_id = self.env.context.get('active_id')
obj_page = self.env['document.page']
page = obj_page.browse(page_id)
res['menu_name'] = page.name
return res
def document_page_menu_create(self, cr, uid, ids, context=None):
if context is None:
context = {}
obj_page = self.pool.get('document.page')
obj_menu = self.pool.get('ir.ui.menu')
obj_action = self.pool.get('ir.actions.act_window')
page_id = context.get('active_id', False)
page = obj_page.browse(cr, uid, page_id, context=context)
@api.multi
def document_page_menu_create(self):
# events = self.env['event.event'].browse(self._context.get('event_ids', []))
# events.do_confirm()
# return {'type': 'ir.actions.act_window_close'}
# def document_page_menu_create(self, cr, uid, ids, context=None):
# if context is None:
# context = {}
obj_page = self.env['document.page']
obj_menu = self.env['ir.ui.menu']
obj_action = self.env['ir.actions.act_window']
page_id = self.env.context.get('active_id', False)
page = obj_page.browse(page_id)
datas = self.browse(cr, uid, ids, context=context)
data = False
if datas:
data = datas[0]
if not data:
return {}
data = self[0]
value = {
'name': 'Document Page',
'view_type': 'form',
@@ -79,16 +74,18 @@ class document_page_create_menu(models.TransientModel):
value['domain'] = "[('parent_id','=',%d)]" % (page.id)
value['res_id'] = page.id
action_id = obj_action.create(cr, SUPERUSER_ID, value)
# only the super user is allowed to create menu due to security rules
# on ir.values
menu_id = obj_menu.create(cr, SUPERUSER_ID, {
# see.: http://goo.gl/Y99S7V
action_id = obj_action.sudo().create(value)
menu_id = obj_menu.sudo().create({
'name': data.menu_name,
'parent_id': data.menu_parent_id.id,
'icon': 'STOCK_DIALOG_QUESTION',
'action': 'ir.actions.act_window,' + str(action_id),
}, context)
obj_page.write(cr, uid, [page_id], {'menu_id': menu_id})
'action': 'ir.actions.act_window,' + str(action_id.id),
})
page.write({'menu_id': menu_id.id})
return {
'type': 'ir.actions.client',
'tag': 'reload',