diff --git a/account_move_adyen_import/README.rst b/account_move_adyen_import/README.rst new file mode 100644 index 00000000..5b971f75 --- /dev/null +++ b/account_move_adyen_import/README.rst @@ -0,0 +1,57 @@ +========================== +Journal Entry Adyen import +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:c51de8a7e48679e6304737fa5c987223979f7dc57d5b53b4fd6ce6e0136ae2dd + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-akretion%2Fak--odoo--incubator-lightgray.png?logo=github + :target: https://github.com/akretion/ak-odoo-incubator/tree/16.0/account_move_adyen_import + :alt: akretion/ak-odoo-incubator + +|badge1| |badge2| |badge3| + +This module extends the functionality of +account_move_base_import, in order to handle the file format used for +Adyen card remitance + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Akretion + +Maintainers +~~~~~~~~~~~ + +This module is part of the `akretion/ak-odoo-incubator `_ project on GitHub. + +You are welcome to contribute. diff --git a/account_move_adyen_import/__init__.py b/account_move_adyen_import/__init__.py new file mode 100644 index 00000000..677a0743 --- /dev/null +++ b/account_move_adyen_import/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) +from . import parser +from . import models diff --git a/account_move_adyen_import/__manifest__.py b/account_move_adyen_import/__manifest__.py new file mode 100644 index 00000000..521e121e --- /dev/null +++ b/account_move_adyen_import/__manifest__.py @@ -0,0 +1,16 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) +{ + "name": "Journal Entry Adyen import", + "version": "16.0.1.0.0", + "author": "Akretion,Odoo Community Association (OCA)", + "maintainer": "Odoo Community Association (OCA)", + "category": "Finance", + "complexity": "normal", + "depends": [ + "account_move_base_import", + ], + "website": "https://github.com/akretion/ak-odoo-incubator", + "installable": True, + "auto_install": False, + "license": "AGPL-3", +} diff --git a/account_move_adyen_import/models/__init__.py b/account_move_adyen_import/models/__init__.py new file mode 100644 index 00000000..357e4b73 --- /dev/null +++ b/account_move_adyen_import/models/__init__.py @@ -0,0 +1,3 @@ +# © 2011-2016 Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) +from . import account_journal diff --git a/account_move_adyen_import/models/account_journal.py b/account_move_adyen_import/models/account_journal.py new file mode 100644 index 00000000..fd630027 --- /dev/null +++ b/account_move_adyen_import/models/account_journal.py @@ -0,0 +1,24 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) +from odoo import fields, models + + +class AccountJournal(models.Model): + _inherit = "account.journal" + + import_type = fields.Selection( + selection_add=[ + ("adyen_cb_csvparser", "Adyen Credit Card .csv"), + ("adyen_multi_move_csvparser", "Adyen Multiple Entries .csv"), + ] + ) + + def _get_global_commission_amount(self, parser): + global_commission_amount = super()._get_global_commission_amount(parser) + if hasattr(parser, "extra_commission"): + extra_commission = ( + parser.commission_sign == "+" + and -parser.extra_commission + or parser.extra_commission + ) + global_commission_amount += extra_commission + return global_commission_amount diff --git a/account_move_adyen_import/parser/__init__.py b/account_move_adyen_import/parser/__init__.py new file mode 100644 index 00000000..eb2c43c9 --- /dev/null +++ b/account_move_adyen_import/parser/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) +from . import adyen_file_parser diff --git a/account_move_adyen_import/parser/adyen_file_parser.py b/account_move_adyen_import/parser/adyen_file_parser.py new file mode 100644 index 00000000..41eba676 --- /dev/null +++ b/account_move_adyen_import/parser/adyen_file_parser.py @@ -0,0 +1,111 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from csv import QUOTE_MINIMAL, Dialect, register_dialect + +from odoo.addons.account_move_base_import.parser.file_parser import ( + FileParser, + float_or_zero, +) + + +class AdyenDialect(Dialect): + delimiter = "," + quotechar = '"' + doublequote = False + skipinitialspace = False + lineterminator = "\n" + quoting = QUOTE_MINIMAL + + +register_dialect("adyen_dialect", AdyenDialect) + + +class AdyenFileParser(FileParser): + def __init__(self, journal, ftype="csv", **kwargs): + conversion_dict = { + "Payment Method": str, + "Type": str, + "Gross Debit (GC)": float_or_zero, + "Gross Credit (GC)": float_or_zero, + "Net Debit (NC)": float_or_zero, + "Commission (NC)": float_or_zero, + "Markup (NC)": float_or_zero, + "Scheme Fees (NC)": float_or_zero, + "Interchange (NC)": float_or_zero, + "Merchant Reference": str, + } + super().__init__( + journal, + ftype=ftype, + extra_fields=conversion_dict, + dialect=AdyenDialect, + **kwargs + ) + self.commission_field = "Commission (NC)" + + @classmethod + def parser_for(cls, parser_name): + """ + Used by the new_bank_statement_parser class factory. Return true if + the providen name is generic_csvxls_so + """ + return parser_name == "adyen_cb_csvparser" + + def get_move_line_vals(self, line, *args, **kwargs): + amount = line["Gross Credit (GC)"] or -line["Gross Debit (GC)"] + res = { + "name": line.get("Merchant Reference", ""), + "credit": amount > 0.0 and amount or 0.0, + "debit": amount < 0.0 and -amount or 0.0, + } + return res + + def _post(self, *args, **kwargs): + res = super()._post(*args, **kwargs) + # there are some fee line... not linked to a payment, we have to take it into + # account + self.extra_commission = 0.0 + final_rows = [] + for row in self.result_row_list: + # account_move_import_base manage only once commission field when + # adyen may have Commission (NC) with total commission or 3 fields with + # detailed commission. => We fill the Commission (NC) in that case to have + # a unique commission field + if not row.get("Commission (NC)") and ( + row.get("Markup (NC)") + or row.get("Scheme Fees (NC)") + or row.get("Interchange (NC)") + ): + row["Commission (NC)"] = ( + row["Markup (NC)"] + + row["Scheme Fees (NC)"] + + row["Interchange (NC)"] + ) + if row.get("Type") in ( + "Settled", + "Refunded", + "SentForSettle", + "SentForRefund", + ): + final_rows.append(row) + elif row["Type"] == "Fee": + self.extra_commission += row["Net Debit (NC)"] + create_date = row["Creation Date"].split(" ")[0] + if not self.move_date or create_date > self.move_date: + self.move_date = create_date + self.result_row_list = final_rows + return res + + +class AdyenPaypalParser(AdyenFileParser): + def __init__(self, journal, ftype="csv", **kwargs): + super().__init__(journal, ftype=ftype, **kwargs) + self.support_multi_moves = True + + @classmethod + def parser_for(cls, parser_name): + """ + Used by the new_bank_statement_parser class factory. Return true if + the providen name is generic_csvxls_so + """ + return parser_name == "adyen_multi_move_csvparser" diff --git a/account_move_adyen_import/readme/CONTRIBUTOR.rst b/account_move_adyen_import/readme/CONTRIBUTOR.rst new file mode 100644 index 00000000..89a21dec --- /dev/null +++ b/account_move_adyen_import/readme/CONTRIBUTOR.rst @@ -0,0 +1 @@ +Florian da Costa diff --git a/account_move_adyen_import/readme/DESCRIPTION.rst b/account_move_adyen_import/readme/DESCRIPTION.rst new file mode 100644 index 00000000..6e54963f --- /dev/null +++ b/account_move_adyen_import/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +This module extends the functionality of +account_move_base_import, in order to handle the file format used for +Adyen card remitance diff --git a/account_move_adyen_import/static/description/index.html b/account_move_adyen_import/static/description/index.html new file mode 100644 index 00000000..e1dee74c --- /dev/null +++ b/account_move_adyen_import/static/description/index.html @@ -0,0 +1,410 @@ + + + + + +Journal Entry Adyen import + + + +
+

Journal Entry Adyen import

+ + +

Beta License: AGPL-3 akretion/ak-odoo-incubator

+

This module extends the functionality of +account_move_base_import, in order to handle the file format used for +Adyen card remitance

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Akretion
  • +
+
+
+

Maintainers

+

This module is part of the akretion/ak-odoo-incubator project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/account_move_adyen_import/tests/__init__.py b/account_move_adyen_import/tests/__init__.py new file mode 100644 index 00000000..c0e62f46 --- /dev/null +++ b/account_move_adyen_import/tests/__init__.py @@ -0,0 +1 @@ +from . import test_adyen_import diff --git a/account_move_adyen_import/tests/files/adyen-cb.csv b/account_move_adyen_import/tests/files/adyen-cb.csv new file mode 100644 index 00000000..42b97c42 --- /dev/null +++ b/account_move_adyen_import/tests/files/adyen-cb.csv @@ -0,0 +1,7 @@ +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 +TestCompany,TestCompany_ECOM_FR,KGNTFLXTQS9JFH65,DEV-C262678,cartebancaire,2024-02-20 06:21:21,PST,Settled,DKW2RK79KMQ7C782,EUR,,1817.20,1.000000000000000,EUR,,1802.11,,10.90,0.01,4.18,cartebancaire,,18,,,,,,, +TestCompany,TestCompany_ECOM_FR,KGNTFLXTQS9JFH65,DEV-C262678,cartebancaire,2024-02-20 07:20:11,PST,Refunded,R467VCDH5HNG5S82,EUR,100.00,,1.000000000000000,EUR,102.00,,2.00,,,,cartebancaire,DEV-C262678,18,,,,,,, +TestCompany,TestCompany_ECOM_FR,Q3F5GDDH5HNG5S82,DEV-C262679,cartebancaire,2024-02-20 07:20:46,PST,Settled,WBZ2RL89KMQ7C782,EUR,,90.19,1.000000000000000,EUR,,89.44,,0.54,0.00,0.21,cartebancaire,,18,,,,,,, +TestCompany,TestCompany_ECOM_FR,W5SQMRZTQS9JFH65,DEV-C262681,bcmc,2024-02-20 07:29:28,PST,Settled,W5SQMRZTQS9JFH65,EUR,,67.88,1.000000000000000,EUR,,66.52,1.36,,,,bcmc,DEV-C262681,18,,,,,,, +TestCompany,TestCompany_ECOM_FR,,,,2024-02-21 17:15:00,PST,Fee,Transaction Fees February 19 2024,,,,,EUR,0.92,,,,,,,,18,,,,,,, +TestCompany,TestCompany_ECOM_FR,,,,2024-02-21 17:15:00,PST,MerchantPayout,"TX10911002001XT batch 18, TestCompany_ECOM_FR",,,,,EUR,1855.15,,,,,,,,18,,,,,,, diff --git a/account_move_adyen_import/tests/test_adyen_import.py b/account_move_adyen_import/tests/test_adyen_import.py new file mode 100644 index 00000000..f6458ddf --- /dev/null +++ b/account_move_adyen_import/tests/test_adyen_import.py @@ -0,0 +1,98 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import base64 + +from odoo.modules.module import get_resource_path +from odoo.tests.common import TransactionCase + + +class TestAdyenImportCardRemitance(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.receivable_account_id = cls.env["account.account"].search( + [ + ( + "account_type", + "=", + "asset_receivable", + ), + ("company_id", "=", cls.env.company.id), + ], + limit=1, + ) + cls.expense_account_id = cls.env["account.account"].search( + [ + ( + "account_type", + "=", + "expense", + ), + ("company_id", "=", cls.env.company.id), + ], + limit=1, + ) + cls.bank_adyen_account = cls.env["account.account"].create( + { + "name": "Adyen bank account", + "code": "511007", + "account_type": "asset_cash", + } + ) + cls.adyen_journal = cls.env["account.journal"].create( + { + "name": "Adyen Payments", + "type": "bank", + "code": "ADY", + "default_account_id": cls.bank_adyen_account.id, + "used_for_import": True, + "import_type": "adyen_cb_csvparser", + "receivable_account_id": cls.receivable_account_id.id, + "commission_account_id": cls.expense_account_id.id, + } + ) + + def _get_import_wizard(self, filename): + file_path = get_resource_path( + "account_move_adyen_import", "tests/files/", filename + ) + data = base64.b64encode(open(file_path, "rb").read()) + wizard = self.env["credit.statement.import"].create( + { + "journal_id": self.adyen_journal.id, + "input_statement": data, + "receivable_account_id": self.receivable_account_id.id, + "commission_account_id": self.expense_account_id.id, + "file_name": filename, + } + ) + return wizard + + def test_import_cb_file(self): + wizard = self._get_import_wizard("adyen-cb.csv") + wizard.import_statement() + move = self.env["account.move"].search( + [("journal_id", "=", self.adyen_journal.id)] + ) + self.assertEqual(len(move), 1) + self.assertEqual(len(move.line_ids), 6) + payment_aml1 = move.line_ids.filtered( + lambda line: line.name == "DEV-C262678" and line.credit > 0 + ) + self.assertAlmostEqual(payment_aml1.credit, 1817.20) + refund_aml1 = move.line_ids.filtered( + lambda line: line.name == "DEV-C262678" and line.debit > 0 + ) + self.assertAlmostEqual(refund_aml1.debit, 100.00) + payment_aml2 = move.line_ids.filtered(lambda line: line.name == "DEV-C262679") + self.assertAlmostEqual(payment_aml2.credit, 90.19) + payment_aml3 = move.line_ids.filtered(lambda line: line.name == "DEV-C262681") + self.assertAlmostEqual(payment_aml3.credit, 67.88) + commission_aml = move.line_ids.filtered( + lambda line: line.account_id == self.expense_account_id + ) + self.assertEqual(commission_aml.debit, 20.12) + counterpart_aml = move.line_ids.filtered( + lambda line: line.account_id == self.bank_adyen_account + ) + self.assertEqual(counterpart_aml.debit, 1855.15) diff --git a/setup/account_move_adyen_import/odoo/addons/account_move_adyen_import b/setup/account_move_adyen_import/odoo/addons/account_move_adyen_import new file mode 120000 index 00000000..5f361434 --- /dev/null +++ b/setup/account_move_adyen_import/odoo/addons/account_move_adyen_import @@ -0,0 +1 @@ +../../../../account_move_adyen_import \ No newline at end of file diff --git a/setup/account_move_adyen_import/setup.py b/setup/account_move_adyen_import/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/account_move_adyen_import/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)