1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
23 from osv import fields,osv
25 class board_board(osv.osv):
28 def create_view(self, cr, uid, ids, context):
30 board = self.pool.get('board.board').browse(cr, uid, ids, context)
33 for line in board.line_ids:
34 linestr = '<action string="%s" name="%d" colspan="4"' % (line.name, line.action_id.id)
36 linestr+=(' height="%d"' % (line.height,))
38 linestr+=(' width="%d"' % (line.width,))
40 if line.position=='left':
44 arch = """<?xml version="1.0"?>
45 <form string="My Board">
54 </form>""" % ('\n'.join(left), '\n'.join(right))
58 def write(self, cr, uid, ids, vals, context={}):
59 result = super(board_board, self).write(cr, uid, ids, vals, context)
62 board = self.pool.get('board.board').browse(cr, uid, ids[0])
64 view = self.create_view(cr, uid, ids[0], context)
66 cr.execute("update ir_ui_view set arch=%s where id=%s" , (view, id))
71 def create(self, cr, user, vals, context=None):
72 if not 'name' in vals:
74 id = super(board_board, self).create(cr, user, vals, context)
75 view_id = self.pool.get('ir.ui.view').create(cr, user, {
77 'model':'board.board',
80 'arch': self.create_view(cr, user, id, context),
83 super(board_board, self).write(cr, user, [id], {'view_id': view_id}, context)
87 def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
89 res = super(board_board, self).fields_view_get(cr, user, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
91 vids = self.pool.get('ir.ui.view.custom').search(cr, user, [('user_id','=',user), ('ref_id','=',view_id)])
94 arch = self.pool.get('ir.ui.view.custom').browse(cr, user, view_id)
95 res['arch'] = arch.arch
97 res['toolbar'] = {'print':[],'action':[],'relate':[]}
101 'name': fields.char('Dashboard', size=64, required=True),
102 'view_id': fields.many2one('ir.ui.view', 'Board View'),
103 'line_ids': fields.one2many('board.board.line', 'board_id', 'Action Views')
106 # the following lines added to let the button on dashboard work.
108 'name': lambda *args: 'Dashboard'
113 class board_line(osv.osv):
114 _name = 'board.board.line'
115 _order = 'position,sequence'
117 'name': fields.char('Title', size=64, required=True),
118 'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of board lines."),
119 'height': fields.integer('Height'),
120 'width': fields.integer('Width'),
121 'board_id': fields.many2one('board.board', 'Dashboard', required=True, ondelete='cascade'),
122 'action_id': fields.many2one('ir.actions.act_window', 'Action', required=True),
123 'position': fields.selection([('left','Left'),('right','Right')], 'Position', required=True)
126 'position': lambda *args: 'left'
130 class board_note_type(osv.osv):
131 _name = 'board.note.type'
133 'name': fields.char('Note Type', size=64, required=True),
137 def _type_get(self, cr, uid, context={}):
138 obj = self.pool.get('board.note.type')
139 ids = obj.search(cr, uid, [])
140 res = obj.read(cr, uid, ids, ['name'], context)
141 res = [(r['name'], r['name']) for r in res]
144 class board_note(osv.osv):
147 'name': fields.char('Subject', size=128, required=True),
148 'note': fields.text('Note'),
149 'user_id': fields.many2one('res.users', 'Author', size=64),
150 'date': fields.date('Date', size=64, required=True),
151 'type': fields.selection(_type_get, 'Note type', size=64),
154 'user_id': lambda object,cr,uid,context: uid,
155 'date': lambda object,cr,uid,context: time.strftime('%Y-%m-%d'),
159 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: