Xavier (Open ERP) has proposed merging 
lp:~openerp-dev/openerp-web/trunk-search-m2o-context-default-xmo into 
lp:openerp-web.

Requested reviews:
  OpenERP R&D Web Team (openerp-dev-web)

For more details, see:
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-search-m2o-context-default-xmo/+merge/112031

Add default_ key in the context by default, if a single (existing) record is 
selected exactly in a m2o field of the search view.
-- 
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-search-m2o-context-default-xmo/+merge/112031
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openerp-web/trunk-search-m2o-context-default-xmo.
=== modified file 'addons/web/static/src/js/search.js'
--- addons/web/static/src/js/search.js	2012-06-25 13:52:15 +0000
+++ addons/web/static/src/js/search.js	2012-06-26 09:16:22 +0000
@@ -1530,6 +1530,15 @@
             return [[name, '=', facetValue.get('value')]];
         }
         return this._super(name, operator, facetValue);
+    },
+    get_context: function (facet) {
+        var values = facet.values;
+        if (!this.attrs.context && values.length === 1) {
+            var c = {};
+            c['default_' + this.attrs.name] = values.at(0).get('value');
+            return c;
+        }
+        return this._super(facet);
     }
 });
 

=== modified file 'addons/web/static/test/search.js'
--- addons/web/static/test/search.js	2012-05-22 13:23:21 +0000
+++ addons/web/static/test/search.js	2012-06-26 09:16:22 +0000
@@ -843,6 +843,25 @@
 
         deepEqual(f.get_domain(facet), [['foo', '=', 42]],
             "m2o should use identity if default domain");
+        deepEqual(f.get_context(facet), {default_foo: 42},
+            "m2o should use value as context default");
+    });
+    test("M2O default multiple values", function () {
+        var f = new instance.web.search.ManyToOneField(
+            {}, {name: 'foo'}, {inputs: []});
+        var facet = new instance.web.search.Facet({
+            field: f,
+            values: [
+                {label: "Foo", value: 42},
+                {label: "Bar", value: 36}
+            ]
+        });
+
+        deepEqual(f.get_domain(facet).__domains,
+            [['|'], [['foo', '=', 42]], [['foo', '=', 36]]],
+            "m2o should or multiple values");
+        equal(f.get_context(facet), null,
+            "m2o should not have default context in case of multiple values");
     });
     test("M2O custom operator", function () {
         var f = new instance.web.search.ManyToOneField(
@@ -854,6 +873,8 @@
 
         deepEqual(f.get_domain(facet), [['foo', 'boos', 'Foo']],
             "m2o should use label with custom operators");
+        deepEqual(f.get_context(facet), {default_foo: 42},
+            "m2o should use value as context default");
     });
     test("M2O custom domain & context", function () {
         var f = new instance.web.search.ManyToOneField({attrs: {

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to