Browse Source

Merge PR #346 into 12.0

Signed-off-by alexey-pelykh
12.0
OCA-git-bot 4 years ago
parent
commit
161b6615ea
  1. 10
      account_bank_statement_import_online_transferwise/models/online_bank_statement_provider_transferwise.py
  2. 85
      account_bank_statement_import_online_transferwise/tests/test_account_bank_statement_import_online_transferwise.py

10
account_bank_statement_import_online_transferwise/models/online_bank_statement_provider_transferwise.py

@ -154,6 +154,7 @@ class OnlineBankStatementProviderTransferwise(models.Model):
@api.model
def _transferwise_transaction_to_lines(self, transaction):
transaction_type = transaction['type']
reference_number = transaction['referenceNumber']
details = transaction.get('details', {})
exchange_details = transaction.get('exchangeDetails')
@ -170,10 +171,15 @@ class OnlineBankStatementProviderTransferwise(models.Model):
)
amount = transaction['amount']
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
unique_import_id = '%s-%s-%s' % (
transaction['type'],
transaction_type,
reference_number,
int(date.timestamp()),
)

85
account_bank_statement_import_online_transferwise/tests/test_account_bank_statement_import_online_transferwise.py

@ -1,4 +1,5 @@
# 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).
from datetime import datetime
@ -549,3 +550,87 @@ class TestAccountBankAccountStatementImportOnlineTransferwise(
'partner_name': 'TransferWise',
'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',
})
Loading…
Cancel
Save