Domain restriction doesn't work with selection widget

Asked by R. Messier on 2009-11-27

When defining a selection widget with values from a table, domain restrictions doesn't seem to work.

Question information

Language:
English Edit question
Status:
Answered
For:
Odoo GTK Client (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) said :
#1

Would you please provide us information what do you do exactly?

Does Selection widget have any method ?
Or
Its manyone with widget="selection" ?

Thank you.

Revision history for this message
R. Messier (raphaelmessier) said :
#2

Hi Jay,

I use a many2one field with a 'widget="selection" attribute in the XML view
definition. Then any domain restriction won't be applied in neither of the two
following cases:

CASE 1

PY model definition:
'country_id': field.many2one('res.country', 'Country'),
'state_id': field.many2one('res.country.state', 'State',
domain="[('country_id','=',country_id)]"),

XML view definition:
<field name="country_id" widget="selection" />
<field name="state_id" widget="selection" />

CASE 2

PY model definition:
'country_id': field.many2one('res.country', 'Country'),
'state_id': field.many2one('res.country.state', 'State'),

XML view definition:
<field name="country_id" widget="selection" />
<field name="state_id" widget="selection"
domain="[('country_id','=',country_id)]" />

In both cases, everything works fine if I remove 'widget="selection"' from
<field name="state_id" .../> (but it doesn't have the final look that I want).

Tell me if you need more information.

Regards,
Raphaël

Quoting "Jay \\(Open ERP\\)" <email address hidden>:

> Would you please provide us information what do you do exactly?
>
> Does Selection widget have any method ?
> Or
> Its manyone with widget="selection" ?
>
> Thank you.
>
> ** Changed in: openobject-client
> Status: New => Incomplete
>
> --
> Domain restriction doesn't work with selection widget
> https://bugs.launchpad.net/bugs/489308
> You received this bug notification because you are a direct subscriber
> of the bug.
>
> Status in OpenObject Application Client - GTK: Incomplete
>
> Bug description:
> As of v5.0.6 on Ubuntu 8.10
>
> When defining a selection widget with values from a table, domain
> restrictions doesn't work.
>
> To unsubscribe from this bug, go to:
> https://bugs.launchpad.net/openobject-client/+bug/489308/+subscribe
>

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) said :
#3

Hello I confirm this bug, that's annoying because we had to use one2many
widget at several places where the select widget would have make much more
sense.
Nothing like an urgent regression, however, would be very nice to be able to
use the widget selection more often...

On Thu, Dec 10, 2009 at 4:17 PM, R. Messier <email address hidden> wrote:

> Hi Jay,
>
> I use a many2one field with a 'widget="selection" attribute in the XML view
> definition. Then any domain restriction won't be applied in neither of the
> two
> following cases:
>
> CASE 1
>
> PY model definition:
> 'country_id': field.many2one('res.country', 'Country'),
> 'state_id': field.many2one('res.country.state', 'State',
> domain="[('country_id','=',country_id)]"),
>
> XML view definition:
> <field name="country_id" widget="selection" />
> <field name="state_id" widget="selection" />
>
>
> CASE 2
>
> PY model definition:
> 'country_id': field.many2one('res.country', 'Country'),
> 'state_id': field.many2one('res.country.state', 'State'),
>
> XML view definition:
> <field name="country_id" widget="selection" />
> <field name="state_id" widget="selection"
> domain="[('country_id','=',country_id)]" />
>
> In both cases, everything works fine if I remove 'widget="selection"' from
> <field name="state_id" .../> (but it doesn't have the final look that I
> want).
>
> Tell me if you need more information.
>
> Regards,
> Raphaël
>
>
> Quoting "Jay \\(Open ERP\\)" <email address hidden>:
>
> > Would you please provide us information what do you do exactly?
> >
> > Does Selection widget have any method ?
> > Or
> > Its manyone with widget="selection" ?
> >
> > Thank you.
> >
> > ** Changed in: openobject-client
> > Status: New => Incomplete
> >
> > --
> > Domain restriction doesn't work with selection widget
> > https://bugs.launchpad.net/bugs/489308
> > You received this bug notification because you are a direct subscriber
> > of the bug.
> >
> > Status in OpenObject Application Client - GTK: Incomplete
> >
> > Bug description:
> > As of v5.0.6 on Ubuntu 8.10
> >
> > When defining a selection widget with values from a table, domain
> > restrictions doesn't work.
> >
> > To unsubscribe from this bug, go to:
> > https://bugs.launchpad.net/openobject-client/+bug/489308/+subscribe
> >
>
>
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
> --
> Domain restriction doesn't work with selection widget
> https://bugs.launchpad.net/bugs/489308
> You received this bug notification because you are a member of OpenERP
> Drivers, which is subscribed to OpenObject Application Client.
>
> Status in OpenObject Application Client - GTK: Incomplete
>
> Bug description:
> As of v5.0.6 on Ubuntu 8.10
>
> When defining a selection widget with values from a table, domain
> restrictions doesn't work.
>
>
>

Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) said :
#4

Hello Raphaël [Addressing both of you :)],

Its a problem of widget="selection" for many2one. I confirm the issue. That's why I asked whether field is selection or M2O.

Thank you.

Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) said :
#5

By the way, when I said "we had to use one2many widgets" I actually meant "we
had to use many2one widgets" of course, sorry for the confusion.

On Thu, Dec 17, 2009 at 5:17 AM, Jay (Open ERP) <email address hidden> wrote:

> Hello Raphaël [Addressing both of you :)],
>
> Its a problem of widget="selection" for many2one. I confirm the issue.
> That's why I asked whether field is selection or M2O.
>
> Thank you.
>
> ** Changed in: openobject-client
> Status: Incomplete => Confirmed
>
> --
> Domain restriction doesn't work with selection widget
> https://bugs.launchpad.net/bugs/489308
> You received this bug notification because you are a member of OpenERP
> Drivers, which is subscribed to OpenObject Application Client.
>
> Status in OpenObject Application Client - GTK: Confirmed
>
> Bug description:
> As of v5.0.6 on Ubuntu 8.10
>
> When defining a selection widget with values from a table, domain
> restrictions doesn't work.
>
>
>

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) said :
#6

Hello Raphaël,

This is not a bug (but probably a undocumented feature), so I will convert it to a question, if Launchpad allows me... and then provide the answer to the question :-)

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) said :
#7

Note: this is normally a question for the framework/server, but since it was reported here, I'm leaving it in the GTK project.

[ Short answer ]
Selection widgets are pre-filtered server-side, and are not meant for dynamic domains, so this will not work and is not a bug.
This is a limitation of all OpenERP version so far (including 6.0), due to semantics of the fields.selection column type.

[ Longer answer ]
On m2o fields, you may specify 3 kinds of domains:
  - string domains at the model (python) level
  - string domains in the XML view
  - literal domains (python lists, not enclosed in quotes) at the model (python) level
Of course at the model level you may only specify one: either a literal OR a string domain, but it can be combined with an XML-level domain.

Literal domains are applied at the server-side when reading data and must be static (no references to dynamic field values, the user or time, etc.). String domains are applied at the client-side and may refer to dynamic data such as other fields values (as in your example).

Now, because selection widgets are pre-filtered at server-side (they must behave like real fields.selection), only the literal domain form is available. As a result, you should not use dynamic string domains for selection widgets, they are really meant for use a static lists of a few values, like a regular field.selection.

FYI, here is an example of what I meant by "literal domain" at model level:

   'country_id': field.many2one('res.country', 'Country'),
   'state_id': field.many2one('res.country.state', 'State',
                                             domain=[('country_id','=', 'France')]), # must be static!

Revision history for this message
Fordy (fordy) said :
#8

Hello,

Is there any update regarding this issue from last 5 Month ?

Or same issue also currently ?

Waiting for experts reply.

Revision history for this message
Naresh(OpenERP) (nch-openerp) said :
#9

Hello Fordy,

We had made a lot of improvements for the widget=selection. here the merge proposals are
https://code.launchpad.net/~openerp-dev/openobject-client/trunk-m2o_with_selection-rga/+merge/58245
https://code.launchpad.net/~openerp-dev/openobject-server/trunk-M2O_with_selection-rga/+merge/53392

can you merge and test your case with it.

waiting for your feedback !

Thanks

Revision history for this message
Fordy (fordy) said :
#10

Hello Naresh thanks for your quick reply !

I will test with this branch and if it works for my case I will thank a lot to your team !

Revision history for this message
Naresh(OpenERP) (nch-openerp) said :
#11

one more thing I needed to add is that after applying the merge the selection field will not prefetch the data it will only get the data once you enter some value in the widget and press the "v" button next to it.

Revision history for this message
Fordy (fordy) said :
#12

thanks for help !

On 5 May 2011 18:02, Naresh(OpenERP)
<email address hidden>wrote:

> Question #135048 on OpenERP GTK Client changed:
> https://answers.launchpad.net/openobject-client/+question/135048
>
> Naresh(OpenERP) posted a new comment:
> one more thing I needed to add is that after applying the merge the
> selection field will not prefetch the data it will only get the data
> once you enter some value in the widget and press the "v" button next
> to it.
>
> --
> You received this question notification because you are a direct
> subscriber of the question.
>

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) said :
#13

Hello,

I'm just facing the same issue. I think we really need this filter for selection widget.

Selection is useful and user friendly when you have few choices.
So being able to use a dynamic domain would be a good option.

Any update in this topic ? Merges seems stalled

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) said :
#14

In crm leads, here are some exemple in which the dynamic filtering would be useful for o2m selection widget as we cannot filter categories using the section :

--------------------- crm/crm_lead_view.xml ---------------------------

<!-- CRM Lead Form View -->
@lines 51-53
<field name="categ_id"
       widget="selection"
       domain="[('object_id.model','=','crm.lead')]"/>

<!-- CRM Lead Search View -->
@lines 335
<field name="categ_id" widget="selection" domain="[('object_id.model', '=', 'crm.lead')]"/>

---------------- crm/crm_opportunity_view.xml -----------------------

<!-- Opportunities Form View -->
@lines 83-85
<field name="categ_id" select="1"
       string="Category" widget="selection"
       domain="[('object_id.model', '=', 'crm.lead')]" />

<!-- Opportunities Search View -->
@lines 325
<field name="categ_id" widget="selection" domain="[('object_id.model', '=', 'crm.lead')]"/>

Can you help with this problem?

Provide an answer of your own, or ask R. Messier for more information if necessary.

To post a message you must log in.