[FIX] m2o fields with selection widget in search view

Plan was originally to just ignore this because "it should just work"
 but turns out m2o and m2o[@widget=selection] fields have very
 different behaviors when it comes to default values, especially
 custom domains and contexts:

 * An m2o field uses its string value always (behaves like a char
   field), for UI and clarity purposes we added an [[name, '=', id]]
   case when the user specifically selects an autocompletion value,
   but that's not "cannon", when it comes to dealing with custom
   domains (filter_domain) and contexts the field always uses its
   string value.

* An m2o[@widget=selection] field on the other hand uses its ids
  always (behaves like a selection field).

  That's not entirely true, really, because it has the converse to
  what we implemented on the m2o field in the web client (in the GTK
  client): if there is no @filter_domain *and* the user has entered a
  value which is not in the dropdown (it's a combobox in the GTK
  client), then it falls back on using 'ilike'. This string value is
  *not* used in custom domains and custom filters, which simply are
  not submitted.

  This second section has *not* been implemented so far in the web
  client, we'll come round to it if people actually need it.

bzr revid: xmo@openerp.com-20111006063949-fl5rbg3wwubcaay8
This commit is contained in:
Xavier Morel 2011-10-06 08:39:49 +02:00
parent aed28ba69b
commit a3a45e18b3
2 changed files with 21 additions and 3 deletions

View File

@ -116,8 +116,9 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
*/
make_field: function (item, field) {
try {
return new (openerp.web.search.fields.get_object(field.type))
(item, field, this);
return new (openerp.web.search.fields.get_any(
[item.attrs.widget, field.type]))
(item, field, this);
} catch (e) {
if (! e instanceof openerp.web.KeyNotFound) {
throw e;
@ -759,7 +760,24 @@ openerp.web.search.FloatField = openerp.web.search.NumberField.extend(/** @lends
* @extends openerp.web.search.Field
*/
openerp.web.search.SelectionField = openerp.web.search.Field.extend(/** @lends openerp.web.search.SelectionField# */{
// This implementation is a basic <select> field, but it may have to be
// altered to be more in line with the GTK client, which uses a combo box
// (~ jquery.autocomplete):
// * If an option was selected in the list, behave as currently
// * If something which is not in the list was entered (via the text input),
// the default domain should become (`ilike` string_value) but **any
// ``context`` or ``filter_domain`` becomes falsy, idem if ``@operator``
// is specified. So at least get_domain needs to be quite a bit
// overridden (if there's no @value and there is no filter_domain and
// there is no @operator, return [[name, 'ilike', str_val]]
template: 'SearchView.field.selection',
init: function () {
this._super.apply(this, arguments);
// prepend empty option if there is no empty option in the selection list
this.prepend_empty = !_(this.attrs.selection).detect(function (item) {
return !item[1];
});
},
get_value: function () {
return this.$element.val();
}

View File

@ -1092,7 +1092,7 @@
<div style="white-space: nowrap;">
<select t-att-name="attrs.name" t-att-id="element_id"
t-att-autofocus="attrs.default_focus === '1' || undefined">
<option/>
<option t-if="prepend_empty"/>
<t t-foreach="attrs.selection" t-as="option">
<t t-set="selected" t-value="defaults[attrs.name] === option[0]"/>
<option t-if="selected"