mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
[MIG] account_statement_import_online_gocardless: Migration to 17.0
This commit is contained in:
@@ -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",
|
||||
],
|
||||
|
||||
@@ -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
|
||||
);
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
);
|
||||
@@ -1,6 +1,8 @@
|
||||
<templates xml:space="preserve">
|
||||
|
||||
<t t-name="OnlineSyncSearchBankGoCardless">
|
||||
<t
|
||||
t-name="account_statement_import_online_gocardless.OnlineSyncSearchBankGoCardless"
|
||||
>
|
||||
<Dialog title="props.title" contentClass="props.contentClass">
|
||||
<div class="institution-content-wrapper">
|
||||
<div id="institution-modal-content">
|
||||
<header class="institution-modal-header">
|
||||
@@ -14,7 +16,25 @@
|
||||
for="country_select"
|
||||
class="font-weight-bold"
|
||||
>Available countries:</label>
|
||||
<select id="country_select" class="country_select o_input" />
|
||||
<select
|
||||
id="country_select"
|
||||
class="country_select o_input"
|
||||
t-on-change="onChangeCountry"
|
||||
>
|
||||
<option>Select Country to Filter</option>
|
||||
<t t-if="country_names.length > 0">
|
||||
<t
|
||||
t-foreach="country_names"
|
||||
t-as="country"
|
||||
t-key="country.code"
|
||||
>
|
||||
<option
|
||||
t-attf-value="#{country.code}"
|
||||
t-esc="country.name"
|
||||
/>
|
||||
</t>
|
||||
</t>
|
||||
</select>
|
||||
</div>
|
||||
<br />
|
||||
<input
|
||||
@@ -22,37 +42,34 @@
|
||||
class="institution-search-input"
|
||||
id="bank_search_input"
|
||||
autofocus="true"
|
||||
t-on-keydown="onInstitutionSearch"
|
||||
/>
|
||||
</div>
|
||||
</header>
|
||||
<div class="institution-container institution-search-bx-body">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
<t t-name="OnlineSyncSearchBankGoCardlessList">
|
||||
<t t-if="institutions.length > 0">
|
||||
<t t-foreach="institutions" t-as="institution">
|
||||
<t
|
||||
t-foreach="state.institutions"
|
||||
t-as="institution"
|
||||
t-key="institution.id"
|
||||
>
|
||||
<div class="list-institution">
|
||||
<a
|
||||
t-attf-class="#{'institution-' + institution.id}"
|
||||
t-attf-data-institution="#{institution.id}"
|
||||
t-on-click.prevent="() => this.props.onClickInstitution(institution.id)"
|
||||
style="cursor:pointer"
|
||||
>
|
||||
<img class="institution-logo" t-attf-src="#{institution.logo}" />
|
||||
<img
|
||||
class="institution-logo"
|
||||
t-attf-src="#{institution.logo}"
|
||||
/>
|
||||
<span t-esc="institution.name" />
|
||||
</a>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
</t>
|
||||
<t t-name="OnlineSyncSearchBankGoCardlessCountries">
|
||||
<option>Select Country to Filter</option>
|
||||
<t t-if="country_names.length > 0">
|
||||
<t t-foreach="country_names" t-as="country">
|
||||
<option t-attf-value="#{country.code}" t-esc="country.name" />
|
||||
</t>
|
||||
</t>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
</t>
|
||||
</templates>
|
||||
|
||||
@@ -12,34 +12,35 @@
|
||||
<group
|
||||
name="gocardless"
|
||||
string="GoCardless"
|
||||
attrs="{'invisible':[('service','!=','gocardless')]}"
|
||||
invisible="service != 'gocardless'"
|
||||
>
|
||||
<field name="username" string="Secret ID" />
|
||||
<field name="password" string="Secret Key" />
|
||||
<field
|
||||
name="gocardless_requisition_id"
|
||||
attrs="{'invisible': [('gocardless_requisition_id', '=', False)]}"
|
||||
invisible="not gocardless_requisition_id"
|
||||
groups="base.group_no_one"
|
||||
/>
|
||||
<field
|
||||
name="gocardless_requisition_expiration"
|
||||
attrs="{'invisible': [('gocardless_requisition_id', '=', False)]}"
|
||||
invisible="not gocardless_requisition_id"
|
||||
groups="base.group_no_one"
|
||||
/>
|
||||
<field
|
||||
name="gocardless_institution_id"
|
||||
attrs="{'invisible': [('gocardless_institution_id', '=', False)]}"
|
||||
invisible="not gocardless_institution_id"
|
||||
groups="base.group_no_one"
|
||||
/>
|
||||
<field
|
||||
name="gocardless_account_id"
|
||||
attrs="{'invisible': [('gocardless_account_id', '=', False)]}"
|
||||
invisible="not gocardless_account_id"
|
||||
groups="base.group_no_one"
|
||||
/>
|
||||
<button
|
||||
name="action_select_gocardless_bank"
|
||||
string="Select Bank Account Identifier"
|
||||
attrs="{'invisible': ['|', ('username', '=', False), ('password', '=', False)]}"
|
||||
colspan="2"
|
||||
invisible="not username or not password"
|
||||
type="object"
|
||||
/>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user