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['custom_view_id'] = view_id
133 res['arch'] = arch.arch
134 res['arch'] = self._arch_preprocessing(cr, user, res['arch'], context=context)
135 res['toolbar'] = {'print': [], 'action': [], 'relate': []}
139 def _arch_preprocessing(self, cr, user, arch, context=None):
140 from lxml import etree
141 def remove_unauthorized_children(node):
142 for child in node.iterchildren():
143 if child.tag=='action' and child.get('invisible'):
146 child=remove_unauthorized_children(child)
150 if isinstance(s, unicode):
151 return s.encode('utf8')
154 archnode = etree.fromstring(encode(arch))
155 return etree.tostring(remove_unauthorized_children(archnode),pretty_print=True)
161 'name': fields.char('Dashboard', size=64, required=True),
162 'view_id': fields.many2one('ir.ui.view', 'Board View'),
163 'line_ids': fields.one2many('board.board.line', 'board_id', 'Action Views')
166 # the following lines added to let the button on dashboard work.
168 'name':lambda *args: 'Dashboard'
171 class board_line(osv.osv):
175 _name = 'board.board.line'
176 _description = "Board Line"
177 _order = 'position,sequence'
179 'name': fields.char('Title', size=64, required=True),
180 'sequence': fields.integer('Sequence', help="Gives the sequence order\
181 when displaying a list of board lines.", select=True),
182 'height': fields.integer('Height'),
183 'width': fields.integer('Width'),
184 'board_id': fields.many2one('board.board', 'Dashboard', required=True, ondelete='cascade'),
185 'action_id': fields.many2one('ir.actions.act_window', 'Action', required=True),
186 'position': fields.selection([('left','Left'),
187 ('right','Right')], 'Position', required=True, select=True)
190 'position': lambda *args: 'left'
193 class res_log_report(osv.osv):
195 _name = "res.log.report"
197 _description = "Log Report"
199 'name': fields.char('Year', size=64, required=False, readonly=True),
200 'month':fields.selection([('01', 'January'), ('02', 'February'), \
201 ('03', 'March'), ('04', 'April'),\
202 ('05', 'May'), ('06', 'June'), \
203 ('07', 'July'), ('08', 'August'),\
204 ('09', 'September'), ('10', 'October'),\
205 ('11', 'November'), ('12', 'December')], 'Month', readonly=True),
206 'day': fields.char('Day', size=128, readonly=True),
207 'creation_date': fields.date('Creation Date', readonly=True),
208 'res_model': fields.char('Object', size=128),
209 'nbr': fields.integer('# of Entries', readonly=True)
215 @param cr: the current row, from the database cursor
217 tools.drop_view_if_exists(cr,'res_log_report')
219 CREATE OR REPLACE VIEW res_log_report AS (
223 to_char(l.create_date, 'YYYY') as name,
224 to_char(l.create_date, 'MM') as month,
225 to_char(l.create_date, 'YYYY-MM-DD') as day,
226 to_char(l.create_date, 'YYYY-MM-DD') as creation_date,
227 l.res_model as res_model,
228 date_trunc('day',l.create_date) as create_date
234 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: