Commit 432b6596848f5556489e465bc098afd060709d26
1 parent
419f72a8
Exists in
master
and in
4 other branches
Sql sum is 0 if None
Showing
1 changed file
with
4 additions
and
3 deletions
Show diff stats
app/db_mgr.py
1 | -from app.models import db | |
1 | +from app.models import db, Period | |
2 | 2 | |
3 | 3 | |
4 | 4 | def projects(): |
... | ... | @@ -8,7 +8,7 @@ def projects(): |
8 | 8 | """ |
9 | 9 | current_period_id = get_current_period() |
10 | 10 | sql_txt = """ |
11 | - select p.id, p.name, sum(tc.charge_rate) as total_charge | |
11 | + select p.id, p.name, IFNULL(sum(tc.charge_rate), 0) as total_charge | |
12 | 12 | from project as p left join |
13 | 13 | ( select c.project_id, c.charge_rate from charge c where c.period_id = {}) |
14 | 14 | tc |
... | ... | @@ -27,7 +27,7 @@ def agents(): |
27 | 27 | """ |
28 | 28 | current_period_id = get_current_period() |
29 | 29 | sql_txt = """ |
30 | - select a.id, a.firstname, a.secondname, sum(tc.charge_rate) as total_charge | |
30 | + select a.id, a.firstname, a.secondname, IFNULL (sum(tc.charge_rate), 0) as total_charge | |
31 | 31 | from agent as a left join |
32 | 32 | ( select c.agent_id, c.charge_rate from charge c where c.period_id = {}) |
33 | 33 | tc |
... | ... | @@ -207,4 +207,5 @@ def get_current_period(): |
207 | 207 | :return: the id of the period of current day |
208 | 208 | """ |
209 | 209 | # TODO: request on dates as soon as periods are dated |
210 | + p = Period.query.filter(Period.name == '2021').one_or_none() | |
210 | 211 | return 14 | ... | ... |