It is currently Mon May 21, 2012 7:34 pm

All times are UTC + 2 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Display a list from a database
PostPosted: Wed Jul 27, 2011 1:37 pm 
Offline

Joined: Tue Jul 26, 2011 1:58 pm
Posts: 6
Hello,

I have to create a module. In this one, users have to complete two informations, in a menu "fields.selection" : Firstly, they have to complete the department (part of a country). Then, when the department is choosen, the menu "Towns" must display only towns situated in this department. This is the line in my XML file :

Code:
<field name="id_dep" on_change="onchange_departement(id_dep)"/>


And my function "onchange" :

Code:
def onchange_departement(self, cr, uid, ids, id_dep):
        v={}
        list_towns={}
        if id_dep!=False:
            sql="""
                SELECT ville_name
                FROM cpratik_villes
                WHERE dpt_id=%s
            """
            cr.execute(sql, (id_dep,))
            list_towns = cr.fetchall()
            v['id_ville']=list_towns
            return {'value':v}


When I try to execute this code, I see on my selection box only one town, instead of the list of towns in the choosen department.

Does someone know where is the problem and how can I resolve it ? Thank you very much in advance.

Mistycal


Top
 Profile  
 
 Post subject: Re: Display a list from a database
PostPosted: Sat Aug 06, 2011 7:20 am 
Offline

Joined: Mon Jan 10, 2011 11:08 am
Posts: 78
Hi...

Onchange event will certainly fetch you only one value..

You can go for another option... i.e give domain condition in xml file, such that it filters those towns situated in that department....
For Example
Quote:
<field name="partner_id" />
<field name="partner_order_id" domain="[('partner_id','=',partner_id)]"/>

In this Example the partner_order_id will show the list only of those belonging to the partner_id which has been choosen..

Hope this might help u...

Browse those the standard module for more examples...
Hint: Ctrl + H


Top
 Profile  
 
 Post subject: Re: Display a list from a database
PostPosted: Sat Aug 06, 2011 9:24 am 
Offline

Joined: Wed Jan 27, 2010 6:21 pm
Posts: 797
Location: Auckland, NZ
This is kind of similar to the country / state in res.partner.address . Also it may be fields.reference is the more appropriate field type, but check how country / state is handled in base and that may answer your question.

_________________
Graeme


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 2 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:

Protected by Anti-Spam ACP