Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
10522 Weergaven

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?

Avatar
Annuleer
Auteur Beste antwoord

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
Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
jan. 19
11420
1
okt. 17
3291
0
mrt. 15
3865
0
apr. 24
1906
1
jan. 22
3735