It is currently Sat Feb 11, 2012 10:42 am

All times are UTC + 2 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: is possible that many2one fields act as selection?
PostPosted: Mon Aug 20, 2007 1:00 pm 
Offline

Joined: Fri Jul 13, 2007 9:19 am
Posts: 82
Location: Girona
Hi,
I'm trying to do that a many2one field act as a selection field only in the view mode, in the database I want to maintain the relation.

I've tried to do <field name="my_field" widget="selection" /> but, the client raises this error:

File "/home/under/Projectes/TinyERP/tinyerp-client-4.2.0-rc1/bin/widget/model/field.py", line 137, in set
if value in [sel[0] for sel in self.attrs['selection']]:
KeyError: 'selection'

that means in the xml view there are not attribute selection, The possible values must be taken from the relation object.


Top
 Profile  
 
 Post subject: SOLVED
PostPosted: Mon Aug 20, 2007 1:18 pm 
Offline

Joined: Fri Jul 13, 2007 9:19 am
Posts: 82
Location: Girona
in the definition of the model do:
Code:
'my_field': fields.many2one('mymodule.relation.model', 'Title', selection=_sel_func),


And then define the _sel_func like this (before the fields definitons):

Code:
def _sel_func(self, cr, uid, context={}):
    obj = self.pool.get('mymodule.relation.model')
    ids = obj.search(cr, uid, [])
    res = obj.read(cr, uid, ids, ['name', 'id'], context)
    res = [(r['id'], r['name']) for r in res]
    return res

That's all! :)


Top
 Profile  
 
 Post subject: Re: is possible that many2one fields act as selection?
PostPosted: Fri Feb 27, 2009 8:59 pm 
Offline

Joined: Sat Jun 28, 2008 2:04 pm
Posts: 24
In version 5 (maybe before) this works simply adding a widget="selection" in the xml arch.

In the model columns:
Code:
'my_field': fields.many2one('mymodule.relation.model', 'Title',),


In the xml arch:
Code:
<field name="my_field" widget="selection" />


Gabriel C. Stabel


Top
 Profile  
 
 Post subject: Re: is possible that many2one fields act as selection?
PostPosted: Tue Mar 03, 2009 7:09 am 
Offline

Joined: Wed Jun 27, 2007 8:21 am
Posts: 54
Location: Kerala, India
gstabel wrote:
In version 5 (maybe before) this works simply adding a widget="selection" in the xml arch.

In the model columns:
Code:
'my_field': fields.many2one('mymodule.relation.model', 'Title',),


In the xml arch:
Code:
<field>


Gabriel C. Stabel


Thats Good :) But I could not see that used anywhere in base OpenERP. Is that widget it officially supported? Its not working on OpenERP Web :(

_________________
Sinoj Sebastian
www.zbeanztech.com
http://g.ho.st/?referral=sinoj


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 03, 2009 7:10 am 
Offline

Joined: Wed Jun 27, 2007 8:21 am
Posts: 54
Location: Kerala, India
@ gstabel
Do you know about any other hidden features on OpneERP? :wink:

_________________
Sinoj Sebastian
www.zbeanztech.com
http://g.ho.st/?referral=sinoj


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 19, 2010 12:24 pm 
Offline

Joined: Fri Oct 16, 2009 12:06 pm
Posts: 95
Location: France
Hi,
The trick given by gstabel is working well on both web/gtk client. But the "official" way from the doc, given by ecarreras doesn't give a selection. Why ??? :shock:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 19, 2010 6:17 pm 
Offline

Joined: Fri Oct 16, 2009 12:06 pm
Posts: 95
Location: France
One question : How can we choose the attribute which the selection operates on ? It works with a "name" attribute, but not anymore if I change "name" by "motive" (by example).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 24, 2010 1:11 pm 
Offline

Joined: Fri Oct 16, 2009 12:06 pm
Posts: 95
Location: France
And one more :wink:
It seems that the domain filter (into the code) is no longer used if there is a widget="selection" on the attribute. Any idea ?
Thx


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2010 7:01 pm 
Offline

Joined: Fri Oct 16, 2009 12:06 pm
Posts: 95
Location: France
rpitorre wrote:
One question : How can we choose the attribute which the selection operates on ? It works with a "name" attribute, but not anymore if I change "name" by "motive" (by example).

I discovered _rec_name...

rpitorre wrote:
And one more :wink:
It seems that the domain filter (into the code) is no longer used if there is a widget="selection" on the attribute. Any idea ?
Thx

Fixed in 5.0.7 :roll:


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 07, 2010 1:34 pm 
Offline

Joined: Sat Jan 02, 2010 10:14 pm
Posts: 3
rpitorre wrote:
And one more :wink:
It seems that the domain filter (into the code) is no longer used if there is a widget="selection" on the attribute. Any idea ?
Thx

Fixed in 5.0.7 :roll:[/quote]

I always have the problem in 5.0.7.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2010 10:43 am 
Offline

Joined: Fri Oct 16, 2009 12:06 pm
Posts: 95
Location: France
Me too! I saw that the bug was fixed here, but it seems it's not working at all. The domain (in .xml or .py) doesn't filter the search with widget="selection".


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 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