Commit e5449e3e1a72798406ee04444c669fe28520b5bd

Authored by hitier
1 parent 89219b30

Fix wrong agents charge sql req

Showing 2 changed files with 11 additions and 6 deletions   Show diff stats
app/db_mgr.py
... ... @@ -4,10 +4,15 @@ from app.models import db, Agent, Charge
4 4  
5 5  
6 6 def agents():
7   - sql_txt = """select a.id, a.firstname, a.secondname, sum(c.charge_rate) as total_charge
8   - from agent as a
9   - inner join charge c on a.id = c.agent_id
10   - group by agent_id;"""
  7 + sql_txt = """
  8 + select a.id, a.firstname, a.secondname, sum(tc.charge_rate) as total_charge
  9 + from agent as a left join
  10 + ( select c.agent_id, c.charge_rate from charge c )
  11 + tc
  12 + on a.id = tc.agent_id
  13 + group by a.id
  14 + order by total_charge desc;
  15 + """
11 16 all_agents = db.session.execute(sql_txt).fetchall()
12 17  
13 18 return all_agents
... ... @@ -22,7 +27,7 @@ def stacked_charges_by_agent(agent_id):
22 27 period_charge = {}
23 28 for project_name, project_rate in db.session.execute(charge_by_project_req):
24 29 period_charge[project_name] = project_rate
25   - all_charges[period_name]=period_charge
  30 + all_charges[period_name] = period_charge
26 31  
27 32 pprint(all_charges)
28 33 return all_charges
... ...
app/main/routes.py
... ... @@ -106,4 +106,4 @@ def agent(agent_id):
106 106 this_agent = Agent.query.get(int(agent_id))
107 107 return render_template('agent.html',
108 108 agent=this_agent,
109   - subtitle="{} {}".format(agent.firstname, agent.secondname))
  109 + subtitle="{} {}".format(this_agent.firstname, this_agent.secondname))
... ...