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
=== modified file 'project/project.py'
--- project/project.py 2012-07-20 15:12:03 +0000
+++ project/project.py 2012-08-07 08:37:26 +0000
@@ -530,22 +530,32 @@
530 border[0]+' '+(task.name or '')+'\n'+ \530 border[0]+' '+(task.name or '')+'\n'+ \
531 (task.description or '')+'\n\n'531 (task.description or '')+'\n\n'
532532
533
534 def convert_hours(self, cr, uid, ids, hours):
535 if not hours:
536 hours = 0.0
537 new_hours = hours / self.pool.get('hr.employee').browse(cr, uid, uid).product_id.uom_id.factor
538 return new_hours
533 # Compute: effective_hours, total_hours, progress539 # Compute: effective_hours, total_hours, progress
534 def _hours_get(self, cr, uid, ids, field_names, args, context=None):540 def _hours_get(self, cr, uid, ids, field_names, args, context=None):
535 res = {}541 res = {}
536 cr.execute("SELECT task_id, COALESCE(SUM(hours),0) FROM project_task_work WHERE task_id IN %s GROUP BY task_id",(tuple(ids),))542 cr.execute("SELECT task_id, COALESCE(SUM(hours),0) FROM project_task_work WHERE task_id IN %s GROUP BY task_id",(tuple(ids),))
537 hours = dict(cr.fetchall())543 hours = dict(cr.fetchall())
544 new_hours = 0.0
538 for task in self.browse(cr, uid, ids, context=context):545 for task in self.browse(cr, uid, ids, context=context):
539 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)}546 if task.company_id.project_time_mode_id.name == 'Day':
547 new_hours = self.convert_hours(cr, uid, ids, hours.get(task.id, 0.0))
548 else:
549 new_hours = hours.get(task.id, 0.0)
550 res[task.id] = {'effective_hours': new_hours, 'total_hours': (task.remaining_hours or 0.0) + new_hours}
540 res[task.id]['delay_hours'] = res[task.id]['total_hours'] - task.planned_hours551 res[task.id]['delay_hours'] = res[task.id]['total_hours'] - task.planned_hours
541 res[task.id]['progress'] = 0.0552 res[task.id]['progress'] = 0.0
542 if (task.remaining_hours + hours.get(task.id, 0.0)):553 if (task.remaining_hours + new_hours):
543 res[task.id]['progress'] = round(min(100.0 * hours.get(task.id, 0.0) / res[task.id]['total_hours'], 99.99),2)554 res[task.id]['progress'] = round(min(100.0 * new_hours / res[task.id]['total_hours'], 99.99),2)
544 if task.state in ('done','cancelled'):555 if task.state in ('done','cancelled'):
545 res[task.id]['progress'] = 100.0556 res[task.id]['progress'] = 100.0
546 return res557 return res
547558
548
549 def onchange_remaining(self, cr, uid, ids, remaining=0.0, planned = 0.0):559 def onchange_remaining(self, cr, uid, ids, remaining=0.0, planned = 0.0):
550 if remaining and not planned:560 if remaining and not planned:
551 return {'value':{'planned_hours': remaining}}561 return {'value':{'planned_hours': remaining}}
@@ -1104,26 +1114,46 @@
1104 'user_id': lambda obj, cr, uid, context: uid,1114 'user_id': lambda obj, cr, uid, context: uid,
1105 'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S')1115 'date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S')
1106 }1116 }
11071117
1108 _order = "date desc"1118 _order = "date desc"
1109 def create(self, cr, uid, vals, *args, **kwargs):1119 def create(self, cr, uid, vals, *args, **kwargs):
1120 old_hours = vals['hours']
1121 task_obj = self.pool.get('project.task')
1122 if self.pool.get('res.company').browse(cr, uid, uid).project_time_mode_id.name == 'Day':
1123 vals.update({'hours': task_obj.convert_hours(cr, uid, uid, hours=vals['hours'])})
1110 if 'hours' in vals and (not vals['hours']):1124 if 'hours' in vals and (not vals['hours']):
1111 vals['hours'] = 0.001125 vals['hours'] = 0.00
1112 if 'task_id' in vals:1126 if 'task_id' in vals:
1113 cr.execute('update project_task set remaining_hours=remaining_hours - %s where id=%s', (vals.get('hours',0.0), vals['task_id']))1127 cr.execute('update project_task set remaining_hours=remaining_hours - %s where id=%s', (vals.get('hours',0.0), vals['task_id']))
1128 vals.update({'hours': old_hours})
1114 return super(project_work,self).create(cr, uid, vals, *args, **kwargs)1129 return super(project_work,self).create(cr, uid, vals, *args, **kwargs)
11151130
1116 def write(self, cr, uid, ids, vals, context=None):1131 def write(self, cr, uid, ids, vals, context=None):
1132 task_obj = self.pool.get('project.task')
1117 if 'hours' in vals and (not vals['hours']):1133 if 'hours' in vals and (not vals['hours']):
1118 vals['hours'] = 0.001134 vals['hours'] = 0.00
1119 if 'hours' in vals:1135 if 'hours' in vals:
1136 old_hours = vals['hours']
1120 for work in self.browse(cr, uid, ids, context=context):1137 for work in self.browse(cr, uid, ids, context=context):
1121 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))1138 if self.pool.get('res.company').browse(cr, uid, uid).project_time_mode_id.name == 'Day':
1139 new_hours = 0.0
1140 vals.update({'hours': task_obj.convert_hours(cr, uid, uid, hours=vals['hours']) })
1141 new_hours = task_obj.convert_hours(cr, uid, ids, hours=work.hours)
1142 else:
1143 new_hours = work.hours
1144 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))
1145 vals.update({'hours': old_hours})
1122 return super(project_work,self).write(cr, uid, ids, vals, context)1146 return super(project_work,self).write(cr, uid, ids, vals, context)
11231147
1124 def unlink(self, cr, uid, ids, *args, **kwargs):1148 def unlink(self, cr, uid, ids, *args, **kwargs):
1149 user_data = self.pool.get('res.company').browse(cr, uid, uid)
1150 task_obj = self.pool.get('project.task')
1125 for work in self.browse(cr, uid, ids):1151 for work in self.browse(cr, uid, ids):
1126 cr.execute('update project_task set remaining_hours=remaining_hours + %s where id=%s', (work.hours, work.task_id.id))1152 if user_data.project_time_mode_id.name == 'Day':
1153 new_hours = task_obj.convert_hours(cr, uid, ids, hours=work.hours)
1154 else:
1155 new_hours = work.hours
1156 cr.execute('update project_task set remaining_hours=remaining_hours + %s where id=%s', (new_hours, work.task_id.id))
1127 return super(project_work,self).unlink(cr, uid, ids,*args, **kwargs)1157 return super(project_work,self).unlink(cr, uid, ids,*args, **kwargs)
1128project_work()1158project_work()
11291159
11301160
=== modified file 'project_timesheet/project_timesheet.py'
--- project_timesheet/project_timesheet.py 2012-01-31 13:36:57 +0000
+++ project_timesheet/project_timesheet.py 2012-08-07 08:37:26 +0000
@@ -79,7 +79,7 @@
79 project_obj = self.pool.get('project.project')79 project_obj = self.pool.get('project.project')
80 task_obj = self.pool.get('project.task')80 task_obj = self.pool.get('project.task')
81 uom_obj = self.pool.get('product.uom')81 uom_obj = self.pool.get('product.uom')
82 82 old_hours = 0.0
83 vals_line = {}83 vals_line = {}
84 context = kwargs.get('context', {})84 context = kwargs.get('context', {})
85 if not context.get('no_analytic_entry',False):85 if not context.get('no_analytic_entry',False):
@@ -93,9 +93,13 @@
93 #calculate quantity based on employee's product's uom 93 #calculate quantity based on employee's product's uom
94 vals_line['unit_amount'] = vals['hours']94 vals_line['unit_amount'] = vals['hours']
9595
96 default_uom = self.pool.get('res.users').browse(cr, uid, uid).company_id.project_time_mode_id.id96 default_uom = self.pool.get('res.users').browse(cr, uid, uid).company_id.project_time_mode_id
97 if result['product_uom_id'] != default_uom:97 if result['product_uom_id'] != default_uom.id:
98 vals_line['unit_amount'] = uom_obj._compute_qty(cr, uid, default_uom, vals['hours'], result['product_uom_id'])98 if default_uom.name == 'Day':
99 old_hours = task_obj.convert_hours(cr, uid, uid, hours=vals['hours'])
100 else:
101 old_hours = vals['hours']
102 vals_line['unit_amount'] = uom_obj._compute_qty(cr, uid, default_uom.id, old_hours, result['product_uom_id'])
99 acc_id = obj_task.project_id and obj_task.project_id.analytic_account_id.id or False103 acc_id = obj_task.project_id and obj_task.project_id.analytic_account_id.id or False
100 if acc_id:104 if acc_id:
101 vals_line['account_id'] = acc_id105 vals_line['account_id'] = acc_id
@@ -126,7 +130,9 @@
126 timesheet_obj = self.pool.get('hr.analytic.timesheet')130 timesheet_obj = self.pool.get('hr.analytic.timesheet')
127 project_obj = self.pool.get('project.project')131 project_obj = self.pool.get('project.project')
128 uom_obj = self.pool.get('product.uom')132 uom_obj = self.pool.get('product.uom')
133 task_obj = self.pool.get('project.task')
129 result = {}134 result = {}
135 old_hours = 0.0
130 136
131 if isinstance(ids, (long, int)):137 if isinstance(ids, (long, int)):
132 ids = [ids,]138 ids = [ids,]
@@ -150,12 +156,16 @@
150 if 'date' in vals:156 if 'date' in vals:
151 vals_line['date'] = vals['date'][:10]157 vals_line['date'] = vals['date'][:10]
152 if 'hours' in vals:158 if 'hours' in vals:
153 default_uom = self.pool.get('res.users').browse(cr, uid, uid).company_id.project_time_mode_id.id159 default_uom = self.pool.get('res.users').browse(cr, uid, uid).company_id.project_time_mode_id
154 vals_line['unit_amount'] = vals['hours']160 vals_line['unit_amount'] = vals['hours']
155 prod_id = vals_line.get('product_id', line_id.product_id.id) # False may be set161 prod_id = vals_line.get('product_id', line_id.product_id.id) # False may be set
156162
157 if result.get('product_uom_id',False) and (not result['product_uom_id'] == default_uom):163 if result.get('product_uom_id',False) and (not result['product_uom_id'] == default_uom.id):
158 vals_line['unit_amount'] = uom_obj._compute_qty(cr, uid, default_uom, vals['hours'], result['product_uom_id'])164 if default_uom.name == 'Day':
165 old_hours = task_obj.convert_hours(cr, uid, ids, hours=vals['hours'])
166 else:
167 old_hours = vals['hours']
168 vals_line['unit_amount'] = uom_obj._compute_qty(cr, uid, default_uom.id, old_hours, result['product_uom_id'])
159 169
160 # Compute based on pricetype170 # Compute based on pricetype
161 amount_unit = timesheet_obj.on_change_unit_amount(cr, uid, line_id.id,171 amount_unit = timesheet_obj.on_change_unit_amount(cr, uid, line_id.id,