Skip to content

Commit

Permalink
[ADD]account_statement_import_online_plaid
Browse files Browse the repository at this point in the history
  • Loading branch information
adasatorres committed Jul 5, 2024
1 parent 9962ba4 commit d8c281f
Show file tree
Hide file tree
Showing 6 changed files with 11,031 additions and 21 deletions.
1 change: 0 additions & 1 deletion account_statement_import_online_plaid/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"assets": {
"web.assets_backend": [
"/account_statement_import_online_plaid/static/src/**/*.js",
"https://cdn.plaid.com/link/v2/stable/link-initialize.js",
],
},
"external_dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,26 @@ def action_sync_with_plaid(self):
plaid_interface = self.env["plaid.interface"]
args = [self.username, self.password, self.plaid_host]
client = plaid_interface._client(*args)
plaid_link_token = plaid_interface._link(client)
lang = self.env["res.lang"].search([("code", "=", self.env.user.lang)]).iso_code
company_name = self.env.user.company_id.name
country_code = self.env.user.company_id.country_id.code
link_token = plaid_interface._link(
client=client,
language=lang,
country_code=country_code,
company_name=company_name,
products=["transactions"],
)
return {
"type": "ir.actions.client",
"tag": "plaid_login",
"args": {"token": plaid_link_token},
"params": {
"call_model": "online.bank.statement.provider",
"call_method": "plaid_create_access_token",
"token": link_token,
"object_id": self.id,
},
"target": "new",
}

def _plaid_retrieve_data(self, date_since, date_until):
Expand All @@ -48,6 +63,7 @@ def _plaid_retrieve_data(self, date_since, date_until):
)
return self._prepare_vals_for_statement(transactions)

@api.model
def plaid_create_access_token(self, public_token, active_id):
provider = self.browse(active_id)
plaid_interface = self.env["plaid.interface"]
Expand Down
12 changes: 6 additions & 6 deletions account_statement_import_online_plaid/models/plaid_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ def _client(self, client_id, secret, host):
except plaid.ApiException as e:
raise ValidationError(_("Error getting client api: %s") % e.body) from e

def _link(self, client):
def _link(self, client, language, country_code, company_name, products):
request = LinkTokenCreateRequest(
products=[Products("transactions")],
client_name="Plaid Test App",
country_codes=[CountryCode("US")],
language="es",
user=LinkTokenCreateRequestUser(client_user_id="client_user_id"),
products=[Products(product) for product in products],
client_name=company_name,
country_codes=[CountryCode(country_code)],
language=language,
user=LinkTokenCreateRequestUser(client_user_id="client"),
)
try:
response = client.link_token_create(request)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
/** @odoo-module **/
/* global Plaid */
import {registry} from "@web/core/registry";

export async function plaid_login(env, action) {
const handler = Plaid.create({
clientName: "Plaid Quickstart",
product: ["transactions"],
onSuccess: (public_token) => {
console.log(env, action);
env.services.orm.call(
"online.bank.statement.provider",
"plaid_create_access_token",
[false, public_token, action.context.active_id]
);
env.services.orm.call(action.params.call_model, action.params.call_method, [
public_token,
action.params.object_id,
]);
},
countryCodes: ["US", "ES"],
language: "es",
token: action.args.token,

token: action.params.token,
});
handler.open();
}
Expand Down
Loading

0 comments on commit d8c281f

Please sign in to comment.