Override create method by inheritance

Hi ,

 I do a inheritance of my class , I redefine my create method and when I fill in my form and create by clicking on the save button ,my create method is called two times, so I have 2 records into my table.

Someone can tell me why !!!!!! It's possible to do inherit with the create method ?????

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Addons (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Serpent Consulting Services
Solved:
2012-10-05
Last query:
2012-10-05
Last reply:
2012-10-05
Niels Huylebroeck (red15) said : #1

Yes it's possible to override create method, why it's calling your create function twice will depend on more factors than you are currently sharing, please include a link if possible to a minimized problem case using http://gist.github.com or similar pasting services.

here, you have my code :

class project_work(osv.osv):

  def create(self, cr, uid, vals, *args, **kwargs):
        obj_timesheet = self.pool.get('hr.analytic.timesheet')
        project_obj = self.pool.get('project.project')
        task_obj = self.pool.get('project.task')
        uom_obj = self.pool.get('product.uom')

        vals_line = {}
        context = kwargs.get('context', {})
        if not context.get('no_analytic_entry',False):
            obj_task = task_obj.browse(cr, uid, vals['task_id'])
            result = self.get_user_related_details(cr, uid, vals.get('user_id', uid))
            vals_line['name'] = '%s: %s' % (tools.ustr(obj_task.name), tools.ustr(vals['name']) or '/')
            vals_line['user_id'] = vals['user_id']
            vals_line['product_id'] = vals['product_id']
            vals_line['date'] = vals['date'][:10]
            vals_line['to_invoice'] = vals['to_invoice']

            #calculate quantity based on employee's product's uom
            vals_line['unit_amount'] = vals['hours']

            default_uom = self.pool.get('res.users').browse(cr, uid, uid).company_id.project_time_mode_id.id
            if result['product_uom_id'] != default_uom:
                vals_line['unit_amount'] = uom_obj._compute_qty(cr, uid, default_uom, vals['hours'], result['product_uom_id'])
            acc_id = obj_task.project_id and obj_task.project_id.analytic_account_id.id or False
            if acc_id:
                vals_line['account_id'] = acc_id
                res = obj_timesheet.on_change_account_id(cr, uid, False, acc_id)
                if res.get('value'):
                    vals_line.update(res['value'])
                vals_line['general_account_id'] = result['general_account_id']
                vals_line['journal_id'] = result['journal_id']
                vals_line['amount'] = 0.0
                vals_line['product_uom_id'] = result['product_uom_id']
                amount = vals_line['unit_amount']
                prod_id = vals_line['product_id']
                unit = False
                timeline_id = obj_timesheet.create(cr, uid, vals=vals_line, context=context)

                # Compute based on pricetype
                amount_unit = obj_timesheet.on_change_unit_amount(cr, uid, timeline_id,
                    prod_id, amount, False, vals['hours'], vals_line['journal_id'],vals['to_invoice'], context=context)
                if amount_unit and 'amount' in amount_unit.get('value',{}):
                    updv = { 'amount': amount_unit['value']['amount'],'billable_amount': amount_unit['value']['billable_amount'] }
                    obj_timesheet.write(cr, uid, [timeline_id], updv, context=context)
                vals['hr_analytic_timesheet_id'] = timeline_id
                vals['billable_amount'] = amount_unit['value']['billable_amount']
        return super(project_work,self).create(cr, uid, vals, *args, **kwargs)

project_work()

I doubt what is the relation between project_work model and hr_analytic_timesheet?

Thanks , I solved the issue.

I solved the issue

Thanks Serpent Consulting Services, that solved my question.