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