Commit 8b3ab81dc660064d64a7257a264e95e6e5c993a8
1 parent
04e2a90d
Exists in
master
and in
4 other branches
All charges now include period with no charge
Showing
2 changed files
with
16 additions
and
2 deletions
Show diff stats
app/db_mgr.py
1 | +from pprint import pprint | |
2 | + | |
1 | 3 | from app.models import db, Agent, Charge |
2 | 4 | |
3 | 5 | |
... | ... | @@ -8,9 +10,17 @@ def agents(): |
8 | 10 | |
9 | 11 | def charges_by_agent(agent_id): |
10 | 12 | # all_charges = db.session.query(Charge).all() |
11 | - sql_txt = "select sum(charge_rate), p.name from charge inner join period p on charge.period_id = p.id\ | |
13 | + periods = db.session.execute("select name from period") | |
14 | + sql_txt = "select p.name, sum(charge_rate) from charge inner join period p on charge.period_id = p.id\ | |
12 | 15 | where agent_id={} group by period_id order by p.name" \ |
13 | 16 | .format(agent_id) |
14 | 17 | request = db.session.execute(sql_txt) |
15 | - all_charges = [[period, rate] for (rate, period) in request.fetchall()] | |
18 | + all_charges = [] | |
19 | + charges_list = [(period, charge) for (period, charge) in request.fetchall()] | |
20 | + charges_dict = dict(charges_list) | |
21 | + for (p,) in periods: | |
22 | + if p in charges_dict.keys(): | |
23 | + all_charges.append([p, charges_dict[p]]) | |
24 | + else: | |
25 | + all_charges.append([p, 0]) | |
16 | 26 | return all_charges | ... | ... |
app/main/routes.py
... | ... | @@ -42,6 +42,7 @@ def agents(): |
42 | 42 | return render_template('agents.html', subtitle="Liste des agents ({})".format(num_agents), |
43 | 43 | agents=all_agents) |
44 | 44 | |
45 | + | |
45 | 46 | @bp.route('/capacities') |
46 | 47 | def capacities(): |
47 | 48 | # get capacities list |
... | ... | @@ -51,6 +52,7 @@ def capacities(): |
51 | 52 | return render_template('capacities.html', subtitle="Liste des fonctions ({})".format(num_capacities), |
52 | 53 | capacities=all_capacities) |
53 | 54 | |
55 | + | |
54 | 56 | @bp.route('/periods') |
55 | 57 | def periods(): |
56 | 58 | # get capacities list |
... | ... | @@ -60,6 +62,7 @@ def periods(): |
60 | 62 | return render_template('periods.html', subtitle="Liste des périodes ({})".format(num_periods), |
61 | 63 | periods=all_periods) |
62 | 64 | |
65 | + | |
63 | 66 | @bp.route('/charge/add') |
64 | 67 | def charge_add(): |
65 | 68 | return render_template('charge.html', subtitle="Affecter un agent") |
... | ... | @@ -75,6 +78,7 @@ def charge_agent(agent_id): |
75 | 78 | resp.headers['Content-Type'] = 'application/json' |
76 | 79 | return resp |
77 | 80 | |
81 | + | |
78 | 82 | @bp.route('/agent/<agent_id>') |
79 | 83 | def agent(agent_id): |
80 | 84 | agent = Agent.query.get(int(agent_id)) | ... | ... |