~xrg/openobject-doc/trunk-xrg

« back to all changes in this revision

Viewing changes to i18n/vi/source/developer/4_14_dashboard/index.rst

  • Committer: TruongSinh Tran
  • Date: 2009-07-17 18:59:45 UTC
  • Revision ID: truongsinh@vipescoserver-20090717185945-ajjp3zso6xh5jddm
[FIX]private issue

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
.. i18n: Dashboard 
 
3
.. i18n: =========
 
4
 
 
5
Dashboard 
 
6
=========
 
7
 
 
8
.. i18n: Open ERP objects can be created from PostgreSQL views. The technique is as follows :
 
9
 
 
10
Open ERP objects can be created from PostgreSQL views. The technique is as follows :
 
11
 
 
12
.. i18n:    1. Declare your _columns dictionary. All fields must have the flag **readonly=True.**
 
13
.. i18n:    2. Specify the parameter **_auto=False** to the Open ERP object, so no table corresponding to the _columns dictionnary is created automatically.
 
14
.. i18n:    3. Add a method **init(self, cr)** that creates a *PostgreSQL* View matching the fields declared in _columns. 
 
15
 
 
16
   1. Declare your _columns dictionary. All fields must have the flag **readonly=True.**
 
17
   2. Specify the parameter **_auto=False** to the Open ERP object, so no table corresponding to the _columns dictionnary is created automatically.
 
18
   3. Add a method **init(self, cr)** that creates a *PostgreSQL* View matching the fields declared in _columns. 
 
19
 
 
20
.. i18n: **Example** The object report_crm_case_user follows this model.
 
21
 
 
22
**Example** The object report_crm_case_user follows this model.
 
23
 
 
24
.. i18n: .. code-block:: python 
 
25
.. i18n: 
 
26
.. i18n:      class report_crm_case_user(osv.osv):
 
27
.. i18n:        _name = "report.crm.case.user"
 
28
.. i18n:        _description = "Cases by user and section"
 
29
.. i18n:        _auto = False
 
30
.. i18n:         _columns = {
 
31
.. i18n:        'name': fields.date('Month', readonly=True),
 
32
.. i18n:        'user_id':fields.many2one('res.users', 'User', readonly=True, relate=True),
 
33
.. i18n:        'section_id':fields.many2one('crm.case.section', 'Section', readonly=True, relate=True),
 
34
.. i18n:        'amount_revenue': fields.float('Est.Revenue', readonly=True),
 
35
.. i18n:           'amount_costs': fields.float('Est.Cost', readonly=True),
 
36
.. i18n:        'amount_revenue_prob': fields.float('Est. Rev*Prob.', readonly=True),
 
37
.. i18n:        'nbr': fields.integer('# of Cases', readonly=True),
 
38
.. i18n:           'probability': fields.float('Avg. Probability', readonly=True),
 
39
.. i18n:        'state': fields.selection(AVAILABLE_STATES, 'State', size=16, readonly=True),
 
40
.. i18n:        'delay_close': fields.integer('Delay to close', readonly=True),
 
41
.. i18n:        }
 
42
.. i18n:         _order = 'name desc, user_id, section_id'
 
43
.. i18n: 
 
44
.. i18n:        def init(self, cr):
 
45
.. i18n:        cr.execute("""
 
46
.. i18n:             create or replace view report_crm_case_user as (
 
47
.. i18n:                 select
 
48
.. i18n:                     min(c.id) as id,
 
49
.. i18n:                     substring(c.create_date for 7)||'-01' as name,
 
50
.. i18n:                     c.state,
 
51
.. i18n:                     c.user_id,
 
52
.. i18n:                     c.section_id,
 
53
.. i18n:                     count(*) as nbr,
 
54
.. i18n:                     sum(planned_revenue) as amount_revenue,
 
55
.. i18n:                     sum(planned_cost) as amount_costs,
 
56
.. i18n:                     sum(planned_revenue*probability)::decimal(16,2) as amount_revenue_prob,
 
57
.. i18n:                     avg(probability)::decimal(16,2) as probability,
 
58
.. i18n:                     to_char(avg(date_closed-c.create_date), 'DD"d" `HH24:MI:SS') as delay_close
 
59
.. i18n:                 from
 
60
.. i18n:                     crm_case c
 
61
.. i18n:                 group by substring(c.create_date for 7), c.state, c.user_id, c.section_id
 
62
.. i18n:        )""")
 
63
.. i18n:        report_crm_case_user()
 
64
 
 
65
.. code-block:: python 
 
66
 
 
67
     class report_crm_case_user(osv.osv):
 
68
        _name = "report.crm.case.user"
 
69
        _description = "Cases by user and section"
 
70
        _auto = False
 
71
         _columns = {
 
72
        'name': fields.date('Month', readonly=True),
 
73
        'user_id':fields.many2one('res.users', 'User', readonly=True, relate=True),
 
74
        'section_id':fields.many2one('crm.case.section', 'Section', readonly=True, relate=True),
 
75
        'amount_revenue': fields.float('Est.Revenue', readonly=True),
 
76
           'amount_costs': fields.float('Est.Cost', readonly=True),
 
77
        'amount_revenue_prob': fields.float('Est. Rev*Prob.', readonly=True),
 
78
        'nbr': fields.integer('# of Cases', readonly=True),
 
79
           'probability': fields.float('Avg. Probability', readonly=True),
 
80
        'state': fields.selection(AVAILABLE_STATES, 'State', size=16, readonly=True),
 
81
        'delay_close': fields.integer('Delay to close', readonly=True),
 
82
        }
 
83
         _order = 'name desc, user_id, section_id'
 
84
 
 
85
        def init(self, cr):
 
86
        cr.execute("""
 
87
             create or replace view report_crm_case_user as (
 
88
                 select
 
89
                     min(c.id) as id,
 
90
                     substring(c.create_date for 7)||'-01' as name,
 
91
                     c.state,
 
92
                     c.user_id,
 
93
                     c.section_id,
 
94
                     count(*) as nbr,
 
95
                     sum(planned_revenue) as amount_revenue,
 
96
                     sum(planned_cost) as amount_costs,
 
97
                     sum(planned_revenue*probability)::decimal(16,2) as amount_revenue_prob,
 
98
                     avg(probability)::decimal(16,2) as probability,
 
99
                     to_char(avg(date_closed-c.create_date), 'DD"d" `HH24:MI:SS') as delay_close
 
100
                 from
 
101
                     crm_case c
 
102
                 group by substring(c.create_date for 7), c.state, c.user_id, c.section_id
 
103
        )""")
 
104
        report_crm_case_user()