Commit ce94a166 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Use virtual field to build the list of people.

parent 57c9cbd1
""" List controllers """
from plugin_dbui import Selector
from reporting_tools import Compute_time_weigth
def hardware():
""" Active hardware for a given period of time, team, ...
......@@ -64,6 +64,9 @@ def people():
q = db.categories.usual != 'stagiaire'
query = (query) & (q)
# define virtual field to be added in the report via extracolumns
db.history.time_weigth = Field.Virtual(Compute_time_weigth(selector).process)
# select the records
rows = db(query).select(db.categories.usual,
......@@ -68,8 +68,8 @@
'Notified': 'Notifié',
'Organization': 'Organisation',
'organizations': 'organisations',
'people': 'personnel',
'People': 'People',
'people': 'personnel',
'Percentage': 'Pourcentage',
'Period': 'Periode',
'Period End': 'Period End',
......@@ -96,12 +96,12 @@
'Tables': 'Tables',
'Team': 'Équipe',
'teams': 'équipes',
'Time': 'Temps',
'Tools': 'Outils',
'undefined': 'undéfini',
'unknown': 'unknown',
'Usual': 'Habituel',
'versions': 'versions',
'Weight': 'Poid',
'Year': 'Année',
'Year End': 'Year End',
'Year Start': 'Year Start',
"""reporting tools module
from datetime import date, datetime
class Compute_time_weigth(object):
"""Tool to compute the fraction of time the person has been
active during the time period. The period is defined by the
user via a selector.
def __init__(self, selector):
ds = datetime.strptime(selector.period_start, '%Y-%m-%d')
self.period_start = date(ds.year, ds.month,
de = datetime.strptime(selector.period_end, '%Y-%m-%d')
self.period_end = date(de.year, de.month,
def process(self, row):
"""The fraction of time for which the person was active
during the selected period.
start = max(self.period_start, row.history.start_date)
end = self.period_end
if row.history.end_date:
end = min(self.period_end, row.history.end_date)
x = (end - start).days
y = (self.period_end - self.period_start).days
z = round(float(x) / float(y), 2)
return z
......@@ -2,39 +2,22 @@
from datetime import date, datetime
ds = datetime.strptime(selector.period_start, '%Y-%m-%d')
period_start = date(ds.year, ds.month,
de = datetime.strptime(selector.period_end, '%Y-%m-%d')
period_end = date(de.year, de.month,
def compute_weight(row, rc):
start = max(period_start, row.history.start_date)
end = period_end
if row.history.end_date:
end = min(period_end, row.history.end_date)
x = (end - start).days
y = (period_end - period_start).days
z = round(float(x) / float(y), 2)
return z
# column with a better display of the CDD flag
cdd = {'label': 'CDD',
'class': '',
'content': lambda row, rc: (CENTER('x') if row.history.cdd_flag else ''),
'selected': False,
'width': ''}
weight = {'label': T('Weight'),
'class': '',
'content': compute_weight,
'selected': False,
'width': ''}
# add a columns with the virtual field time_weight
time_weight = {'label': T('Time'),
'class': '',
'content': lambda row, rc: row.history.time_weigth,
'selected': False,
'width': ''}
# render the table
table = SQLTABLE(rows,
......@@ -42,7 +25,7 @@
headers={'categories.usual': T('Category'),
'people.last_name': T('Name'),
'categories.code': T('Level')},
extracolumns=[cdd, weight],
extracolumns=[cdd, time_weight],
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment