Blame view

app/db_mgr.py 506 Bytes
1aeda847   hitier   Two db request wr...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from app.models import db, Agent, Charge


def agents():
    all_agents = [a.firstname for a in Agent.query.all()]
    return all_agents


def charges_by_agent(agent_id):
    # all_charges = db.session.query(Charge).all()
    sql_txt = "select sum(charge_rate), p.name from charge inner join period p on charge.period_id = p.id\
                where agent_id={} group by period_id order by p.name"\
                .format(agent_id)
    request = db.session.execute(sql_txt)
    return request.fetchall()