Merge lp:~openerp-dev/openobject-addons/6.1-opw-576096-ado into lp:openobject-addons/6.1

Proposed by Amit Dodiya (OpenERP)
Status: Approved
Approved by: Naresh(OpenERP)
Approved revision: 6882
Proposed branch: lp:~openerp-dev/openobject-addons/6.1-opw-576096-ado
Merge into: lp:openobject-addons/6.1
Diff against target: 150 lines (+54/-14)
2 files modified
project/project.py (+37/-7)
project_timesheet/project_timesheet.py (+17/-7)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/6.1-opw-576096-ado
Reviewer Review Type Date Requested Status
Naresh(OpenERP) (community) Approve
Review via email: mp+118510@code.launchpad.net

Description of the change

Hello,

"[FIX] For project when we set the company "Project time unit" to work by day for task encoding the time encoding is consider in day so problem is that you encode 8 hours in timesheet entry it actually consider it as 8 days it should consider 8 hours"

There is a bug when you want to encode time in a task. If you set the company to work by day for task encoding the time encoding is still in hour. The problem is that you encode 8 hours, it actually consider it as 8 days. I have created a task with 10 Planned days, and I encoded a work of 8 hours, but my Remaining day is 2.

Steps:
1). Set the "Project time unit = Day" in company configuration
2). Create a task with 10 days and add taskwork entry for 2 hours
You will see it will deduct 2 days instead of 2 hours.
It should deduct 2 hours from 10 days.
So the system has taken days instead of hours, It should always take hours.

Regards,
Amit Dodiya

To post a comment you must log in.
Revision history for this message
Naresh(OpenERP) (nch-openerp) :
review: Approve
Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

Hello,

This bug was qualified as Confirmed on Trunk (means still existing and reproducible). A Merge Proposal for trunk was created to fix it. Here is the link to follow the MP on Launchpad https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-opw-576096-port-mma/+merge/134888 and be informed once it's been merged in trunk: ... If this Merge Proposal could not be merged in v6.1 at the release of v7.0, it will be closed.

Thanks,
Naresh Soni

Unmerged revisions

6882. By Amit Dodiya<email address hidden>

[FIX] For project when we set the company to work by day for task encoding the time encoding is consider in day so problem is that you encode 8 hours in timesheet entry it actually consider it as 8 days it should consider 8 hours

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'project/project.py'
2--- project/project.py 2012-07-20 15:12:03 +0000
3+++ project/project.py 2012-08-07 08:37:26 +0000
4@@ -530,22 +530,32 @@
5 border[0]+' '+(task.name or '')+'\n'+ \
6 (task.description or '')+'\n\n'
7
8+
9+ def convert_hours(self, cr, uid, ids, hours):
10+ if not hours:
11+ hours = 0.0
12+ new_hours = hours / self.pool.get('hr.employee').browse(cr, uid, uid).product_id.uom_id.factor
13+ return new_hours
14 # Compute: effective_hours, total_hours, progress
15 def _hours_get(self, cr, uid, ids, field_names, args, context=None):
16 res = {}
17 cr.execute("SELECT task_id, COALESCE(SUM(hours),0) FROM project_task_work WHERE task_id IN %s GROUP BY task_id",(tuple(ids),))
18 hours = dict(cr.fetchall())
19+ new_hours = 0.0
20 for task in self.browse(cr, uid, ids, context=context):
21- res[task.id] = {'effective_hours': hours.get(task.id, 0.0), 'total_hours': (task.remaining_hours or 0.0) + hours.get(task.id, 0.0)}
22+ if task.company_id.project_time_mode_id.name == 'Day':
23+ new_hours = self.convert_hours(cr, uid, ids, hours.get(task.id, 0.0))
24+ else:
25+ new_hours = hours.get(task.id, 0.0)
26+ res[task.id] = {'effective_hours': new_hours, 'total_hours': (task.remaining_hours or 0.0) + new_hours}
27 res[task.id]['delay_hours'] = res[task.id]['total_hours'] - task.planned_hours
28 res[task.id]['progress'] = 0.0
29- if (task.remaining_hours + hours.get(task.id, 0.0)):
30- res[task.id]['progress'] = round(min(100.0 * hours.get(task.id, 0.0) / res[task.id]['total_hours'], 99.99),2)
31+ if (task.remaining_hours + new_hours):
32+ res[task.id]['progress'] = round(min(100.0 * new_hours / res[task.id]['total_hours'], 99.99),2)
33 if task.state in ('done','cancelled'):
34 res[task.id]['progress'] = 100.0
35 return res
36
37-
38 def onchange_remaining(self, cr, uid, ids, remaining=0.0, planned = 0.0):
39 if remaining and not planned:
40 return {'value':{'planned_hours': remaining}}
41@@ -1104,26 +1114,46 @@
42 'user_id': lambda obj, cr, uid, context: uid,
43 'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S')
44 }
45-
46+
47 _order = "date desc"
48 def create(self, cr, uid, vals, *args, **kwargs):
49+ old_hours = vals['hours']
50+ task_obj = self.pool.get('project.task')
51+ if self.pool.get('res.company').browse(cr, uid, uid).project_time_mode_id.name == 'Day':
52+ vals.update({'hours': task_obj.convert_hours(cr, uid, uid, hours=vals['hours'])})
53 if 'hours' in vals and (not vals['hours']):
54 vals['hours'] = 0.00
55 if 'task_id' in vals:
56 cr.execute('update project_task set remaining_hours=remaining_hours - %s where id=%s', (vals.get('hours',0.0), vals['task_id']))
57+ vals.update({'hours': old_hours})
58 return super(project_work,self).create(cr, uid, vals, *args, **kwargs)
59
60 def write(self, cr, uid, ids, vals, context=None):
61+ task_obj = self.pool.get('project.task')
62 if 'hours' in vals and (not vals['hours']):
63 vals['hours'] = 0.00
64 if 'hours' in vals:
65+ old_hours = vals['hours']
66 for work in self.browse(cr, uid, ids, context=context):
67- cr.execute('update project_task set remaining_hours=remaining_hours - %s + (%s) where id=%s', (vals.get('hours',0.0), work.hours, work.task_id.id))
68+ if self.pool.get('res.company').browse(cr, uid, uid).project_time_mode_id.name == 'Day':
69+ new_hours = 0.0
70+ vals.update({'hours': task_obj.convert_hours(cr, uid, uid, hours=vals['hours']) })
71+ new_hours = task_obj.convert_hours(cr, uid, ids, hours=work.hours)
72+ else:
73+ new_hours = work.hours
74+ cr.execute('update project_task set remaining_hours=remaining_hours - %s + (%s) where id=%s', (vals.get('hours',0.0), new_hours, work.task_id.id))
75+ vals.update({'hours': old_hours})
76 return super(project_work,self).write(cr, uid, ids, vals, context)
77
78 def unlink(self, cr, uid, ids, *args, **kwargs):
79+ user_data = self.pool.get('res.company').browse(cr, uid, uid)
80+ task_obj = self.pool.get('project.task')
81 for work in self.browse(cr, uid, ids):
82- cr.execute('update project_task set remaining_hours=remaining_hours + %s where id=%s', (work.hours, work.task_id.id))
83+ if user_data.project_time_mode_id.name == 'Day':
84+ new_hours = task_obj.convert_hours(cr, uid, ids, hours=work.hours)
85+ else:
86+ new_hours = work.hours
87+ cr.execute('update project_task set remaining_hours=remaining_hours + %s where id=%s', (new_hours, work.task_id.id))
88 return super(project_work,self).unlink(cr, uid, ids,*args, **kwargs)
89 project_work()
90
91
92=== modified file 'project_timesheet/project_timesheet.py'
93--- project_timesheet/project_timesheet.py 2012-01-31 13:36:57 +0000
94+++ project_timesheet/project_timesheet.py 2012-08-07 08:37:26 +0000
95@@ -79,7 +79,7 @@
96 project_obj = self.pool.get('project.project')
97 task_obj = self.pool.get('project.task')
98 uom_obj = self.pool.get('product.uom')
99-
100+ old_hours = 0.0
101 vals_line = {}
102 context = kwargs.get('context', {})
103 if not context.get('no_analytic_entry',False):
104@@ -93,9 +93,13 @@
105 #calculate quantity based on employee's product's uom
106 vals_line['unit_amount'] = vals['hours']
107
108- default_uom = self.pool.get('res.users').browse(cr, uid, uid).company_id.project_time_mode_id.id
109- if result['product_uom_id'] != default_uom:
110- vals_line['unit_amount'] = uom_obj._compute_qty(cr, uid, default_uom, vals['hours'], result['product_uom_id'])
111+ default_uom = self.pool.get('res.users').browse(cr, uid, uid).company_id.project_time_mode_id
112+ if result['product_uom_id'] != default_uom.id:
113+ if default_uom.name == 'Day':
114+ old_hours = task_obj.convert_hours(cr, uid, uid, hours=vals['hours'])
115+ else:
116+ old_hours = vals['hours']
117+ vals_line['unit_amount'] = uom_obj._compute_qty(cr, uid, default_uom.id, old_hours, result['product_uom_id'])
118 acc_id = obj_task.project_id and obj_task.project_id.analytic_account_id.id or False
119 if acc_id:
120 vals_line['account_id'] = acc_id
121@@ -126,7 +130,9 @@
122 timesheet_obj = self.pool.get('hr.analytic.timesheet')
123 project_obj = self.pool.get('project.project')
124 uom_obj = self.pool.get('product.uom')
125+ task_obj = self.pool.get('project.task')
126 result = {}
127+ old_hours = 0.0
128
129 if isinstance(ids, (long, int)):
130 ids = [ids,]
131@@ -150,12 +156,16 @@
132 if 'date' in vals:
133 vals_line['date'] = vals['date'][:10]
134 if 'hours' in vals:
135- default_uom = self.pool.get('res.users').browse(cr, uid, uid).company_id.project_time_mode_id.id
136+ default_uom = self.pool.get('res.users').browse(cr, uid, uid).company_id.project_time_mode_id
137 vals_line['unit_amount'] = vals['hours']
138 prod_id = vals_line.get('product_id', line_id.product_id.id) # False may be set
139
140- if result.get('product_uom_id',False) and (not result['product_uom_id'] == default_uom):
141- vals_line['unit_amount'] = uom_obj._compute_qty(cr, uid, default_uom, vals['hours'], result['product_uom_id'])
142+ if result.get('product_uom_id',False) and (not result['product_uom_id'] == default_uom.id):
143+ if default_uom.name == 'Day':
144+ old_hours = task_obj.convert_hours(cr, uid, ids, hours=vals['hours'])
145+ else:
146+ old_hours = vals['hours']
147+ vals_line['unit_amount'] = uom_obj._compute_qty(cr, uid, default_uom.id, old_hours, result['product_uom_id'])
148
149 # Compute based on pricetype
150 amount_unit = timesheet_obj.on_change_unit_amount(cr, uid, line_id.id,