Commit 0a8a3ec6a44727ce3dc7644858d2b3ac0a60501b

Authored by hitier
1 parent 796a5688

Convert charge from % to ETP after db request result

Showing 1 changed file with 12 additions and 3 deletions   Show diff stats
app/db_mgr.py
1 1 from app.models import db, Period
2 2  
  3 +# TODO: make this configurable, and choose another place to use it,
  4 +# in 'routes.py' maybe
  5 +# Charge as stored on a 100% basis, percent of total worked time;
  6 +# Here it is possible to convert to an ETP basis, dividing by 100
  7 +# or we set it to '1' if we want to keep the percent basis
  8 +charge_unit = 100
  9 +
3 10  
4 11 def projects():
5 12 """
... ... @@ -86,6 +93,8 @@ def charges_by_project_stacked(project_id, category="service"):
86 93 .
87 94 .
88 95 per_n, value_n0, value_n1, ....., value_nn,
  96 +
  97 + TODO: common with charges_by_agent_stacked(agent_id): code to extrat
89 98 """
90 99 if category == 'capacity':
91 100 category_table = 'capacity'
... ... @@ -117,7 +126,7 @@ def charges_by_project_stacked(project_id, category="service"):
117 126 # build the charges line for the current period
118 127 category_charges = [period_name]
119 128 for (category_rate,) in db.session.execute(charge_by_categorie_req):
120   - category_rate = str(category_rate) if category_rate else '0'
  129 + category_rate = str(round(category_rate / charge_unit, 2)) if category_rate else '0'
121 130 category_charges.append(category_rate)
122 131 all_charges.append(category_charges)
123 132  
... ... @@ -127,6 +136,7 @@ def charges_by_project_stacked(project_id, category="service"):
127 136 def charges_by_agent_stacked(agent_id):
128 137 """
129 138 Build the list of charges for all projects of one agent, period by period
  139 + TODO: common with charges_by_project_stacked(project_id, ..) code to extrat
130 140 :param agent_id:
131 141 :return:
132 142 """
... ... @@ -143,10 +153,9 @@ def charges_by_agent_stacked(agent_id):
143 153 group by p.id
144 154 order by p.id
145 155 """.format(agent_id, period_id)
146   - print(charge_by_project_req)
147 156 category_charges = [period_name]
148 157 for (category_rate,) in db.session.execute(charge_by_project_req):
149   - category_rate = str(category_rate) if category_rate else '0'
  158 + category_rate = str(round(category_rate / charge_unit, 2)) if category_rate else '0'
150 159 category_charges.append(category_rate)
151 160 all_charges.append(category_charges)
152 161 return all_charges
... ...