Skip to content

Commit 30268a1

Browse files
CreamasterSandip-scs
authored andcommitted
Migrate web_search_with_and from 8.0 to 10.0
1 parent 34ebf75 commit 30268a1

File tree

5 files changed

+54
-35
lines changed

5 files changed

+54
-35
lines changed

web_search_with_and/README.rst

+11-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ Usage
2626

2727
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
2828
:alt: Try me on Runbot
29-
:target: https://runbot.odoo-community.org/runbot/162/8.0
29+
:target: https://runbot.odoo-community.org/runbot/162/10.0
30+
31+
Bug Tracker
32+
===========
33+
34+
Bugs are tracked on `GitHub Issues
35+
<https://github.com/OCA/{project_repo}/issues>`_. In case of trouble, please
36+
check there if your issue has already been reported. If you spotted it first,
37+
help us smash it by providing detailed and welcomed feedback.
3038

3139
Credits
3240
=======
@@ -35,6 +43,7 @@ Contributors
3543
------------
3644

3745
* Andrius Preimantas <andrius@versada.lt>
46+
* Adrien Didenot <adrien.didenot@horanet.com>
3847

3948
Maintainer
4049
----------
@@ -49,4 +58,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
4958
mission is to support the collaborative development of Odoo features and
5059
promote its widespread use.
5160

52-
To contribute to this module, please visit http://odoo-community.org.
61+
To contribute to this module, please visit http://odoo-community.org.

web_search_with_and/__openerp__.py web_search_with_and/__manifest__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# -*- coding: utf-8 -*-
2-
# © 2015 Andrius Preimantas <andrius@versada.lt>
2+
# Copyright 2015 Andrius Preimantas <andrius@versada.lt>
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
44

55
{
66
'name': "Use AND conditions on omnibar search",
7-
'version': '8.0.1.0.0',
7+
'version': '10.0.1.0.0',
88
'author': 'Versada UAB, Odoo Community Association (OCA)',
99
'license': 'AGPL-3',
1010
'category': 'web',

web_search_with_and/data/data.xml

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<openerp>
3-
<data>
4-
<template id="assets_backend" name="web_view_editor assets" inherit_id="web.assets_backend">
5-
<xpath expr="." position="inside">
6-
<script type="text/javascript" src="/web_search_with_and/static/src/js/search.js"/>
7-
</xpath>
8-
</template>
9-
</data>
10-
</openerp>
2+
<odoo>
3+
<template id="assets_backend" name="web_view_editor assets" inherit_id="web.assets_backend">
4+
<xpath expr="." position="inside">
5+
<script type="text/javascript" src="/web_search_with_and/static/src/js/search.js"/>
6+
</xpath>
7+
</template>
8+
</odoo>
9.23 KB
Loading
+34-22
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,55 @@
1-
openerp.web_search_with_and = function (instance) {
1+
odoo.define('web_search_with_and', function (require) {
2+
"use strict";
23

3-
instance.web.SearchView = instance.web.SearchView.extend({
4+
var SearchView = require('web.SearchView');
5+
var Backbone = window.Backbone;
6+
7+
SearchView.include({
8+
// Override the base method to detect a 'shift' event
49
select_completion: function (e, ui) {
5-
var self = this;
6-
if (e.shiftKey) {
10+
if (e.shiftKey
11+
&& ui.item.facet.values
12+
&& ui.item.facet.values.length
13+
&& String(ui.item.facet.values[0].value).trim() !== "") {
14+
// In case of an 'AND' search a new facet is added regarding of the previous facets
715
e.preventDefault();
816

9-
var input_index = _(this.input_subviews).indexOf(
10-
this.subviewForRoot(
11-
this.$('div.oe_searchview_input:focus')[0]));
12-
this.query.add(ui.item.facet, {at: input_index / 2, shiftKey: true});
17+
this.query.add(ui.item.facet, {shiftKey: true});
1318
} else {
14-
this._super(e, ui);
19+
20+
return this._super.apply(this, arguments);
1521
}
16-
},
22+
}
1723
});
1824

19-
instance.web.search.SearchQuery = instance.web.search.SearchQuery.extend({
25+
SearchView.SearchQuery.prototype = SearchView.SearchQuery.extend({
26+
// Override the odoo method to (conditionally) add a search facet even if a existing
27+
// facet for the same field/category already exists.
28+
// The prototype is used to override the 'add' function in order to execute the
29+
// following code before the Odoo native override (trick)
2030
add: function (values, options) {
21-
2231
options = options || {};
32+
if (options.shiftKey) {
2333

24-
if (!values) {
25-
values = [];
26-
} else if (!(values instanceof Array)) {
27-
values = [values];
28-
}
34+
if (!values) {
35+
values = [];
36+
}
37+
else if (!(values instanceof Array)) {
38+
values = [values];
39+
}
2940

30-
if (options.shiftKey) {
3141
delete options.shiftKey;
3242
_(values).each(function (value) {
3343
var model = this._prepareModel(value, options);
3444
Backbone.Collection.prototype.add.call(this, model, options);
3545
}, this);
46+
3647
return this;
3748
}
3849
else {
39-
return this.constructor.__super__.add.apply(this, arguments);
50+
return this.constructor.__super__.add.call(this, values, options);
4051
}
41-
},
42-
});
43-
};
52+
}
53+
}).prototype;
54+
55+
});

0 commit comments

Comments
 (0)