Skip to content

Commit 8cc8127

Browse files
committed
add filler to contracts
1 parent eae0e17 commit 8cc8127

File tree

5 files changed

+41
-21
lines changed

5 files changed

+41
-21
lines changed

por/dashboard/backlog.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,14 @@ def __init__(self, request):
4747
self.context = request.context
4848

4949

50-
def fetch_estimations(self):
50+
def fetch_estimations(self, projects):
51+
project_ids = [a.id for a in projects]
5152
return dict(
52-
(row[0], datetime.timedelta(days=row[1]/3.0)) # 8 vs 24 hour days
53-
for row in DBSession.execute("""
54-
SELECT customer_request_id, SUM(days)
55-
FROM estimations
56-
GROUP BY customer_request_id
57-
""")
53+
(row.id, datetime.timedelta(days=row.estimation_days/3.0)) # 8 vs 24 hour days
54+
for row in DBSession().query(CustomerRequest)\
55+
.filter(CustomerRequest.project_id.in_(project_ids))
5856
)
5957

60-
6158
def fetch_done(self, projects):
6259
cr_done = collections.defaultdict(lambda: datetime.timedelta(0))
6360
for project in projects:
@@ -89,7 +86,7 @@ def backlog(self, projects=None):
8986
projects = sorted(self.request.filter_viewables(projects.filter(Project.active)),
9087
key=lambda p: (p.customer.name.lower(), p.customer.name.lower()))
9188

92-
estimations_cache = self.fetch_estimations()
89+
estimations_cache = self.fetch_estimations(projects)
9390
done_cache = self.fetch_done(projects)
9491

9592
bgbs = [ProjectBGB(p, estimations_cache, done_cache) for p in projects]

por/dashboard/events.py

+3
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ def before_customerrequest_render(context, event):
327327
del fs._render_fields['project_id']
328328
if not event.request.has_permission('contract', context):
329329
del fs._render_fields['contract']
330+
if fs.readonly:
331+
fs.append(Field('estimation_days', type=fatypes.Float))
332+
fs.estimation_days._value = context.estimation_days
330333

331334

332335
#TimeEntry events

por/dashboard/forms/customer_request.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ def configurate(config):
117117
permission='estimations',
118118
attrs=dict(href="request.fa_url(request.model_name, request.model_id, 'estimations')")),)
119119

120+
customer_request_tabs_without_estimations = actions.TabsActions(actions.TabAction("show",
121+
content="View",
122+
permission='view',
123+
attrs=dict(href="request.fa_url(request.model_name, request.model_id, '')")),
124+
actions.TabAction("tickets",
125+
content="Tickets",
126+
permission='view',
127+
attrs=dict(href="request.fa_url(request.model_name, request.model_id, 'tickets')")))
120128

121129
add_ticket = actions.UIButton(id='add_ticket',
122130
content='Add ticket',
@@ -143,7 +151,10 @@ class CustomerRequestModelView(ModelView):
143151
def __init__(self, *args, **kwargs):
144152
super(CustomerRequestModelView, self).__init__(*args, **kwargs)
145153
self.defaults_actions.update(show_buttons=actions.Actions(actions.edit))
146-
cr_actions = deepcopy(customer_request_tabs)
154+
if self.context.get_instance().filler:
155+
cr_actions = deepcopy(customer_request_tabs_without_estimations)
156+
else:
157+
cr_actions = deepcopy(customer_request_tabs)
147158
wf = workflow.change_workflow(self.context)
148159
if wf:
149160
cr_actions.append(wf)

por/dashboard/skins/tekken.pt

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
data-placement="${cr.placement if can_view_placement else nothing}"
8989
data-cr-editable="${1 if can_edit_cr[cr] else nothing}"
9090
data-workflow-state="${cr.workflow_state}"
91+
data-filler="${cr.filler}"
9192
data-contract="${cr.contract and cr.contract.id or ''}"
9293
data-contract-days="${cr.contract and cr.contract.days or ''}"
9394
data-duration-estimate="${bgb.get_estimate(cr) if can_view_estimate[bgb.project] else nothing}"
@@ -98,6 +99,7 @@
9899
<a href="/admin/CustomerRequest/${cr.id}">
99100
${cr.name}
100101
</a>
102+
<span tal:condition="cr.filler" class="label label-inverse pull-right">Filler</span>
101103
</td>
102104
<td class="backlog-workflow">${cr.workflow_state}</td>
103105
<td tal:condition="can_view_estimate_column" class="backlog-duration">&nbsp;</td>

por/dashboard/static/por_backlog/tekken.js

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
11
var tekken;
22
var tekkendata;
3-
var showfiller = true;
43

54
function drawChart(){
65
function TimeEntriesEnd(data, rowNum){
76
return data.getValue(rowNum, 0)
87
}
98
function CR2Perc(data, rowNum){
10-
return Math.floor(data.getValue(rowNum, 1) / data.getValue(rowNum, 2) * 100)
9+
return Math.floor(data.getValue(rowNum, 1) / data.getValue(rowNum, 3) * 100)
1110
}
1211
function Filler2Perc(data, rowNum){
13-
return Math.floor((data.getValue(rowNum, 2) - data.getValue(rowNum, 1)) / data.getValue(rowNum, 2) * 101) // make sure the math.round will get 100
12+
return Math.floor(data.getValue(rowNum, 2) / data.getValue(rowNum, 3) * 100)
1413
}
1514
function CRTooltip(data, rowNum){
16-
return '<p id="first_tooltip" class="google-visualization-tooltip-item"><strong>Estimated CR:</strong> ' + data.getValue(rowNum,1) + ' days<br/><strong>Total project:</strong> ' + data.getValue(rowNum, 2) + ' days<br/><strong>Time entries:</strong> ' + data.getValue(rowNum, 0) + ' days</p>'
15+
return '<p id="first_tooltip" class="google-visualization-tooltip-item"><strong>Estimated CR:</strong> ' + data.getValue(rowNum,1) + ' days<br/><strong>Total project:</strong> ' + data.getValue(rowNum, 3) + ' days<br/><strong>Time entries:</strong> ' + data.getValue(rowNum, 0) + ' days</p>'
1716
}
1817
var view=new google.visualization.DataView(tekkendata);
1918
columns = [{calc: function() {return ''}, type: 'string'},
2019
{calc: CR2Perc, type: 'number'},
2120
{calc: function() {return 0}, type: 'number', role:'interval'},
2221
{calc: TimeEntriesEnd, type: 'number', role:'interval'},
2322
{calc: CRTooltip, type: 'string', role:'tooltip', 'properties': {'html':true}},
23+
{calc: Filler2Perc, type: 'number'},
24+
{calc: function() {return 'Filler CR'}, type: 'string', role:'tooltip'}
2425
]
25-
if (showfiller){
26-
columns.push({calc: Filler2Perc, type: 'number'})
27-
columns.push({calc: function() {return 'Filler CR'}, type: 'string', role:'tooltip'})
28-
}
2926
view.setColumns(columns);
3027
tekken.draw(view,
3128
{title:"Tekken bar",
@@ -54,6 +51,7 @@ function drawVisualization() {
5451
tekkendata = new google.visualization.DataTable();
5552
tekkendata.addColumn('number', 'Time Entries');
5653
tekkendata.addColumn('number', 'CR estimated');
54+
tekkendata.addColumn('number', 'CR filler');
5755
tekkendata.addColumn('number', 'Total project');
5856
tekkendata.addRows(1);
5957
tekken = new google.visualization.BarChart(document.getElementById('visualization'));
@@ -77,17 +75,24 @@ google.setOnLoadCallback(function() {
7775
var update_project_totals = function($bgb_header) {
7876
var totals = {},
7977
total_estimate = 0,
78+
total_filler = 0,
8079
total_done = 0,
8180
total_days = 0,
8281
$bgb = $bgb_header.next('.bgb-project');
8382

84-
$bgb.find('tr[data-workflow-state]:visible').each(function() {
85-
total_estimate += parseInt($(this).data('duration-estimate'), 10);
83+
$bgb.find('tr[data-contract]:visible').each(function() {
8684
total_done += parseInt($(this).data('duration-done'), 10);
8785
total_days = parseInt($(this).data('contract-days'), 10);
8886
});
87+
$bgb.find('tr[data-contract]:not([data-filler]):visible').each(function() {
88+
total_estimate += parseInt($(this).data('duration-estimate'), 10);
89+
});
90+
$bgb.find('tr[data-filler]:visible').each(function() {
91+
total_filler += parseInt($(this).data('duration-estimate'), 10);
92+
});
8993
return {
9094
total_estimate: Math.round(total_estimate / 60 / 60 / 8),
95+
total_filler: Math.round(total_filler / 60 / 60 / 8),
9196
total_done: Math.round(total_done / 60/ 60 / 8),
9297
total_days: total_days,
9398
};
@@ -96,9 +101,11 @@ google.setOnLoadCallback(function() {
96101
// update the tekken bar
97102
var update_tekken = function() {
98103
var totals = update_project_totals($('.bgb-project-header'));
104+
console.log(totals);
99105
tekkendata.setValue(0, 0, totals.total_done);
100106
tekkendata.setValue(0, 1, totals.total_estimate);
101-
tekkendata.setValue(0, 2, totals.total_days);
107+
tekkendata.setValue(0, 2, totals.total_filler);
108+
tekkendata.setValue(0, 3, totals.total_days);
102109
drawChart();
103110
};
104111

0 commit comments

Comments
 (0)