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

class hotel_account(osv.osv):
    
    _name='hotel.account'
    
    _columns={
              'account_name': fields.char('Account Name',required=True),

}

def create(self, cr, uid, vals, context=None):
         for record in self.browse(cr,uid,vals,context=context):
             lower = record.account_name
             value=lower.upper()
             vals.update({'account_name':value})
             return super(hotel_account,self).create(cr,uid,vals,context=context)

頭像
捨棄
最佳答案

Yes Libu, Ludo is right.

for you case you should write your create method as below.

def create(self, cr, uid, vals, context=None):
         if vals.get('account_name', False):
             lower = vals.get('account_name', False)
             value=lower.upper()
             vals.update({'account_name':value})
         return super(hotel_account,self).create(cr,uid,vals,context=context)

 

頭像
捨棄
作者

Hi Ajay ,Thanks for your valuable replay..

最佳答案

You are using a self browse in a create, trying to go over all existing records when creating a new record and you are using "vals" when browsing as the ids. This does not make sense to me?

Anyway, the result of that browse will most likely by an empty list and a Nonetype actually has no account_name :)

頭像
捨棄
最佳答案

Actualy, Ludo gave half precise answer :) 
that self.browse method will do apsolutly nothing, you did not send ids to it so it will always return null... 

when you are createing record, you are apssing a lis of values (vals) in dictionaly form {'key':value}
now if you need uppercase name saved... 
probably the easiest way is to remove complete browse  part and instead just update vals:
vals['account_name'] = vals['account_name'] and vals['account_name'].upper or False
and then return super call to create......
also might be useful to think about write method.. (and converting to upper while writing...not only on create) 

hope it helps ..

頭像
捨棄