1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
24 from osv import fields,osv
26 class board_board(osv.osv):
29 def create_view(self, cr, uid, ids, context):
31 board = self.pool.get('board.board').browse(cr, uid, ids, context)
34 for line in board.line_ids:
35 linestr = '<action string="%s" name="%d" colspan="4"' % (line.name, line.action_id.id)
37 linestr+=(' height="%d"' % (line.height,))
39 linestr+=(' width="%d"' % (line.width,))
41 if line.position=='left':
45 arch = """<?xml version="1.0"?>
46 <form string="My Board">
55 </form>""" % ('\n'.join(left), '\n'.join(right))
59 def write(self, cr, uid, ids, vals, context={}):
60 result = super(board_board, self).write(cr, uid, ids, vals, context)
63 board = self.pool.get('board.board').browse(cr, uid, ids[0])
65 view = self.create_view(cr, uid, ids[0], context)
68 cr.execute("update ir_ui_view set arch='%s' where id=%s" % (view, id))
73 def create(self, cr, user, vals, context=None):
74 if not 'name' in vals:
76 id = super(board_board, self).create(cr, user, vals, context)
77 view_id = self.pool.get('ir.ui.view').create(cr, user, {
79 'model':'board.board',
82 'arch': self.create_view(cr, user, id, context),
85 super(board_board, self).write(cr, user, [id], {'view_id': view_id}, context)
89 def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False):
91 res = super(board_board, self).fields_view_get(cr, user, view_id, view_type, context, toolbar)
93 vids = self.pool.get('ir.ui.view.custom').search(cr, user, [('user_id','=',user), ('ref_id','=',view_id)])
96 arch = self.pool.get('ir.ui.view.custom').browse(cr, user, view_id)
97 res['arch'] = arch.arch
99 res['toolbar'] = {'print':[],'action':[],'relate':[]}
103 'name': fields.char('Dashboard', size=64, required=True),
104 'view_id': fields.many2one('ir.ui.view', 'Board View'),
105 'line_ids': fields.one2many('board.board.line', 'board_id', 'Action Views')
108 # the following lines added to let the button on dashboard work.
110 'name': lambda *args: 'Dashboard'
115 class board_line(osv.osv):
116 _name = 'board.board.line'
117 _order = 'position,sequence'
119 'name': fields.char('Title', size=64, required=True),
120 'sequence': fields.integer('Sequence'),
121 'height': fields.integer('Height'),
122 'width': fields.integer('Width'),
123 'board_id': fields.many2one('board.board', 'Dashboard', required=True, ondelete='cascade'),
124 'action_id': fields.many2one('ir.actions.act_window', 'Action', required=True),
125 'position': fields.selection([('left','Left'),('right','Right')], 'Position', required=True)
128 'position': lambda *args: 'left'
132 class board_note_type(osv.osv):
133 _name = 'board.note.type'
135 'name': fields.char('Note Type', size=64, required=True),
139 def _type_get(self, cr, uid, context={}):
140 obj = self.pool.get('board.note.type')
141 ids = obj.search(cr, uid, [])
142 res = obj.read(cr, uid, ids, ['name'], context)
143 res = [(r['name'], r['name']) for r in res]
146 class board_note(osv.osv):
149 'name': fields.char('Subject', size=128, required=True),
150 'note': fields.text('Note'),
151 'user_id': fields.many2one('res.users', 'Author', size=64),
152 'date': fields.date('Date', size=64, required=True),
153 'type': fields.selection(_type_get, 'Note type', size=64),
156 'user_id': lambda object,cr,uid,context: uid,
157 'date': lambda object,cr,uid,context: time.strftime('%Y-%m-%d'),
161 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: