[MIG] web_widget_domain_editor_dialog: Migration to 16.0

pull/2875/head
Carlos Roca 2023-11-14 07:53:01 +01:00 committed by David
parent 8589826a89
commit a832fb51d3
8 changed files with 139 additions and 161 deletions

View File

@ -7,7 +7,7 @@ Web Widget Domain Editor Dialog
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:d65154dd6473cf94aca066e7ee90fd83de2f10290940733267e9bc0e44177281 !! source digest: sha256:556e58fec03e10a766775e9fcf51a71af99cd84efaa2ee47cd937bee7ef9312f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@ -17,13 +17,13 @@ Web Widget Domain Editor Dialog
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
:target: https://github.com/OCA/web/tree/15.0/web_widget_domain_editor_dialog :target: https://github.com/OCA/web/tree/16.0/web_widget_domain_editor_dialog
:alt: OCA/web :alt: OCA/web
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_widget_domain_editor_dialog :target: https://translation.odoo-community.org/projects/web-16-0/web-16-0-web_widget_domain_editor_dialog
:alt: Translate me on Weblate :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=15.0 :target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=16.0
:alt: Try me on Runboat :alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
@ -60,7 +60,7 @@ with a user filter:
You can still edit the filter with Odoo's widget after that. You can still edit the filter with Odoo's widget after that.
.. figure:: https://raw.githubusercontent.com/OCA/web/15.0/web_widget_domain_editor_dialog/static/src/img/behaviour.gif .. figure:: https://raw.githubusercontent.com/OCA/web/16.0/web_widget_domain_editor_dialog/static/src/img/behaviour.gif
:align: center :align: center
:width: 600 px :width: 600 px
@ -70,7 +70,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_. 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. In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_widget_domain_editor_dialog%0Aversion:%2015.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_widget_domain_editor_dialog%0Aversion:%2016.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. Do not contact contributors directly about support or help with technical issues.
@ -108,6 +108,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
This module is part of the `OCA/web <https://github.com/OCA/web/tree/15.0/web_widget_domain_editor_dialog>`_ project on GitHub. This module is part of the `OCA/web <https://github.com/OCA/web/tree/16.0/web_widget_domain_editor_dialog>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -3,7 +3,7 @@
{ {
"name": "Web Widget Domain Editor Dialog", "name": "Web Widget Domain Editor Dialog",
"summary": "Recovers the Domain Editor Dialog functionality", "summary": "Recovers the Domain Editor Dialog functionality",
"version": "15.0.1.0.1", "version": "16.0.1.0.0",
"category": "Web", "category": "Web",
"author": "Tecnativa," "Odoo Community Association (OCA)", "author": "Tecnativa," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/web", "website": "https://github.com/OCA/web",
@ -11,7 +11,7 @@
"depends": ["web"], "depends": ["web"],
"assets": { "assets": {
"web.assets_backend": [ "web.assets_backend": [
"/web_widget_domain_editor_dialog/static/src/js/*.js", "/web_widget_domain_editor_dialog/static/src/js/*.esm.js",
], ],
}, },
"installable": True, "installable": True,

View File

@ -4,7 +4,7 @@
# #
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 15.0\n" "Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"Last-Translator: \n" "Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
@ -14,15 +14,15 @@ msgstr ""
"Plural-Forms: \n" "Plural-Forms: \n"
#. module: web_widget_domain_editor_dialog #. module: web_widget_domain_editor_dialog
#. openerp-web #. odoo-javascript
#: code:addons/web_widget_domain_editor_dialog/static/src/js/basic_fields.js:0 #: code:addons/web_widget_domain_editor_dialog/static/src/js/domain_field.esm.js:0
#, python-format #, python-format
msgid "Select records..." msgid "Select records..."
msgstr "" msgstr ""
#. module: web_widget_domain_editor_dialog #. module: web_widget_domain_editor_dialog
#. openerp-web #. odoo-javascript
#: code:addons/web_widget_domain_editor_dialog/static/src/js/widget_domain_editor_dialog.js:0 #: code:addons/web_widget_domain_editor_dialog/static/src/js/domain_field.esm.js:0
#, python-format #, python-format
msgid "Selected domain" msgid "Selected domain"
msgstr "" msgstr ""

View File

@ -367,9 +367,9 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:d65154dd6473cf94aca066e7ee90fd83de2f10290940733267e9bc0e44177281 !! source digest: sha256:556e58fec03e10a766775e9fcf51a71af99cd84efaa2ee47cd937bee7ef9312f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" 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 image-reference" 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 image-reference" href="https://github.com/OCA/web/tree/15.0/web_widget_domain_editor_dialog"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_widget_domain_editor_dialog"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p> <p><a class="reference external image-reference" 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 image-reference" 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 image-reference" href="https://github.com/OCA/web/tree/16.0/web_widget_domain_editor_dialog"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-16-0/web-16-0-web_widget_domain_editor_dialog"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Since v11 introduced the new domain editor widget its not possible to edit <p>Since v11 introduced the new domain editor widget its not possible to edit
the selected records from the current domain.</p> the selected records from the current domain.</p>
<p>This module reintroduces that dialog to complement the current widget with the <p>This module reintroduces that dialog to complement the current widget with the
@ -410,7 +410,7 @@ records and those unfolded groups will be set as filters to.</li>
</blockquote> </blockquote>
<p>You can still edit the filter with Odoos widget after that.</p> <p>You can still edit the filter with Odoos widget after that.</p>
<div class="figure align-center"> <div class="figure align-center">
<img alt="https://raw.githubusercontent.com/OCA/web/15.0/web_widget_domain_editor_dialog/static/src/img/behaviour.gif" src="https://raw.githubusercontent.com/OCA/web/15.0/web_widget_domain_editor_dialog/static/src/img/behaviour.gif" style="width: 600px;" /> <img alt="https://raw.githubusercontent.com/OCA/web/16.0/web_widget_domain_editor_dialog/static/src/img/behaviour.gif" src="https://raw.githubusercontent.com/OCA/web/16.0/web_widget_domain_editor_dialog/static/src/img/behaviour.gif" style="width: 600px;" />
</div> </div>
</div> </div>
<div class="section" id="bug-tracker"> <div class="section" id="bug-tracker">
@ -418,7 +418,7 @@ records and those unfolded groups will be set as filters to.</li>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web/issues">GitHub Issues</a>. <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. In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_widget_domain_editor_dialog%0Aversion:%2015.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_widget_domain_editor_dialog%0Aversion:%2016.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> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@ -450,7 +450,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/15.0/web_widget_domain_editor_dialog">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/16.0/web_widget_domain_editor_dialog">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> <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>
</div> </div>

View File

@ -1,58 +0,0 @@
/* Copyright 2019 Tecnativa - David Vidal
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
odoo.define("web_widget_domain_editor_dialog.basic_fields", function (require) {
"use strict";
const {_t} = require("web.core");
const {FieldDomain} = require("web.basic_fields");
const DomainEditorDialog = require("web_widget_domain_editor_dialog.DomainEditorDialog");
FieldDomain.include({
_onShowSelectionButtonClick: function (event) {
event.preventDefault();
const _this = this;
if (this.mode === "readonly") {
return this._super.apply(this, arguments);
}
if (!this.value) {
this.value = [];
}
const dialog = new DomainEditorDialog(this, {
title: _t("Select records..."),
res_model: this._domainModel,
default_domain: this.value,
readonly: false,
disable_multiple_selection: false,
no_create: true,
context: this.record.getContext({
fieldName: this.name,
viewType: this.viewType,
}),
on_selected: function (selected_ids) {
_this.inDomainEditor = true;
_this.domainSelector
.setDomain(this.get_domain(selected_ids))
.then(_this._replaceContent.bind(_this));
// Trigger from domainSelector instead of _this
// for execute https://github.com/odoo/odoo/blob/15.0/addons/web/static/src/legacy/js/widgets/domain_selector.js#L623
_this.domainSelector.trigger_up("domain_changed", {
child: _this,
noRedraw: true,
});
},
}).open();
this.trigger("dialog_opened", dialog);
return dialog;
},
_onDomainSelectorValueChange: function () {
// This allows the domain editor to work with in dialog mode
const inDialog = this.inDialog;
if (this.inDomainEditor) {
this.inDialog = false;
}
this._super.apply(this, arguments);
this.inDialog = inDialog;
},
});
});

View File

@ -0,0 +1,39 @@
/** @odoo-module **/
/* Copyright 2019 Tecnativa - David Vidal
* Copyright 2024 Tecnativa - Carlos Roca
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
import {DomainField} from "@web/views/fields/domain/domain_field";
import {DomainEditorDialog} from "./widget_domain_editor_dialog.esm";
import {patch} from "@web/core/utils/patch";
patch(DomainField.prototype, "web_widget_domain_editor_dialog.DomainField", {
onButtonClick(ev) {
ev.preventDefault();
const self = this;
if (this.props.readonly) {
return this._super.apply(this, arguments);
}
if (!this.props.value) {
this.props.value = "[]";
}
this.addDialog(DomainEditorDialog, {
title: this.env._t("Select records..."),
noCreate: true,
multiSelect: true,
resModel: this.getResModel(this.props),
dynamicFilters: [
{
description: this.env._t("Selected domain"),
domain:
this.getDomain(this.props.value).toList(
this.getContext(this.props)
) || [],
},
],
context: this.getContext(this.props) || {},
onSelected: function (resIds) {
self.update(this.get_domain(resIds));
},
});
},
});

View File

@ -0,0 +1,81 @@
/** @odoo-module **/
/* Copyright 2019 Tecnativa - David Vidal
* Copyright 2024 Tecnativa - Carlos Roca
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
import {SelectCreateDialog} from "@web/views/view_dialogs/select_create_dialog";
import {Domain} from "@web/core/domain";
export function findChildren(comp, predicate = (e) => e) {
const queue = [];
[].unshift.apply(queue, Object.values(comp.__owl__.children));
while (queue.length > 0) {
const curNode = queue.pop();
if (predicate(curNode)) {
return curNode;
}
[].unshift.apply(queue, Object.values(curNode.component.__owl__.children));
}
}
export class DomainEditorDialog extends SelectCreateDialog {
/**
* Bind this to allow call get_domain from onSelected function definition.
*
* @override
*/
async select(resIds) {
if (this.props.onSelected) {
const onselected = this.props.onSelected.bind(this);
await onselected(resIds);
this.props.close();
}
}
_getDomainOfGroups(groups, domain) {
const groups_unfolded = _.filter(groups, (g) => !g.isFolded);
var groups_domain = [];
for (var group of groups_unfolded) {
var group_list = group.list;
if (group_list.groupBy.length) {
groups_domain.push(this._getDomainOfGroups(group_list.groups, domain));
} else {
var group_domain = group_list.domain;
_.each(domain, (d) => {
group_domain = _.without(
group_domain,
_.filter(group_domain, (x) => {
return _.isEqual(x, d);
})[0]
);
});
group_domain = _.without(group_domain, "&");
groups_domain.push(group_domain);
}
}
return Domain.or(groups_domain).toList();
}
get_domain(resIds) {
const dynamicList = findChildren(
this,
(node) =>
node.component &&
node.component.model &&
node.component.model.root &&
["DynamicGroupList", "DynamicRecordList"].includes(
node.component.model.root.constructor.name
)
).component.model.root;
let domain = dynamicList.domain;
let group_domain = [];
if ($(".o_list_record_selector input").prop("checked")) {
if (dynamicList.groupBy.length) {
group_domain = this._getDomainOfGroups(dynamicList.groups, domain);
}
} else {
domain = domain.concat([["id", "in", resIds]]);
}
return JSON.stringify(domain.concat(group_domain));
}
}

View File

@ -1,84 +0,0 @@
/* Copyright 2019 Tecnativa - David Vidal
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
odoo.define("web_widget_domain_editor_dialog.DomainEditorDialog", function (require) {
"use strict";
const {_t} = require("web.core");
const {SelectCreateDialog} = require("web.view_dialogs");
const Domain = require("web.Domain");
const DomainEditorDialog = SelectCreateDialog.extend({
init: function () {
this._super.apply(this, arguments);
const _this = this;
let domain = Domain.prototype.stringToArray(_this.options.default_domain);
// HACK: dynamicFilters don't work fine with booleans as they pass through
// pyeval as a jason domain. This way, they're full compatible and we avoid
// making an _rpc call.
domain = domain.map((tuple) => {
if (tuple[2] === true) {
tuple[2] = 1;
}
if (tuple[2] === false) {
tuple[2] = 0;
}
return tuple;
});
this.options = _.defaults(this.options, {
dynamicFilters: [
{
description: _t("Selected domain"),
domain: domain,
},
],
});
},
get_domain: function (selected_ids) {
let group_domain = [];
const search_data = this.viewController.renderer.state;
let domain = search_data.domain;
if (this.$(".o_list_record_selector input").prop("checked")) {
if (search_data.groupedBy.length) {
group_domain = _.filter(search_data.data, (x) => {
return x.res_ids.length;
}).map((x) => {
return x.domain;
});
group_domain = _.flatten(group_domain, true);
// Compute domain difference
_.each(domain, (d) => {
group_domain = _.without(
group_domain,
_.filter(group_domain, (x) => {
return _.isEqual(x, d);
})[0]
);
});
// Strip operators to leave just the group domains
group_domain = _.without(group_domain, "&");
// Add OR operators if there is more than one group
group_domain = _.times(
group_domain.length - 1,
_.constant("|")
).concat(group_domain);
}
} else {
const ids = selected_ids.map((x) => {
return x.id;
});
domain = domain.concat([["id", "in", ids]]);
}
return domain.concat(group_domain);
},
on_view_list_loaded: function () {
this.$(".o_list_record_selector input").prop("checked", true);
this.$footer
.find(".o_selectcreatepopup_search_select")
.prop("disabled", false);
},
});
return DomainEditorDialog;
});