How to get selection field value in RML

620 views Asked by At

I have a selection field and I want to print the selected value but I got the key.

Python code:

'transport': fields.selection([('plain','Plain'),
                               ('train','Train'),
                               ('taxi','Taxi'),
                               ('bus','Bus'), 
                               ('sv','Service vehicle')],'Means of transport'),

RML:

[[ o.transport or '']]

When I select Plain the printed value is plain.

How to get Plain in the printed report instead of plain?

1

There are 1 answers

1
Bhavesh Odedra On

We may achieve in two ways.

  1. Direct condition on .rml and
  2. Using function

Direct condition on .rml

For example:

[[ o.transport == 'avion' and 'Avion' or o.transport == 'train' and 'Train' ]] 

Using function

We need to add function on report .py file

def _get_value_from_selection_field(self, model, field, value):

    selection = self.pool.get(model)._columns.get(field).selection

    res = ''

    for v in selection:

        if v[0] == value:

            res = v[1]

        break

    return res