mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
[IMP] *_import_adyen: Support statements without payout
This commit is contained in:
committed by
Ronald Portier (Therp BV)
parent
2edfc66a9b
commit
0f54cfbbe9
@@ -84,6 +84,7 @@ class AccountBankStatementImport(models.TransientModel):
|
|||||||
|
|
||||||
An Exception will be thrown if file cannot be parsed.
|
An Exception will be thrown if file cannot be parsed.
|
||||||
"""
|
"""
|
||||||
|
# pylint: disable=too-many-locals,too-many-branches
|
||||||
statement = None
|
statement = None
|
||||||
headers = False
|
headers = False
|
||||||
batch_number = False
|
batch_number = False
|
||||||
@@ -133,7 +134,7 @@ class AccountBankStatementImport(models.TransientModel):
|
|||||||
balance -= fees
|
balance -= fees
|
||||||
self._add_fees_transaction(statement, fees, batch_number)
|
self._add_fees_transaction(statement, fees, batch_number)
|
||||||
if statement["transactions"] and not payout:
|
if statement["transactions"] and not payout:
|
||||||
raise UserError(_("No payout detected in Adyen statement."))
|
_logger.info(_("No payout detected in Adyen statement."))
|
||||||
if self.env.user.company_id.currency_id.compare_amounts(balance, payout) != 0:
|
if self.env.user.company_id.currency_id.compare_amounts(balance, payout) != 0:
|
||||||
raise UserError(
|
raise UserError(
|
||||||
_("Parse error. Balance %s not equal to merchant " "payout %s")
|
_("Parse error. Balance %s not equal to merchant " "payout %s")
|
||||||
@@ -169,6 +170,8 @@ class AccountBankStatementImport(models.TransientModel):
|
|||||||
"""Set columns from headers. There MUST be a 'Company Account' header."""
|
"""Set columns from headers. There MUST be a 'Company Account' header."""
|
||||||
seen_company_account = False
|
seen_company_account = False
|
||||||
for num, header in enumerate(row):
|
for num, header in enumerate(row):
|
||||||
|
if not header.strip():
|
||||||
|
continue # Ignore empty columns.
|
||||||
if header == "Company Account":
|
if header == "Company Account":
|
||||||
seen_company_account = True
|
seen_company_account = True
|
||||||
if header not in COLUMNS:
|
if header not in COLUMNS:
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
Company Account,Merchant Account,Psp Reference,Merchant Reference,Payment Method,Creation Date,TimeZone,Type,Modification Reference,Gross Currency,Gross Debit (GC),Gross Credit (GC),Exchange Rate,Net Currency,Net Debit (NC),Net Credit (NC),Commission (NC),Markup (NC),Scheme Fees (NC),Interchange (NC),Payment Method Variant,Modification Merchant Reference,Batch Number,Reserved4,Reserved5,Reserved6,Reserved7,Reserved8,Reserved9,Reserved10
|
||||||
|
CompanyNL,YOURCOMPANY_ACCOUNT,,,,2022-02-22 00:24:23,CET,Balancetransfer,Balancetransfer,,,,,EUR,,454331.99,,,,,,Balancetransfer from batch 237,238,,,,,,,
|
||||||
|
CompanyNL,YOURCOMPANY_ACCOUNT,,,,2022-03-02 02:21:49,CET,Fee,Transaction Fees March 01 2022,,,,,EUR,0.09,,,,,,,,238,,,,,,,
|
||||||
|
CompanyNL,YOURCOMPANY_ACCOUNT,,,,2022-03-02 02:21:49,CET,Balancetransfer,Balancetransfer,,,,,EUR,454331.90,,,,,,,Balancetransfer to batch 239,238,,,,,,,
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
# Copyright 2017 Opener BV <https://opener.amsterdam>
|
# Copyright 2017 Opener BV <https://opener.amsterdam>
|
||||||
# Copyright 2020 Vanmoof BV <https://www.vanmoof.com>
|
# Copyright 2020 Vanmoof BV <https://www.vanmoof.com>
|
||||||
# Copyright 2015-2021 Therp BV <https://therp.nl>)
|
# Copyright 2015-2022 Therp BV <https://therp.nl>)
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||||
|
"""Run test imports of Adyen files."""
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
@@ -10,6 +11,8 @@ from odoo.tests.common import SavepointCase
|
|||||||
|
|
||||||
|
|
||||||
class TestImportAdyen(SavepointCase):
|
class TestImportAdyen(SavepointCase):
|
||||||
|
"""Run test imports of Adyen files."""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super().setUpClass()
|
super().setUpClass()
|
||||||
@@ -72,6 +75,23 @@ class TestImportAdyen(SavepointCase):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_05_import_adyen_csv(self):
|
||||||
|
""" Test that the Adyen statement without Merchant Payoutcan be imported."""
|
||||||
|
self._test_statement_import(
|
||||||
|
"settlement_detail_report_batch_238.csv", "YOURCOMPANY_ACCOUNT 2022/238",
|
||||||
|
)
|
||||||
|
statement = self.env["account.bank.statement"].search(
|
||||||
|
[], order="create_date desc", limit=1
|
||||||
|
)
|
||||||
|
self.assertEqual(statement.journal_id, self.journal)
|
||||||
|
# Csv lines has 4 lines. Minus 1 header. No extra transaction line.
|
||||||
|
self.assertEqual(len(statement.line_ids), 3)
|
||||||
|
self.assertTrue(
|
||||||
|
self.env.user.company_id.currency_id.is_zero(
|
||||||
|
sum(line.amount for line in statement.line_ids)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def _test_statement_import(self, file_name, statement_name):
|
def _test_statement_import(self, file_name, statement_name):
|
||||||
"""Test correct creation of single statement."""
|
"""Test correct creation of single statement."""
|
||||||
testfile = get_module_resource(
|
testfile = get_module_resource(
|
||||||
@@ -83,7 +103,10 @@ class TestImportAdyen(SavepointCase):
|
|||||||
{"attachment_ids": [(0, 0, {"name": file_name, "datas": data_file})]}
|
{"attachment_ids": [(0, 0, {"name": file_name, "datas": data_file})]}
|
||||||
)
|
)
|
||||||
import_wizard.with_context(
|
import_wizard.with_context(
|
||||||
{"account_bank_statement_import_adyen": True}
|
{
|
||||||
|
"account_bank_statement_import_adyen": True,
|
||||||
|
"journal_id": self.journal.id,
|
||||||
|
}
|
||||||
).import_file()
|
).import_file()
|
||||||
# statement name is account number + '-' + date of last line.
|
# statement name is account number + '-' + date of last line.
|
||||||
statements = self.env["account.bank.statement"].search(
|
statements = self.env["account.bank.statement"].search(
|
||||||
|
|||||||
Reference in New Issue
Block a user