3
0
Fork 0

[MIG] web_advance_search: Migration to 13.0

15.0-ocabot-merge-pr-2789-by-pedrobaeza-bump-patch
Alexandre Díaz 2020-03-18 03:32:52 +01:00 committed by Ivàn Todorovich
parent ee83cde3e3
commit 92e0b435a9
No known key found for this signature in database
GPG Key ID: E7222FC36B138243
7 changed files with 141 additions and 118 deletions

View File

@ -14,13 +14,13 @@ Advanced search
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
:target: https://github.com/OCA/web/tree/12.0/web_advanced_search
:target: https://github.com/OCA/web/tree/13.0/web_advanced_search
:alt: OCA/web
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/web-12-0/web-12-0-web_advanced_search
:target: https://translation.odoo-community.org/projects/web-13-0/web-13-0-web_advanced_search
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/162/12.0
:target: https://runbot.odoo-community.org/runbot/162/13.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
@ -71,6 +71,10 @@ Improvements to the search view in this addon:
* Use widgets ``many2many_tags`` when searching ``many2many`` fields
* Allow to edit current full search using the advanced domain editor
Issues:
* Grouped totals can show incorrect values. See https://github.com/odoo/odoo/issues/47950
Changelog
=========
@ -121,7 +125,7 @@ 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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_advanced_search%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_advanced_search%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
@ -138,12 +142,15 @@ Contributors
~~~~~~~~~~~~
* Holger Brunn <hbrunn@therp.nl>
* Vicent Cubells <vicent.cubells@tecnativa.com>
* Jairo Llopis <jairo.llopis@tecnativa.com>
* Rami Alwafaie <rami.alwafaie@initos.com>
* Jose Mª Bernet <josemaria.bernet@guadaltech.es>
* Simone Orsi <simone.orsi@camptocamp.com>
* Dennis Sluijk <d.sluijk@onestein.nl>
* `Tecnativa <https://www.tecnativa.com>`_:
* Vicent Cubells
* Jairo Llopis
* Alexandre Díaz
Maintainers
~~~~~~~~~~~
@ -158,6 +165,6 @@ 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.
This module is part of the `OCA/web <https://github.com/OCA/web/tree/12.0/web_advanced_search>`_ project on GitHub.
This module is part of the `OCA/web <https://github.com/OCA/web/tree/13.0/web_advanced_search>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -1,7 +1,10 @@
* Holger Brunn <hbrunn@therp.nl>
* Vicent Cubells <vicent.cubells@tecnativa.com>
* Jairo Llopis <jairo.llopis@tecnativa.com>
* Rami Alwafaie <rami.alwafaie@initos.com>
* Jose Mª Bernet <josemaria.bernet@guadaltech.es>
* Simone Orsi <simone.orsi@camptocamp.com>
* Dennis Sluijk <d.sluijk@onestein.nl>
* `Tecnativa <https://www.tecnativa.com>`_:
* Vicent Cubells
* Jairo Llopis
* Alexandre Díaz

View File

@ -8,3 +8,7 @@ Improvements to the search view in this addon:
* Use widgets ``one2many_tags`` when searching ``one2many`` fields
* Use widgets ``many2many_tags`` when searching ``many2many`` fields
* Allow to edit current full search using the advanced domain editor
Issues:
* Grouped totals can show incorrect values. See https://github.com/odoo/odoo/issues/47950

View File

@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/web/tree/12.0/web_advanced_search"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/web-12-0/web-12-0-web_advanced_search"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/162/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/web/tree/13.0/web_advanced_search"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/web-13-0/web-13-0-web_advanced_search"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/162/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>More powerful and easy to use search, especially for related fields.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
@ -426,6 +426,10 @@ to a journal which has a user who is member of a certain group etc.</p>
<li>Use widgets <tt class="docutils literal">many2many_tags</tt> when searching <tt class="docutils literal">many2many</tt> fields</li>
<li>Allow to edit current full search using the advanced domain editor</li>
</ul>
<p>Issues:</p>
<ul class="simple">
<li>Grouped totals can show incorrect values. See <a class="reference external" href="https://github.com/odoo/odoo/issues/47950">https://github.com/odoo/odoo/issues/47950</a></li>
</ul>
</div>
<div class="section" id="changelog">
<h1><a class="toc-backref" href="#id6">Changelog</a></h1>
@ -473,7 +477,7 @@ search as expected too.</p>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_advanced_search%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_advanced_search%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
@ -489,12 +493,16 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<h2><a class="toc-backref" href="#id13">Contributors</a></h2>
<ul class="simple">
<li>Holger Brunn &lt;<a class="reference external" href="mailto:hbrunn&#64;therp.nl">hbrunn&#64;therp.nl</a>&gt;</li>
<li>Vicent Cubells &lt;<a class="reference external" href="mailto:vicent.cubells&#64;tecnativa.com">vicent.cubells&#64;tecnativa.com</a>&gt;</li>
<li>Jairo Llopis &lt;<a class="reference external" href="mailto:jairo.llopis&#64;tecnativa.com">jairo.llopis&#64;tecnativa.com</a>&gt;</li>
<li>Rami Alwafaie &lt;<a class="reference external" href="mailto:rami.alwafaie&#64;initos.com">rami.alwafaie&#64;initos.com</a>&gt;</li>
<li>Jose Mª Bernet &lt;<a class="reference external" href="mailto:josemaria.bernet&#64;guadaltech.es">josemaria.bernet&#64;guadaltech.es</a>&gt;</li>
<li>Simone Orsi &lt;<a class="reference external" href="mailto:simone.orsi&#64;camptocamp.com">simone.orsi&#64;camptocamp.com</a>&gt;</li>
<li>Dennis Sluijk &lt;<a class="reference external" href="mailto:d.sluijk&#64;onestein.nl">d.sluijk&#64;onestein.nl</a>&gt;</li>
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Vicent Cubells</li>
<li>Jairo Llopis</li>
<li>Alexandre Díaz</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
@ -504,7 +512,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/12.0/web_advanced_search">OCA/web</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/13.0/web_advanced_search">OCA/web</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>

View File

@ -1,69 +1,58 @@
/* Copyright 2018 Tecnativa - Jairo Llopis
* Copyright 2020 Tecnativa - Alexandre Díaz
* 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() {
"use strict";
var DomainSelector = require("web.DomainSelector");
var join_mapping = {
const 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 = {
const human_domain_methods = {
DomainTree: function() {
var human_domains = [];
_.each(this.children, function(child) {
const human_domains = [];
_.each(this.children, child => {
human_domains.push(human_domain_methods[child.template].apply(child));
});
return _.str.sprintf(
"(%s)",
human_domains.join(join_mapping[this.operator])
);
return `(${human_domains.join(join_mapping[this.operator])})`;
},
DomainSelector: function() {
var result = human_domain_methods.DomainTree.apply(this, arguments);
const result = human_domain_methods.DomainTree.apply(this, arguments);
// Remove surrounding parenthesis
return result.slice(1, -1);
},
DomainLeaf: function() {
var chain = [],
operator = this.operator_mapping[this.operator],
value = _.str.sprintf('"%s"', this.value);
const chain = [];
let operator = this.operator_mapping[this.operator],
value = `"${this.value}"`;
// Humanize chain
this.chain.split(".").forEach(function(element, index) {
const chain_splitted = this.chain.split(".");
const len = chain_splitted.length;
for (let x = 0; x < len; ++x) {
const element = chain_splitted[x];
chain.push(
_.findWhere(this.fieldSelector.pages[index], {name: element})
.string || element
_.findWhere(this.fieldSelector.pages[x], {name: element}).string ||
element
);
}, this);
}
// Special beautiness for some values
if (this.operator === "=" && _.isBoolean(this.value)) {
operator = this.operator_mapping[this.value ? "set" : "not set"];
value = "";
} else if (_.isArray(this.value)) {
value = _.str.sprintf('["%s"]', this.value.join('", "'));
value = `["${this.value.join('", "')}"]`;
}
return _.str
.sprintf("%s %s %s", chain.join("→"), operator || this.operator, value)
.trim();
return `${chain.join("→")} ${operator || this.operator} ${value}`.trim();
},
};
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);
domain_selector.destroy();
dummy_parent.destroy();
return result;
function getHumanDomain(domain_selector) {
return human_domain_methods.DomainSelector.apply(domain_selector);
}
return {

View File

@ -1,44 +1,27 @@
/* Copyright 2015 Therp BV <http://therp.nl>
* Copyright 2017-2018 Jairo Llopis <jairo.llopis@tecnativa.com>
* Copyright 2020 Alexandre Díaz
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
odoo.define("web_advanced_search", function(require) {
"use strict";
var core = require("web.core");
var Domain = require("web.Domain");
var DomainSelectorDialog = require("web.DomainSelectorDialog");
var field_registry = require("web.field_registry");
var FieldManagerMixin = require("web.FieldManagerMixin");
var FiltersMenu = require("web.FiltersMenu");
var human_domain = require("web_advanced_search.human_domain");
var SearchView = require("web.SearchView");
var Widget = require("web.Widget");
var Char = core.search_filters_registry.get("char");
SearchView.include({
custom_events: _.extend({}, SearchView.prototype.custom_events, {
get_dataset: "_on_get_dataset",
}),
/**
* Add or update a `dataset` attribute in event target
*
* The search view dataset includes things such as the model, which
* is required to make some parts of search views smarter.
*
* @param {OdooEvent} event The target will get the dataset.
*/
_on_get_dataset: function(event) {
event.target.dataset = this.dataset;
event.stopPropagation();
},
});
const config = require("web.config");
const Domain = require("web.Domain");
const DomainSelector = require("web.DomainSelector");
const DomainSelectorDialog = require("web.DomainSelectorDialog");
const field_registry = require("web.field_registry");
const FieldManagerMixin = require("web.FieldManagerMixin");
const FilterMenu = require("web.FilterMenu");
const human_domain = require("web_advanced_search.human_domain");
const Widget = require("web.Widget");
const search_filters_registry = require("web.search_filters_registry");
const Char = search_filters_registry.get("char");
/**
* An almost dummy search proposition, to use with domain widget
*/
var AdvancedSearchProposition = Widget.extend({
const AdvancedSearchProposition = Widget.extend({
/**
* @override
*/
@ -47,38 +30,49 @@ odoo.define("web_advanced_search", function(require) {
this.model = model;
this.domain = new Domain(domain);
this.domain_array = domain;
this._createDomainSelector();
},
/**
* Produce a filter descriptor for advanced searches.
*
* @returns {Object} In the format expected by `web.FiltersMenu`.
* @returns {Object} In the format expected by `web.FilterMenu`.
*/
get_filter: function() {
return {
attrs: {
domain: this.domain_array,
// TODO Remove when merged
// https://github.com/odoo/odoo/pull/25922
string: human_domain.getHumanDomain(
this,
this.model,
this.domain_array
),
string: human_domain.getHumanDomain(this.domain_selector),
},
children: [],
tag: "filter",
};
},
_createDomainSelector: function() {
this.domain_selector = new DomainSelector(
this,
this.model,
this.domain_array
);
this.dummy_parent = $("<div>");
return this.domain_selector.appendTo(this.dummy_parent);
},
destroy: function() {
this.domain_selector.destroy();
this.dummy_parent.remove();
return this._super.apply(this, arguments);
},
});
// Add advanced search features
FiltersMenu.include({
custom_events: _.extend({}, FiltersMenu.prototype.custom_events, {
FilterMenu.include({
custom_events: _.extend({}, FilterMenu.prototype.custom_events, {
domain_selected: "advanced_search_commit",
}),
events: _.extend({}, FiltersMenu.prototype.events, {
events: _.extend({}, FilterMenu.prototype.events, {
"click .o_add_advanced_search": "advanced_search_open",
}),
@ -87,7 +81,9 @@ odoo.define("web_advanced_search", function(require) {
*/
init: function() {
this._super.apply(this, arguments);
this.trigger_up("get_dataset");
this._context = this.getParent().context;
this._modelName = this.getParent().getParent().modelName;
},
/**
@ -96,16 +92,16 @@ odoo.define("web_advanced_search", function(require) {
* @returns {$.Deferred} The opening dialog itself.
*/
advanced_search_open: function() {
var domain_selector_dialog = new DomainSelectorDialog(
const domain_selector_dialog = new DomainSelectorDialog(
this,
this.dataset.model,
this._modelName,
"[]",
{
debugMode: core.debug,
debugMode: config.debug,
readonly: false,
}
);
domain_selector_dialog.opened(function() {
domain_selector_dialog.opened(() => {
// Add 1st domain node by default
domain_selector_dialog.domainSelector._onAddFirstButtonClick();
});
@ -119,13 +115,19 @@ odoo.define("web_advanced_search", function(require) {
*/
advanced_search_commit: function(event) {
_.invoke(this.propositions, "destroy");
var proposition = new AdvancedSearchProposition(
const proposition = new AdvancedSearchProposition(
this,
this.dataset.model,
this._modelName,
event.data.domain
);
// Necessary to ensure that the porposition have the 'fieldSelector'
// is filled
_.defer(
function() {
this.propositions = [proposition];
this._commitSearch();
}.bind(this)
);
},
});
@ -139,7 +141,7 @@ odoo.define("web_advanced_search", function(require) {
* model implementation, which can only hold fake data, given a search view
* has no data on it by definition.
*/
var Relational = Char.extend(FieldManagerMixin, {
const Relational = Char.extend(FieldManagerMixin, {
tagName: "div",
className: "x2x_container",
attributes: {},
@ -153,7 +155,7 @@ odoo.define("web_advanced_search", function(require) {
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) {
this.operators = _.sortBy(this.operators, op => {
switch (op.value) {
case "=":
return -2;
@ -164,26 +166,25 @@ odoo.define("web_advanced_search", function(require) {
}
});
// Create dummy record with only the field the user is searching
var params = {
const params = {
fieldNames: [this.field.name],
modelName: this.dataset.model,
context: this.dataset.context,
fields: {},
type: "record",
viewType: "default",
fieldsInfo: {
default: {},
},
};
// See https://stackoverflow.com/a/11508530/1468388
// to know how to include this in the previous step in ES6
params.fields[this.field.name] = _.omit(
fields: {
[this.field.name]: _.omit(
this.field,
// User needs all records, to actually produce a new domain
"domain",
// Onchanges make no sense in this context, there's no record
"onChange"
);
),
},
};
if (this.field.type.endsWith("2many")) {
// X2many fields behave like m2o in the search context
params.fields[this.field.name].type = "many2one";
@ -200,7 +201,7 @@ odoo.define("web_advanced_search", function(require) {
* @override
*/
start: function() {
var result = this._super.apply(this, arguments);
const result = this._super.apply(this, arguments);
// Render the initial widget
result.done($.proxy(this, "show_inputs", $("<input value='='/>")));
return result;
@ -240,14 +241,14 @@ odoo.define("web_advanced_search", function(require) {
default:
this._field_widget_name = "char";
}
var _Widget = field_registry.get(this._field_widget_name);
const _Widget = field_registry.get(this._field_widget_name);
// Destroy previous widget, if any
if (this._field_widget) {
this._field_widget.destroy();
delete this._field_widget;
}
// Create new widget
var options = {
const options = {
mode: "edit",
attrs: {
options: {
@ -283,7 +284,9 @@ odoo.define("web_advanced_search", function(require) {
return FieldManagerMixin._applyChanges.apply(this, arguments);
}
return $.Deferred().resolve();
return new Promise(resolve => {
resolve();
});
},
/**
@ -335,7 +338,7 @@ odoo.define("web_advanced_search", function(require) {
});
// Register search filter widgets
core.search_filters_registry
search_filters_registry
.add("many2many", Relational)
.add("many2one", Relational)
.add("one2many", Relational);

View File

@ -2,10 +2,19 @@
<!-- 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-extend="FilterMenuGenerator">
<t t-jquery=".o_add_filter_menu" t-operation="after">
<div role="separator" class="dropdown-divider" />
<a class="dropdown-item o_add_advanced_search">Add Advanced Filter</a>
<div
t-if="Object.keys(widget.fields).length !== 0"
role="separator"
class="dropdown-divider o_generator_menu"
/>
<button
t-if="Object.keys(widget.fields).length !== 0"
type="button"
class="dropdown-item o_generator_menu o_add_advanced_search"
aria-expanded="false"
>Add Advanced Filter</button>
</t>
</t>
</templates>