how to access the text of a functional field ?

Asked by Ferdinand

     _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:
Odoo Server (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Sharoon Thomas http://openlabs.co.in (sharoonthomas) said :
#1

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),

Revision history for this message
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.

Revision history for this message
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

Revision history for this message
Jordi Esteve (www.zikzakmedia.com) (jesteve-zikzakmedia) said :
#4

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):

Revision history for this message
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?

Revision history for this message
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..

Revision history for this message
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.