From 34afe9ae05e81ff118432930cdba3038df118286 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Fri, 18 Sep 2020 19:47:52 +0300 Subject: [PATCH] [FIX] account_bank_statement_import_txt_xlsx: handle empty currency --- ...ount_bank_statement_import_sheet_parser.py | 15 ++++++--- .../tests/fixtures/original_currency.csv | 2 +- .../fixtures/original_currency_empty.csv | 2 ++ ..._account_bank_statement_import_txt_xlsx.py | 31 +++++++++++++++++++ 4 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 account_bank_statement_import_txt_xlsx/tests/fixtures/original_currency_empty.csv diff --git a/account_bank_statement_import_txt_xlsx/models/account_bank_statement_import_sheet_parser.py b/account_bank_statement_import_txt_xlsx/models/account_bank_statement_import_sheet_parser.py index 1b0952e..d66e39a 100644 --- a/account_bank_statement_import_txt_xlsx/models/account_bank_statement_import_sheet_parser.py +++ b/account_bank_statement_import_txt_xlsx/models/account_bank_statement_import_sheet_parser.py @@ -206,22 +206,27 @@ class AccountBankStatementImportSheetParser(models.TransientModel): ) amount = self._parse_decimal(amount, mapping) - if balance is not None: + if balance: balance = self._parse_decimal(balance, mapping) + else: + balance = None - if debit_credit is not None: + if debit_credit: amount = amount.copy_abs() if debit_credit == mapping.debit_value: amount = -amount - if original_currency is None: + if not original_currency: original_currency = currency original_amount = amount elif original_currency == currency: original_amount = amount - if original_amount is not None: - original_amount = self._parse_decimal(original_amount, mapping) + if original_amount: + original_amount = self._parse_decimal( + original_amount, + mapping + ).copy_sign(amount) else: original_amount = 0.0 diff --git a/account_bank_statement_import_txt_xlsx/tests/fixtures/original_currency.csv b/account_bank_statement_import_txt_xlsx/tests/fixtures/original_currency.csv index e025cf0..04731cf 100644 --- a/account_bank_statement_import_txt_xlsx/tests/fixtures/original_currency.csv +++ b/account_bank_statement_import_txt_xlsx/tests/fixtures/original_currency.csv @@ -1,2 +1,2 @@ "Date","Label","Currency","Amount","Amount Currency","Partner Name","Bank Account" -"12/15/2018","Your payment","EUR","1,525.00","1,000.00","Azure Interior","" +"12/15/2018","Your payment","EUR","1,525.00","-1,000.00","Azure Interior","" diff --git a/account_bank_statement_import_txt_xlsx/tests/fixtures/original_currency_empty.csv b/account_bank_statement_import_txt_xlsx/tests/fixtures/original_currency_empty.csv new file mode 100644 index 0000000..6db95ba --- /dev/null +++ b/account_bank_statement_import_txt_xlsx/tests/fixtures/original_currency_empty.csv @@ -0,0 +1,2 @@ +"Date","Label","Currency","Amount","Amount Currency","Partner Name","Bank Account" +"12/15/2018","Your payment",,"1,525.00",,"Azure Interior","" diff --git a/account_bank_statement_import_txt_xlsx/tests/test_account_bank_statement_import_txt_xlsx.py b/account_bank_statement_import_txt_xlsx/tests/test_account_bank_statement_import_txt_xlsx.py index 9f8709b..22a00f9 100644 --- a/account_bank_statement_import_txt_xlsx/tests/test_account_bank_statement_import_txt_xlsx.py +++ b/account_bank_statement_import_txt_xlsx/tests/test_account_bank_statement_import_txt_xlsx.py @@ -217,6 +217,37 @@ class TestAccountBankStatementImportTxtXlsx(common.TransactionCase): self.assertEqual(line.currency_id, self.currency_eur) self.assertEqual(line.amount_currency, 1000.0) + def test_original_currency_empty(self): + journal = self.AccountJournal.create({ + 'name': 'Bank', + 'type': 'bank', + 'code': 'BANK', + 'currency_id': self.currency_usd.id, + }) + wizard = self.AccountBankStatementImport.with_context({ + 'journal_id': journal.id, + }).create({ + 'filename': 'fixtures/original_currency_empty.csv', + 'data_file': self._data_file( + 'fixtures/original_currency_empty.csv', + 'utf-8' + ), + 'sheet_mapping_id': self.sample_statement_map.id, + }) + wizard.with_context({ + 'journal_id': journal.id, + 'account_bank_statement_import_txt_xlsx_test': True, + }).import_file() + statement = self.AccountBankStatement.search([ + ('journal_id', '=', journal.id), + ]) + self.assertEqual(len(statement), 1) + self.assertEqual(len(statement.line_ids), 1) + + line = statement.line_ids + self.assertFalse(line.currency_id) + self.assertEqual(line.amount_currency, 0.0) + def test_multi_currency(self): journal = self.AccountJournal.create({ 'name': 'Bank',