diff --git a/account_statement_import_online_gocardless/__manifest__.py b/account_statement_import_online_gocardless/__manifest__.py index 9ae2ce99..145d04b8 100644 --- a/account_statement_import_online_gocardless/__manifest__.py +++ b/account_statement_import_online_gocardless/__manifest__.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { "name": "Online Bank Statements: GoCardless", - "version": "16.0.1.2.4", + "version": "17.0.1.0.0", "category": "Account", "website": "https://github.com/OCA/bank-statement-import", "author": "ForgeFlow, Tecnativa, Odoo Community Association (OCA)", @@ -22,7 +22,7 @@ "account_statement_import_online_gocardless/static/src/" "lib/gocardless-ui/selector.css", "account_statement_import_online_gocardless/static/src/" - "js/select_bank_widget.js", + "js/select_bank_widget.esm.js", "account_statement_import_online_gocardless/static/src/" "xml/select_bank_widget.xml", ], diff --git a/account_statement_import_online_gocardless/static/src/js/select_bank_widget.esm.js b/account_statement_import_online_gocardless/static/src/js/select_bank_widget.esm.js new file mode 100644 index 00000000..cf70be76 --- /dev/null +++ b/account_statement_import_online_gocardless/static/src/js/select_bank_widget.esm.js @@ -0,0 +1,87 @@ +/** @odoo-module **/ +import {Component, useState} from "@odoo/owl"; +import {Dialog} from "@web/core/dialog/dialog"; +import {_t} from "@web/core/l10n/translation"; +import {registry} from "@web/core/registry"; + +export class GocardlessDialog extends Component { + setup() { + this.state = useState({ + searchString: "", + country: false, + institutions: this.props.context.institutions, + }); + } + onChangeCountry(event) { + var country = false; + if ( + event.target.selectedOptions.length && + event.target.selectedOptions[0].attributes.length + ) { + country = event.target.selectedOptions[0].value; + } + this.state.country = country; + this.state.institutions = this.get_institutions( + country, + this.state.searchString + ); + } + onInstitutionSearch(event) { + var searchString = event.target.value; + this.state.searchString = searchString; + this.state.institutions = this.get_institutions( + this.state.country, + searchString + ); + } + get_institutions(country, searchString) { + var institutions = this.props.context.institutions; + if (country) { + institutions.filter((institution) => + institution.countries.includes(country) + ); + } + return institutions.filter((institution) => + institution.name.toUpperCase().includes(searchString.toUpperCase()) + ); + } + + get country_names() { + return this.props.context.country_names; + } +} +GocardlessDialog.template = + "account_statement_import_online_gocardless.OnlineSyncSearchBankGoCardless"; +GocardlessDialog.components = {Dialog}; + +async function OnlineSyncAccountInstitutionSelector(env, action) { + env.services.dialog.add(GocardlessDialog, { + title: _t("Gocardless selection"), + context: action.context, + onClickInstitution: async function (institutionId) { + if (!institutionId) { + return; + } + await env.services.orm.write( + "online.bank.statement.provider", + [action.context.provider_id], + {gocardless_institution_id: institutionId} + ); + var redirect_url = await env.services.orm.call( + "online.bank.statement.provider", + "action_check_gocardless_agreement", + [[action.context.provider_id]] + ); + if (redirect_url !== undefined) { + window.location.replace(redirect_url); + } + }, + }); +} + +registry + .category("actions") + .add( + "online_sync_institution_selector_gocardless", + OnlineSyncAccountInstitutionSelector + ); diff --git a/account_statement_import_online_gocardless/static/src/js/select_bank_widget.js b/account_statement_import_online_gocardless/static/src/js/select_bank_widget.js deleted file mode 100644 index f257ce4f..00000000 --- a/account_statement_import_online_gocardless/static/src/js/select_bank_widget.js +++ /dev/null @@ -1,121 +0,0 @@ -odoo.define( - "account_bank_statement_import_online_gocardless.acc_config_widget_gocardless", - function (require) { - "use strict"; - - require("web.dom_ready"); - var core = require("web.core"); - var AbstractAction = require("web.AbstractAction"); - var QWeb = core.qweb; - var framework = require("web.framework"); - - var OnlineSyncAccountInstitutionSelector = AbstractAction.extend({ - template: "OnlineSyncSearchBankGoCardless", - init: function (parent, action, options) { - this._super(parent, action, options); - this.context = action.context; - this.results = action.context.institutions; - this.country_names = action.context.country_names; - this.country_selected = action.context.country; - }, - - start: function () { - const self = this; - const $selectCountries = this.$el.find(".country_select"); - const $countryOptions = $( - QWeb.render("OnlineSyncSearchBankGoCardlessCountries", { - country_names: this.country_names, - }) - ); - $countryOptions.appendTo($selectCountries); - if ( - $selectCountries.find("option[value=" + this.country_selected + "]") - .length !== 0 - ) { - $selectCountries.val(this.country_selected); - $selectCountries.change(); - } - $selectCountries.change(function () { - self.country_selected = this.selectedOptions[0].value; - return self.renderSearchResult(); - }); - this.displayState(); - self.$el.find("#bank_search_input").on("keyup", function () { - const input = $(".institution-search-input"); - const filter = input[0].value.toUpperCase(); - const institutionList = $(".list-institution"); - - for (let i = 0; i < institutionList.length; i++) { - const txtValue = institutionList[i].textContent; - if (txtValue.toUpperCase().indexOf(filter) > -1) { - institutionList[i].style.display = ""; - } else { - institutionList[i].style.display = "none"; - } - } - }); - }, - - displayState: function () { - if (this.results.length > 0) { - this.renderSearchResult(); - } - }, - - renderElement: function () { - this._super.apply(this, arguments); - }, - - renderSearchResult: function () { - var self = this; - this.$(".institution-container").html(""); - const filteredInstitutions = this.results.filter(function ( - institution - ) { - return institution.countries.includes(self.country_selected); - }); - var $searchResults = $( - QWeb.render("OnlineSyncSearchBankGoCardlessList", { - institutions: filteredInstitutions, - }) - ); - $searchResults.find("a").click(function () { - framework.blockUI(); - const id = this.getAttribute("data-institution"); - if (id) { - return self - ._rpc({ - model: "online.bank.statement.provider", - method: "write", - args: [ - [self.context.provider_id], - {gocardless_institution_id: id}, - ], - }) - .then(function () { - return self - ._rpc({ - model: "online.bank.statement.provider", - method: "action_check_gocardless_agreement", - args: [[self.context.active_id]], - }) - .then(function (redirect_url) { - if (redirect_url !== undefined) { - window.location.replace(redirect_url); - } - }); - }); - } - }); - $searchResults.appendTo(self.$(".institution-container")); - }, - }); - core.action_registry.add( - "online_sync_institution_selector_gocardless", - OnlineSyncAccountInstitutionSelector - ); - return { - OnlineSyncAccountInstitutionSelector: OnlineSyncAccountInstitutionSelector, - }; - } -); diff --git a/account_statement_import_online_gocardless/static/src/xml/select_bank_widget.xml b/account_statement_import_online_gocardless/static/src/xml/select_bank_widget.xml index d2b4b978..b9c6a680 100644 --- a/account_statement_import_online_gocardless/static/src/xml/select_bank_widget.xml +++ b/account_statement_import_online_gocardless/static/src/xml/select_bank_widget.xml @@ -1,58 +1,75 @@ - - -
-
-
-
- -
- - + + + + + + +
+
+ +
+
+
+ + +
-
-
- -
-
-
- + +
- - - - - - - - - - - - - - -
diff --git a/account_statement_import_online_gocardless/view/online_bank_statement_provider.xml b/account_statement_import_online_gocardless/view/online_bank_statement_provider.xml index 2c8ca375..07b200ef 100644 --- a/account_statement_import_online_gocardless/view/online_bank_statement_provider.xml +++ b/account_statement_import_online_gocardless/view/online_bank_statement_provider.xml @@ -12,34 +12,35 @@