[IMP]: board: code optimization and apply csv file
bzr revid: atp@tinyerp.co.in-20100317102207-1cjejv359e9smpfu
This commit is contained in:
parent
3acf0a3c44
commit
c759fe8400
|
@ -19,8 +19,8 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields, osv
|
||||
import time
|
||||
from osv import fields,osv
|
||||
|
||||
class board_board(osv.osv):
|
||||
"""
|
||||
|
@ -29,20 +29,28 @@ class board_board(osv.osv):
|
|||
_name = 'board.board'
|
||||
_description = "Board"
|
||||
|
||||
def create_view(self, cr, uid, ids, context):
|
||||
|
||||
board = self.pool.get('board.board').browse(cr, uid, ids, context)
|
||||
def create_view(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Create view
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param ids: List of Board's IDs
|
||||
@return: arch of xml view.
|
||||
"""
|
||||
if not context:
|
||||
context = {}
|
||||
board = self.pool.get('board.board').browse(cr, uid, ids, context=context)
|
||||
left = []
|
||||
right = []
|
||||
#start Loop
|
||||
for line in board.line_ids:
|
||||
linestr = '<action string="%s" name="%d" colspan="4"' % (line.name, line.action_id.id)
|
||||
if line.height:
|
||||
linestr+=(' height="%d"' % (line.height,))
|
||||
linestr += (' height="%d"' % (line.height, ))
|
||||
if line.width:
|
||||
linestr+=(' width="%d"' % (line.width,))
|
||||
linestr += (' width="%d"' % (line.width, ))
|
||||
linestr += '/>'
|
||||
if line.position=='left':
|
||||
if line.position == 'left':
|
||||
left.append(linestr)
|
||||
else:
|
||||
right.append(linestr)
|
||||
|
@ -58,23 +66,40 @@ class board_board(osv.osv):
|
|||
</child2>
|
||||
</hpaned>
|
||||
</form>""" % ('\n'.join(left), '\n'.join(right))
|
||||
|
||||
|
||||
return arch
|
||||
|
||||
def write(self, cr, uid, ids, vals, context={}):
|
||||
def write(self, cr, uid, ids, vals, context = {}):
|
||||
|
||||
"""
|
||||
Writes values in one or several fields.
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param ids: List of Board's IDs
|
||||
@param vals: dictionary with values to update.
|
||||
dictionary must be with the form: {‘name_of_the_field’: value, ...}.
|
||||
@return: True
|
||||
"""
|
||||
result = super(board_board, self).write(cr, uid, ids, vals, context)
|
||||
cr.commit()
|
||||
|
||||
board = self.pool.get('board.board').browse(cr, uid, ids[0])
|
||||
|
||||
view = self.create_view(cr, uid, ids[0], context)
|
||||
id = board.view_id.id
|
||||
cr.execute("update ir_ui_view set arch=%s where id=%s" , (view, id))
|
||||
cr.execute("update ir_ui_view set arch=%s where id=%s", (view, id))
|
||||
cr.commit()
|
||||
|
||||
return result
|
||||
|
||||
def create(self, cr, user, vals, context=None):
|
||||
"""
|
||||
create new record.
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param vals: dictionary of values for every field.
|
||||
dictionary must use this form: {‘name_of_the_field’: value, ...}
|
||||
@return: id of new created record of board.board.
|
||||
"""
|
||||
|
||||
if not context:
|
||||
context = {}
|
||||
|
||||
|
@ -83,41 +108,45 @@ class board_board(osv.osv):
|
|||
id = super(board_board, self).create(cr, user, vals, context)
|
||||
view_id = self.pool.get('ir.ui.view').create(cr, user, {
|
||||
'name': vals['name'],
|
||||
'model':'board.board',
|
||||
'priority':16,
|
||||
'model': 'board.board',
|
||||
'priority': 16,
|
||||
'type': 'form',
|
||||
'arch': self.create_view(cr, user, id, context),
|
||||
})
|
||||
|
||||
super(board_board, self).write(cr, user, [id], {'view_id': view_id}, context)
|
||||
|
||||
|
||||
return id
|
||||
|
||||
def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
|
||||
"""
|
||||
Overrides orm field_view_get.
|
||||
@return: Dictionary of Fields, arch and toolbar.
|
||||
"""
|
||||
if not context:
|
||||
context={}
|
||||
context = {}
|
||||
|
||||
res = {}
|
||||
res = super(board_board, self).fields_view_get(cr, user, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
|
||||
|
||||
vids = self.pool.get('ir.ui.view.custom').search(cr, user, [('user_id','=',user), ('ref_id','=',view_id)])
|
||||
vids = self.pool.get('ir.ui.view.custom').search(cr, user, [('user_id', '=', user), ('ref_id' ,'=', view_id)])
|
||||
if vids:
|
||||
view_id = vids[0]
|
||||
arch = self.pool.get('ir.ui.view.custom').browse(cr, user, view_id)
|
||||
res['arch'] = arch.arch
|
||||
|
||||
res['toolbar'] = {'print':[],'action':[],'relate':[]}
|
||||
res['toolbar'] = {'print': [], 'action': [], 'relate': []}
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Dashboard', size=64, required=True),
|
||||
'view_id': fields.many2one('ir.ui.view', 'Board View'),
|
||||
'name': fields.char('Dashboard', size=64, required=True),
|
||||
'view_id': fields.many2one('ir.ui.view', 'Board View'),
|
||||
'line_ids': fields.one2many('board.board.line', 'board_id', 'Action Views')
|
||||
}
|
||||
|
||||
# the following lines added to let the button on dashboard work.
|
||||
_defaults = {
|
||||
'name': lambda *args: 'Dashboard'
|
||||
'name': lambda *args: 'Dashboard'
|
||||
}
|
||||
|
||||
board_board()
|
||||
|
@ -158,6 +187,9 @@ class board_note_type(osv.osv):
|
|||
board_note_type()
|
||||
|
||||
def _type_get(self, cr, uid, context={}):
|
||||
"""
|
||||
Get by default Note type.
|
||||
"""
|
||||
obj = self.pool.get('board.note.type')
|
||||
ids = obj.search(cr, uid, [])
|
||||
res = obj.read(cr, uid, ids, ['name'], context)
|
||||
|
@ -179,8 +211,8 @@ class board_note(osv.osv):
|
|||
'type': fields.selection(_type_get, 'Note type', size=64),
|
||||
}
|
||||
_defaults = {
|
||||
'user_id': lambda object,cr,uid,context: uid,
|
||||
'date': lambda object,cr,uid,context: time.strftime('%Y-%m-%d'),
|
||||
'user_id': lambda object, cr, uid, context: uid,
|
||||
'date': lambda object, cr, uid, context: time.strftime('%Y-%m-%d'),
|
||||
}
|
||||
board_note()
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_board_board,board.board,model_board_board,base.group_user,1,1,1,1
|
||||
access_board_board_line,board.board.line,model_board_board_line,base.group_user,1,1,1,1
|
||||
access_board_note_type,board.note.type,model_board_note_type,base.group_user,1,1,1,1
|
||||
access_board_note,board.note,model_board_note,base.group_user,1,1,1,1
|
||||
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
|
||||
"access_board_board","board.board","model_board_board","base.group_user",1,1,1,1
|
||||
"access_board_board_line","board.board.line","model_board_board_line","base.group_user",1,1,1,1
|
||||
"access_board_note_type","board.note.type","model_board_note_type","base.group_user",1,1,1,1
|
||||
"access_board_note","board.note","model_board_note","base.group_user",1,1,1,1
|
||||
"access_board_menu_create","board.menu.create","model_board_menu_create","base.group_user",1,1,1,1
|
||||
|
|
|
|
@ -27,12 +27,16 @@ class board_menu_create(osv.osv_memory):
|
|||
Create Menu
|
||||
"""
|
||||
def check_views(self, cr, uid, context):
|
||||
|
||||
"""
|
||||
check dashboard view on menu name field.
|
||||
@return: False
|
||||
"""
|
||||
data = context and context.get('active_id', False) or False
|
||||
if data:
|
||||
board = self.pool.get('board.board').browse(cr, uid, data)
|
||||
if not board.line_ids:
|
||||
raise osv.except_osv(_('User Error!'), _('Please Insert Dashboard View(s) !'))
|
||||
raise osv.except_osv(_('User Error!'),
|
||||
_('Please Insert Dashboard View(s) !'))
|
||||
return False
|
||||
|
||||
def board_menu_create(self, cr, uid, ids, context=None):
|
||||
|
@ -44,7 +48,7 @@ class board_menu_create(osv.osv_memory):
|
|||
@return : Dictionary {}.
|
||||
"""
|
||||
if not context:
|
||||
context={}
|
||||
context = {}
|
||||
|
||||
context_id = context and context.get('active_id', False) or False
|
||||
if context_id:
|
||||
|
@ -63,7 +67,7 @@ class board_menu_create(osv.osv_memory):
|
|||
'name': data.get('menu_name'),
|
||||
'parent_id': data.get('menu_parent_id'),
|
||||
'icon': 'STOCK_SELECT_COLOR',
|
||||
'action': 'ir.actions.act_window,'+str(action_id)
|
||||
'action': 'ir.actions.act_window,' + str(action_id)
|
||||
}, context=context)
|
||||
#End Loop
|
||||
return {}
|
||||
|
@ -71,11 +75,11 @@ class board_menu_create(osv.osv_memory):
|
|||
_name = "board.menu.create"
|
||||
_description = "Menu Create"
|
||||
_columns = {
|
||||
'menu_name':fields.char('Menu Name', size=64, required=True),
|
||||
'menu_parent_id':fields.many2one('ir.ui.menu', 'Parent Menu', required=True),
|
||||
'menu_name': fields.char('Menu Name', size=64, required=True),
|
||||
'menu_parent_id': fields.many2one('ir.ui.menu', 'Parent Menu', required=True),
|
||||
}
|
||||
_defaults = {
|
||||
'menu_name':check_views,
|
||||
'menu_name': check_views,
|
||||
}
|
||||
|
||||
board_menu_create()
|
||||
|
|
Loading…
Reference in New Issue