c2c-oerpscenario team mailing list archive
-
c2c-oerpscenario team
-
Mailing list archive
-
Message #27706
[Bug 803979] Re: project_timesheet: inherited project.task write def updates all work entries
I replaced now the code to version 6 and also tested it...so this should
solve the problem...at least for me ;-)
** Description changed:
- It is not possible to write a specific task works (in an module which
+ It is not possible to write a specific task work (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):
+ 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']):
+ if vals.get('project_id',False) or vals.get('name',False):
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
-
+ task_obj_l = self.browse(cr, uid, ids, context=context)
+ if vals.get('project_id',False):
+ project_obj = self.pool.get('project.project').browse(cr, uid, vals['project_id'], context=context)
+ acc_id = project_obj.analytic_account_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]
+ if not task_work.hr_analytic_timesheet_id:
+ continue
line_id = task_work.hr_analytic_timesheet_id
- if (vals.has_key('project_id') and vals['project_id']):
+
+ if vals.get('project_id',False):
vals_line['account_id'] = acc_id
- if (vals.has_key('name') and vals['name']):
+ if vals.get('name',False):
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, {})
+
+ import netsvc
+ logger = netsvc.Logger()
+ logger.notifyChannel("fuck", netsvc.LOG_INFO, ('update (%s, %s)') % (line_id, vals_line))
+ hr_anlytic_timesheet.write(cr, uid, [line_id.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']):
+ if not task_work.hr_analytic_timesheet_id:
+ continue
+ line_id = task_work.hr_analytic_timesheet_id.id
+ if vals.get('project_id',False):
vals_line['account_id'] = acc_id
- if (vals.has_key('name') and vals['name']):
+ if vals.get('name',False):
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
** Description changed:
It is not possible to write a specific task work (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 vals.get('project_id',False) or vals.get('name',False):
- vals_line = {}
- hr_anlytic_timesheet = self.pool.get('hr.analytic.timesheet')
- task_obj_l = self.browse(cr, uid, ids, context=context)
- if vals.get('project_id',False):
- project_obj = self.pool.get('project.project').browse(cr, uid, vals['project_id'], context=context)
- acc_id = project_obj.analytic_account_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]
-
- if not task_work.hr_analytic_timesheet_id:
- continue
- line_id = task_work.hr_analytic_timesheet_id
-
- if vals.get('project_id',False):
- vals_line['account_id'] = acc_id
- if vals.get('name',False):
- vals_line['name'] = '%s: %s' % (tools.ustr(vals['name']), tools.ustr(task_work.name) or '/')
+ def write(self, cr, uid, ids,vals,context=None):
+ if context is None:
+ context = {}
+ if vals.get('project_id',False) or vals.get('name',False):
+ vals_line = {}
+ hr_anlytic_timesheet = self.pool.get('hr.analytic.timesheet')
+ task_obj_l = self.browse(cr, uid, ids, context=context)
+ if vals.get('project_id',False):
+ project_obj = self.pool.get('project.project').browse(cr, uid, vals['project_id'], context=context)
+ acc_id = project_obj.analytic_account_id.id
- import netsvc
- logger = netsvc.Logger()
- logger.notifyChannel("fuck", netsvc.LOG_INFO, ('update (%s, %s)') % (line_id, vals_line))
- hr_anlytic_timesheet.write(cr, uid, [line_id.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:
- if not task_work.hr_analytic_timesheet_id:
- continue
- line_id = task_work.hr_analytic_timesheet_id.id
- if vals.get('project_id',False):
- vals_line['account_id'] = acc_id
- if vals.get('name',False):
- 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)
+ 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]
+
+ if not task_work.hr_analytic_timesheet_id:
+ continue
+ line_id = task_work.hr_analytic_timesheet_id
+
+ if vals.get('project_id',False):
+ vals_line['account_id'] = acc_id
+ if vals.get('name',False):
+ vals_line['name'] = '%s: %s' % (tools.ustr(vals['name']), tools.ustr(task_work.name) or '/')
+ hr_anlytic_timesheet.write(cr, uid, [line_id.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:
+ if not task_work.hr_analytic_timesheet_id:
+ continue
+ line_id = task_work.hr_analytic_timesheet_id.id
+ if vals.get('project_id',False):
+ vals_line['account_id'] = acc_id
+ if vals.get('name',False):
+ 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
--
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 work (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 vals.get('project_id',False) or vals.get('name',False):
vals_line = {}
hr_anlytic_timesheet = self.pool.get('hr.analytic.timesheet')
task_obj_l = self.browse(cr, uid, ids, context=context)
if vals.get('project_id',False):
project_obj = self.pool.get('project.project').browse(cr, uid, vals['project_id'], context=context)
acc_id = project_obj.analytic_account_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]
if not task_work.hr_analytic_timesheet_id:
continue
line_id = task_work.hr_analytic_timesheet_id
if vals.get('project_id',False):
vals_line['account_id'] = acc_id
if vals.get('name',False):
vals_line['name'] = '%s: %s' % (tools.ustr(vals['name']), tools.ustr(task_work.name) or '/')
hr_anlytic_timesheet.write(cr, uid, [line_id.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:
if not task_work.hr_analytic_timesheet_id:
continue
line_id = task_work.hr_analytic_timesheet_id.id
if vals.get('project_id',False):
vals_line['account_id'] = acc_id
if vals.get('name',False):
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
References