Skip to Content
Menu
This question has been flagged
2 Replies
13546 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"/>
</record>

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"/>
                </tree>
            </field>
        </record>

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):
            records=self.browse(cr,uid,ids)
            result={}
            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.

Avatar
Discard

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

Author

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

Best Answer

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

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

or

<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!

Avatar
Discard
Author

It dosnt work !!

here a picture of my problem:

[URL=http://www.imagup.com/data/1176824638.html][IMG]http://data.imagup.com/12/1176824638.png[/IMG][/URL]

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

Author

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

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

Author

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

Author

any help !!

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

Please update your question with the code of "_get_concatenate_values"

Did it work?

Author

no !! I have the same problem.

Author

I updated my question

Best Answer

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.

Avatar
Discard

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

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

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

Author

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
Author
  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
=============
Author

can you help me plz ?!

def _get_concatenate_values(self, cr, uid, ids, field_name, arg, context=None):
    records=self.browse(cr,uid,ids)
    result={}
    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.

Author

can anyone help me plz!

Related Posts Replies Views Activity
1
Dec 17
13586
2
Dec 23
22519
1
Mar 15
6224
1
Mar 15
4098
0
Mar 15
3762