From 0a8a3ec6a44727ce3dc7644858d2b3ac0a60501b Mon Sep 17 00:00:00 2001 From: Richard Hitier Date: Mon, 19 Apr 2021 11:41:18 +0200 Subject: [PATCH] Convert charge from % to ETP after db request result --- app/db_mgr.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/db_mgr.py b/app/db_mgr.py index 2682360..1a58398 100644 --- a/app/db_mgr.py +++ b/app/db_mgr.py @@ -1,5 +1,12 @@ from app.models import db, Period +# TODO: make this configurable, and choose another place to use it, +# in 'routes.py' maybe +# Charge as stored on a 100% basis, percent of total worked time; +# Here it is possible to convert to an ETP basis, dividing by 100 +# or we set it to '1' if we want to keep the percent basis +charge_unit = 100 + def projects(): """ @@ -86,6 +93,8 @@ def charges_by_project_stacked(project_id, category="service"): . . per_n, value_n0, value_n1, ....., value_nn, + + TODO: common with charges_by_agent_stacked(agent_id): code to extrat """ if category == 'capacity': category_table = 'capacity' @@ -117,7 +126,7 @@ def charges_by_project_stacked(project_id, category="service"): # build the charges line for the current period category_charges = [period_name] for (category_rate,) in db.session.execute(charge_by_categorie_req): - category_rate = str(category_rate) if category_rate else '0' + category_rate = str(round(category_rate / charge_unit, 2)) if category_rate else '0' category_charges.append(category_rate) all_charges.append(category_charges) @@ -127,6 +136,7 @@ def charges_by_project_stacked(project_id, category="service"): def charges_by_agent_stacked(agent_id): """ Build the list of charges for all projects of one agent, period by period + TODO: common with charges_by_project_stacked(project_id, ..) code to extrat :param agent_id: :return: """ @@ -143,10 +153,9 @@ def charges_by_agent_stacked(agent_id): group by p.id order by p.id """.format(agent_id, period_id) - print(charge_by_project_req) category_charges = [period_name] for (category_rate,) in db.session.execute(charge_by_project_req): - category_rate = str(category_rate) if category_rate else '0' + category_rate = str(round(category_rate / charge_unit, 2)) if category_rate else '0' category_charges.append(category_rate) all_charges.append(category_charges) return all_charges -- libgit2 0.21.2