mirror of https://github.com/OCA/web.git
[IMP] web_advanced_search: black, isort
parent
03e9cb5602
commit
ee83cde3e3
|
@ -5,23 +5,15 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "Advanced search",
|
"name": "Advanced search",
|
||||||
"version": "12.0.1.0.2",
|
"version": "13.0.1.0.0",
|
||||||
"author": "Therp BV, "
|
"author": "Therp BV, " "Tecnativa, " "Odoo Community Association (OCA)",
|
||||||
"Tecnativa, "
|
|
||||||
"Odoo Community Association (OCA)",
|
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"category": "Usability",
|
"category": "Usability",
|
||||||
"summary": "Easier and more powerful searching tools",
|
"summary": "Easier and more powerful searching tools",
|
||||||
"website": "https://github.com/OCA/web",
|
"website": "https://github.com/OCA/web",
|
||||||
"depends": [
|
"depends": ["web"],
|
||||||
'web',
|
"data": ["views/templates.xml"],
|
||||||
],
|
"qweb": ["static/src/xml/web_advanced_search.xml"],
|
||||||
"data": [
|
|
||||||
'views/templates.xml',
|
|
||||||
],
|
|
||||||
"qweb": [
|
|
||||||
'static/src/xml/web_advanced_search.xml',
|
|
||||||
],
|
|
||||||
"installable": True,
|
"installable": True,
|
||||||
"application": False,
|
"application": False,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* Copyright 2018 Tecnativa - Jairo Llopis
|
/* Copyright 2018 Tecnativa - Jairo Llopis
|
||||||
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
|
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
|
||||||
|
|
||||||
odoo.define("web_advanced_search.human_domain", function (require) {
|
odoo.define("web_advanced_search.human_domain", function(require) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var DomainSelector = require("web.DomainSelector");
|
var DomainSelector = require("web.DomainSelector");
|
||||||
|
@ -15,12 +15,10 @@
|
||||||
// HACK I should extend classes, but they are not exposed
|
// HACK I should extend classes, but they are not exposed
|
||||||
// TODO Remove file when merged https://github.com/odoo/odoo/pull/25922
|
// TODO Remove file when merged https://github.com/odoo/odoo/pull/25922
|
||||||
var human_domain_methods = {
|
var human_domain_methods = {
|
||||||
DomainTree: function () {
|
DomainTree: function() {
|
||||||
var human_domains = [];
|
var human_domains = [];
|
||||||
_.each(this.children, function (child) {
|
_.each(this.children, function(child) {
|
||||||
human_domains.push(
|
human_domains.push(human_domain_methods[child.template].apply(child));
|
||||||
human_domain_methods[child.template].apply(child)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
return _.str.sprintf(
|
return _.str.sprintf(
|
||||||
"(%s)",
|
"(%s)",
|
||||||
|
@ -28,23 +26,21 @@
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
DomainSelector: function () {
|
DomainSelector: function() {
|
||||||
var result = human_domain_methods.DomainTree.apply(this, arguments);
|
var result = human_domain_methods.DomainTree.apply(this, arguments);
|
||||||
// Remove surrounding parenthesis
|
// Remove surrounding parenthesis
|
||||||
return result.slice(1, -1);
|
return result.slice(1, -1);
|
||||||
},
|
},
|
||||||
|
|
||||||
DomainLeaf: function () {
|
DomainLeaf: function() {
|
||||||
var chain = [],
|
var chain = [],
|
||||||
operator = this.operator_mapping[this.operator],
|
operator = this.operator_mapping[this.operator],
|
||||||
value = _.str.sprintf('"%s"', this.value);
|
value = _.str.sprintf('"%s"', this.value);
|
||||||
// Humanize chain
|
// Humanize chain
|
||||||
this.chain.split(".").forEach(function (element, index) {
|
this.chain.split(".").forEach(function(element, index) {
|
||||||
chain.push(
|
chain.push(
|
||||||
_.findWhere(
|
_.findWhere(this.fieldSelector.pages[index], {name: element})
|
||||||
this.fieldSelector.pages[index],
|
.string || element
|
||||||
{name: element}
|
|
||||||
).string || element
|
|
||||||
);
|
);
|
||||||
}, this);
|
}, this);
|
||||||
// Special beautiness for some values
|
// Special beautiness for some values
|
||||||
|
@ -54,27 +50,17 @@
|
||||||
} else if (_.isArray(this.value)) {
|
} else if (_.isArray(this.value)) {
|
||||||
value = _.str.sprintf('["%s"]', this.value.join('", "'));
|
value = _.str.sprintf('["%s"]', this.value.join('", "'));
|
||||||
}
|
}
|
||||||
return _.str.sprintf(
|
return _.str
|
||||||
"%s %s %s",
|
.sprintf("%s %s %s", chain.join("→"), operator || this.operator, value)
|
||||||
chain.join("→"),
|
.trim();
|
||||||
operator || this.operator,
|
|
||||||
value
|
|
||||||
).trim();
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function getHumanDomain (parent, model, domain, options) {
|
function getHumanDomain(parent, model, domain, options) {
|
||||||
var domain_selector = new DomainSelector(
|
var domain_selector = new DomainSelector(parent, model, domain, options);
|
||||||
parent,
|
|
||||||
model,
|
|
||||||
domain,
|
|
||||||
options
|
|
||||||
);
|
|
||||||
var dummy_parent = $("<div>");
|
var dummy_parent = $("<div>");
|
||||||
domain_selector.appendTo(dummy_parent);
|
domain_selector.appendTo(dummy_parent);
|
||||||
var result = human_domain_methods.DomainSelector.apply(
|
var result = human_domain_methods.DomainSelector.apply(domain_selector);
|
||||||
domain_selector
|
|
||||||
);
|
|
||||||
domain_selector.destroy();
|
domain_selector.destroy();
|
||||||
dummy_parent.destroy();
|
dummy_parent.destroy();
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Copyright 2017-2018 Jairo Llopis <jairo.llopis@tecnativa.com>
|
* Copyright 2017-2018 Jairo Llopis <jairo.llopis@tecnativa.com>
|
||||||
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
|
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
|
||||||
|
|
||||||
odoo.define("web_advanced_search", function (require) {
|
odoo.define("web_advanced_search", function(require) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var core = require("web.core");
|
var core = require("web.core");
|
||||||
|
@ -18,7 +18,7 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
|
|
||||||
SearchView.include({
|
SearchView.include({
|
||||||
custom_events: _.extend({}, SearchView.prototype.custom_events, {
|
custom_events: _.extend({}, SearchView.prototype.custom_events, {
|
||||||
"get_dataset": "_on_get_dataset",
|
get_dataset: "_on_get_dataset",
|
||||||
}),
|
}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,7 +29,7 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
*
|
*
|
||||||
* @param {OdooEvent} event The target will get the dataset.
|
* @param {OdooEvent} event The target will get the dataset.
|
||||||
*/
|
*/
|
||||||
_on_get_dataset: function (event) {
|
_on_get_dataset: function(event) {
|
||||||
event.target.dataset = this.dataset;
|
event.target.dataset = this.dataset;
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
},
|
},
|
||||||
|
@ -39,11 +39,10 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
* An almost dummy search proposition, to use with domain widget
|
* An almost dummy search proposition, to use with domain widget
|
||||||
*/
|
*/
|
||||||
var AdvancedSearchProposition = Widget.extend({
|
var AdvancedSearchProposition = Widget.extend({
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
init: function (parent, model, domain) {
|
init: function(parent, model, domain) {
|
||||||
this._super(parent);
|
this._super(parent);
|
||||||
this.model = model;
|
this.model = model;
|
||||||
this.domain = new Domain(domain);
|
this.domain = new Domain(domain);
|
||||||
|
@ -55,7 +54,7 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
*
|
*
|
||||||
* @returns {Object} In the format expected by `web.FiltersMenu`.
|
* @returns {Object} In the format expected by `web.FiltersMenu`.
|
||||||
*/
|
*/
|
||||||
get_filter: function () {
|
get_filter: function() {
|
||||||
return {
|
return {
|
||||||
attrs: {
|
attrs: {
|
||||||
domain: this.domain_array,
|
domain: this.domain_array,
|
||||||
|
@ -76,7 +75,7 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
// Add advanced search features
|
// Add advanced search features
|
||||||
FiltersMenu.include({
|
FiltersMenu.include({
|
||||||
custom_events: _.extend({}, FiltersMenu.prototype.custom_events, {
|
custom_events: _.extend({}, FiltersMenu.prototype.custom_events, {
|
||||||
"domain_selected": "advanced_search_commit",
|
domain_selected: "advanced_search_commit",
|
||||||
}),
|
}),
|
||||||
|
|
||||||
events: _.extend({}, FiltersMenu.prototype.events, {
|
events: _.extend({}, FiltersMenu.prototype.events, {
|
||||||
|
@ -86,7 +85,7 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
init: function () {
|
init: function() {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
this.trigger_up("get_dataset");
|
this.trigger_up("get_dataset");
|
||||||
},
|
},
|
||||||
|
@ -96,7 +95,7 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
*
|
*
|
||||||
* @returns {$.Deferred} The opening dialog itself.
|
* @returns {$.Deferred} The opening dialog itself.
|
||||||
*/
|
*/
|
||||||
advanced_search_open: function () {
|
advanced_search_open: function() {
|
||||||
var domain_selector_dialog = new DomainSelectorDialog(
|
var domain_selector_dialog = new DomainSelectorDialog(
|
||||||
this,
|
this,
|
||||||
this.dataset.model,
|
this.dataset.model,
|
||||||
|
@ -106,7 +105,7 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
readonly: false,
|
readonly: false,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
domain_selector_dialog.opened(function () {
|
domain_selector_dialog.opened(function() {
|
||||||
// Add 1st domain node by default
|
// Add 1st domain node by default
|
||||||
domain_selector_dialog.domainSelector._onAddFirstButtonClick();
|
domain_selector_dialog.domainSelector._onAddFirstButtonClick();
|
||||||
});
|
});
|
||||||
|
@ -118,7 +117,7 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
*
|
*
|
||||||
* @param {OdooEvent} event A `domain_selected` event from the dialog.
|
* @param {OdooEvent} event A `domain_selected` event from the dialog.
|
||||||
*/
|
*/
|
||||||
advanced_search_commit: function (event) {
|
advanced_search_commit: function(event) {
|
||||||
_.invoke(this.propositions, "destroy");
|
_.invoke(this.propositions, "destroy");
|
||||||
var proposition = new AdvancedSearchProposition(
|
var proposition = new AdvancedSearchProposition(
|
||||||
this,
|
this,
|
||||||
|
@ -148,15 +147,13 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
init: function () {
|
init: function() {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
// To make widgets work, we need a model and an empty record
|
// To make widgets work, we need a model and an empty record
|
||||||
FieldManagerMixin.init.call(this);
|
FieldManagerMixin.init.call(this);
|
||||||
this.trigger_up("get_dataset");
|
this.trigger_up("get_dataset");
|
||||||
// Make equal and not equal appear 1st and 2nd
|
// Make equal and not equal appear 1st and 2nd
|
||||||
this.operators = _.sortBy(
|
this.operators = _.sortBy(this.operators, function(op) {
|
||||||
this.operators,
|
|
||||||
function (op) {
|
|
||||||
switch (op.value) {
|
switch (op.value) {
|
||||||
case "=":
|
case "=":
|
||||||
return -2;
|
return -2;
|
||||||
|
@ -194,11 +191,7 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
params.fieldsInfo.default[this.field.name] = {};
|
params.fieldsInfo.default[this.field.name] = {};
|
||||||
// Emulate `model.load()`, without RPC-calling `default_get()`
|
// Emulate `model.load()`, without RPC-calling `default_get()`
|
||||||
this.datapoint_id = this.model._makeDataPoint(params).id;
|
this.datapoint_id = this.model._makeDataPoint(params).id;
|
||||||
this.model.applyDefaultValues(
|
this.model.applyDefaultValues(this.datapoint_id, {}, params.fieldNames);
|
||||||
this.datapoint_id,
|
|
||||||
{},
|
|
||||||
params.fieldNames
|
|
||||||
);
|
|
||||||
// To generate a new fake ID
|
// To generate a new fake ID
|
||||||
this._fake_id = -1;
|
this._fake_id = -1;
|
||||||
},
|
},
|
||||||
|
@ -206,7 +199,7 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
start: function () {
|
start: function() {
|
||||||
var result = this._super.apply(this, arguments);
|
var result = this._super.apply(this, arguments);
|
||||||
// Render the initial widget
|
// Render the initial widget
|
||||||
result.done($.proxy(this, "show_inputs", $("<input value='='/>")));
|
result.done($.proxy(this, "show_inputs", $("<input value='='/>")));
|
||||||
|
@ -216,7 +209,7 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
destroy: function () {
|
destroy: function() {
|
||||||
if (this._field_widget) {
|
if (this._field_widget) {
|
||||||
this._field_widget.destroy();
|
this._field_widget.destroy();
|
||||||
}
|
}
|
||||||
|
@ -230,14 +223,14 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
*
|
*
|
||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
_get_record: function () {
|
_get_record: function() {
|
||||||
return this.model.get(this.datapoint_id);
|
return this.model.get(this.datapoint_id);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
show_inputs: function ($operator) {
|
show_inputs: function($operator) {
|
||||||
// Get widget class to be used
|
// Get widget class to be used
|
||||||
switch ($operator.val()) {
|
switch ($operator.val()) {
|
||||||
case "=":
|
case "=":
|
||||||
|
@ -278,8 +271,8 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
_applyChanges: function (dataPointID, changes, event) {
|
_applyChanges: function(dataPointID, changes, event) {
|
||||||
if (this._field_widget_name === 'many2one') {
|
if (this._field_widget_name === "many2one") {
|
||||||
// Make char updates look like valid x2one updates
|
// Make char updates look like valid x2one updates
|
||||||
if (_.isNaN(changes[this.field.name].id)) {
|
if (_.isNaN(changes[this.field.name].id)) {
|
||||||
changes[this.field.name] = {
|
changes[this.field.name] = {
|
||||||
|
@ -296,7 +289,7 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
_confirmChange: function (id, fields, event) {
|
_confirmChange: function(id, fields, event) {
|
||||||
this.datapoint_id = id;
|
this.datapoint_id = id;
|
||||||
return this._field_widget.reset(this._get_record(), event);
|
return this._field_widget.reset(this._get_record(), event);
|
||||||
},
|
},
|
||||||
|
@ -304,7 +297,7 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
get_value: function () {
|
get_value: function() {
|
||||||
try {
|
try {
|
||||||
switch (this._field_widget_name) {
|
switch (this._field_widget_name) {
|
||||||
case "many2one":
|
case "many2one":
|
||||||
|
@ -324,7 +317,7 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
*
|
*
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
toString: function () {
|
toString: function() {
|
||||||
try {
|
try {
|
||||||
switch (this._field_widget_name) {
|
switch (this._field_widget_name) {
|
||||||
case "many2one":
|
case "many2one":
|
||||||
|
@ -332,12 +325,12 @@ odoo.define("web_advanced_search", function (require) {
|
||||||
default:
|
default:
|
||||||
return this._field_widget.$el.val();
|
return this._field_widget.$el.val();
|
||||||
}
|
}
|
||||||
return this._super.apply(this, arguments);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.name === "TypeError") {
|
if (error.name === "TypeError") {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<!-- Copyright 2017-2018 Jairo Llopis <jairo.llopis@tecnativa.com>
|
<!-- Copyright 2017-2018 Jairo Llopis <jairo.llopis@tecnativa.com>
|
||||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||||
<templates>
|
<templates>
|
||||||
<t t-extend="FiltersMenuGenerator">
|
<t t-extend="FiltersMenuGenerator">
|
||||||
<t t-jquery=".o_add_filter_menu" t-operation="after">
|
<t t-jquery=".o_add_filter_menu" t-operation="after">
|
||||||
<div role="separator" class="dropdown-divider"/>
|
<div role="separator" class="dropdown-divider" />
|
||||||
<a class="dropdown-item o_add_advanced_search">Add Advanced Filter</a>
|
<a class="dropdown-item o_add_advanced_search">Add Advanced Filter</a>
|
||||||
</t>
|
</t>
|
||||||
</t>
|
</t>
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<!-- Copyright 2017-2018 Jairo Llopis <jairo.llopis@tecnativa.com>
|
<!-- Copyright 2017-2018 Jairo Llopis <jairo.llopis@tecnativa.com>
|
||||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||||
<odoo>
|
<odoo>
|
||||||
|
|
||||||
<template id="assets_backend" inherit_id="web.assets_backend">
|
<template id="assets_backend" inherit_id="web.assets_backend">
|
||||||
<xpath expr="." position="inside">
|
<xpath expr="." position="inside">
|
||||||
<script type="text/javascript" src="/web_advanced_search/static/src/js/human_domain.js"/>
|
<script
|
||||||
<script type="text/javascript" src="/web_advanced_search/static/src/js/web_advanced_search.js"/>
|
type="text/javascript"
|
||||||
|
src="/web_advanced_search/static/src/js/human_domain.js"
|
||||||
|
/>
|
||||||
|
<script
|
||||||
|
type="text/javascript"
|
||||||
|
src="/web_advanced_search/static/src/js/web_advanced_search.js"
|
||||||
|
/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
Loading…
Reference in New Issue