Commit 9705f04bb25bbd655d49dd8527a27b71253e44ad

Authored by hitier
1 parent de63cb72

Fix project charges sql request

now aggregating (sum) on the category (service or capacity)
Showing 1 changed file with 7 additions and 5 deletions   Show diff stats
@@ -79,26 +79,28 @@ def charges_by_project_stacked(project_id, category="service"): @@ -79,26 +79,28 @@ def charges_by_project_stacked(project_id, category="service"):
79 :param category: what dict to build for each period, 'service' or 'capacity' ? 79 :param category: what dict to build for each period, 'service' or 'capacity' ?
80 :return: a 2 dim table with header as first line and datas next, of the form 80 :return: a 2 dim table with header as first line and datas next, of the form
81 period, category_0, category_1, ....., category_n, 81 period, category_0, category_1, ....., category_n,
82 - sem_0, value_00, value_01, ....., value_0n,  
83 - sem_1, value_10, value_11, ....., value_1n, 82 + per_0, value_00, value_01, ....., value_0n,
  83 + per_1, value_10, value_11, ....., value_1n,
84 . 84 .
85 . 85 .
86 - sem_n, value_n0, value_n1, ....., value_nn, 86 + per_n, value_n0, value_n1, ....., value_nn,
87 """ 87 """
88 if category == 'capacity': 88 if category == 'capacity':
89 category_table = 'capacity' 89 category_table = 'capacity'
90 sql_req = """ 90 sql_req = """
91 - select c.charge_rate 91 + select sum(c.charge_rate)
92 from capacity c1 left join 92 from capacity c1 left join
93 charge c on c1.id = c.capacity_id and project_id = {} and period_id={} 93 charge c on c1.id = c.capacity_id and project_id = {} and period_id={}
  94 + group by c1.id
94 order by c1.id 95 order by c1.id
95 """ 96 """
96 elif category == 'service': 97 elif category == 'service':
97 category_table = 'service' 98 category_table = 'service'
98 sql_req = """ 99 sql_req = """
99 - select c.charge_rate 100 + select sum(c.charge_rate)
100 from service s left join 101 from service s left join
101 charge c on s.id = c.service_id and project_id = {} and period_id={} 102 charge c on s.id = c.service_id and project_id = {} and period_id={}
  103 + group by s.id
102 order by s.id 104 order by s.id
103 """ 105 """
104 else: 106 else: