[FIX] Schedule jobs even if their next time has passed.
[odoo/odoo.git] / addons / board / board.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution   
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
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.
12 #
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.
17 #
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/>.
20 #
21 ##############################################################################
22
23 import time
24 from osv import fields,osv
25
26 class board_board(osv.osv):
27     _name = 'board.board'
28     
29     def create_view(self, cr, uid, ids, context):
30         
31         board = self.pool.get('board.board').browse(cr, uid, ids, context)
32         left = []
33         right = []
34         for line in board.line_ids:
35             linestr = '<action string="%s" name="%d" colspan="4"' % (line.name, line.action_id.id)
36             if line.height:
37                 linestr+=(' height="%d"' % (line.height,))
38             if line.width:
39                 linestr+=(' width="%d"' % (line.width,))
40             linestr += '/>'
41             if line.position=='left':
42                 left.append(linestr)
43             else:
44                 right.append(linestr)
45         arch = """<?xml version="1.0"?>
46             <form string="My Board">
47             <hpaned>
48                 <child1>
49                     %s
50                 </child1>
51                 <child2>
52                     %s
53                 </child2>
54             </hpaned>
55             </form>""" % ('\n'.join(left), '\n'.join(right))
56         
57         return arch
58
59     def write(self, cr, uid, ids, vals, context={}):
60         result = super(board_board, self).write(cr, uid, ids, vals, context)
61         cr.commit()
62         
63         board = self.pool.get('board.board').browse(cr, uid, ids[0])
64         
65         view = self.create_view(cr, uid, ids[0], context)
66         id = board.view_id.id
67         
68         cr.execute("update ir_ui_view set arch='%s' where id=%s" % (view, id))
69         cr.commit()
70                 
71         return result
72     
73     def create(self, cr, user, vals, context=None):
74         if not 'name' in vals:
75             return False
76         id = super(board_board, self).create(cr, user, vals, context)
77         view_id = self.pool.get('ir.ui.view').create(cr, user, {
78             'name': vals['name'],
79             'model':'board.board',
80             'priority':16,
81             'type': 'form',
82             'arch': self.create_view(cr, user, id, context),
83         })
84
85         super(board_board, self).write(cr, user, [id], {'view_id': view_id}, context)
86
87         return id
88     
89     def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False):
90         res = {}
91         res = super(board_board, self).fields_view_get(cr, user, view_id, view_type, context, toolbar)
92         
93         vids = self.pool.get('ir.ui.view.custom').search(cr, user, [('user_id','=',user), ('ref_id','=',view_id)])
94         if vids:
95             view_id = vids[0]
96             arch = self.pool.get('ir.ui.view.custom').browse(cr, user, view_id)
97             res['arch'] = arch.arch
98             
99         res['toolbar'] = {'print':[],'action':[],'relate':[]}
100         return res
101     
102     _columns = {
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')
106     }
107     
108     # the following lines added to let the button on dashboard work.
109     _defaults = {
110         'name': lambda *args: 'Dashboard'
111     }
112     
113 board_board()
114
115 class board_line(osv.osv):
116     _name = 'board.board.line'
117     _order = 'position,sequence'
118     _columns = {
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)
126     }
127     _defaults = {
128         'position': lambda *args: 'left'
129     }
130 board_line()
131
132 class board_note_type(osv.osv):
133     _name = 'board.note.type'
134     _columns = {
135         'name': fields.char('Note Type', size=64, required=True),
136     }
137 board_note_type()
138
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]
144     return res
145
146 class board_note(osv.osv):
147     _name = 'board.note'
148     _columns = {
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),
154     }
155     _defaults = {
156         'user_id': lambda object,cr,uid,context: uid,
157         'date': lambda object,cr,uid,context: time.strftime('%Y-%m-%d'),
158     }
159 board_note()
160
161 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
162