コンテンツへスキップ
メニュー
この質問にフラグが付けられました
3 返信
5314 ビュー

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

アバター
破棄