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

How to get selection value translated in python code

_name = 'pos.session'

POS_SESSION_STATE = [
    ('opening_control', 'Opening Control'),
    ('opened', 'In Progress'),
    ('closing_control', 'Closing Control'),
    ('closed', 'Closed & Posted'),
]

state = fields.Selection(
    POS_SESSION_STATE, string='Status',
    required=True, readonly=True,
    index=True, copy=False, default='opening_control')

When I do a print in python code the state value returns me translated as the qweb reports


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

Hi David,

If you want to get the translation of the value, you could try something like this:

dict(self._fields['state']._description_selection(self.env)).get(self.state)


อวตาร
ละทิ้ง
ผู้เขียน

Exactly what I was looking for

Thank you

Related Posts ตอบกลับ มุมมอง กิจกรรม
0
มี.ค. 15
3937
2
ต.ค. 23
992
0
เม.ย. 24
3558
4
พ.ค. 19
12417
0
มิ.ย. 21
8344