← Back to team overview

credativ team mailing list archive

[Bug 695089] Re: domain is not working with widget="selection"

 

For the record, closing this bug report for trunk because it's not a
bug, it's a problem of understanding how domains and selection widgets
work:

1. Selection widgets (for selection fields or m2o fields with
widget=selection) cannot have dynamic domains at all. Their values are
statically determined by the server when the view is opened (when
fields_view_get is called), and the domain is evaluated at that moment,
so it cannot be dynamic.

2. What is a dynamic vs a static domain? When defining a m2o domain at the model level (domain parameter for the fields.many2one constructor), the domain can be passed as a string or as a Python list. When passing as a Python list, the domain is STATIC (it's constructed with only literals) and can be evaluated server-side, specifically to initialize the possible values if widget=selection is used.
When passed as a string, the domain is DYNAMIC and never evaluated server-side because it can contain field names to represent the value of other fields in the view (not only literals), so it is meant to be evaluated on client-side.
For the case of a m2o with widget=selection, the domain should ALWAYS be passed as a Python list (STATIC), because dynamic domains are not supported, so giving a string (client-side) domain will be IGNORED.

I hope this makes things very clear. And to be 100% sure, let's take an example: imagine I make a m2o field to select a Partner, that I would like to display as a selection widget that only allows selecting Customers, not Suppliers.
I could write 3 versions, but only the first one will do what I want:

A.
 at model level:
     'partner_id': fields.many2one('res.partner', 'Customer', domain=[('customer', '=', True)])
 at view level:
   <field name="partner_id" widget="selection"/>
=> GOOD!

B.
 at model level:
     'partner_id': fields.many2one('res.partner', 'Customer', domain="[('customer', '=', True)]")
 at view level:
   <field name="partner_id" widget="selection"/>
=> BAD - notice that domain is a string! - this will NOT work! (as explained above)

C.
 at model level:
     'partner_id': fields.many2one('res.partner', 'Customer')
 at view level:
   <field name="partner_id" widget="selection" domain="[('customer', '=', True)]"/>
=> BAD too - it is equivalent to the previous one

Let me repeat: the reason why B and C will not work is because they are using a client-side DYNAMIC domains, which is not supported for selection widgets (m2o or selection fields). A dynamic client-side domain is sometimes useful for normal m2o fields (widget=many2one) to do something like:
   <field name="partner_id" domain="[('category_id', '=', category_id)]"/>
This allows selecting a partner from the category selected in the other "category_id" field in the form view. As this depends on the dynamic value of a client-side field, it cannot be supported by the server-side when the view is initially opened. That is why dynamic domains are simply ignored for selection widgets.

If this is still not clear, please read again the examples or have a
look at the ORM code until you fully understand :-)

** Changed in: openobject-server/trunk
       Status: Confirmed => Won't Fix

** Changed in: openobject-server/trunk
     Assignee: OpenERP's Framework R&D (openerp-dev-framework) => (unassigned)

** Changed in: openobject-server
     Assignee: OpenERP's Framework R&D (openerp-dev-framework) => (unassigned)

** Changed in: openobject-client/trunk
       Status: Invalid => Won't Fix

** No longer affects: openobject-server/5.0

** No longer affects: openobject-client/5.0

** No longer affects: openobject-client/trunk

** No longer affects: openobject-server/trunk

-- 
You received this bug notification because you are a member of OpenERP
Framework Experts, which is subscribed to OpenERP Server.
https://bugs.launchpad.net/bugs/695089

Title:
  domain is not working with widget="selection"

Status in OpenERP Server:
  Won't Fix

Bug description:
  I get a M2O field:
   'myfield_id': fields.many2one('object', 'Field', domain="['type','=','foo']"),
   in view get <field name="myfield_id" widget="selection"/>

  The selection widget dont restrict the data, remove the
  widget="selection" domain works fine.

  Regards,

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-server/+bug/695089/+subscriptions