Merge lp:~camptocamp/hr-timesheet/7.0-fix-1206843-yvr into lp:~hr-core-editors/hr-timesheet/7.0

Proposed by Yannick Vaucher @ Camptocamp
Status: Merged
Merged at revision: 54
Proposed branch: lp:~camptocamp/hr-timesheet/7.0-fix-1206843-yvr
Merge into: lp:~hr-core-editors/hr-timesheet/7.0
Diff against target: 80 lines (+40/-4)
1 file modified
timesheet_task/project_task.py (+40/-4)
To merge this branch: bzr merge lp:~camptocamp/hr-timesheet/7.0-fix-1206843-yvr
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp Approve
Stéphane Bidoul (Acsone) (community) code review and test Approve
Vincent Renaville@camptocamp (community) Approve
Review via email: mp+177812@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

The 'method=True' argument is deprecated in fields.function.

The comment you put in the function does not help me to understand why do you need to do that. I don't understand it. Can you elaborate or reword it please? Thanks!

review: Needs Fixing
49. By Yannick Vaucher @ Camptocamp

[IMP] timesheet_task - remove deprecated method=True un function fields

50. By Yannick Vaucher @ Camptocamp

[IMP] comments

Revision history for this message
Vincent Renaville@camptocamp (vrenaville-c2c) wrote :

I have just test this branch and it fix problem when you want to rename a task by exemple

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

I just made a test on a fresh v7 database with the ocb branches and the latest version of hr-timesheet. I installed timesheet_task, created a project a task and entered some time on the task. Then I renamed the task and everything went fine.

To reproduce the bug, I had to install project_timesheet.

Now, I personally always considered timesheet_task to be incompatible with project_timesheet as they have a fundamentally different approach. Is there a reason to install project_timesheet when one uses timesheet_task, possibly in combination with hr_timesheet_task?

Regarding this MP, it makes me quite uncomfortable to add a dummy field that always return empty value. This can be misleading. That said, I don't immediately see a clean way to make timesheet_task and project_timesheet compatible.

review: Needs Information (code review and test)
Revision history for this message
Stéphane Bidoul (Acsone) (sbi) wrote :

I investigated and tested this one a bit further and I conclude it does indeed make timesheet_task compatible with project_timesheet. project_timesheet in turns does bring some useful UI shortcuts related to timesheets so this makes sense. Thanks!

review: Approve (code review and test)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Thanks for the review and tests Stéphane!

It is indead not as clean as I would like it to be.

I think the main issue here is that we are changing the relation of a field so it can leads to modules expecting a behavior the new relation doesn't have. I'm just fixing this here by simulating the missing behavior.

An other option would be some cross module monkey patching to disable unwanted actions. I'm not sure it would be much cleaner nor easy to do.

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Thanks for the changes

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'timesheet_task/project_task.py'
2--- timesheet_task/project_task.py 2013-06-11 08:07:08 +0000
3+++ timesheet_task/project_task.py 2013-08-14 15:05:29 +0000
4@@ -61,22 +61,22 @@
5 _columns = {'work_ids': fields.one2many('hr.analytic.timesheet', 'task_id', 'Work done'),
6
7
8- 'effective_hours': fields.function(_progress_rate, multi="progress", method=True, string='Time Spent',
9+ 'effective_hours': fields.function(_progress_rate, multi="progress", string='Time Spent',
10 help="Sum of spent hours of all tasks related to this project and its child projects.",
11 store={'project.task': (lambda self, cr, uid, ids, c={}: ids, TASK_WATCHERS, 20),
12 'account.analytic.line': (_get_analytic_line, TIMESHEET_WATCHERS, 20)}),
13
14- 'delay_hours': fields.function(_progress_rate, multi="progress", method=True, string='Deduced Hours',
15+ 'delay_hours': fields.function(_progress_rate, multi="progress", string='Deduced Hours',
16 help="Sum of spent hours with invoice factor of all tasks related to this project and its child projects.",
17 store={'project.task': (lambda self, cr, uid, ids, c={}: ids, TASK_WATCHERS, 20),
18 'account.analytic.line': (_get_analytic_line, TIMESHEET_WATCHERS, 20)}),
19
20- 'total_hours': fields.function(_progress_rate, multi="progress", method=True, string='Total Time',
21+ 'total_hours': fields.function(_progress_rate, multi="progress", string='Total Time',
22 help="Sum of total hours of all tasks related to this project and its child projects.",
23 store={'project.task': (lambda self, cr, uid, ids, c={}: ids, TASK_WATCHERS, 20),
24 'account.analytic.line': (_get_analytic_line, TIMESHEET_WATCHERS, 20)}),
25
26- 'progress': fields.function(_progress_rate, multi="progress", method=True, string='Progress', type='float', group_operator="avg",
27+ 'progress': fields.function(_progress_rate, multi="progress", string='Progress', type='float', group_operator="avg",
28 help="Percent of tasks closed according to the total of tasks todo.",
29 store={'project.task': (lambda self, cr, uid, ids, c={}: ids, TASK_WATCHERS, 20),
30 'account.analytic.line': (_get_analytic_line, TIMESHEET_WATCHERS, 20)})}
31@@ -93,6 +93,32 @@
32 return res
33
34 class HrAnalyticTimesheet(orm.Model):
35+ """
36+ Add field:
37+ - hr_analytic_timesheet_id:
38+ This field is added to make sure a hr.analytic.timesheet can be used
39+ instead of a project.task.work.
40+
41+ This field will always return false as we want to by pass next operations
42+ in project.task write method.
43+
44+ Without this field, it is impossible to write a project.task in which
45+ work_ids is empty as a check on it would raise an AttributeError.
46+
47+ This is because, in project_timesheet module, project.task's write method
48+ checks if there is an hr_analytic_timesheet_id on each work_ids.
49+
50+ (project_timesheet.py, line 250, in write)
51+ if not task_work.hr_analytic_timesheet_id:
52+ continue
53+
54+ But as we redefine work_ids to be a relation to hr_analytic_timesheet
55+ instead of project.task.work, hr_analytic_timesheet doesn't exists
56+ in hr_analytic_timesheet... so it fails.
57+
58+ An other option would be to monkey patch the project.task's write method...
59+ As this method doesn't fit with the change of work_ids relation in model.
60+ """
61 _inherit = "hr.analytic.timesheet"
62 _name = "hr.analytic.timesheet"
63
64@@ -116,6 +142,16 @@
65 res['value']['to_invoice'] = p.to_invoice.id
66 return res
67
68+ def _get_dummy_hr_analytic_timesheet_id(self, cr, uid, ids, names, arg, context=None):
69+ """
70+ Ensure all hr_analytic_timesheet_id is always False
71+ """
72+ return dict.fromkeys(ids, False)
73+
74+ _columns = {
75+ 'hr_analytic_timesheet_id': fields.function(_get_dummy_hr_analytic_timesheet_id, string='Related Timeline Id', type='boolean')
76+ }
77+
78 class AccountAnalyticLine(orm.Model):
79 """We add task_id on AA and manage update of linked task indicators"""
80 _inherit = "account.analytic.line"

Subscribers

People subscribed via source and target branches