Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
5302 มุมมอง

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

อวตาร
ละทิ้ง