Odoo Help


field.function in tree view

on 3/1/13, 12:26 PM 6,362 views

hi !

I have in my new module a functional field, whene i put it in my tree view i can't open my view.

here the action code :

    <record id="my_module_normal_action" model="ir.actions.act_window">
    <field name="name">My module</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">mymodule</field>
<field name="domain">[('my_field','=',True)]</field>
    <field name="view_type">form</field>
    <field name="view_id" ref="my_module_tree_view"/>
    <field name="search_view_id" ref="my_module_search_form_view"/>

my code xml :

<record id="my_module_tree_view" model="ir.ui.view">
            <field name="name">my.module.tree</field>
            <field name="model">mymodule</field>
            <field name="type">tree</field>
            <field eval="7" name="priority"/>
            <field name="arch" type="xml">
                <tree string="my module">
                   <field name="my_string"/>
            <field name="my_field"/>

in my python code :

  'my_field': fields.function(_get_concatenate_values, method=True, string='Reference', type='char'),

this is the function's code :

def _get_concatenate_values(self, cr, uid, ids, field_name, arg, context=None):
            for r in records:
                if(r.field1 and r.field2):
                    result[r.id]= str(r.field1.name)+'.'+ str(r.field2.name)
                return result

"my_field"'s value is the concatenation of the two fields :field1 and field2

thanks for your reply.

What version of OpenERP are you using? Your field is called 'code' but you use 'my_string' and 'my_module' in the view?

Andreas Brueckl
on 3/1/13, 12:46 PM

I use V6.0.2 , my feild's name is 'my_field', 'my_sring' is an other field in my module. so I rectify the python code : 'my_field': fields.function(_get_concatenate_values, method=True, string='Reference', type='char'),

on 3/1/13, 1:25 PM



| 5 4 7
Buenos Aires, Argentina
Karma will give me a place in heaven!
On 3/1/13, 12:54 PM

In the definition of the action, you need to add:

<field name="view_mode">tree,form</field>


<field name="view_mode">form,tree</field>

depending in the order you want the views to be accessed.

(Or maybe just <field name="view_mode">tree</field> if you do not have a form view.)

I think the problem is in your domain statement in the definition of the action!

<field name="domain">[('my_field','=',True)]</field>

I think you are trying to say that it is not empty, but this restriction is satisfied only if the field has the boolean value True. Change it to:

 <field name="domain">[('my_field','&lt;&gt',False)]</field>

This means that is different to False that, I think, is more acccurate.

Hope it helps!

It dosnt work !!

here a picture of my problem:


I have 3 rows but invisible, when I delete the line <field name="my_field"/> from the tree code it works and I have my liste

on 3/1/13, 1:35 PM

link to the picture : http://www.imagup.com/data/1176824638.html

on 3/1/13, 1:46 PM

Without the 'my_field' field it works just fine? What's the message error you are getting?

on 3/1/13, 2:01 PM

yes without 'my_fiels' it works fine, i have no msg error, i can't see my data?

on 3/3/13, 5:52 PM

any help !!

on 3/4/13, 9:41 AM

I updated my answer, maybe that is the problem! I do not see any other possibility of change!

on 3/4/13, 10:51 AM

Please update your question with the code of "_get_concatenate_values"

Andreas Brueckl
on 3/4/13, 11:01 AM

Did it work?

on 3/4/13, 11:55 AM

no !! I have the same problem.

on 3/4/13, 1:23 PM

I updated my question

on 3/5/13, 5:33 AM
Tony Gu
On 3/4/13, 11:46 AM

You defined a domain in act_window based on the function field 'my_field', while you didn't define a "fnct_search" search method for that function field.

Update: Another option would be to add store=True to the function field.

As far as I know, store=True will be used for the value of the field to be stored in the database. But, is this necessary to just show it in a tree view and filter the domain? I think it is not, but then again, I am not sure

on 3/4/13, 1:19 PM

For the domain filter only, the store flag is not required. Only if you want to use in the SearchView.

Andreas Brueckl
on 3/4/13, 2:09 PM

Yes, in that case, I see what you are saying! Thanks!

on 3/4/13, 2:25 PM

I added "store=True" to my function field but during the installation of the module I get this error :

Traceback (most recent call last):
  File "netsvc.pyo", line 489, in dispatch
  File "service\web_services.pyo", line 599, in dispatch
  File "osv\osv.pyo", line 122, in wrapper
  File "osv\osv.pyo", line 176, in execute
  File "osv\osv.pyo", line 167, in execute_cr
  File "C:\Program Files\OpenERP 6.0\Server\addons\base\module\wizard\base_module_upgrade.py", line 98, in upgrade_module
  File "pooler.pyo", line 60, in restart_pool
on 3/5/13, 6:13 AM
  File "pooler.pyo", line 39, in get_db_and_pool
  File "addons\__init__.pyo", line 883, in load_modules
  File "addons\__init__.pyo", line 719, in load_module_graph
  File "addons\__init__.pyo", line 414, in init_module_objects
  File "osv\orm.pyo", line 2651, in _auto_init
  File "osv\orm.pyo", line 378, in get_pg_type
TypeError: int argument required
on 3/5/13, 6:14 AM

can you help me plz ?!

on 3/6/13, 5:17 AM
def _get_concatenate_values(self, cr, uid, ids, field_name, arg, context=None):
    for r in records:
        if(r.field1 and r.field2):
            result[r.id]= str(r.field1.name)+'.'+ str(r.field2.name)
        #return result
    return result

I think there is a problem of you return value.

on 3/7/13, 10:06 AM

can anyone help me plz!

on 3/7/13, 12:49 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 3/1/13, 12:26 PM
Seen: 6362 times
Last updated: 3/16/15, 8:10 AM