跳至内容
菜单
此问题已终结
5 回复
4089 查看

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 ...

形象
丢弃
最佳答案

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

形象
丢弃
编写者

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

编写者

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

最佳答案

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

形象
丢弃
编写者

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