Skip to content

Commit

Permalink
Merge pull request #296 from akretion/16-account_move_import_adyen
Browse files Browse the repository at this point in the history
16 account move import adyen
  • Loading branch information
florian-dacosta authored Jun 5, 2024
2 parents 21bdf41 + 167ad02 commit b3ce2e5
Show file tree
Hide file tree
Showing 15 changed files with 743 additions and 0 deletions.
57 changes: 57 additions & 0 deletions account_move_adyen_import/README.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/akretion/ak-odoo-incubator/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/akretion/ak-odoo-incubator/issues/new?body=module:%20account_move_adyen_import%0Aversion:%2016.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
~~~~~~~

* Akretion

Maintainers
~~~~~~~~~~~

This module is part of the `akretion/ak-odoo-incubator <https://github.com/akretion/ak-odoo-incubator/tree/16.0/account_move_adyen_import>`_ project on GitHub.

You are welcome to contribute.
3 changes: 3 additions & 0 deletions account_move_adyen_import/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from . import parser
from . import models
16 changes: 16 additions & 0 deletions account_move_adyen_import/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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",
}
3 changes: 3 additions & 0 deletions account_move_adyen_import/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# © 2011-2016 Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from . import account_journal
24 changes: 24 additions & 0 deletions account_move_adyen_import/models/account_journal.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions account_move_adyen_import/parser/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from . import adyen_file_parser
111 changes: 111 additions & 0 deletions account_move_adyen_import/parser/adyen_file_parser.py
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions account_move_adyen_import/readme/CONTRIBUTOR.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Florian da Costa <[email protected]>
3 changes: 3 additions & 0 deletions account_move_adyen_import/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit b3ce2e5

Please sign in to comment.