mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
[FIX] account_bank_statement_import_online_transferwise: fees for refund and top-up
This commit is contained in:
committed by
Emanuel Cino
parent
f079a33312
commit
e2b6c60d27
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Online Bank Statements: TransferWise.com',
|
'name': 'Online Bank Statements: TransferWise.com',
|
||||||
'version': '12.0.1.0.1',
|
'version': '12.0.1.0.2',
|
||||||
'author':
|
'author':
|
||||||
'CorporateHub, '
|
'CorporateHub, '
|
||||||
'Odoo Community Association (OCA)',
|
'Odoo Community Association (OCA)',
|
||||||
|
|||||||
@@ -30,13 +30,13 @@ msgid "Ending balance unavailable"
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#. module: account_bank_statement_import_online_transferwise
|
#. module: account_bank_statement_import_online_transferwise
|
||||||
#: code:addons/account_bank_statement_import_online_transferwise/models/online_bank_statement_provider_transferwise.py:239
|
#: code:addons/account_bank_statement_import_online_transferwise/models/online_bank_statement_provider_transferwise.py:245
|
||||||
#, python-format
|
#, python-format
|
||||||
msgid "Fee for %s"
|
msgid "Fee for %s"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#. module: account_bank_statement_import_online_transferwise
|
#. module: account_bank_statement_import_online_transferwise
|
||||||
#: code:addons/account_bank_statement_import_online_transferwise/models/online_bank_statement_provider_transferwise.py:270
|
#: code:addons/account_bank_statement_import_online_transferwise/models/online_bank_statement_provider_transferwise.py:276
|
||||||
#, python-format
|
#, python-format
|
||||||
msgid "No API key specified!"
|
msgid "No API key specified!"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
@@ -52,7 +52,7 @@ msgid "Profile"
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#. module: account_bank_statement_import_online_transferwise
|
#. module: account_bank_statement_import_online_transferwise
|
||||||
#: code:addons/account_bank_statement_import_online_transferwise/models/online_bank_statement_provider_transferwise.py:244
|
#: code:addons/account_bank_statement_import_online_transferwise/models/online_bank_statement_provider_transferwise.py:250
|
||||||
#, python-format
|
#, python-format
|
||||||
msgid "Transaction fee for %s"
|
msgid "Transaction fee for %s"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|||||||
@@ -154,6 +154,7 @@ class OnlineBankStatementProviderTransferwise(models.Model):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _transferwise_transaction_to_lines(self, transaction):
|
def _transferwise_transaction_to_lines(self, transaction):
|
||||||
|
transaction_type = transaction['type']
|
||||||
reference_number = transaction['referenceNumber']
|
reference_number = transaction['referenceNumber']
|
||||||
details = transaction.get('details', {})
|
details = transaction.get('details', {})
|
||||||
exchange_details = transaction.get('exchangeDetails')
|
exchange_details = transaction.get('exchangeDetails')
|
||||||
@@ -170,10 +171,15 @@ class OnlineBankStatementProviderTransferwise(models.Model):
|
|||||||
)
|
)
|
||||||
amount = transaction['amount']
|
amount = transaction['amount']
|
||||||
amount_value = amount.get('value', 0)
|
amount_value = amount.get('value', 0)
|
||||||
fees_value = total_fees.get('value', Decimal()).copy_negate()
|
fees_value = total_fees.get('value', Decimal())
|
||||||
|
if transaction_type == 'CREDIT' \
|
||||||
|
and details.get('type') == 'MONEY_ADDED':
|
||||||
|
fees_value = fees_value.copy_negate()
|
||||||
|
else:
|
||||||
|
fees_value = fees_value.copy_sign(amount_value)
|
||||||
amount_value -= fees_value
|
amount_value -= fees_value
|
||||||
unique_import_id = '%s-%s-%s' % (
|
unique_import_id = '%s-%s-%s' % (
|
||||||
transaction['type'],
|
transaction_type,
|
||||||
reference_number,
|
reference_number,
|
||||||
int(date.timestamp()),
|
int(date.timestamp()),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
|
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
|
||||||
|
# Copyright 2020 CorporateHub (https://corporatehub.eu)
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@@ -549,3 +550,87 @@ class TestAccountBankAccountStatementImportOnlineTransferwise(
|
|||||||
'partner_name': 'TransferWise',
|
'partner_name': 'TransferWise',
|
||||||
'unique_import_id': 'DEBIT-BALANCE-123456789-946684800-FEE',
|
'unique_import_id': 'DEBIT-BALANCE-123456789-946684800-FEE',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def test_transaction_parse_9(self):
|
||||||
|
lines = self.transferwise_parse_transaction("""{
|
||||||
|
"type": "CREDIT",
|
||||||
|
"date": "2000-01-01T00:00:00.000Z",
|
||||||
|
"amount": {
|
||||||
|
"value": 25.00,
|
||||||
|
"currency": "USD"
|
||||||
|
},
|
||||||
|
"totalFees": {
|
||||||
|
"value": 0.68,
|
||||||
|
"currency": "USD"
|
||||||
|
},
|
||||||
|
"details": {
|
||||||
|
"type": "MONEY_ADDED",
|
||||||
|
"description": "Topped up balance"
|
||||||
|
},
|
||||||
|
"exchangeDetails": null,
|
||||||
|
"runningBalance": {
|
||||||
|
"value": 25.68,
|
||||||
|
"currency": "USD"
|
||||||
|
},
|
||||||
|
"referenceNumber": "TRANSFER-123456789"
|
||||||
|
}""")
|
||||||
|
self.assertEqual(len(lines), 2)
|
||||||
|
self.assertEqual(lines[0], {
|
||||||
|
'date': datetime(2000, 1, 1),
|
||||||
|
'name': 'Topped up balance',
|
||||||
|
'note': 'TRANSFER-123456789: Topped up balance',
|
||||||
|
'amount': '25.68',
|
||||||
|
'unique_import_id': 'CREDIT-TRANSFER-123456789-946684800',
|
||||||
|
})
|
||||||
|
self.assertEqual(lines[1], {
|
||||||
|
'date': datetime(2000, 1, 1),
|
||||||
|
'name': 'Fee for TRANSFER-123456789',
|
||||||
|
'note': 'Transaction fee for TRANSFER-123456789',
|
||||||
|
'amount': '-0.68',
|
||||||
|
'partner_name': 'TransferWise',
|
||||||
|
'unique_import_id': 'CREDIT-TRANSFER-123456789-946684800-FEE',
|
||||||
|
})
|
||||||
|
|
||||||
|
def test_transaction_parse_10(self):
|
||||||
|
lines = self.transferwise_parse_transaction("""{
|
||||||
|
"type": "CREDIT",
|
||||||
|
"date": "2000-01-01T00:00:00.000Z",
|
||||||
|
"amount": {
|
||||||
|
"value": 1804.33,
|
||||||
|
"currency": "USD"
|
||||||
|
},
|
||||||
|
"totalFees": {
|
||||||
|
"value": 4.33,
|
||||||
|
"currency": "USD"
|
||||||
|
},
|
||||||
|
"details": {
|
||||||
|
"type": "TRANSFER",
|
||||||
|
"description": "Sent money to Acme Inc.",
|
||||||
|
"recipient": {
|
||||||
|
"name": "Acme Inc."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"exchangeDetails": null,
|
||||||
|
"runningBalance": {
|
||||||
|
"value": 1804.33,
|
||||||
|
"currency": "USD"
|
||||||
|
},
|
||||||
|
"referenceNumber": "TRANSFER-123456789"
|
||||||
|
}""")
|
||||||
|
self.assertEqual(len(lines), 2)
|
||||||
|
self.assertEqual(lines[0], {
|
||||||
|
'date': datetime(2000, 1, 1),
|
||||||
|
'name': 'Sent money to Acme Inc.',
|
||||||
|
'note': 'TRANSFER-123456789: Sent money to Acme Inc.',
|
||||||
|
'partner_name': 'Acme Inc.',
|
||||||
|
'amount': '1800.00',
|
||||||
|
'unique_import_id': 'CREDIT-TRANSFER-123456789-946684800',
|
||||||
|
})
|
||||||
|
self.assertEqual(lines[1], {
|
||||||
|
'date': datetime(2000, 1, 1),
|
||||||
|
'name': 'Fee for TRANSFER-123456789',
|
||||||
|
'note': 'Transaction fee for TRANSFER-123456789',
|
||||||
|
'amount': '4.33',
|
||||||
|
'partner_name': 'TransferWise',
|
||||||
|
'unique_import_id': 'CREDIT-TRANSFER-123456789-946684800-FEE',
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user