T0662: Added some basic tests for the account_statement_import_sftp module.

This commit is contained in:
luca
2024-03-05 09:05:59 +01:00
committed by ecino
parent e4c6c56fc2
commit 645582f0a0
5 changed files with 258 additions and 38 deletions

View File

@@ -16,11 +16,17 @@ Bank Statement SFTP import
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png .. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-CompassionCH%2Fbank--statement--import-lightgray.png?logo=github .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github
:target: https://github.com/CompassionCH/bank-statement-import/tree/14.0/account_statement_import_sftp :target: https://github.com/OCA/bank-statement-import/tree/14.0/account_statement_import_sftp
:alt: CompassionCH/bank-statement-import :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_sftp
: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| |badge1| |badge2| |badge3| |badge4| |badge5|
This module add the functionality to automatically import into bank statement the files retrieved from SFTP. This module add the functionality to automatically import into bank statement the files retrieved from SFTP.
@@ -43,10 +49,10 @@ Then when the scheduled action of EDI will run you will get your statement impor
Bug Tracker Bug Tracker
=========== ===========
Bugs are tracked on `GitHub Issues <https://github.com/CompassionCH/bank-statement-import/issues>`_. 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. 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 If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/CompassionCH/bank-statement-import/issues/new?body=module:%20account_statement_import_sftp%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. `feedback <https://github.com/OCA/bank-statement-import/issues/new?body=module:%20account_statement_import_sftp%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. Do not contact contributors directly about support or help with technical issues.
@@ -61,20 +67,29 @@ Authors
Contributors Contributors
~~~~~~~~~~~~ ~~~~~~~~~~~~
* Compassion CH (https://www.compassion.ch) * Simon Gonzalez <simon.gonzalez@bluewin.ch>
* Simon Gonzalez <simon.gonzalez@bluewin.ch>
Maintainers 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.
.. |maintainer-OCA| image:: https://github.com/OCA.png?size=40px .. |maintainer-OCA| image:: https://github.com/OCA.png?size=40px
:target: https://github.com/OCA :target: https://github.com/OCA
:alt: OCA :alt: OCA
Current maintainer: Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
|maintainer-OCA| |maintainer-OCA|
This module is part of the `CompassionCH/bank-statement-import <https://github.com/CompassionCH/bank-statement-import/tree/14.0/account_statement_import_sftp>`_ project on GitHub. This module is part of the `OCA/bank-statement-import <https://github.com/OCA/bank-statement-import/tree/14.0/account_statement_import_sftp>`_ project on GitHub.
You are welcome to contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -1,20 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" /> <meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>Bank Statement SFTP import</title> <title>Bank Statement SFTP import</title>
<style type="text/css"> <style type="text/css">
/* /*
:Author: David Goodger (goodger@python.org) :Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $ :Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Copyright: This stylesheet has been placed in the public domain. :Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils. Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet. customize this style sheet.
*/ */
@@ -369,60 +368,64 @@ ul.auto-toc {
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5c3cf1f51472f25338373320dc7fb418546e2fa8d4de688e6f32a1c937267b6a !! source digest: sha256:5c3cf1f51472f25338373320dc7fb418546e2fa8d4de688e6f32a1c937267b6a
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/CompassionCH/bank-statement-import/tree/14.0/account_statement_import_sftp"><img alt="CompassionCH/bank-statement-import" src="https://img.shields.io/badge/github-CompassionCH%2Fbank--statement--import-lightgray.png?logo=github" /></a></p> <p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/bank-statement-import/tree/14.0/account_statement_import_sftp"><img alt="OCA/bank-statement-import" src="https://img.shields.io/badge/github-OCA%2Fbank--statement--import-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/bank-statement-import-14-0/bank-statement-import-14-0-account_statement_import_sftp"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/bank-statement-import&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module add the functionality to automatically import into bank statement the files retrieved from SFTP.</p> <p>This module add the functionality to automatically import into bank statement the files retrieved from SFTP.</p>
<p><strong>Table of contents</strong></p> <p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents"> <div class="contents local topic" id="contents">
<ul class="simple"> <ul class="simple">
<li><a class="reference internal" href="#configuration" id="id1">Configuration</a></li> <li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="id2">Usage</a></li> <li><a class="reference internal" href="#usage" id="toc-entry-2">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id3">Bug Tracker</a></li> <li><a class="reference internal" href="#bug-tracker" id="toc-entry-3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id4">Credits</a><ul> <li><a class="reference internal" href="#credits" id="toc-entry-4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id5">Authors</a></li> <li><a class="reference internal" href="#authors" id="toc-entry-5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id6">Contributors</a></li> <li><a class="reference internal" href="#contributors" id="toc-entry-6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li> <li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
</div> </div>
<div class="section" id="configuration"> <div class="section" id="configuration">
<h1><a class="toc-backref" href="#id1">Configuration</a></h1> <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>To configure you should configure an EDI Backend with the backend type <em>Bank SFTP</em></p> <p>To configure you should configure an EDI Backend with the backend type <em>Bank SFTP</em></p>
</div> </div>
<div class="section" id="usage"> <div class="section" id="usage">
<h1><a class="toc-backref" href="#id2">Usage</a></h1> <h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<p>To use this module you should configure an exchange type and a backend SFTP. <p>To use this module you should configure an exchange type and a backend SFTP.
Then when the scheduled action of EDI will run you will get your statement imported automatically.</p> Then when the scheduled action of EDI will run you will get your statement imported automatically.</p>
</div> </div>
<div class="section" id="bug-tracker"> <div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1> <h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/CompassionCH/bank-statement-import/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/bank-statement-import/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported. 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 If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/CompassionCH/bank-statement-import/issues/new?body=module:%20account_statement_import_sftp%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> <a class="reference external" href="https://github.com/OCA/bank-statement-import/issues/new?body=module:%20account_statement_import_sftp%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
<h1><a class="toc-backref" href="#id4">Credits</a></h1> <h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
<div class="section" id="authors"> <div class="section" id="authors">
<h2><a class="toc-backref" href="#id5">Authors</a></h2> <h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<ul class="simple"> <ul class="simple">
<li>Compassion CH</li> <li>Compassion CH</li>
</ul> </ul>
</div> </div>
<div class="section" id="contributors"> <div class="section" id="contributors">
<h2><a class="toc-backref" href="#id6">Contributors</a></h2> <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple"> <ul class="simple">
<li>Compassion CH (<a class="reference external" href="https://www.compassion.ch">https://www.compassion.ch</a>) <li>Simon Gonzalez &lt;<a class="reference external" href="mailto:simon.gonzalez&#64;bluewin.ch">simon.gonzalez&#64;bluewin.ch</a>&gt;</li>
* Simon Gonzalez &lt;<a class="reference external" href="mailto:simon.gonzalez&#64;bluewin.ch">simon.gonzalez&#64;bluewin.ch</a>&gt;</li>
</ul> </ul>
</div> </div>
<div class="section" id="maintainers"> <div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id7">Maintainers</a></h2> <h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>Current maintainer:</p> <p>This module is maintained by the OCA.</p>
<p><a class="reference external" href="https://github.com/OCA"><img alt="OCA" src="https://github.com/OCA.png?size=40px" /></a></p> <a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>This module is part of the <a class="reference external" href="https://github.com/CompassionCH/bank-statement-import/tree/14.0/account_statement_import_sftp">CompassionCH/bank-statement-import</a> project on GitHub.</p> <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
<p>You are welcome to contribute.</p> mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/OCA"><img alt="OCA" src="https://github.com/OCA.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/bank-statement-import/tree/14.0/account_statement_import_sftp">OCA/bank-statement-import</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -0,0 +1,103 @@
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.053.001.02">
<BkToCstmrStmt>
<GrpHdr>
<MsgId>NEWBANK/NL/20240304120000</MsgId>
<CreDtTm>2024-03-04T12:00:00.000Z</CreDtTm>
</GrpHdr>
<Stmt>
<Id>5678ABC/1</Id>
<LglSeqNb>1</LglSeqNb>
<CreDtTm>2024-03-04T12:00:00.000Z</CreDtTm>
<FrToDt>
<FrDtTm>2024-03-01T00:00:00.000Z</FrDtTm>
<ToDtTm>2024-03-03T23:59:59.999Z</ToDtTm>
</FrToDt>
<Acct>
<Id>
<IBAN>NL12ABCD3456789012</IBAN>
</Id>
<Nm>New Company Ltd</Nm>
<Svcr>
<FinInstnId>
<BIC>NEWBNL2X</BIC>
</FinInstnId>
</Svcr>
</Acct>
<Bal>
<Tp>
<CdOrPrtry>
<Cd>OPBD</Cd>
</CdOrPrtry>
</Tp>
<Amt Ccy="EUR">75000.00</Amt>
<CdtDbtInd>CRDT</CdtDbtInd>
<Dt>
<Dt>2024-03-03</Dt>
</Dt>
</Bal>
<Ntry>
<Amt Ccy="EUR">1200.00</Amt>
<CdtDbtInd>DBIT</CdtDbtInd>
<Sts>BOOK</Sts>
<BookgDt>
<Dt>2024-03-02</Dt>
</BookgDt>
<ValDt>
<Dt>2024-03-02</Dt>
</ValDt>
<BkTxCd>
<Domn>
<Cd>PMNT</Cd>
<Fmly>
<Cd>DBIT</Cd>
<SubFmlyCd>SALR</SubFmlyCd>
</Fmly>
</Domn>
<Prtry>
<Cd>SLRY</Cd>
</Prtry>
</BkTxCd>
<NtryDtls>
<TxDtls>
<Refs>
<InstrId>NEWBANK/NL/20240302/001</InstrId>
<EndToEndId>1234567890-NEWBNL2X</EndToEndId>
<MndtId>987654321</MndtId>
</Refs>
<AmtDtls>
<TxAmt>
<Amt Ccy="EUR">1200.00</Amt>
</TxAmt>
</AmtDtls>
<RltdPties>
<Cdtr>
<Nm>Employee X</Nm>
<PstlAdr>
<StrtNm>Street 123</StrtNm>
<TwnNm>City ABC</TwnNm>
<Ctry>NL</Ctry>
</PstlAdr>
</Cdtr>
<CdtrAcct>
<Id>
<IBAN>NL34EFGH5678901234</IBAN>
</Id>
</CdtrAcct>
</RltdPties>
<RltdAgts>
<CdtrAgt>
<FinInstnId>
<BIC>NEWBNL2X</BIC>
</FinInstnId>
</CdtrAgt>
</RltdAgts>
<RmtInf>
<Ustrd>Salary payment for March</Ustrd>
</RmtInf>
<AddtlTxInf>Employee ID: 123456</AddtlTxInf>
</TxDtls>
</NtryDtls>
</Ntry>
</Stmt>
</BkToCstmrStmt>
</Document>

View File

@@ -0,0 +1 @@
from . import test_account_statement_import_process

View File

@@ -0,0 +1,98 @@
import base64
import datetime
from odoo.modules.module import get_module_resource
from odoo.tests.common import TransactionCase
from ..components.account_statement_import_process import EdiBankStatementImportProcess
class MockExchangeRecord:
__slots__ = ["exchange_file", "exchange_filename"]
def __init__(self, exchange_file, exchange_filename: str):
self.exchange_file = exchange_file
self.exchange_filename = exchange_filename
class MockWorkContext:
__slots__ = ["env"]
def __init__(self, env):
self.env = env
class EdiBankStatementImportProcessTest(EdiBankStatementImportProcess):
_name = "edi.input.process.bank.statement.import.test"
_inherit = "edi.input.process.bank.statement.import"
def __init__(self, exchange_record: MockExchangeRecord, *args, **kwargs):
super().__init__(*args, **kwargs)
self.exchange_record = exchange_record
class TestAccountStatementImportProcess(TransactionCase):
def setUp(self):
super(TestAccountStatementImportProcess, self).setUp()
bank = self.env["res.partner.bank"].create(
{
"acc_number": "NL12ABCD3456789012",
"partner_id": self.env.ref("base.main_partner").id,
"company_id": self.env.ref("base.main_company").id,
"bank_id": self.env.ref("base.res_bank_1").id,
}
)
self.env["account.journal"].create(
{
"name": "Bank Journal",
"type": "bank",
"bank_account_id": bank.id,
"currency_id": self.env.ref("base.EUR").id,
}
)
def test_account_statement_import_process(self):
filename = "camt053"
stmt_id = "5678ABC/1"
self._assert_account_statement_import_count(0, filename)
data = get_module_resource(
"account_statement_import_sftp", "test_files", filename
)
with open(data, "rb") as datafile:
file = base64.b64encode(datafile.read())
mock_exchange_record = MockExchangeRecord(file, filename)
mock_work_context = MockWorkContext(self.env)
EdiBankStatementImportProcessTest(
mock_exchange_record,
mock_work_context,
).process()
elt = self.env["account.bank.statement"].search(
[("name", "=", stmt_id)],
)
tot = 75000.0
diff = -1200.0
self.assertEqual("5678ABC/1", elt.name)
self.assertEqual(tot, elt.balance_start)
self.assertEqual(tot + diff, elt.balance_end)
self.assertEqual(datetime.date(2024, 3, 2), elt.date)
self.assertEqual("open", elt.state)
lines = elt.line_ids
self.assertEqual(diff, lines[0].amount)
self._assert_account_statement_import_count(1, filename)
def _assert_account_statement_import_count(self, count, filename):
self.assertEqual(
count,
self.env["account.statement.import"].search_count(
[("statement_filename", "=", filename)]
),
)