mirror of
https://github.com/OCA/knowledge.git
synced 2025-12-19 03:42:19 -06:00
use new API
This commit is contained in:
committed by
FernandoRomera
parent
742c9c90e1
commit
cd11965527
@@ -18,50 +18,43 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp import SUPERUSER_ID
|
||||
from openerp.osv import fields, osv
|
||||
from openerp import models, fields, api
|
||||
|
||||
|
||||
class document_page_create_menu(osv.osv_memory):
|
||||
class document_page_create_menu(models.TransientModel):
|
||||
""" Create Menu """
|
||||
_name = "document.page.create.menu"
|
||||
_description = "Wizard Create Menu"
|
||||
|
||||
_columns = {
|
||||
'menu_name': fields.char('Menu Name', size=256, required=True),
|
||||
'menu_parent_id': fields.many2one('ir.ui.menu', 'Parent Menu',
|
||||
required=True),
|
||||
}
|
||||
menu_name = fields.Char(
|
||||
'Menu Name',
|
||||
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)
|
||||
menu_parent_id = fields.Many2one(
|
||||
'ir.ui.menu',
|
||||
'Parent Menu',
|
||||
required=True
|
||||
)
|
||||
|
||||
@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):
|
||||
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',
|
||||
@@ -74,16 +67,18 @@ class document_page_create_menu(osv.osv_memory):
|
||||
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',
|
||||
|
||||
Reference in New Issue
Block a user