Skip to content
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
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ repos:
rev: 3.1.8
hooks:
- id: setuptools-odoo-make-default
additional_dependencies: ["setuptools<72"]
- id: setuptools-odoo-get-requirements
additional_dependencies: ["setuptools<72"]
args:
- --output
- requirements.txt
Expand Down
119 changes: 119 additions & 0 deletions account_statement_import_online_qonto/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
=============================
Online Bank Statements: Qonto
=============================

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

.. |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/14.0/account_statement_import_online_qonto
: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-14-0/bank-statement-import-14-0-account_statement_import_online_qonto
: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=14.0
:alt: Try me on Runboat

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

This module provides online bank statements from Qonto Bank.

**Table of contents**

.. contents::
:local:

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

To configure online bank statements provider:

#. Go to *Invoicing > Configuration > Bank Accounts*
#. Open bank account to configure and edit it
#. Set *Bank Feeds* to *Online*
#. Select *Qonto* as online bank statements provider in
*Online Bank Statements (OCA)* section
#. Save the bank account
#. Click on provider and configure provider-specific settings.

or, alternatively:

#. Go to *Invoicing > Overview*
#. Open settings of the corresponding journal account
#. Switch to *Bank Account* tab
#. Set *Bank Feeds* to *Online*
#. Select *Qonto* as online bank statements provider in
*Online Bank Statements (OCA)* section
#. Save the bank account
#. Click on provider and configure provider-specific settings.

To obtain *Login* and *Key*:

#. Open `Qonto <https://app.qonto.com/>`__.
#. Go to *Settings*
#. Go to *Api Integration*, click *Generate Key*

Usage
=====

To pull historical bank statements:

#. Go to *Invoicing > Configuration > Bank Accounts*
#. Select specific bank accounts
#. Launch *Actions > Online Bank Statements Pull Wizard*
#. Configure date interval and click *Pull*

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_qonto%0Aversion:%2014.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
~~~~~~~

* Florent de Labarre

Contributors
~~~~~~~~~~~~

* Florent de Labarre
* `Tecnativa <https://www.tecnativa.com>`__:

* Pedro M. Baeza

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/14.0/account_statement_import_online_qonto>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions account_statement_import_online_qonto/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
12 changes: 12 additions & 0 deletions account_statement_import_online_qonto/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Online Bank Statements: Qonto",
"version": "14.0.1.0.0",
"category": "Account",
"website": "https://github.com/OCA/bank-statement-import",
"author": "Florent de Labarre, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": ["account_statement_import_online"],
"data": ["views/online_bank_statement_provider.xml"],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_statement_import_online_qonto
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: account_statement_import_online_qonto
#: code:addons/account_statement_import_online_qonto/models/online_bank_statement_provider_qonto.py:0
#: code:addons/account_statement_import_online_qonto/models/online_bank_statement_provider_qonto.py:0
#, python-format
msgid ""
"%s \n"
"\n"
" %s"
msgstr ""

#. module: account_statement_import_online_qonto
#: code:addons/account_statement_import_online_qonto/models/online_bank_statement_provider_qonto.py:0
#, python-format
msgid "Currency %s used in transaction ID %s doesn't exist in Odoo."
msgstr ""

#. module: account_statement_import_online_qonto
#: model_terms:ir.ui.view,arch_db:account_statement_import_online_qonto.online_bank_statement_provider_form
msgid "Key"
msgstr ""

#. module: account_statement_import_online_qonto
#: model_terms:ir.ui.view,arch_db:account_statement_import_online_qonto.online_bank_statement_provider_form
msgid "Login"
msgstr ""

#. module: account_statement_import_online_qonto
#: model:ir.model,name:account_statement_import_online_qonto.model_online_bank_statement_provider
msgid "Online Bank Statement Provider"
msgstr ""

#. module: account_statement_import_online_qonto
#: code:addons/account_statement_import_online_qonto/models/online_bank_statement_provider_qonto.py:0
#, python-format
msgid "Please fill login and key"
msgstr ""

#. module: account_statement_import_online_qonto
#: code:addons/account_statement_import_online_qonto/models/online_bank_statement_provider_qonto.py:0
#, python-format
msgid "Qonto : wrong configuration, unknow account %s"
msgstr ""

#. module: account_statement_import_online_qonto
#: code:addons/account_statement_import_online_qonto/models/online_bank_statement_provider_qonto.py:0
#, python-format
msgid "Transaction ID %s has not local_currency. This should never happen."
msgstr ""
4 changes: 4 additions & 0 deletions account_statement_import_online_qonto/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2020 Florent de Labarre
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import online_bank_statement_provider_qonto
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Copyright 2020 Florent de Labarre
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import json
from datetime import datetime

import pytz
import requests

from odoo import _, api, fields, models
from odoo.exceptions import UserError

from odoo.addons.base.models.res_bank import sanitize_account_number

QONTO_ENDPOINT = "https://thirdparty.qonto.com/v2"


class OnlineBankStatementProviderQonto(models.Model):
_inherit = "online.bank.statement.provider"

@api.model
def _get_available_services(self):
return super()._get_available_services() + [
("qonto", "Qonto"),
]

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

def _get_statement_date(self, date_since, date_until):
self.ensure_one()
if self.service != "qonto":
return super()._get_statement_date(date_since, date_until)
return date_since.astimezone(pytz.timezone("Europe/Paris")).date()

#########
# qonto #
#########

def _qonto_header(self):
self.ensure_one()
if self.username and self.password:
return {"Authorization": "{}:{}".format(self.username, self.password)}
raise UserError(_("Please fill login and key"))

def _qonto_get_bank_account_ids(self):
self.ensure_one()
url = QONTO_ENDPOINT + "/organization"
response = requests.get(url, headers=self._qonto_header(), timeout=10)
if response.status_code == 200:
data = json.loads(response.text)
res = {}
organization_data = data.get("organization", {})
for account in organization_data.get("bank_accounts", []):
iban = sanitize_account_number(account.get("iban", ""))
res[iban] = account.get("id", "")
return res
raise UserError(_("%s \n\n %s") % (response.status_code, response.text))

def _qonto_obtain_transactions(self, bank_account_id, date_since, date_until):
self.ensure_one()
url = QONTO_ENDPOINT + "/transactions"
params = {"iban": self.account_number}
if bank_account_id:
params.update({"bank_account_id": bank_account_id})
# settled_at_to param isn't well formatted (ISO 8601) or year is out of range".
# We set the last day of the year in such case.
if date_since and date_until and date_since.year != date_until.year:
date_until = fields.Datetime.from_string(
"%s-12-31 23:59:59" % date_since.year
)
if date_since:
params["settled_at_from"] = (
date_since.replace(microsecond=0).isoformat() + "Z"
)
if date_until:
params["settled_at_to"] = (
date_until.replace(microsecond=0).isoformat() + "Z"
)
transactions = []
current_page = 1
total_pages = 1
while current_page <= total_pages:
params["current_page"] = current_page
data = self._qonto_get_transactions(url, params)
transactions.extend(data.get("transactions", []))
total_pages = data["meta"]["total_pages"]
current_page += 1
return transactions

def _qonto_get_transactions(self, url, params):
response = requests.get(
url,
params=params,
headers=self._qonto_header(),
timeout=10,
)
if response.status_code == 200:
return json.loads(response.text)
raise UserError(_("%s \n\n %s") % (response.status_code, response.text))

def _qonto_prepare_statement_line(
self, transaction, sequence, journal_currency, currencies_code2id
):
date = datetime.strptime(transaction["settled_at"], "%Y-%m-%dT%H:%M:%S.%fZ")
side = 1 if transaction["side"] == "credit" else -1
payment_ref_list = [
transaction["label"],
transaction["reference"],
]
vals_line = {
"sequence": sequence,
"date": date,
"payment_ref": " - ".join([x for x in payment_ref_list if x]) or "/",
"ref": transaction["reference"],
"narration": transaction["note"],
"transaction_type": transaction["operation_type"],
"unique_import_id": transaction["transaction_id"],
"amount": transaction["amount"] * side,
}
if not transaction["local_currency"]:
raise UserError(
_(
"Transaction ID %s has not local_currency. "
"This should never happen."
)
% transaction["transaction_id"]
)
if transaction["local_currency"] not in currencies_code2id:
raise UserError(
_("Currency %s used in transaction ID %s doesn't exist in Odoo.")
% (transaction["local_currency"], transaction["transaction_id"])
)
line_currency_id = currencies_code2id[transaction["local_currency"]]
if journal_currency.id != line_currency_id:
vals_line.update(
{
"foreign_currency_id": line_currency_id,
"amount_currency": transaction["local_amount"] * side,
}
)
return vals_line

def _qonto_obtain_statement_data(self, date_since, date_until):
self.ensure_one()
journal = self.journal_id
bank_account_ids = self._qonto_get_bank_account_ids()
bank_account_id = bank_account_ids.get(self.account_number)
if not bank_account_id:
raise UserError(
_("Qonto : wrong configuration, unknow account %s")
% journal.bank_account_id.acc_number
)
transactions = self._qonto_obtain_transactions(
bank_account_id, date_since, date_until
)
journal_currency = journal.currency_id or journal.company_id.currency_id
all_currencies = self.env["res.currency"].search_read([], ["name"])
currencies_code2id = {x["name"]: x["id"] for x in all_currencies}
new_transactions = []
sequence = 0
for transaction in transactions:
sequence += 1
vals_line = self._qonto_prepare_statement_line(
transaction, sequence, journal_currency, currencies_code2id
)
new_transactions.append(vals_line)
if new_transactions:
return new_transactions, {}
return
Loading
Loading