Get value from selection field - Nereid Transation filter (translate selected fields)

101 views
Skip to first unread message

Raimon Esteve

unread,
Oct 17, 2013, 3:30:48 AM10/17/13
to tryto...@googlegroups.com
Hello dev,

I'm working a translation filter in Nereid (1). First I develop how to
get a value from selection field but "key,value" from selection field
not always coincide to find in ir.translation

Example:

>>> print invoice.type
>>> in_invoice

In this case print key from option selection field, but I like to
print value option selection field: Supplier Invoice

>>> print invoice.type
>>> Supplier Invoice

Could somebody how to get value from option selection field and not
key? (I think is Transaction is other language -not English-, I get
value option translated field)

Example:

>>> print invoice.type
>>> Factura de client

(1) https://github.com/raimonesteve/nereid/commit/c2e11ef4ad8e0b0e03e27681574aa4720a8ddebc

Raimon

Cédric Krier

unread,
Oct 17, 2013, 4:29:57 AM10/17/13
to tryto...@googlegroups.com
On 17/10/13 09:30 +0200, Raimon Esteve wrote:
> Hello dev,
>
> I'm working a translation filter in Nereid (1). First I develop how to
> get a value from selection field but "key,value" from selection field
> not always coincide to find in ir.translation
>
> Example:
>
> >>> print invoice.type
> >>> in_invoice
>
> In this case print key from option selection field, but I like to
> print value option selection field: Supplier Invoice
>
> >>> print invoice.type
> >>> Supplier Invoice
>
> Could somebody how to get value from option selection field and not
> key? (I think is Transaction is other language -not English-, I get
> value option translated field)

For static view, you just have to do like in report, put the string in
the view and let the translation view mechanism working.
If you want to display a field than you have to use the Model.fields_get

--
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email/Jabber: cedric...@b2ck.com
Website: http://www.b2ck.com/

Sharoon Thomas

unread,
Oct 17, 2013, 4:33:34 AM10/17/13
to tryto...@googlegroups.com
On Oct 17, 2013, at 1:00 PM, Raimon Esteve <res...@zikzakmedia.com> wrote:

> Hello dev,
>
> I'm working a translation filter in Nereid (1). First I develop how to
> get a value from selection field but "key,value" from selection field
> not always coincide to find in ir.translation

Raimon,

fields.Selection allows for translation [1]. So getting the value and displaying it should
work straight depending on the language in the context.

However, I am not sure of how to get the translated selection options. If you find a way
I think we could build a custom SelectField based on WtForms select field which handles
the selection options with translation automatically.


[1] https://github.com/tryton/trytond/blob/develop/trytond/model/fields/selection.py#L17

Thanks & Regards


Sharoon Thomas
Openlabs Technologies & Consulting (P) Limited

w: http://www.openlabs.co.in
m: +1 813.793.6736 (OPEN) Extn. 200
t: @sharoonthomas

- We win when our customers win
signature.asc

Raimon Esteve

unread,
Oct 17, 2013, 5:26:15 AM10/17/13
to tryto...@googlegroups.com
> If you want to display a field than you have to use the Model.fields_get

Great! I think I have this feature. Thanks

Raimon Esteve

unread,
Oct 17, 2013, 5:46:33 AM10/17/13
to tryto...@googlegroups.com
2013/10/17 Sharoon Thomas <sharoon...@openlabs.co.in>:
> fields.Selection allows for translation [1]. So getting the value and displaying it should
> work straight depending on the language in the context.
>
> However, I am not sure of how to get the translated selection options. If you find a way
> I think we could build a custom SelectField based on WtForms select field which handles
> the selection options with translation automatically.

Ups! I think is more complex use WtForms, not?

I improve this feature use fields_get (1). I like it because not need
to translate this values in template - Get translation value from
Transaction language (remember is pending fix (2) )

Thanks

(1) https://github.com/openlabs/nereid/pull/101#issuecomment-26490940
(2) https://github.com/openlabs/nereid/pull/100
Reply all
Reply to author
Forward
0 new messages