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 ##############################################################################
22 from osv import fields, osv
26 class board_board(osv.osv):
31 _description = "Board"
33 def create_view(self, cr, uid, ids, context=None):
36 @param cr: the current row, from the database cursor,
37 @param uid: the current user’s ID for security checks,
38 @param ids: List of Board's IDs
39 @return: arch of xml view.
41 board = self.pool.get('board.board').browse(cr, uid, ids, context=context)
45 for line in board.line_ids:
46 linestr = '<action string="%s" name="%d" colspan="4"' % (line.name, line.action_id.id)
48 linestr += (' height="%d"' % (line.height, ))
50 linestr += (' width="%d"' % (line.width, ))
52 if line.position == 'left':
57 arch = """<?xml version="1.0"?>
58 <form string="My Board">
67 </form>""" % ('\n'.join(left), '\n'.join(right))
71 def write(self, cr, uid, ids, vals, context=None):
74 Writes values in one or several fields.
75 @param cr: the current row, from the database cursor,
76 @param uid: the current user’s ID for security checks,
77 @param ids: List of Board's IDs
78 @param vals: dictionary with values to update.
79 dictionary must be with the form: {‘name_of_the_field’: value, ...}.
82 result = super(board_board, self).write(cr, uid, ids, vals, context=context)
84 board = self.pool.get('board.board').browse(cr, uid, ids[0], context=context)
85 view = self.create_view(cr, uid, ids[0], context=context)
87 cr.execute("update ir_ui_view set arch=%s where id=%s", (view, id))
90 def create(self, cr, user, vals, context=None):
93 @param cr: the current row, from the database cursor,
94 @param uid: the current user’s ID for security checks,
95 @param vals: dictionary of values for every field.
96 dictionary must use this form: {‘name_of_the_field’: value, ...}
97 @return: id of new created record of board.board.
101 if not 'name' in vals:
103 id = super(board_board, self).create(cr, user, vals, context=context)
104 view_id = self.pool.get('ir.ui.view').create(cr, user, {
105 'name': vals['name'],
106 'model': 'board.board',
109 'arch': self.create_view(cr, user, id, context=context),
112 super(board_board, self).write(cr, user, [id], {'view_id': view_id}, context)
116 def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None,\
117 toolbar=False, submenu=False):
119 Overrides orm field_view_get.
120 @return: Dictionary of Fields, arch and toolbar.
124 res = super(board_board, self).fields_view_get(cr, user, view_id, view_type,\
125 context, toolbar=toolbar, submenu=submenu)
127 vids = self.pool.get('ir.ui.view.custom').search(cr, user,\
128 [('user_id', '=', user), ('ref_id' ,'=', view_id)])
131 arch = self.pool.get('ir.ui.view.custom').browse(cr, user, view_id, context=context)
132 res['arch'] = arch.arch
133 res['arch'] = self._arch_preprocessing(cr, user, res['arch'], context=context)
134 res['toolbar'] = {'print': [], 'action': [], 'relate': []}
138 def _arch_preprocessing(self, cr, user, arch, context=None):
139 from lxml import etree
140 def remove_unauthorized_children(node):
141 for child in node.iterchildren():
142 if child.tag=='action' and child.get('invisible'):
145 child=remove_unauthorized_children(child)
149 if isinstance(s, unicode):
150 return s.encode('utf8')
153 archnode = etree.fromstring(encode(arch))
154 return etree.tostring(remove_unauthorized_children(archnode),pretty_print=True)
160 'name': fields.char('Dashboard', size=64, required=True),
161 'view_id': fields.many2one('ir.ui.view', 'Board View'),
162 'line_ids': fields.one2many('board.board.line', 'board_id', 'Action Views')
165 # the following lines added to let the button on dashboard work.
167 'name':lambda *args: 'Dashboard'
173 class board_line(osv.osv):
177 _name = 'board.board.line'
178 _description = "Board Line"
179 _order = 'position,sequence'
181 'name': fields.char('Title', size=64, required=True),
182 'sequence': fields.integer('Sequence', help="Gives the sequence order\
183 when displaying a list of board lines."),
184 'height': fields.integer('Height'),
185 'width': fields.integer('Width'),
186 'board_id': fields.many2one('board.board', 'Dashboard', required=True, ondelete='cascade'),
187 'action_id': fields.many2one('ir.actions.act_window', 'Action', required=True),
188 'position': fields.selection([('left','Left'),
189 ('right','Right')], 'Position', required=True)
192 'position': lambda *args: 'left'
198 class board_note_type(osv.osv):
202 _name = 'board.note.type'
203 _description = "Note Type"
206 'name': fields.char('Note Type', size=64, required=True),
211 def _type_get(self, cr, uid, context=None):
213 Get by default Note type.
215 obj = self.pool.get('board.note.type')
216 ids = obj.search(cr, uid, [])
217 res = obj.read(cr, uid, ids, ['name'], context=context)
218 res = [(r['name'], r['name']) for r in res]
222 class board_note(osv.osv):
227 _description = "Note"
229 'name': fields.char('Subject', size=128, required=True),
230 'note': fields.text('Note'),
231 'user_id': fields.many2one('res.users', 'Author', size=64),
232 'date': fields.date('Date', size=64, required=True),
233 'type': fields.selection(_type_get, 'Note type', size=64),
236 'user_id': lambda object, cr, uid, context: uid,
237 'date': lambda object, cr, uid, context: time.strftime('%Y-%m-%d'),
242 class res_log_report(osv.osv):
244 _name = "res.log.report"
246 _description = "Log Report"
248 'name': fields.char('Year', size=64, required=False, readonly=True),
249 'month':fields.selection([('01', 'January'), ('02', 'February'), \
250 ('03', 'March'), ('04', 'April'),\
251 ('05', 'May'), ('06', 'June'), \
252 ('07', 'July'), ('08', 'August'),\
253 ('09', 'September'), ('10', 'October'),\
254 ('11', 'November'), ('12', 'December')], 'Month', readonly=True),
255 'day': fields.char('Day', size=128, readonly=True),
256 'creation_date': fields.date('Creation Date', readonly=True),
257 'res_model': fields.char('Object', size=128),
258 'nbr': fields.integer('# of Entries', readonly=True)
264 @param cr: the current row, from the database cursor
266 tools.drop_view_if_exists(cr,'res_log_report')
268 CREATE OR REPLACE VIEW res_log_report AS (
272 to_char(l.create_date, 'YYYY') as name,
273 to_char(l.create_date, 'MM') as month,
274 to_char(l.create_date, 'YYYY-MM-DD') as day,
275 to_char(l.create_date, 'YYYY-MM-DD') as creation_date,
276 l.res_model as res_model,
277 date_trunc('day',l.create_date) as create_date
283 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: