Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][MIG] account_statement_import_online_plaid #742

Open
wants to merge 2 commits into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions account_statement_import_online_plaid/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
=================================
Online Bank Statements: plaid.com
=================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:a7b84e04274ce7746346dbb4b33c1d2d98df5306dfde3a173ce2982576104eae
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github
:target: https://github.com/OCA/bank-statement-import/tree/17.0/account_statement_import_online_plaid
:alt: OCA/bank-statement-import
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/bank-statement-import-17-0/bank-statement-import-17-0-account_statement_import_online_plaid
: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/bank-statement-import&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module provides online bank statements from Plaid.com.

**Table of contents**

.. contents::
:local:

Configuration
=============

To configure online bank statements provider:

1. Go to *Invoicing > Configuration > Bank Accounts*
2. Open bank account to configure and edit it
3. Set *Bank Feeds* to *Online*
4. Select *Plaid.com* as online bank statements provider in *Online Bank
Statements (OCA)* section
5. Save the bank account
6. Click on provider and configure provider-specific settings.

or, alternatively:

1. Go to *Invoicing > Overview*
2. Open settings of the corresponding journal account
3. Switch to *Bank Account* tab
4. Set *Bank Feeds* to *Online*
5. Select *Plaid.com* as online bank statements provider in *Online Bank
Statements (OCA)* section
6. Save the bank account
7. Click on provider and configure provider-specific settings.

To obtain *Login* and *Key*:

1. Open `Plaid.com <https://plaid.com/>`__.

Check also ``account_bank_statement_import_online`` configuration
instructions for more information.

Usage
=====

To pull historical bank statements:

1. Go to *Invoicing > Configuration > Bank Accounts*
2. Select specific bank accounts
3. Configure username, password and host for plaid
4. Launch *Actions > Sync with plaid.com*
5. After launch *Actions > Online Bank Statements Pull Wizard*
6. Configure date interval and click *Pull*

If historical data is not needed, then just simply wait for the
scheduled activity "Pull Online Bank Statements" to be executed for
getting new transactions.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/bank-statement-import/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 <https://github.com/OCA/bank-statement-import/issues/new?body=module:%20account_statement_import_online_plaid%0Aversion:%2017.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.

Credits
=======

Authors
-------

* Binhex

Contributors
------------

- `Binhex <https://binhex.cloud>`__:

- Adasat Torres de León <a.torres@binhex.cloud>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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/bank-statement-import <https://github.com/OCA/bank-statement-import/tree/17.0/account_statement_import_online_plaid>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions account_statement_import_online_plaid/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
24 changes: 24 additions & 0 deletions account_statement_import_online_plaid/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2024 Binhex - Adasat Torres de León.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Online Bank Statements: plaid.com",
"version": "17.0.1.0.0",
"category": "Account",
"website": "https://github.com/OCA/bank-statement-import",
"author": "Binhex, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": ["account_statement_import_online"],
"data": [
"security/ir.model.access.csv",
"views/online_bank_statement_provider.xml",
],
"assets": {
"web.assets_backend": [
"/account_statement_import_online_plaid/static/src/**/*.js",
],
},
"external_dependencies": {
"python": ["plaid-python==23.0.0"],
},
}
102 changes: 102 additions & 0 deletions account_statement_import_online_plaid/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_statement_import_online_plaid
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0-20240104\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-05-22 12:02+0000\n"
"PO-Revision-Date: 2024-05-22 13:04+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 3.4.3\n"

#. module: account_statement_import_online_plaid
#: model:ir.model.fields.selection,name:account_statement_import_online_plaid.selection__online_bank_statement_provider__plaid_host__development
msgid "Development"
msgstr "Desarrollo"

#. module: account_statement_import_online_plaid
#. odoo-python
#: code:addons/account_statement_import_online_plaid/models/plaid_interface.py:0
#, python-format
msgid "Error getting access token: %s"
msgstr "Error al obtener el token de acceso: %s"

#. module: account_statement_import_online_plaid
#. odoo-python
#: code:addons/account_statement_import_online_plaid/models/plaid_interface.py:0
#, python-format
msgid "Error getting client api: %s"
msgstr "Error obteniendo api de cliente: %s"

#. module: account_statement_import_online_plaid
#. odoo-python
#: code:addons/account_statement_import_online_plaid/models/plaid_interface.py:0
#, python-format
msgid "Error getting link token: %s"
msgstr "Error al obtener el token de enlace: %s"

#. module: account_statement_import_online_plaid
#. odoo-python
#: code:addons/account_statement_import_online_plaid/models/plaid_interface.py:0
#, python-format
msgid "Error getting transactions: %s"
msgstr "Error al obtener transacciones: %s"

#. module: account_statement_import_online_plaid
#: model_terms:ir.ui.view,arch_db:account_statement_import_online_plaid.online_bank_statement_provider_form
msgid "Login"
msgstr "Iniciar sesión"

#. module: account_statement_import_online_plaid
#: model:ir.model,name:account_statement_import_online_plaid.model_online_bank_statement_provider
msgid "Online Bank Statement Provider"
msgstr "Proveedor de extractos bancarios en línea"

#. module: account_statement_import_online_plaid
#: model:ir.model.fields,field_description:account_statement_import_online_plaid.field_online_bank_statement_provider__plaid_access_token
msgid "Plaid Access Token"
msgstr "Ficha de acceso Plaid"

#. module: account_statement_import_online_plaid
#: model:ir.model.fields,field_description:account_statement_import_online_plaid.field_online_bank_statement_provider__plaid_host
#: model_terms:ir.ui.view,arch_db:account_statement_import_online_plaid.online_bank_statement_provider_form
msgid "Plaid Host"
msgstr "Anfitrión"

#. module: account_statement_import_online_plaid
#: model:ir.model,name:account_statement_import_online_plaid.model_plaid_interface
msgid "Plaid Interface"
msgstr "Interfaz plaid"

#. module: account_statement_import_online_plaid
#: model_terms:ir.ui.view,arch_db:account_statement_import_online_plaid.online_bank_statement_provider_form
msgid "Plaid config"
msgstr "Configuración plaid"

#. module: account_statement_import_online_plaid
#: model:ir.model.fields.selection,name:account_statement_import_online_plaid.selection__online_bank_statement_provider__plaid_host__production
msgid "Production"
msgstr "Producción"

#. module: account_statement_import_online_plaid
#: model:ir.model.fields.selection,name:account_statement_import_online_plaid.selection__online_bank_statement_provider__plaid_host__sandbox
msgid "Sandbox"
msgstr "Salvadera"

#. module: account_statement_import_online_plaid
#: model_terms:ir.ui.view,arch_db:account_statement_import_online_plaid.online_bank_statement_provider_form
msgid "Secret Key"
msgstr "LLave secreta"

#. module: account_statement_import_online_plaid
#: model_terms:ir.ui.view,arch_db:account_statement_import_online_plaid.online_bank_statement_provider_form
msgid "Sync with Plaid.com"
msgstr "Sincronizar con plaid.com"
3 changes: 3 additions & 0 deletions account_statement_import_online_plaid/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import online_bank_statement_provider_plaid
from . import plaid_interface
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copyright 2024 Binhex - Adasat Torres de León.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models


class OnlineBankStatementProvider(models.Model):
_inherit = "online.bank.statement.provider"
plaid_access_token = fields.Char()
plaid_host = fields.Selection(
[
("development", "Development"),
("sandbox", "Sandbox"),
("production", "Production"),
],
default="sandbox",
)

def _obtain_statement_data(self, date_since, date_until):
self.ensure_one()
if self.service != "plaid":
return super()._obtain_statement_data(date_since, date_until)

Check warning on line 21 in account_statement_import_online_plaid/models/online_bank_statement_provider_plaid.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_online_plaid/models/online_bank_statement_provider_plaid.py#L21

Added line #L21 was not covered by tests
return self._plaid_retrieve_data(date_since, date_until), {}

@api.model
def _get_available_services(self):
return super()._get_available_services() + [
("plaid", "Plaid.com"),
]

def action_sync_with_plaid(self):
self.ensure_one()
plaid_interface = self.env["plaid.interface"]
args = [self.username, self.password, self.plaid_host]
client = plaid_interface._client(*args)
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",
"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):
plaid_interface = self.env["plaid.interface"]
args = [self.username, self.password, self.plaid_host]
client = plaid_interface._client(*args)
transactions = plaid_interface._get_transactions(
client, self.plaid_access_token, 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"]
client = plaid_interface._client(

Check warning on line 70 in account_statement_import_online_plaid/models/online_bank_statement_provider_plaid.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_online_plaid/models/online_bank_statement_provider_plaid.py#L68-L70

Added lines #L68 - L70 were not covered by tests
provider.username, provider.password, provider.plaid_host
)
args = [client, public_token]
provider.plaid_access_token = plaid_interface._login(*args)

Check warning on line 74 in account_statement_import_online_plaid/models/online_bank_statement_provider_plaid.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_online_plaid/models/online_bank_statement_provider_plaid.py#L73-L74

Added lines #L73 - L74 were not covered by tests
if provider.plaid_access_token:
return True
return False

Check warning on line 77 in account_statement_import_online_plaid/models/online_bank_statement_provider_plaid.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_online_plaid/models/online_bank_statement_provider_plaid.py#L76-L77

Added lines #L76 - L77 were not covered by tests

def _prepare_vals_for_statement(self, transactions):
return [
{
"date": transaction["date"],
"ref": transaction["name"],
"payment_ref": transaction["name"],
"unique_import_id": transaction["transaction_id"],
"amount": transaction["amount"],
"raw_data": transaction,
}
for transaction in transactions
]
Loading
Loading