Merge lp:~laetitia-gangloff/acsone-addons/hr_utilization into lp:~acsone-openerp/acsone-addons/6.1

Proposed by Laetitia Gangloff (Acsone)
Status: Merged
Merged at revision: 26
Proposed branch: lp:~laetitia-gangloff/acsone-addons/hr_utilization
Merge into: lp:~acsone-openerp/acsone-addons/6.1
Diff against target: 70 lines (+20/-6)
1 file modified
hr_utilization/report/hr_utilization_report.py (+20/-6)
To merge this branch: bzr merge lp:~laetitia-gangloff/acsone-addons/hr_utilization
Reviewer Review Type Date Requested Status
Stéphane Bidoul (Acsone) Approve
Review via email: mp+157391@code.launchpad.net

Description of the change

hr_utilization: make it compatible with python 2.6

To post a comment you must log in.
Revision history for this message
Stéphane Bidoul (Acsone) (sbi) wrote :

Laetitia,

I think the method double_list_to_dictionary makes things more difficult to understand. In my opinion, the loop creating the dictionary could be put in place in the code, as this does not create code duplication.

list_to_default_dictionary is fine, except the docstring should be more explicit, such as
''' create a dictionary with the elements of item_list as keys and default_value as value '''

-sbi

review: Needs Fixing (code review)
25. By lga

hr_utilization: remove double_list_to_dictionary, correct docstring of list_to_default_dictionary

Revision history for this message
Laetitia Gangloff (Acsone) (laetitia-gangloff) wrote :

As you suggest, I remove double_list_to_dictionary and set the for in the code.
And I replace the docstring of list_to_default_dictionary .

Revision history for this message
Stéphane Bidoul (Acsone) (sbi) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hr_utilization/report/hr_utilization_report.py'
2--- hr_utilization/report/hr_utilization_report.py 2013-02-01 10:26:05 +0000
3+++ hr_utilization/report/hr_utilization_report.py 2013-04-05 15:20:32 +0000
4@@ -104,6 +104,13 @@
5 end = min(period_end,contract.date_end or period_end)
6 hours += self.get_planned_working_hours(contract.working_hours, start, end)
7 return hours
8+
9+ def list_to_default_dictionary(self, default_value, item_list):
10+ ''' create a dictionary with the elements of item_list as keys and default_value as value '''
11+ res = {}
12+ for item in item_list:
13+ res[item] = default_value
14+ return res
15
16 def set_context(self, objects, data, ids, report_type = None):
17 ''' Build variables to print in the report '''
18@@ -176,7 +183,7 @@
19 res[key] = {
20 'name': user_name,
21 'company_id': company_id,
22- 'hours': {column_name:0.0 for column_name in column_names},
23+ 'hours': self.list_to_default_dictionary(0.0, column_names),
24 'contracts': {}, # contract_id: contract
25 }
26 if only_total:
27@@ -195,13 +202,13 @@
28
29 res_total = {
30 'name': TOTAL,
31- 'hours': {column_name:0.0 for column_name in column_names},
32+ 'hours': self.list_to_default_dictionary(0.0, column_names),
33 }
34 if with_fte:
35 res_total['fte'] = 0.0
36 res_nc_total = {
37 'name': TOTAL,
38- 'hours': {column_name:0.0 for column_name in column_names},
39+ 'hours': self.list_to_default_dictionary(0.0, column_names),
40 }
41
42 # row total, percentages and fte for each row
43@@ -217,7 +224,10 @@
44 # percentage
45 available_hours = self.get_total_planned_working_hours(data['period_start'], data['period_end'], u['contracts'].values())
46 total_available_hours += available_hours
47- u['pct'] = { column_name: hours/available_hours for column_name, hours in u['hours'].items() }
48+ u['pct'] = {}
49+ for column_name, hours in u['hours'].items():
50+ u['pct'][column_name] = hours/available_hours
51+
52 # fte
53 if with_fte:
54 company = company_obj.browse(self.cr, self.uid, [u['company_id']])[0]
55@@ -237,9 +247,13 @@
56
57 # total average percentage
58 if total_available_hours:
59- res_total['pct'] = { column_name: hours/total_available_hours for column_name, hours in res_total['hours'].items() }
60+ res_total['pct'] = {}
61+ for column_name, hours in res_total['hours'].items():
62+ res_total['pct'][column_name] = hours/total_available_hours
63 else:
64- res_total['pct'] = { column_name: 0.0 for column_name, hours in res_total['hours'].items() }
65+ res_total['pct'] = {}
66+ for column_name, hours in res_total['hours'].items():
67+ res_total['pct'][column_name] = 0.0
68
69 # total fte
70 if with_fte and fte_with_na and not(res_total['fte']):

Subscribers

People subscribed via source and target branches