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

Hi,

I have a field called

name = fields.Char('Serial Number', required=True, translate=True)

By defaultly if i want to enter character it should take upper case..

How can we achieve this in odoo10.0?

Thanku

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello,

you can try this for when enter character it should take upper case.

in XML file.

<field name="name" style="text-transform: uppercase;"/>

after that  upgrade your module and see changes.

อวตาร
ละทิ้ง

this is ok but the value is written in the database as lowercase

You need to add onchange / depends on function in the PY file and operate similarly as @Niyas answer for Save Value in Databse

คำตอบที่ดีที่สุด

Hi,

In the onchange of the corresponding field you can write a function like this.

@api.onchange('field_name')
def set_caps(self):
val = str(self.field_name)
self.field_name = val.upper()

string.upper() will capitalize the entered string

Thanks

อวตาร
ละทิ้ง

Right

คำตอบที่ดีที่สุด

Shouldn't you check if the value if not null (None) before transforming it?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello Kundan,

You can use onchange method to capitalize your field (Permanent Change)

In above image i have shown

customer is the field name that you want to capitalize, and you need not to check whether field is empty or not because empty field won't show any difference

Hope this will be helpful for you

อวตาร
ละทิ้ง