From a832fb51d3aa386fcbec895132dccaa55b5b39b1 Mon Sep 17 00:00:00 2001 From: Carlos Roca Date: Tue, 14 Nov 2023 07:53:01 +0100 Subject: [PATCH] [MIG] web_widget_domain_editor_dialog: Migration to 16.0 --- web_widget_domain_editor_dialog/README.rst | 14 ++-- .../__manifest__.py | 4 +- .../i18n/web_widget_domain_editor_dialog.pot | 10 +-- .../static/description/index.html | 10 +-- .../static/src/js/basic_fields.js | 58 ------------- .../static/src/js/domain_field.esm.js | 39 +++++++++ .../src/js/widget_domain_editor_dialog.esm.js | 81 ++++++++++++++++++ .../src/js/widget_domain_editor_dialog.js | 84 ------------------- 8 files changed, 139 insertions(+), 161 deletions(-) delete mode 100644 web_widget_domain_editor_dialog/static/src/js/basic_fields.js create mode 100644 web_widget_domain_editor_dialog/static/src/js/domain_field.esm.js create mode 100644 web_widget_domain_editor_dialog/static/src/js/widget_domain_editor_dialog.esm.js delete mode 100644 web_widget_domain_editor_dialog/static/src/js/widget_domain_editor_dialog.js diff --git a/web_widget_domain_editor_dialog/README.rst b/web_widget_domain_editor_dialog/README.rst index 0a806f931..e4730794b 100644 --- a/web_widget_domain_editor_dialog/README.rst +++ b/web_widget_domain_editor_dialog/README.rst @@ -7,7 +7,7 @@ Web Widget Domain Editor Dialog !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:d65154dd6473cf94aca066e7ee90fd83de2f10290940733267e9bc0e44177281 + !! source digest: sha256:556e58fec03e10a766775e9fcf51a71af99cd84efaa2ee47cd937bee7ef9312f !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |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 :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/15.0/web_widget_domain_editor_dialog + :target: https://github.com/OCA/web/tree/16.0/web_widget_domain_editor_dialog :alt: OCA/web .. |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 .. |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 |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. -.. 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 :width: 600 px @@ -70,7 +70,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. 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 -`feedback `_. +`feedback `_. 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 promote its widespread use. -This module is part of the `OCA/web `_ project on GitHub. +This module is part of the `OCA/web `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_widget_domain_editor_dialog/__manifest__.py b/web_widget_domain_editor_dialog/__manifest__.py index c5a343d74..7dfdd8a4c 100644 --- a/web_widget_domain_editor_dialog/__manifest__.py +++ b/web_widget_domain_editor_dialog/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Web Widget Domain Editor Dialog", "summary": "Recovers the Domain Editor Dialog functionality", - "version": "15.0.1.0.1", + "version": "16.0.1.0.0", "category": "Web", "author": "Tecnativa," "Odoo Community Association (OCA)", "website": "https://github.com/OCA/web", @@ -11,7 +11,7 @@ "depends": ["web"], "assets": { "web.assets_backend": [ - "/web_widget_domain_editor_dialog/static/src/js/*.js", + "/web_widget_domain_editor_dialog/static/src/js/*.esm.js", ], }, "installable": True, diff --git a/web_widget_domain_editor_dialog/i18n/web_widget_domain_editor_dialog.pot b/web_widget_domain_editor_dialog/i18n/web_widget_domain_editor_dialog.pot index 859e49f6b..e36150d0a 100644 --- a/web_widget_domain_editor_dialog/i18n/web_widget_domain_editor_dialog.pot +++ b/web_widget_domain_editor_dialog/i18n/web_widget_domain_editor_dialog.pot @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 15.0\n" +"Project-Id-Version: Odoo Server 16.0\n" "Report-Msgid-Bugs-To: \n" "Last-Translator: \n" "Language-Team: \n" @@ -14,15 +14,15 @@ msgstr "" "Plural-Forms: \n" #. module: web_widget_domain_editor_dialog -#. openerp-web -#: code:addons/web_widget_domain_editor_dialog/static/src/js/basic_fields.js:0 +#. odoo-javascript +#: code:addons/web_widget_domain_editor_dialog/static/src/js/domain_field.esm.js:0 #, python-format msgid "Select records..." msgstr "" #. module: web_widget_domain_editor_dialog -#. openerp-web -#: code:addons/web_widget_domain_editor_dialog/static/src/js/widget_domain_editor_dialog.js:0 +#. odoo-javascript +#: code:addons/web_widget_domain_editor_dialog/static/src/js/domain_field.esm.js:0 #, python-format msgid "Selected domain" msgstr "" diff --git a/web_widget_domain_editor_dialog/static/description/index.html b/web_widget_domain_editor_dialog/static/description/index.html index acb4697b6..8405baf43 100644 --- a/web_widget_domain_editor_dialog/static/description/index.html +++ b/web_widget_domain_editor_dialog/static/description/index.html @@ -367,9 +367,9 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:d65154dd6473cf94aca066e7ee90fd83de2f10290940733267e9bc0e44177281 +!! source digest: sha256:556e58fec03e10a766775e9fcf51a71af99cd84efaa2ee47cd937bee7ef9312f !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runboat

Since v11 introduced the new domain editor widget it’s not possible to edit the selected records from the current domain.

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.

You can still edit the filter with Odoo’s widget after that.

-https://raw.githubusercontent.com/OCA/web/15.0/web_widget_domain_editor_dialog/static/src/img/behaviour.gif +https://raw.githubusercontent.com/OCA/web/16.0/web_widget_domain_editor_dialog/static/src/img/behaviour.gif
@@ -418,7 +418,7 @@ records and those unfolded groups will be set as filters to.

Bugs are tracked on GitHub Issues. 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 -feedback.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -450,7 +450,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome

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 project on GitHub.

+

This module is part of the OCA/web project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/web_widget_domain_editor_dialog/static/src/js/basic_fields.js b/web_widget_domain_editor_dialog/static/src/js/basic_fields.js deleted file mode 100644 index 23950a3c7..000000000 --- a/web_widget_domain_editor_dialog/static/src/js/basic_fields.js +++ /dev/null @@ -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; - }, - }); -}); diff --git a/web_widget_domain_editor_dialog/static/src/js/domain_field.esm.js b/web_widget_domain_editor_dialog/static/src/js/domain_field.esm.js new file mode 100644 index 000000000..4d7544977 --- /dev/null +++ b/web_widget_domain_editor_dialog/static/src/js/domain_field.esm.js @@ -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)); + }, + }); + }, +}); diff --git a/web_widget_domain_editor_dialog/static/src/js/widget_domain_editor_dialog.esm.js b/web_widget_domain_editor_dialog/static/src/js/widget_domain_editor_dialog.esm.js new file mode 100644 index 000000000..ab004de16 --- /dev/null +++ b/web_widget_domain_editor_dialog/static/src/js/widget_domain_editor_dialog.esm.js @@ -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)); + } +} diff --git a/web_widget_domain_editor_dialog/static/src/js/widget_domain_editor_dialog.js b/web_widget_domain_editor_dialog/static/src/js/widget_domain_editor_dialog.js deleted file mode 100644 index 8590abc94..000000000 --- a/web_widget_domain_editor_dialog/static/src/js/widget_domain_editor_dialog.js +++ /dev/null @@ -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; -});