Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
14040 Lượt xem

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


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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)


Ảnh đại diện
Huỷ bỏ
Tác giả

Exactly what I was looking for

Thank you

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 3 15
3895
2
thg 10 23
970
0
thg 4 24
3502
4
thg 5 19
12382
0
thg 6 21
8270