how to access the text of a functional field ?

Asked by Ferdinand on 2010-04-18

     _columns = {
       'activity' : fields.selection([
                              ('dehumidify','Dehumidify'),
                              ('restore','Restore'),
....

     def onchange_product_id_activity(self, cr, uid, ids,product_id,activity):
        if not product_id:
            return {}
        product = self.pool.get('product.product').browse(cr, uid, [product_id])[0]
        result = {
            'name' : activity,

name should be filled with the String associated with the filed value
Example
currently "dehumidify" is copied to name but "Dehumidify" should be copied.

Question information

Language:
English Edit question
Status:
Answered
For:
OpenERP Server Edit question
Assignee:
No assignee Edit question
Last query:
2010-04-18
Last reply:
2010-04-19

A temporary workaround (cleanest as far as i Know) we use in our code is:

ACTIVITY_SELECTION = {'dehumidify':'Dehumidify', 'restore':'Restore'}

 _columns = {
       'activity' : fields.selection([(k,v) for k,v in ACTIVITY_SELECTION.items()]
....

     def onchange_product_id_activity(self, cr, uid, ids,product_id,activity):
        if not product_id:
            return {}
        product = self.pool.get('product.product').browse(cr, uid, [product_id])[0]
        result = {
            'name' : ACTIVITY_SELECTION.get(activity),

xrg (xrg) said : #2

On Sunday 18 April 2010, you wrote:
> New question #107767 on OpenObject Server:
> https://answers.launchpad.net/openobject-server/+question/107767
>
> _columns = {
> 'activity' : fields.selection([
> ('dehumidify','Dehumidify'),
> ('restore','Restore'),

Try to define the tuples of selection into a different variable, and then use
that to dereference the value of the field:

 _activity_values = [ ('dehumidify','Dehumidify'), ('restore','Restore'),]

_columns = 'activity': fields.selection(_activity_values, ...)

and then use _activity_values to retrieve the text.

Ferdinand (office-chricar) said : #3

thanks -
I went for Sharoons solution

BTW I had to use
'name' : <class_name>.ACTIVITY_SELECTION.get(activity),

Next issue: How to get these values translated ?
Neither Sharoons nor xrg suggestion gives the possibility to translate

You could search in ir.translation object. See in addons/base/ir/ir_translation.py file this method:

    def _get_source(self, cr, uid, name, tt, lang, source=None):

Ferdinand (office-chricar) said : #5

Hmm,
 this will probably help, once the data are entered there "manually" "

OpenERP seems not to support this in the current translation mechanism?

xrg (xrg) said : #6

On Sunday 18 April 2010, you wrote:
> Question #107767 on OpenObject Server changed:
> https://answers.launchpad.net/openobject-server/+question/107767
>
> Status: Answered => Open
>
> Ferdinand @ ChriCar is still having a problem:
> thanks -
> I went for Sharoons solution
>
> BTW I had to use
> 'name' : <class_name>.ACTIVITY_SELECTION.get(activity),
>
> Next issue: How to get these values translated ?
> Neither Sharoons nor xrg suggestion gives the possibility to translate
>

from tools.misc import UpdateableStr, UpdateableDict

_some_global_var = { 'key': UpdateableStr( _("English text") ) }

I think something like that could work..

Ferdinand (office-chricar) said : #7

Hmm, did't find out how to write this

Can you help with this problem?

Provide an answer of your own, or ask Ferdinand for more information if necessary.

To post a message you must log in.