~trobz/web-addons/trunk

« back to all changes in this revision

Viewing changes to dashboard/model/dashboard_board.py

  • Committer: Michel Meyer
  • Date: 2013-12-02 12:23:07 UTC
  • mfrom: (9.2.1 web-unleashed)
  • Revision ID: mmeyer@trobz.com-20131202122307-p3e3qjp889sr06ia
[Merge] dashboard branch merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
 
 
4
from openerp.osv import osv, fields
 
5
 
 
6
 
 
7
class dashboard_board(osv.osv):
 
8
 
 
9
    _name = "dashboard.board"
 
10
    _description = "Dashboard"
 
11
 
 
12
    def extra_fields(self, cr, uid, ids, field_names, arg, context=None):
 
13
        result = {}
 
14
        
 
15
        for board in self.browse(cr, uid, ids, context=context):
 
16
            widgets = []
 
17
            for widget in board.widget_ids:
 
18
                
 
19
                sequence = 0
 
20
                width = 10 
 
21
                for rel in board.widget_rel:
 
22
                    if rel.widget_id == widget.id:
 
23
                        sequence = rel.sequence
 
24
                        width = rel.width
 
25
                        
 
26
                widgets.append({
 
27
                    'id': widget.id,
 
28
                    'name': widget.name,
 
29
                    'type': widget.type,
 
30
                    'method': widget.method,
 
31
                    'limit': widget.limit,
 
32
                    'sequence': sequence,
 
33
                    'width': width,
 
34
                    'metrics': widget.metrics,
 
35
                })
 
36
            
 
37
            result[board.id] = {
 
38
                'widgets': widgets
 
39
            }
 
40
            
 
41
        return result
 
42
 
 
43
    _columns = {
 
44
        'name': fields.char('Name'),
 
45
        
 
46
        'global_field_refs': fields.serialized(string='Global Field References'),
 
47
        
 
48
        'widget_ids': fields.many2many('dashboard.widget', 'dashboard_board_to_widget_rel', id1='board_id',id2='widget_id', string='Widgets', ondelete='cascade'),
 
49
        
 
50
        
 
51
        'widget_rel': fields.one2many('dashboard.board_to_widget_rel', 'board_id', 'widget relation'),
 
52
    
 
53
        'period_name': fields.selection(
 
54
                                        (('day','Day'), ('week','Week'), ('month','Month'), ('quarter','Quarter'), ('semester','Semester'), ('year','Year')), 
 
55
                                        'Period Name'
 
56
                                        ),
 
57
        'period_type':  fields.selection((('rolling','Rolling'), ('calendar','Calendar')), 'Period Type'),
 
58
        'period_start_at': fields.date('Period Start', help="override Period Name and Period Type if defined"),
 
59
        'period_end_at': fields.date('Period End', help="override Period Name and Period Type if defined"),
 
60
    
 
61
        # get widget details directly by JSON-RPC (no need to query dashboard.widget on web side)
 
62
        'widgets': fields.function(extra_fields, method=True, multi=True, type='serialized', string='Metrics Data', readonly=True),
 
63
    }
 
64
    
 
65
    _defaults = {
 
66
        'period_name': 'month',
 
67
        'period_type': 'calendar',
 
68
        'global_field_refs': []
 
69
        
 
70
    }
 
71
    
 
72
 
 
73
dashboard_board()
 
74
 
 
75
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
76