from osv import fields, osv
import time
+import tools
class board_board(osv.osv):
"""
@param ids: List of Board's IDs
@return: arch of xml view.
"""
- if not context:
- context = {}
board = self.pool.get('board.board').browse(cr, uid, ids, context=context)
left = []
right = []
return arch
- def write(self, cr, uid, ids, vals, context = {}):
+ def write(self, cr, uid, ids, vals, context=None):
"""
Writes values in one or several fields.
dictionary must be with the form: {‘name_of_the_field’: value, ...}.
@return: True
"""
- result = super(board_board, self).write(cr, uid, ids, vals, context)
+ result = super(board_board, self).write(cr, uid, ids, vals, context=context)
- board = self.pool.get('board.board').browse(cr, uid, ids[0])
- view = self.create_view(cr, uid, ids[0], context)
+ board = self.pool.get('board.board').browse(cr, uid, ids[0], context=context)
+ view = self.create_view(cr, uid, ids[0], context=context)
id = board.view_id.id
cr.execute("update ir_ui_view set arch=%s where id=%s", (view, id))
return result
@return: id of new created record of board.board.
"""
- if not context:
- context = {}
if not 'name' in vals:
return False
- id = super(board_board, self).create(cr, user, vals, context)
+ id = super(board_board, self).create(cr, user, vals, context=context)
view_id = self.pool.get('ir.ui.view').create(cr, user, {
'name': vals['name'],
'model': 'board.board',
'priority': 16,
'type': 'form',
- 'arch': self.create_view(cr, user, id, context),
+ 'arch': self.create_view(cr, user, id, context=context),
})
super(board_board, self).write(cr, user, [id], {'view_id': view_id}, context)
@return: Dictionary of Fields, arch and toolbar.
"""
- if not context:
- context = {}
-
res = {}
res = super(board_board, self).fields_view_get(cr, user, view_id, view_type,\
context, toolbar=toolbar, submenu=submenu)
[('user_id', '=', user), ('ref_id' ,'=', view_id)])
if vids:
view_id = vids[0]
- arch = self.pool.get('ir.ui.view.custom').browse(cr, user, view_id)
+ arch = self.pool.get('ir.ui.view.custom').browse(cr, user, view_id, context=context)
res['arch'] = arch.arch
-
+ res['arch'] = self._arch_preprocessing(cr, user, res['arch'], context=context)
res['toolbar'] = {'print': [], 'action': [], 'relate': []}
return res
+
+
+ def _arch_preprocessing(self, cr, user, arch, context=None):
+ from lxml import etree
+ def remove_unauthorized_children(node):
+ for child in node.iterchildren():
+ if child.tag=='action' and child.get('invisible'):
+ node.remove(child)
+ else:
+ child=remove_unauthorized_children(child)
+ return node
+
+ def encode(s):
+ if isinstance(s, unicode):
+ return s.encode('utf8')
+ return s
+
+ archnode = etree.fromstring(encode(arch))
+ return etree.tostring(remove_unauthorized_children(archnode),pretty_print=True)
+
+
+
_columns = {
'name': fields.char('Dashboard', size=64, required=True),
Board note Type
"""
_name = 'board.note.type'
- _description = "NOte Type"
+ _description = "Note Type"
_columns = {
'name': fields.char('Note Type', size=64, required=True),
board_note_type()
-def _type_get(self, cr, uid, context={}):
+def _type_get(self, cr, uid, context=None):
"""
Get by default Note type.
"""
obj = self.pool.get('board.note.type')
ids = obj.search(cr, uid, [])
- res = obj.read(cr, uid, ids, ['name'], context)
+ res = obj.read(cr, uid, ids, ['name'], context=context)
res = [(r['name'], r['name']) for r in res]
return res
board_note()
-class temp_log(osv.osv_memory):
- _inherit = 'res.log'
- _description = 'Temporary Log'
- _columns = {'count': fields.integer("Count")}
- _defaults = {'count': lambda *a: True}
-
-temp_log()
+class res_log_report(osv.osv):
+ """ Log Report """
+ _name = "res.log.report"
+ _auto = False
+ _description = "Log Report"
+ _columns = {
+ 'name': fields.char('Year', size=64, required=False, readonly=True),
+ 'month':fields.selection([('01', 'January'), ('02', 'February'), \
+ ('03', 'March'), ('04', 'April'),\
+ ('05', 'May'), ('06', 'June'), \
+ ('07', 'July'), ('08', 'August'),\
+ ('09', 'September'), ('10', 'October'),\
+ ('11', 'November'), ('12', 'December')], 'Month', readonly=True),
+ 'day': fields.char('Day', size=128, readonly=True),
+ 'creation_date': fields.date('Creation Date', readonly=True),
+ 'res_model': fields.char('Object', size=128),
+ 'nbr': fields.integer('# of Entries', readonly=True)
+ }
+
+ def init(self, cr):
+ """
+ Log Report
+ @param cr: the current row, from the database cursor
+ """
+ tools.drop_view_if_exists(cr,'res_log_report')
+ cr.execute("""
+ CREATE OR REPLACE VIEW res_log_report AS (
+ SELECT
+ l.id as id,
+ 1 as nbr,
+ to_char(l.create_date, 'YYYY') as name,
+ to_char(l.create_date, 'MM') as month,
+ to_char(l.create_date, 'YYYY-MM-DD') as day,
+ to_char(l.create_date, 'YYYY-MM-DD') as creation_date,
+ l.res_model as res_model,
+ date_trunc('day',l.create_date) as create_date
+ FROM
+ res_log l
+ )""")
+res_log_report()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: