-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
11.0 mig web search with and #895
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | ||
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
|
||
==================================== | ||
Use AND conditions on omnibar search | ||
==================================== | ||
|
||
When searching for records on same field Odoo joins multiple queries with OR. | ||
For example: | ||
|
||
* Perform a search for customer "John" on field Name | ||
* Odoo displays customers containing "John" | ||
* Search for "Smith" on same field Name | ||
* Odoo displays customers containing "John" OR "Smith" | ||
|
||
With this module installed you can press Shift key before searching for "Smith" | ||
and Odoo finds customers containing "John" AND "Smith" | ||
|
||
Usage | ||
===== | ||
|
||
* Enter your value in omnibar search field | ||
* Press and hold Shift key | ||
* Select field with mouse or keyboard to perform search on | ||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/162/11.0 | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues | ||
<https://github.com/OCA/web/issues>`_. In case of trouble, please | ||
check there if your issue has already been reported. If you spotted it first, | ||
help us smash it by providing detailed and welcomed feedback. | ||
|
||
Credits | ||
======= | ||
|
||
Contributors | ||
------------ | ||
|
||
* Andrius Preimantas <andrius@versada.lt> | ||
* Adrien Didenot <adrien.didenot@horanet.com> | ||
* Francesco Apruzzese <f.apruzzese@apuliasoftware.it> | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
This module is maintained by the OCA. | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
To contribute to this module, please visit https://odoo-community.org. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright 2015 Andrius Preimantas <andrius@versada.lt> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
'name': "Use AND conditions on omnibar search", | ||
'version': '11.0.1.0.0', | ||
'author': 'Versada UAB, Odoo Community Association (OCA)', | ||
'license': 'AGPL-3', | ||
'category': 'web', | ||
'website': 'https://github.com/OCA/web', | ||
'depends': [ | ||
'web', | ||
], | ||
'data': [ | ||
'data/data.xml', | ||
], | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<template id="assets_backend" name="web_view_editor assets" inherit_id="web.assets_backend"> | ||
<xpath expr="." position="inside"> | ||
<script type="text/javascript" src="/web_search_with_and/static/src/js/search.js"/> | ||
</xpath> | ||
</template> | ||
</odoo> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
odoo.define('web_search_with_and', function (require) { | ||
"use strict"; | ||
|
||
var SearchView = require('web.SearchView'); | ||
var Backbone = window.Backbone; | ||
|
||
SearchView.include({ | ||
// Override the base method to detect a 'shift' event | ||
select_completion: function (e, ui) { | ||
if (e.shiftKey | ||
&& ui.item.facet.values | ||
&& ui.item.facet.values.length | ||
&& String(ui.item.facet.values[0].value).trim() !== "") { | ||
// In case of an 'AND' search a new facet is added regarding of the previous facets | ||
e.preventDefault(); | ||
|
||
this.query.add(ui.item.facet, {shiftKey: true}); | ||
} else { | ||
|
||
return this._super.apply(this, arguments); | ||
} | ||
} | ||
}); | ||
|
||
SearchView.SearchQuery.prototype = SearchView.SearchQuery.extend({ | ||
// Override the odoo method to (conditionally) add a search facet even if a existing | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @simahawk where I can find documentation about include and _super? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a couple of lines above? 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried it. It seems that it doesn't work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a comment about this here (2 lines down):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tarteo well, I saw it but I was wondering if it was still the case 😜 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @simahawk Oh ok haha ;) |
||
// facet for the same field/category already exists. | ||
// The prototype is used to override the 'add' function in order to execute the | ||
// following code before the Odoo native override (trick) | ||
add: function (values, options) { | ||
options = options || {}; | ||
if (options.shiftKey) { | ||
|
||
if (!values) { | ||
values = []; | ||
} | ||
else if (!(values instanceof Array)) { | ||
values = [values]; | ||
} | ||
|
||
delete options.shiftKey; | ||
_(values).each(function (value) { | ||
var model = this._prepareModel(value, options); | ||
Backbone.Collection.prototype.add.call(this, model, options); | ||
}, this); | ||
|
||
return this; | ||
} | ||
else { | ||
return this.constructor.__super__.add.call(this, values, options); | ||
} | ||
} | ||
}).prototype; | ||
|
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace http by https in all sections down under.