Skip to content

Commit b3ce2e5

Browse files
Merge pull request #296 from akretion/16-account_move_import_adyen
16 account move import adyen
2 parents 21bdf41 + 167ad02 commit b3ce2e5

File tree

15 files changed

+743
-0
lines changed

15 files changed

+743
-0
lines changed

account_move_adyen_import/README.rst

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
==========================
2+
Journal Entry Adyen import
3+
==========================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:c51de8a7e48679e6304737fa5c987223979f7dc57d5b53b4fd6ce6e0136ae2dd
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-akretion%2Fak--odoo--incubator-lightgray.png?logo=github
20+
:target: https://github.com/akretion/ak-odoo-incubator/tree/16.0/account_move_adyen_import
21+
:alt: akretion/ak-odoo-incubator
22+
23+
|badge1| |badge2| |badge3|
24+
25+
This module extends the functionality of
26+
account_move_base_import, in order to handle the file format used for
27+
Adyen card remitance
28+
29+
**Table of contents**
30+
31+
.. contents::
32+
:local:
33+
34+
Bug Tracker
35+
===========
36+
37+
Bugs are tracked on `GitHub Issues <https://github.com/akretion/ak-odoo-incubator/issues>`_.
38+
In case of trouble, please check there if your issue has already been reported.
39+
If you spotted it first, help us to smash it by providing a detailed and welcomed
40+
`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**>`_.
41+
42+
Do not contact contributors directly about support or help with technical issues.
43+
44+
Credits
45+
=======
46+
47+
Authors
48+
~~~~~~~
49+
50+
* Akretion
51+
52+
Maintainers
53+
~~~~~~~~~~~
54+
55+
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.
56+
57+
You are welcome to contribute.

account_move_adyen_import/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
2+
from . import parser
3+
from . import models
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
2+
{
3+
"name": "Journal Entry Adyen import",
4+
"version": "16.0.1.0.0",
5+
"author": "Akretion,Odoo Community Association (OCA)",
6+
"maintainer": "Odoo Community Association (OCA)",
7+
"category": "Finance",
8+
"complexity": "normal",
9+
"depends": [
10+
"account_move_base_import",
11+
],
12+
"website": "https://github.com/akretion/ak-odoo-incubator",
13+
"installable": True,
14+
"auto_install": False,
15+
"license": "AGPL-3",
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# © 2011-2016 Akretion
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
3+
from . import account_journal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
2+
from odoo import fields, models
3+
4+
5+
class AccountJournal(models.Model):
6+
_inherit = "account.journal"
7+
8+
import_type = fields.Selection(
9+
selection_add=[
10+
("adyen_cb_csvparser", "Adyen Credit Card .csv"),
11+
("adyen_multi_move_csvparser", "Adyen Multiple Entries .csv"),
12+
]
13+
)
14+
15+
def _get_global_commission_amount(self, parser):
16+
global_commission_amount = super()._get_global_commission_amount(parser)
17+
if hasattr(parser, "extra_commission"):
18+
extra_commission = (
19+
parser.commission_sign == "+"
20+
and -parser.extra_commission
21+
or parser.extra_commission
22+
)
23+
global_commission_amount += extra_commission
24+
return global_commission_amount
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
2+
from . import adyen_file_parser
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
2+
3+
from csv import QUOTE_MINIMAL, Dialect, register_dialect
4+
5+
from odoo.addons.account_move_base_import.parser.file_parser import (
6+
FileParser,
7+
float_or_zero,
8+
)
9+
10+
11+
class AdyenDialect(Dialect):
12+
delimiter = ","
13+
quotechar = '"'
14+
doublequote = False
15+
skipinitialspace = False
16+
lineterminator = "\n"
17+
quoting = QUOTE_MINIMAL
18+
19+
20+
register_dialect("adyen_dialect", AdyenDialect)
21+
22+
23+
class AdyenFileParser(FileParser):
24+
def __init__(self, journal, ftype="csv", **kwargs):
25+
conversion_dict = {
26+
"Payment Method": str,
27+
"Type": str,
28+
"Gross Debit (GC)": float_or_zero,
29+
"Gross Credit (GC)": float_or_zero,
30+
"Net Debit (NC)": float_or_zero,
31+
"Commission (NC)": float_or_zero,
32+
"Markup (NC)": float_or_zero,
33+
"Scheme Fees (NC)": float_or_zero,
34+
"Interchange (NC)": float_or_zero,
35+
"Merchant Reference": str,
36+
}
37+
super().__init__(
38+
journal,
39+
ftype=ftype,
40+
extra_fields=conversion_dict,
41+
dialect=AdyenDialect,
42+
**kwargs
43+
)
44+
self.commission_field = "Commission (NC)"
45+
46+
@classmethod
47+
def parser_for(cls, parser_name):
48+
"""
49+
Used by the new_bank_statement_parser class factory. Return true if
50+
the providen name is generic_csvxls_so
51+
"""
52+
return parser_name == "adyen_cb_csvparser"
53+
54+
def get_move_line_vals(self, line, *args, **kwargs):
55+
amount = line["Gross Credit (GC)"] or -line["Gross Debit (GC)"]
56+
res = {
57+
"name": line.get("Merchant Reference", ""),
58+
"credit": amount > 0.0 and amount or 0.0,
59+
"debit": amount < 0.0 and -amount or 0.0,
60+
}
61+
return res
62+
63+
def _post(self, *args, **kwargs):
64+
res = super()._post(*args, **kwargs)
65+
# there are some fee line... not linked to a payment, we have to take it into
66+
# account
67+
self.extra_commission = 0.0
68+
final_rows = []
69+
for row in self.result_row_list:
70+
# account_move_import_base manage only once commission field when
71+
# adyen may have Commission (NC) with total commission or 3 fields with
72+
# detailed commission. => We fill the Commission (NC) in that case to have
73+
# a unique commission field
74+
if not row.get("Commission (NC)") and (
75+
row.get("Markup (NC)")
76+
or row.get("Scheme Fees (NC)")
77+
or row.get("Interchange (NC)")
78+
):
79+
row["Commission (NC)"] = (
80+
row["Markup (NC)"]
81+
+ row["Scheme Fees (NC)"]
82+
+ row["Interchange (NC)"]
83+
)
84+
if row.get("Type") in (
85+
"Settled",
86+
"Refunded",
87+
"SentForSettle",
88+
"SentForRefund",
89+
):
90+
final_rows.append(row)
91+
elif row["Type"] == "Fee":
92+
self.extra_commission += row["Net Debit (NC)"]
93+
create_date = row["Creation Date"].split(" ")[0]
94+
if not self.move_date or create_date > self.move_date:
95+
self.move_date = create_date
96+
self.result_row_list = final_rows
97+
return res
98+
99+
100+
class AdyenPaypalParser(AdyenFileParser):
101+
def __init__(self, journal, ftype="csv", **kwargs):
102+
super().__init__(journal, ftype=ftype, **kwargs)
103+
self.support_multi_moves = True
104+
105+
@classmethod
106+
def parser_for(cls, parser_name):
107+
"""
108+
Used by the new_bank_statement_parser class factory. Return true if
109+
the providen name is generic_csvxls_so
110+
"""
111+
return parser_name == "adyen_multi_move_csvparser"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Florian da Costa <florian.dacosta@akretion.com>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This module extends the functionality of
2+
account_move_base_import, in order to handle the file format used for
3+
Adyen card remitance

0 commit comments

Comments
 (0)