跳至內容
選單
此問題已被標幟
1 回覆
5468 瀏覽次數

I have a class:

class activeuser(osv.osv):

_name = activeuser

_columns = {

'name':fields.char('Name', size=128),

'description_about':fields.text('About Name'),

}

activeuser()

I want get every word of 'name' field into new fields that I will create, lets say:

'first_word'

'second_word'

'third_word'

'fourth_word'

How to do that?

頭像
捨棄

Can Create Three fields First Name, Last Name, Middle Name in the fourth fields Complete Name con-cat all the three fields using Functional Fields or on_change event

作者

can you explain more spesific?

最佳答案

Code:

overridden Create and Write Method

class activeuser(osv.osv):
_name = activeuser
_columns = {
'first_name':fields.char('First Name', size=128),
'middle_name':fields.char('Middle Name', size=128),
'last_name':fields.char('Last Name', size=128),
'name':fields.char('Full Name', size=128),
'description_about':fields.text('About Name'),
}
activeuser

    def create(self, cr, user, vals, context=None):
        vals['full_name'] = vals['first_name'] + ' ' + str(vals['middle_name'] or '') + ' ' + vals['last_name']
        return super(activeuser,self).create(cr, user, vals, context)

    def write(self, cr, user, ids, vals, context=None):
        for res in self.browse(cr,user,ids):
            print "name"
        if not 'first_name' in vals:   
            vals['first_name'] =  res.first_name
        if not 'middle_name' in vals:       
            vals['middle_name'] =  res.middle_name
        if not 'last_name' in vals:           
            vals['last_name'] =  res.last_name
        vals['full_name'] = vals['first_name'] + ' ' + str(vals['middle_name'] or '') + ' ' + vals['last_name']
        return super(activeuser,self).write(cr, user, ids, vals, context)
頭像
捨棄
作者

ok, thanks in advance, I'll try first, how to apply it in on_change method?

相關帖文 回覆 瀏覽次數 活動
3
8月 19
7960
0
6月 15
3143
2
8月 24
2385
1
3月 15
4151
0
3月 15
3727