Merge lp:~openerp-dev/openobject-addons/trunk-timeuomprojecttasks-jco into lp:openobject-addons

Proposed by Josse Colpaert (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/trunk-timeuomprojecttasks-jco
Merge into: lp:openobject-addons
Diff against target: 186 lines (+92/-17)
3 files modified
hr_timesheet/hr_timesheet_view.xml (+4/-4)
project/project.py (+73/-5)
project/project_view.xml (+15/-8)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/trunk-timeuomprojecttasks-jco
Reviewer Review Type Date Requested Status
qdp (OpenERP) Needs Fixing
Review via email: mp+158665@code.launchpad.net

Description of the change

When changing the uom of project tasks to days it will not put the time format, but the default float format in the timesheets of a task. Then it takes into account the UoM for calculating the timesheets taking into account the product used.

To post a comment you must log in.
Revision history for this message
qdp (OpenERP) (qdp) wrote :

It needs some fixing/explanation:

1) line 15: you removed widget="float_time", but it seems that 'hours' is still the default uom for project management, and if you do things like:
52 + if hours:
53 + return res
then it means that you should leave the float_time widget, no?

2) please add some comments + docstrings in the fields_view_get inheritance to explain what's done there

3) it seems that the same function is duplicated 3 times. Can you make a generic function that will be use 3 times with the model as extra_parameter instead? Factorizing the code is good :-)

that's all i can think of, so far.

review: Needs Fixing
Revision history for this message
qdp (OpenERP) (qdp) wrote :

> It needs some fixing/explanation:
>
> 1) line 15: you removed widget="float_time", but it seems that 'hours' is
> still the default uom for project management, and if you do things like:
> 52 + if hours:
> 53 + return res
> then it means that you should leave the float_time widget, no?
>
> 2) please add some comments + docstrings in the fields_view_get inheritance to
> explain what's done there
>
> 3) it seems that the same function is duplicated 3 times. Can you make a
> generic function that will be use 3 times with the model as extra_parameter
> instead? Factorizing the code is good :-)
>
> that's all i can think of, so far.

Unmerged revisions

8546. By Josse Colpaert (OpenERP)

[IMP] Read-only UOM field in timesheet activities and amount in float instead of time

8545. By Josse Colpaert (OpenERP)

[IMP] Shows work time as time or float depending on project UOM and adds uoms in timesheet activities view

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hr_timesheet/hr_timesheet_view.xml'
2--- hr_timesheet/hr_timesheet_view.xml 2013-03-18 11:39:48 +0000
3+++ hr_timesheet/hr_timesheet_view.xml 2013-04-12 16:15:36 +0000
4@@ -6,14 +6,14 @@
5 <field name="name">hr.analytic.timesheet.tree</field>
6 <field name="model">hr.analytic.timesheet</field>
7 <field name="arch" type="xml">
8- <tree editable="top" string="Timesheet Activities">
9+ <tree editable="top" string="Timesheet Activities">
10 <field name="date" on_change="on_change_date(date)"/>
11 <field name="user_id" on_change="on_change_user_id(user_id)" required="1" options='{"no_open": True}'
12 context="{'default_groups_ref': [base.group_user']}"/>
13 <field name="name"/>
14 <field domain="[('type','=','normal'),('use_timesheets','=',1)]" name="account_id" context="{'default_use_timesheets': 1, 'default_type': 'contract'}"/>
15- <field name="unit_amount" string="Duration" on_change="on_change_unit_amount(product_id, unit_amount, False, product_uom_id,journal_id)" sum="Total time" widget="float_time"/>
16- <field name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, False, product_uom_id,journal_id)" invisible="1"/>
17+ <field name="unit_amount" string="Duration" on_change="on_change_unit_amount(product_id, unit_amount, False, product_uom_id,journal_id)" sum="Total time"/>
18+ <field name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, False, product_uom_id,journal_id)" readonly="1"/>
19 <field name="journal_id" invisible="1"/>
20 <field name="amount" sum="Total cost" invisible="1"/>
21 <field name="general_account_id" invisible="1"/>
22@@ -45,7 +45,7 @@
23 <label string="Duration" for="unit_amount"/>
24 <div>
25 <field name="unit_amount" on_change="on_change_unit_amount(product_id, unit_amount, False, product_uom_id,journal_id)" class="oe_inline"/>
26- <field name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, False, product_uom_id,journal_id)" class="oe_inline"/>
27+ <field name="product_uom_id" on_change="on_change_unit_amount(product_id, unit_amount, False, product_uom_id,journal_id)" class="oe_inline" readonly="1"/>
28 </div>
29 </group>
30 <group string="Accounting">
31
32=== modified file 'project/project.py'
33--- project/project.py 2013-04-05 15:19:14 +0000
34+++ project/project.py 2013-04-12 16:15:36 +0000
35@@ -551,6 +551,40 @@
36 vals.update(alias_model_id=model_ids[0])
37 return super(project, self).write(cr, uid, ids, vals, context=context)
38
39+
40+ # Override view according to the company definition
41+ def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
42+ users_obj = self.pool.get('res.users')
43+ if context is None: context = {}
44+ # read uom as admin to avoid access rights issues, e.g. for portal/share users,
45+ # this should be safe (no context passed to avoid side-effects)
46+ obj_tm = users_obj.browse(cr, SUPERUSER_ID, uid, context=context).company_id.project_time_mode_id
47+ hour_ids = self.pool.get('product.uom').search(cr, uid, ['|', '|', ('name','=','Hour(s)'), ('name','=','Hour'), ('name','=','Hours')])
48+ tm = obj_tm and obj_tm.name or 'Hours'
49+ hours = obj_tm and (obj_tm.id in hour_ids) or (tm == 'Hours')
50+ res = super(project, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu=submenu)
51+
52+ if hours:
53+ return res
54+ eview = etree.fromstring(res['arch'])
55+
56+ def _check_rec(eview):
57+ if eview.attrib.get('widget','') == 'float_time':
58+ eview.set('widget','float')
59+ for child in eview:
60+ _check_rec(child)
61+ return True
62+
63+ _check_rec(eview)
64+
65+ res['arch'] = etree.tostring(eview)
66+
67+ hour_tran = _('Hours')
68+ for f in res['fields']:
69+ if hour_tran in res['fields'][f]['string']:
70+ res['fields'][f]['string'] = res['fields'][f]['string'].replace(hour_tran,tm)
71+ return res
72+
73 class task(base_stage, osv.osv):
74 _name = "project.task"
75 _description = "Task"
76@@ -862,13 +896,13 @@
77 # read uom as admin to avoid access rights issues, e.g. for portal/share users,
78 # this should be safe (no context passed to avoid side-effects)
79 obj_tm = users_obj.browse(cr, SUPERUSER_ID, uid, context=context).company_id.project_time_mode_id
80+ hour_ids = self.pool.get('product.uom').search(cr, uid, ['|', '|', ('name','=','Hour(s)'), ('name','=','Hour'), ('name','=','Hours')])
81 tm = obj_tm and obj_tm.name or 'Hours'
82-
83+ hours = obj_tm and (obj_tm.id in hour_ids) or (tm == 'Hours')
84 res = super(task, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu=submenu)
85
86- if tm in ['Hours','Hour']:
87+ if hours:
88 return res
89-
90 eview = etree.fromstring(res['arch'])
91
92 def _check_rec(eview):
93@@ -882,9 +916,10 @@
94
95 res['arch'] = etree.tostring(eview)
96
97+ hour_tran = _('Hours')
98 for f in res['fields']:
99- if 'Hours' in res['fields'][f]['string']:
100- res['fields'][f]['string'] = res['fields'][f]['string'].replace('Hours',tm)
101+ if hour_tran in res['fields'][f]['string']:
102+ res['fields'][f]['string'] = res['fields'][f]['string'].replace(hour_tran,tm)
103 return res
104
105 def get_empty_list_help(self, cr, uid, help, context=None):
106@@ -1259,6 +1294,39 @@
107 return super(project_work,self).unlink(cr, uid, ids,*args, **kwargs)
108
109
110+ # Override view according to the company definition
111+ def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
112+ users_obj = self.pool.get('res.users')
113+ if context is None: context = {}
114+ # read uom as admin to avoid access rights issues, e.g. for portal/share users,
115+ # this should be safe (no context passed to avoid side-effects)
116+ obj_tm = users_obj.browse(cr, SUPERUSER_ID, uid, context=context).company_id.project_time_mode_id
117+ hour_ids = self.pool.get('product.uom').search(cr, uid, ['|', '|', ('name','=','Hour(s)'), ('name','=','Hour'), ('name','=','Hours')])
118+ tm = obj_tm and obj_tm.name or 'Hours'
119+ hours = obj_tm and (obj_tm.id in hour_ids) or (tm == 'Hours')
120+ res = super(project_work, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu=submenu)
121+
122+ if hours:
123+ return res
124+ eview = etree.fromstring(res['arch'])
125+
126+ def _check_rec(eview):
127+ if eview.attrib.get('widget','') == 'float_time':
128+ eview.set('widget','float')
129+ for child in eview:
130+ _check_rec(child)
131+ return True
132+
133+ _check_rec(eview)
134+
135+ res['arch'] = etree.tostring(eview)
136+
137+ hour_tran = _('Hours')
138+ for f in res['fields']:
139+ if hour_tran in res['fields'][f]['string']:
140+ res['fields'][f]['string'] = res['fields'][f]['string'].replace(hour_tran,tm)
141+ return res
142+
143 class account_analytic_account(osv.osv):
144 _inherit = 'account.analytic.account'
145 _description = 'Analytic Account'
146
147=== modified file 'project/project_view.xml'
148--- project/project_view.xml 2013-04-05 11:07:37 +0000
149+++ project/project_view.xml 2013-04-12 16:15:36 +0000
150@@ -355,6 +355,20 @@
151 </field>
152 </record>
153
154+
155+ <record id="view_task_work_tree_embed" model="ir.ui.view">
156+ <field name="name">project.task.work.tree</field>
157+ <field name="model">project.task.work</field>
158+ <field name="arch" type="xml">
159+ <tree string="Task Work" editable="top">
160+ <field name="name"/>
161+ <field name="hours" widget="float_time" sum="Spent Hours"/>
162+ <field name="date"/>
163+ <field name="user_id"/>
164+ </tree>
165+ </field>
166+ </record>
167+
168 <!-- Task -->
169
170 <record id="view_task_form2" model="ir.ui.view">
171@@ -407,14 +421,7 @@
172 <notebook>
173 <page string="Description">
174 <field name="description" attrs="{'readonly':[('state','=','done')]}" placeholder="Add a Description..."/>
175- <field name="work_ids" groups="project.group_tasks_work_on_tasks">
176- <tree string="Task Work" editable="top">
177- <field name="name"/>
178- <field name="hours" widget="float_time" sum="Spent Hours"/>
179- <field name="date"/>
180- <field name="user_id"/>
181- </tree>
182- </field>
183+ <field name="work_ids" groups="project.group_tasks_work_on_tasks" context="{'tree_view_ref':'view_task_work_tree_embed'}"/>
184 <group>
185 <group class="oe_subtotal_footer oe_right" name="project_hours" groups="project.group_time_work_estimation_tasks">
186 <field name="effective_hours" widget="float_time"/>

Subscribers

People subscribed via source and target branches

to all changes: