Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Project_timesheet issue

By
Aitor Bouzas
on 4/15/15, 12:10 PM 408 views

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 4/15/15, 12:10 PM
Seen: 408 times
Last updated: 4/17/15, 3:40 AM