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

Call method after creating record?

By
Andrius Laukavičius
on 1/2/14, 6:28 AM 1,442 views

How could I call my method just after creation of record was made. So far:

def _compute_stage_deadline(self, cr, uid, ids, context=None):
    for lead in self.browse(cr, uid, ids):

        stage_deadline = datetime.now() + lead.stage_id.days_for_stage
        print "Testing stage datetime: ", stage_deadline.strftime("%Y-%m-%d %H:%M:%S")
    return stage_deadline   

def create(self, cr, uid, ids, context=None):
    self._compute_stage_deadline(cr, uid, ids, context)
    return super(CRM_Lead, self).create(cr, uid, ids, context=context)

But there I call it just before creating record, so when in _compute_stage_deadline I try to access that record I get this error (because that record does not exist yet):

AttributeError: 'NoneType' object has no attribute 'stage_id'

How could I bypass it and call my method just after creation?

0

Solved this problem using this approach:

def _compute_stage_deadline(self, cr, uid, lead, context=None):        
    stage_deadline = datetime.now() + lead.stage_id.days_for_stage
    print "Testing stage datetime: ", stage_deadline.strftime("%Y-%m-%d %H:%M:%S")
    return stage_deadline   

def create(self, cr, uid, vals, context=None):
    new_id = super(CRM_Lead, self).create(cr, uid, vals, context=context)
    lead = self.browse(cr, uid, new_id, context=context)
    self._compute_stage_deadline(cr, uid, lead, context)
    return new_id

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

0 follower(s)

Stats

Asked: 1/2/14, 6:28 AM
Seen: 1442 times
Last updated: 3/16/15, 8:10 AM