This question has been flagged
5 Replies
3103 Views

Hi, i have problems.

i want to make sequence and make workflow .

i make 2 method : method 'create' and 'proses_aplikan' .

but i don't know , how to call method 'proses_aplikan'.


i make method create , like this :


def create(self, cr, uid, vals, context=None):

obj = self.pool.get('gelombang.pendaftaran').browse(cr, uid, vals['tahun_akademik_id']).name.name.name    

seq_name = 'A/{0}'.format(obj)

seq = self.pool.get('ir.sequence')

ids = seq.search(cr, uid, [('name','=',seq_name)])

if not ids:

prefix = seq_name

ids = seq.create(cr, uid, {

'name':seq_name,

'prefix': prefix,

'padding': 4,

'implementation': 'no_gap',

})

vals['name'] = seq.get_id(cr,uid,ids)

return super(data_aplikan, self).create(cr, uid, vals, context=context)


and method 'proses_aplikan' , like this :


def proses_aplikan(self, cr, uid, ids, context=None):

self.write(cr, uid, ids,{'context':'aplikan'})



How i call method 'proses_aplikan' to use in method 'create'  ?


thanks in advance ...

Avatar
Discard
Best Answer

instead of:  return super(data_aplikan, self).create(cr, uid, vals, context=context)

save id returned by the create method:

_id = super(data_aplikan, self).create(cr, uid, vals, context=context)

(here you can check if call of create was successfull: if not _id: return _id )

-then you can call proses_aplikan as follows:

 self.proses_aplikan(cr, uid, [ _id ] )

OR:

if isinstance( _id, (int,long)):
    _ids = [ _id ]
else:
    _ids = _id

self.proses_aplikan(cr, uid, _ids )


and finally return the saved id:

return _id

Avatar
Discard
Author

Temur, method 'create' don't have parameter 'ids' ... so, i can't use parameter 'ids'

ah, I see.. so you'll need to call it after calling of create() of super class.... let me update the answer

please refer to updated answer

Author

it's work ... thank you very much for your solution ..

Best Answer

try this :

----------------------------------------------------------------------------------------

def create(self, cr, uid, vals, context=None):

obj = self.pool.get('gelombang.pendaftaran').browse(cr, uid, vals['tahun_akademik_id']).name.name.name

seq_name = 'A/{0}'.format(obj)

seq = self.pool.get('ir.sequence')

ids = seq.search(cr, uid, [('name','=',seq_name)])

if not ids:

prefix = seq_name

ids = seq.create(cr, uid, {

                                 'name':seq_name,

                                 'prefix': prefix,

                                 'padding': 4,

                                 'implementation': 'no_gap',

})

vals['name'] = seq.get_id(cr,uid,ids)

res = super(data_aplikan, self).create(cr, uid, vals, context=context)
self.proses_aplikan(cr,uid,res,context=context)

return res

Avatar
Discard
Author

wow extraordinary ... it's work Jeng ... thank you ...