← Back to team overview

c2c-oerpscenario team mailing list archive

[Bug 803979] Re: project_timesheet: inherited project.task write def updates all work entries

 

Hello Wolfgang,

That is good, you have setting this as an "Opinion". So the community
can share their views here.

Thanks.

-- 
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):
  Opinion

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