c2c-oerpscenario team mailing list archive
-
c2c-oerpscenario team
-
Mailing list archive
-
Message #27704
[Bug 803979] [NEW] project_timesheet: inherited project.task write def updates all work entries
Public bug reported:
It is not possible to write a specific task works (in an module which
calls project.task write and wants to trigger an update of analytic
timesheet)
It will always run into an exception when work entries of a task are
already in a confirmed state because the for loop tries to update ALL
work entries instead of specific ones.
I compared the mechanism of the task view and rebuilt the vals structure
and added an if condition...probably the else could be eliminated but
this should be evaluated before :-)
def write(self, cr, uid, ids, vals, context=None):
if context is None:
context = {}
if isinstance(ids, (int, long)):
ids = [ids]
if (vals.has_key('project_id') and vals['project_id']) or (vals.has_key('name') and vals['name']):
vals_line = {}
hr_anlytic_timesheet = self.pool.get('hr.analytic.timesheet')
task_obj_l = self.browse(cr, uid, ids, context)
if (vals.has_key('project_id') and vals['project_id']):
project_obj = self.pool.get('project.project').browse(cr, uid, vals['project_id'])
acc_id = project_obj.category_id.id
if 'work_ids' in vals:
for work in vals['work_ids']:
task_work = self.pool.get('project.task.work').browse(cr, uid, [work[1]])[0]
line_id = task_work.hr_analytic_timesheet_id
if (vals.has_key('project_id') and vals['project_id']):
vals_line['account_id'] = acc_id
if (vals.has_key('name') and vals['name']):
vals_line['name'] = '%s: %s' % (tools.ustr(vals['name']), tools.ustr(task_work.name) or '/')
hr_anlytic_timesheet.write(cr, uid, [line_id], vals_line, {})
else:
for task_obj in task_obj_l:
if len(task_obj.work_ids):
for task_work in task_obj.work_ids:
line_id = task_work.hr_analytic_timesheet_id
if (vals.has_key('project_id') and vals['project_id']):
vals_line['account_id'] = acc_id
if (vals.has_key('name') and vals['name']):
vals_line['name'] = '%s: %s' % (tools.ustr(vals['name']), tools.ustr(task_work.name) or '/')
hr_anlytic_timesheet.write(cr, uid, [line_id], vals_line, {})
return super(task,self).write(cr, uid, ids, vals, context)
Hope you were able to follow :-)
Best regards,
Wolfgang
** Affects: openobject-addons
Importance: Undecided
Status: New
--
You received this bug notification because you are a member of C2C
OERPScenario, which is subscribed to the OpenERP Project Group.
https://bugs.launchpad.net/bugs/803979
Title:
project_timesheet: inherited project.task write def updates all work
entries
Status in OpenERP Modules (addons):
New
Bug description:
It is not possible to write a specific task works (in an module which
calls project.task write and wants to trigger an update of analytic
timesheet)
It will always run into an exception when work entries of a task are
already in a confirmed state because the for loop tries to update ALL
work entries instead of specific ones.
I compared the mechanism of the task view and rebuilt the vals
structure and added an if condition...probably the else could be
eliminated but this should be evaluated before :-)
def write(self, cr, uid, ids, vals, context=None):
if context is None:
context = {}
if isinstance(ids, (int, long)):
ids = [ids]
if (vals.has_key('project_id') and vals['project_id']) or (vals.has_key('name') and vals['name']):
vals_line = {}
hr_anlytic_timesheet = self.pool.get('hr.analytic.timesheet')
task_obj_l = self.browse(cr, uid, ids, context)
if (vals.has_key('project_id') and vals['project_id']):
project_obj = self.pool.get('project.project').browse(cr, uid, vals['project_id'])
acc_id = project_obj.category_id.id
if 'work_ids' in vals:
for work in vals['work_ids']:
task_work = self.pool.get('project.task.work').browse(cr, uid, [work[1]])[0]
line_id = task_work.hr_analytic_timesheet_id
if (vals.has_key('project_id') and vals['project_id']):
vals_line['account_id'] = acc_id
if (vals.has_key('name') and vals['name']):
vals_line['name'] = '%s: %s' % (tools.ustr(vals['name']), tools.ustr(task_work.name) or '/')
hr_anlytic_timesheet.write(cr, uid, [line_id], vals_line, {})
else:
for task_obj in task_obj_l:
if len(task_obj.work_ids):
for task_work in task_obj.work_ids:
line_id = task_work.hr_analytic_timesheet_id
if (vals.has_key('project_id') and vals['project_id']):
vals_line['account_id'] = acc_id
if (vals.has_key('name') and vals['name']):
vals_line['name'] = '%s: %s' % (tools.ustr(vals['name']), tools.ustr(task_work.name) or '/')
hr_anlytic_timesheet.write(cr, uid, [line_id], vals_line, {})
return super(task,self).write(cr, uid, ids, vals, context)
Hope you were able to follow :-)
Best regards,
Wolfgang
To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-addons/+bug/803979/+subscriptions
Follow ups
-
[Bug 803979] Re: project_timesheet: inherited project.task write def updates all work entries
From: Amit Parik (OpenERP), 2011-08-04
-
[Bug 803979] Re: project_timesheet: inherited project.task write def updates all work entries
From: Amit Parik (OpenERP), 2011-08-04
-
[Bug 803979] Re: project_timesheet: inherited project.task write def updates all work entries
From: Wolfgang Taferner [TaPo-IT], 2011-08-04
-
[Bug 803979] Re: project_timesheet: inherited project.task write def updates all work entries
From: Wolfgang Taferner [TaPo-IT], 2011-08-01
-
[Bug 803979] Re: project_timesheet: inherited project.task write def updates all work entries
From: Amit Parik (OpenERP), 2011-08-01
-
[Bug 803979] Re: project_timesheet: inherited project.task write def updates all work entries
From: Amit Parik (OpenERP), 2011-08-01
-
[Bug 803979] Re: project_timesheet: inherited project.task write def updates all work entries
From: Wolfgang Taferner [TaPo-IT], 2011-07-29
-
[Bug 803979] Re: project_timesheet: inherited project.task write def updates all work entries
From: Amit Parik (OpenERP), 2011-07-29
-
[Bug 803979] Re: project_timesheet: inherited project.task write def updates all work entries
From: Amit Parik (OpenERP), 2011-07-29
-
[Bug 803979] Re: project_timesheet: inherited project.task write def updates all work entries
From: Wolfgang Taferner [TaPo-IT], 2011-06-30
-
[Bug 803979] Re: project_timesheet: inherited project.task write def updates all work entries
From: Wolfgang Taferner [TaPo-IT], 2011-06-30
-
[Bug 803979] [NEW] project_timesheet: inherited project.task write def updates all work entries
From: Wolfgang Taferner [TaPo-IT], 2011-06-30
References