This question has been flagged

I'm trying to inherit a method from project_issue module to override a project.task method. The method I want to override is write but I don't know how to do this...

This is the method in project_issue:

def write(self, cr, uid, ids, vals, context=None):
        if context is None:
            context = {}
        task_work_obj = self.pool['project.task.work']
        acc_id = False
        missing_analytic_entries = {}
        if vals.get('project_id',False) or vals.get('name',False):
            vals_line = {}
            hr_anlytic_timesheet = self.pool.get('hr.analytic.timesheet')
            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
            for task_obj in self.browse(cr, uid, ids, context=context):
                if len(task_obj.work_ids):
                    for task_work in task_obj.work_ids:
                        if not task_work.hr_analytic_timesheet_id:
                            if acc_id :
                                # missing timesheet activities to generate
                                missing_analytic_entries[task_work.id] = {
                                    'name' : task_work.name,
                                    'user_id' : task_work.user_id.id,
                                    'date' : task_work.date and task_work.date[:10] or False,
                                    'account_id': acc_id,
                                    'hours' : task_work.hours,
                                    'task_id' : task_obj.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, {})
        res = super(task,self).write(cr, uid, ids, vals, context)
        for task_work_id, analytic_entry in missing_analytic_entries.items():
            timeline_id = task_work_obj._create_analytic_entries(cr, uid, analytic_entry, context=context)
            task_work_obj.write(cr, uid, task_work_id, {'hr_analytic_timesheet_id' : timeline_id}, context=context)
        return res

And I need to add some fields in:

                                missing_analytic_entries[task_work.id] = {
      'name' : task_work.name,
      'user_id' : task_work.user_id.id,
      'date' : task_work.date and task_work.date[:10] or False,
      'account_id': acc_id,
      'hours' : task_work.hours,
      'task_id' : task_obj.id
}

It is impossible to me to add some fields there, and I need it because I added fields with a module to project.task.work model... The problem is that after this, in this code:

timeline_id = task_work_obj._create_analytic_entries(cr, uid, analytic_entry, context=context)   

Those fields are sent to _create_analytic_entries, and this method expects for those fields I want to add with inheritance...

What can I do? Any help or workaround? Thanks in advice

Avatar
Discard