1
|
|
|
# Copyright 2013 Mathias WOLFF |
2
|
|
|
# This file is part of pyfreebilling. |
3
|
|
|
# |
4
|
|
|
# pyfreebilling is free software: you can redistribute it and/or modify |
5
|
|
|
# it under the terms of the GNU General Public License as published by |
6
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
7
|
|
|
# (at your option) any later version. |
8
|
|
|
# |
9
|
|
|
# pyfreebilling is distributed in the hope that it will be useful, |
10
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
11
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12
|
|
|
# GNU General Public License for more details. |
13
|
|
|
# |
14
|
|
|
# You should have received a copy of the GNU General Public License |
15
|
|
|
# along with pyfreebilling. If not, see <http://www.gnu.org/licenses/> |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
from django.db.models import Sum, Avg, Count |
19
|
|
|
|
20
|
|
|
from pyfreebilling.cdr.models import CDR |
21
|
|
|
|
22
|
|
|
from model_report.report import reports, ReportAdmin |
23
|
|
|
from model_report.utils import (usd_format, avg_column, sum_column, count_column) |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
class CDRReport(ReportAdmin): |
27
|
|
|
title = 'CDR stats' |
28
|
|
|
model = CDR |
29
|
|
|
fields = [ |
30
|
|
|
'customer__name', |
31
|
|
|
'effective_duration', |
32
|
|
|
'total_sell', |
33
|
|
|
'total_cost'] |
34
|
|
|
list_order_by = ('customer__name',) |
35
|
|
|
list_group_by = ('customer__name',) |
36
|
|
|
list_filter = ('start_stamp',) |
37
|
|
|
type = 'report' |
38
|
|
|
group_totals = { |
39
|
|
|
'total_sell': sum_column, |
40
|
|
|
'total_cost': sum_column, |
41
|
|
|
'effective_duration': sum_column, |
42
|
|
|
} |
43
|
|
|
report_totals = { |
44
|
|
|
'total_sell': sum_column, |
45
|
|
|
'total_cost': sum_column, |
46
|
|
|
'effective_duration': sum_column, |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
# verbose_name = 'CDR stats' |
50
|
|
|
# annotate = ( |
51
|
|
|
# ('id', Count, 'Nb Calls'), |
52
|
|
|
# ('effective_duration', Sum), |
53
|
|
|
# ('effective_duration', Avg), |
54
|
|
|
# ('billsec', Sum), |
55
|
|
|
# ('total_cost', Sum), |
56
|
|
|
# ('total_sell', Sum), |
57
|
|
|
# ) |
58
|
|
|
# aggregate = ( |
59
|
|
|
# ('id', Count, 'Nb Calls'), |
60
|
|
|
# ('effective_duration', Sum), |
61
|
|
|
# ('effective_duration', Avg), |
62
|
|
|
# ('billsec', Sum), |
63
|
|
|
# ('total_cost', Sum), |
64
|
|
|
# ('total_sell', Sum), |
65
|
|
|
# ) |
66
|
|
|
# group_by = [ |
67
|
|
|
# 'customer__name', |
68
|
|
|
# ('customer__name', 'sell_destination'), |
69
|
|
|
# 'sell_destination', |
70
|
|
|
# 'lcr_carrier_id__name', |
71
|
|
|
# ('lcr_carrier_id__name', 'cost_destination'), |
72
|
|
|
# 'cost_destination', |
73
|
|
|
# ] |
74
|
|
|
# list_filter = [ |
75
|
|
|
# 'sell_destination', |
76
|
|
|
# 'lcr_carrier_id__name', |
77
|
|
|
# ] |
78
|
|
|
|
79
|
|
|
# date_hierarchy = 'start_stamp' |
80
|
|
|
|
81
|
|
|
reports.register('CDR-report', CDRReport) |
82
|
|
|
|