Merge lp:~openerp-dev/openobject-addons/trunk-opw-576096-port-mma into lp:openobject-addons

Proposed by Mayur Maheshwari(OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/trunk-opw-576096-port-mma
Merge into: lp:openobject-addons
Diff against target: 124 lines (+45/-10)
2 files modified
project/project.py (+28/-4)
project_timesheet/project_timesheet.py (+17/-6)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/trunk-opw-576096-port-mma
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+134888@code.launchpad.net

Description of the change

Hello,
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.

Thanks
Mayur

To post a comment you must log in.

Unmerged revisions

8074. By Amit Dodiya(OpenERP)

[FIX]project: 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-11-15 12:38:51 +0000
3+++ project/project.py 2012-11-19 12:29:29 +0000
4@@ -662,17 +662,28 @@
5 border[0]+' '+(task.name or '')+'\n'+ \
6 (task.description or '')+'\n\n'
7
8+ def convert_hours(self, cr, uid, ids, hours):
9+ if not hours:
10+ hours = 0.0
11+ new_hours = hours / self.pool.get('hr.employee').browse(cr, uid, uid).product_id.uom_id.factor
12+ return new_hours
13+
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@@ -1336,18 +1347,31 @@
37
38 _order = "date desc"
39 def create(self, cr, uid, vals, *args, **kwargs):
40+ old_hours = vals['hours']
41+ task_obj = self.pool.get('project.task')
42+ if self.pool.get('res.company').browse(cr, uid, uid).project_time_mode_id.name == 'Day':
43+ vals.update({'hours': task_obj.convert_hours(cr, uid, uid, hours=vals['hours'])})
44 if 'hours' in vals and (not vals['hours']):
45 vals['hours'] = 0.00
46 if 'task_id' in vals:
47 cr.execute('update project_task set remaining_hours=remaining_hours - %s where id=%s', (vals.get('hours',0.0), vals['task_id']))
48+ vals.update({'hours': old_hours})
49 return super(project_work,self).create(cr, uid, vals, *args, **kwargs)
50
51 def write(self, cr, uid, ids, vals, context=None):
52+ task_obj = self.pool.get('project.task')
53 if 'hours' in vals and (not vals['hours']):
54+ old_hours = vals['hours']
55 vals['hours'] = 0.00
56 if 'hours' in vals:
57 for work in self.browse(cr, uid, ids, context=context):
58- 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))
59+ if self.pool.get('res.company').browse(cr, uid, uid).project_time_mode_id.name == 'Day':
60+ new_hours = 0.0
61+ vals.update({'hours': task_obj.convert_hours(cr, uid, uid, hours=vals['hours']) })
62+ new_hours = task_obj.convert_hours(cr, uid, ids, hours=work.hours)
63+ else:
64+ new_hours = work.hours
65+ 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))
66 return super(project_work,self).write(cr, uid, ids, vals, context)
67
68 def unlink(self, cr, uid, ids, *args, **kwargs):
69
70=== modified file 'project_timesheet/project_timesheet.py'
71--- project_timesheet/project_timesheet.py 2012-11-15 12:30:05 +0000
72+++ project_timesheet/project_timesheet.py 2012-11-19 12:29:29 +0000
73@@ -110,6 +110,7 @@
74 task_obj = self.pool.get('project.task')
75 uom_obj = self.pool.get('product.uom')
76
77+ old_hours = 0.0
78 vals_line = {}
79 context = kwargs.get('context', {})
80 if not context.get('no_analytic_entry',False):
81@@ -123,9 +124,13 @@
82 # Calculate quantity based on employee's product's uom
83 vals_line['unit_amount'] = vals['hours']
84
85- default_uom = self.pool.get('res.users').browse(cr, uid, uid).company_id.project_time_mode_id.id
86- if result['product_uom_id'] != default_uom:
87- vals_line['unit_amount'] = uom_obj._compute_qty(cr, uid, default_uom, vals['hours'], result['product_uom_id'])
88+ default_uom = self.pool.get('res.users').browse(cr, uid, uid).company_id.project_time_mode_id
89+ if result['product_uom_id'] != default_uom.id:
90+ if default_uom.name == 'Day':
91+ old_hours = task_obj.convert_hours(cr, uid, uid, hours=vals['hours'])
92+ else:
93+ old_hours = vals['hours']
94+ vals_line['unit_amount'] = uom_obj._compute_qty(cr, uid, default_uom.id, old_hours, result['product_uom_id'])
95 acc_id = task_obj.project_id and task_obj.project_id.analytic_account_id.id or False
96 if acc_id:
97 vals_line['account_id'] = acc_id
98@@ -158,7 +163,9 @@
99 context = {}
100 timesheet_obj = self.pool.get('hr.analytic.timesheet')
101 uom_obj = self.pool.get('product.uom')
102+ task_obj = self.pool.get('project.task')
103 result = {}
104+ old_hours = 0.0
105
106 if isinstance(ids, (long, int)):
107 ids = [ids]
108@@ -188,9 +195,13 @@
109 vals_line[field] = details[field]
110
111 # Check if user's default UOM differs from product's UOM
112- user_default_uom_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.project_time_mode_id.id
113- if details.get('product_uom_id', False) and details['product_uom_id'] != user_default_uom_id:
114- vals_line['unit_amount'] = uom_obj._compute_qty(cr, uid, user_default_uom_id, vals['hours'], details['product_uom_id'])
115+ user_default_uom = self.pool.get('res.users').browse(cr, uid, uid).company_id.project_time_mode_id
116+ if details.get('product_uom_id', False) and details['product_uom_id'] != user_default_uom:
117+ if user_default_uom.name == 'Day':
118+ old_hours = task_obj.convert_hours(cr, uid, ids, hours=vals['hours'])
119+ else:
120+ old_hours = vals['hours']
121+ vals_line['unit_amount'] = uom_obj._compute_qty(cr, uid, user_default_uom_id, old_hours, details['product_uom_id'])
122
123 # Compute based on pricetype
124 amount_unit = timesheet_obj.on_change_unit_amount(cr, uid, line_id.id,

Subscribers

People subscribed via source and target branches

to all changes: