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

i have a selection field in my model i want to get string value from that selection field. suppose user select 'A' i want to get 'Apple'.

select_val = fields.Selection([
                        ('A', 'Apple'),
                        ('B', 'Ball')], ... etc


อวตาร
ละทิ้ง

selection_value = dict(self._fields['your_selection_field']._description_selection(self.env))[self.your_selection_field]

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

Hi,

If you want to get the string from selection field follow the steps below

python :-

selection_field = fields.Selection([("1", "One"),("2", "Two"),("3","Three"),],string="Selection")

string_value = dict(self._fields['selection_field'].selection).get(self.selection_field))

In qweb:-

<t t-esc="dict(docs.fields_get(allfields=['selection_field'])['selection_field']['selection'])[docs.selection_field]"/>


Regards

อวตาร
ละทิ้ง

Proper way (at least on v16) seems to be this:

self._fields['state'].convert_to_export(self.state, self)

It handles translation better

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

Hello,
You can create a compute char field [selection_str = fields.Char(compute="comp_str")]

def comp_str (self):        

    self. selection_str = dict(self._fields['select_val']._description_selection(self.env)).get(self.celect_val)

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

Approach #1:
make a global dictionary for converting like:

SELECTION = {'A': 'Apple', ...}

and use SELECTION[obj.select_var] wherever you need the string.

Approach 2#:

selected_string = fields.Char(compute="_compute_string", store=False)

def _compute_string(self):

    for rec in self:

        rec.selected_string = dict(self._fields.get('select_var').selection).get(rec.select_var)


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

Hello Vinoth N,

Please find below code it may help you to resolve this issue,


print dict(self._fields['select_val'].selection).get(self.select_val)

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ส.ค. 23
1256
1
ก.ย. 25
2017
1
มิ.ย. 25
2038
3
ก.ค. 25
3622
1
พ.ค. 25
1750