You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
5.0 KiB
132 lines
5.0 KiB
# Copyright 2019 Tecnativa - Vicent Cubells
|
|
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
|
|
|
from odoo import fields
|
|
from odoo.exceptions import UserError
|
|
from odoo.tests import common
|
|
|
|
from base64 import b64encode
|
|
from os import path
|
|
|
|
|
|
class TestAccountBankStatementImportPayPal(common.TransactionCase):
|
|
def setUp(self):
|
|
super().setUp()
|
|
|
|
self.now = fields.Datetime.now()
|
|
self.currency_eur = self.env.ref('base.EUR')
|
|
self.currency_usd = self.env.ref('base.USD')
|
|
self.paypal_statement_map_en = self.env.ref(
|
|
'account_bank_statement_import_paypal.paypal_statement_map_en'
|
|
)
|
|
self.paypal_activity_map_en = self.env.ref(
|
|
'account_bank_statement_import_paypal.paypal_activity_map_en'
|
|
)
|
|
self.AccountJournal = self.env['account.journal']
|
|
self.AccountBankStatement = self.env['account.bank.statement']
|
|
self.AccountBankStatementImport = self.env[
|
|
'account.bank.statement.import'
|
|
]
|
|
self.AccountBankStatementImportPayPalMapping = self.env[
|
|
'account.bank.statement.import.paypal.mapping'
|
|
]
|
|
self.AccountBankStatementImportPayPalMappingWizard = self.env[
|
|
'account.bank.statement.import.paypal.mapping.wizard'
|
|
]
|
|
|
|
def _data_file(self, filename):
|
|
with open(path.join(path.dirname(__file__), filename)) as file:
|
|
return b64encode(file.read().encode('utf-8'))
|
|
|
|
def test_import_statement_en(self):
|
|
journal = self.AccountJournal.create({
|
|
'name': 'PayPal',
|
|
'type': 'bank',
|
|
'code': 'PP',
|
|
'currency_id': self.currency_usd.id,
|
|
})
|
|
wizard = self.AccountBankStatementImport.with_context({
|
|
'journal_id': journal.id,
|
|
}).create({
|
|
'filename': 'fixtures/statement_en.csv',
|
|
'data_file': self._data_file('fixtures/statement_en.csv'),
|
|
'paypal_mapping_id': self.paypal_statement_map_en.id,
|
|
})
|
|
wizard.with_context({
|
|
'journal_id': journal.id,
|
|
'account_bank_statement_import_paypal_test': True,
|
|
}).import_file()
|
|
statement = self.AccountBankStatement.search([
|
|
('journal_id', '=', journal.id),
|
|
])
|
|
self.assertEqual(len(statement), 1)
|
|
self.assertEqual(len(statement.line_ids), 18)
|
|
|
|
def test_import_activity_en(self):
|
|
journal = self.AccountJournal.create({
|
|
'name': 'PayPal',
|
|
'type': 'bank',
|
|
'code': 'PP',
|
|
'currency_id': self.currency_usd.id,
|
|
})
|
|
wizard = self.AccountBankStatementImport.with_context({
|
|
'journal_id': journal.id,
|
|
}).create({
|
|
'filename': 'fixtures/activity_en.csv',
|
|
'data_file': self._data_file('fixtures/activity_en.csv'),
|
|
'paypal_mapping_id': self.paypal_activity_map_en.id,
|
|
})
|
|
wizard.with_context({
|
|
'journal_id': journal.id,
|
|
'account_bank_statement_import_paypal_test': True,
|
|
}).import_file()
|
|
statement = self.AccountBankStatement.search([
|
|
('journal_id', '=', journal.id),
|
|
])
|
|
self.assertEqual(len(statement), 1)
|
|
self.assertEqual(len(statement.line_ids), 71)
|
|
|
|
def test_import_empty_activity(self):
|
|
journal = self.AccountJournal.create({
|
|
'name': 'PayPal',
|
|
'type': 'bank',
|
|
'code': 'PP',
|
|
'currency_id': self.currency_usd.id,
|
|
})
|
|
wizard = self.AccountBankStatementImport.with_context({
|
|
'journal_id': journal.id,
|
|
}).create({
|
|
'filename': 'fixtures/empty_activity.csv',
|
|
'data_file': self._data_file('fixtures/empty_activity.csv'),
|
|
'paypal_mapping_id': self.paypal_activity_map_en.id,
|
|
})
|
|
with self.assertRaises(UserError):
|
|
wizard.with_context({
|
|
'journal_id': journal.id,
|
|
'account_bank_statement_import_paypal_test': True,
|
|
}).import_file()
|
|
statement = self.AccountBankStatement.search([
|
|
('journal_id', '=', journal.id),
|
|
])
|
|
self.assertEqual(len(statement), 0)
|
|
|
|
def test_import_activity_mapping_en(self):
|
|
wizard = self.AccountBankStatementImportPayPalMappingWizard.create({
|
|
'filename': 'fixtures/activity_en.csv',
|
|
'data_file': self._data_file('fixtures/activity_en.csv'),
|
|
})
|
|
mapping = self.AccountBankStatementImportPayPalMapping.browse(
|
|
wizard.import_mapping()['res_id']
|
|
)
|
|
self.assertTrue(mapping)
|
|
|
|
def test_import_statement_mapping_en(self):
|
|
wizard = self.AccountBankStatementImportPayPalMappingWizard.create({
|
|
'filename': 'fixtures/statement_en.csv',
|
|
'data_file': self._data_file('fixtures/statement_en.csv'),
|
|
})
|
|
mapping = self.AccountBankStatementImportPayPalMapping.browse(
|
|
wizard.import_mapping()['res_id']
|
|
)
|
|
self.assertTrue(mapping)
|