Holger Brunn
10 years ago
8 changed files with 246 additions and 0 deletions
-
45web_advanced_search_x2many/README.rst
-
20web_advanced_search_x2many/__init__.py
-
45web_advanced_search_x2many/__openerp__.py
-
BINweb_advanced_search_x2many/static/description/icon.png
-
4web_advanced_search_x2many/static/src/css/web_advanced_search_x2many.css
-
112web_advanced_search_x2many/static/src/js/web_advanced_search_x2many.js
-
9web_advanced_search_x2many/static/src/xml/web_advanced_search_x2many.xml
-
11web_advanced_search_x2many/views/templates.xml
@ -0,0 +1,45 @@ |
|||||
|
Search for x2x records in advanced search |
||||
|
========================================= |
||||
|
|
||||
|
Standard behavior in advanced search for one2many, many2many and many2one fields is to do a `name_search`. This is not always satisfactionary as you might want to search for other properties. There might also be cases where you don't exactly know what you're searching for, then a list of possible options is necessary too. This module enables you to have a full search view to select the record in question. |
||||
|
|
||||
|
Usage |
||||
|
===== |
||||
|
|
||||
|
To use this module, you need to: |
||||
|
|
||||
|
* open the advanced search options in a search view |
||||
|
* select a one2many, many2many or many2one field |
||||
|
* select operator `is equal to` or `is not equal to` |
||||
|
* the textfield changes to a many2one selection field where you can search for the record in question |
||||
|
* to select multiple records, add another condition for the same field before applying the conditions (that's standard behavior) |
||||
|
|
||||
|
For further information, please visit: |
||||
|
|
||||
|
* https://www.odoo.com/forum/help-1 |
||||
|
|
||||
|
Known issues / Roadmap |
||||
|
====================== |
||||
|
|
||||
|
* from what we have now, it shouldn't be too difficult to add an operator `use condition`, show a search view for the field's model and use the domain filled in there. This way we can have conditions like `[('journal_id.user_id.groups_id.name', '=', 'test')]` |
||||
|
|
||||
|
Credits |
||||
|
======= |
||||
|
|
||||
|
Contributors |
||||
|
------------ |
||||
|
|
||||
|
* Holger Brunn <hbrunn@therp.nl> |
||||
|
|
||||
|
Maintainer |
||||
|
---------- |
||||
|
|
||||
|
.. image:: http://odoo-community.org/logo.png |
||||
|
:alt: Odoo Community Association |
||||
|
:target: http://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 http://odoo-community.org. |
@ -0,0 +1,20 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# OpenERP, Open Source Management Solution |
||||
|
# This module copyright (C) 2015 Therp BV <http://therp.nl>. |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
@ -0,0 +1,45 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# OpenERP, Open Source Management Solution |
||||
|
# This module copyright (C) 2015 Therp BV <http://therp.nl>. |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
{ |
||||
|
"name": "Search x2x fields", |
||||
|
"version": "1.0", |
||||
|
"author": "Therp BV", |
||||
|
"license": "AGPL-3", |
||||
|
"category": "Usability", |
||||
|
"summary": "Use a search widget in advanced search for x2x fields", |
||||
|
"depends": [ |
||||
|
'web', |
||||
|
], |
||||
|
"data": [ |
||||
|
'views/templates.xml', |
||||
|
], |
||||
|
"qweb": [ |
||||
|
'static/src/xml/web_advanced_search_x2many.xml', |
||||
|
], |
||||
|
"test": [ |
||||
|
], |
||||
|
"auto_install": False, |
||||
|
"installable": True, |
||||
|
"application": False, |
||||
|
"external_dependencies": { |
||||
|
'python': [], |
||||
|
}, |
||||
|
} |
After Width: 80 | Height: 80 | Size: 1.1 KiB |
@ -0,0 +1,4 @@ |
|||||
|
.openerp .searchview_extended_prop_value .oe_form_field_with_button |
||||
|
{ |
||||
|
position: relative; |
||||
|
} |
@ -0,0 +1,112 @@ |
|||||
|
//-*- coding: utf-8 -*-
|
||||
|
//############################################################################
|
||||
|
//
|
||||
|
// OpenERP, Open Source Management Solution
|
||||
|
// This module copyright (C) 2015 Therp BV <http://therp.nl>.
|
||||
|
//
|
||||
|
// This program is free software: you can redistribute it and/or modify
|
||||
|
// it under the terms of the GNU Affero General Public License as
|
||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||
|
// License, or (at your option) any later version.
|
||||
|
//
|
||||
|
// This program is distributed in the hope that it will be useful,
|
||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
|
// GNU Affero General Public License for more details.
|
||||
|
//
|
||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
//
|
||||
|
//############################################################################
|
||||
|
|
||||
|
openerp.web_advanced_search_x2many = function(instance) |
||||
|
{ |
||||
|
instance.web_advanced_search_x2many.ExtendedSearchPropositionMany2One = |
||||
|
instance.web.search.ExtendedSearchProposition.Char.extend( |
||||
|
instance.web.form.FieldManagerMixin, |
||||
|
{ |
||||
|
template: 'web_advanced_search_x2many.extended_search.proposition.many2one', |
||||
|
searchfield: null, |
||||
|
start: function() |
||||
|
{ |
||||
|
this.getParent().$('.searchview_extended_prop_op') |
||||
|
.on('change', this.proxy('operator_changed')); |
||||
|
return this._super.apply(this, arguments); |
||||
|
}, |
||||
|
get_field_desc() |
||||
|
{ |
||||
|
return this.field; |
||||
|
}, |
||||
|
create_searchfield_node: function() |
||||
|
{ |
||||
|
return { |
||||
|
attrs: { |
||||
|
name: this.field.name, |
||||
|
options: '{"no_create": true}', |
||||
|
}, |
||||
|
} |
||||
|
}, |
||||
|
create_searchfield: function() |
||||
|
{ |
||||
|
if(this.searchfield) |
||||
|
{ |
||||
|
this.searchfield.destroy(); |
||||
|
} |
||||
|
this.searchfield = new instance.web.form.FieldMany2One( |
||||
|
this, this.create_searchfield_node()); |
||||
|
return this.searchfield; |
||||
|
}, |
||||
|
operator_changed: function(e) |
||||
|
{ |
||||
|
this.renderElement(); |
||||
|
if(this.show_searchfield()) |
||||
|
{ |
||||
|
this.create_searchfield().appendTo(this.$el.empty()); |
||||
|
} |
||||
|
}, |
||||
|
show_searchfield: function() |
||||
|
{ |
||||
|
if(this.isDestroyed()) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
var operator = this.getParent().$('.searchview_extended_prop_op') |
||||
|
.val(); |
||||
|
return operator == '=' || operator == '!='; |
||||
|
}, |
||||
|
get_value: function() |
||||
|
{ |
||||
|
if(this.show_searchfield() && this.searchfield) |
||||
|
{ |
||||
|
return this.searchfield.get_value(); |
||||
|
} |
||||
|
return this._super.apply(this, arguments); |
||||
|
}, |
||||
|
format_label: function(format, field, operator) |
||||
|
{ |
||||
|
if(this.show_searchfield() && this.searchfield) |
||||
|
{ |
||||
|
return _.str.sprintf( |
||||
|
format, |
||||
|
{ |
||||
|
field: field.string, |
||||
|
operator: operator.label || operator.text, |
||||
|
value: this.searchfield.display_value[ |
||||
|
String(this.searchfield.get_value())], |
||||
|
|
||||
|
} |
||||
|
); |
||||
|
} |
||||
|
return this._super.apply(this, arguments); |
||||
|
}, |
||||
|
}); |
||||
|
instance.web.search.custom_filters.add( |
||||
|
'one2many', |
||||
|
'instance.web_advanced_search_x2many.ExtendedSearchPropositionMany2One'); |
||||
|
instance.web.search.custom_filters.add( |
||||
|
'many2many', |
||||
|
'instance.web_advanced_search_x2many.ExtendedSearchPropositionMany2One'); |
||||
|
instance.web.search.custom_filters.add( |
||||
|
'many2one', |
||||
|
'instance.web_advanced_search_x2many.ExtendedSearchPropositionMany2One'); |
||||
|
} |
@ -0,0 +1,9 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<templates> |
||||
|
<t t-name="web_advanced_search_x2many.extended_search.proposition.many2one"> |
||||
|
<t t-if="!widget.show_searchfield()"> |
||||
|
<t t-call="SearchView.extended_search.proposition.char" /> |
||||
|
</t> |
||||
|
<span /> |
||||
|
</t> |
||||
|
</templates> |
@ -0,0 +1,11 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
<template id="assets_backend" name="web_advanced_search_x2many assets" inherit_id="web.assets_backend"> |
||||
|
<xpath expr="." position="inside"> |
||||
|
<script type="text/javascript" src="/web_advanced_search_x2many/static/src/js/web_advanced_search_x2many.js"></script> |
||||
|
<link rel="stylesheet" href="/web_advanced_search_x2many/static/src/css/web_advanced_search_x2many.css"/> |
||||
|
</xpath> |
||||
|
</template> |
||||
|
</data> |
||||
|
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue