From 184b7abb863843a16f28b1eb025360d9c2aab2de Mon Sep 17 00:00:00 2001 From: Vincent Barrier Date: Wed, 3 Jul 2019 20:57:01 +0200 Subject: [PATCH 1/3] fix exception when using multiple files type fix exception when using multiple files type (ofx for example) --- .../wizards/account_bank_statement_import_paypal.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/account_bank_statement_import_paypal/wizards/account_bank_statement_import_paypal.py b/account_bank_statement_import_paypal/wizards/account_bank_statement_import_paypal.py index ba79b53..6d0506f 100644 --- a/account_bank_statement_import_paypal/wizards/account_bank_statement_import_paypal.py +++ b/account_bank_statement_import_paypal/wizards/account_bank_statement_import_paypal.py @@ -66,7 +66,11 @@ class AccountBankStatementImport(models.TransientModel): @api.model def _check_paypal(self, data_file): - data_file = self._get_paypal_str_data(data_file) + try: + data_file = self._get_paypal_str_data(data_file) + except Exception as e: + _logger.debug(e) + return False if not self.paypal_map_id: return False headers = self.mapped('paypal_map_id.map_line_ids.name') From 6b5153913259564810c78e362a045e410faae553 Mon Sep 17 00:00:00 2001 From: Vincent Barrier Date: Wed, 3 Jul 2019 22:04:54 +0200 Subject: [PATCH 2/3] Filter Exception => UnicodeDecodeError --- .../wizards/account_bank_statement_import_paypal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_bank_statement_import_paypal/wizards/account_bank_statement_import_paypal.py b/account_bank_statement_import_paypal/wizards/account_bank_statement_import_paypal.py index 6d0506f..76018dc 100644 --- a/account_bank_statement_import_paypal/wizards/account_bank_statement_import_paypal.py +++ b/account_bank_statement_import_paypal/wizards/account_bank_statement_import_paypal.py @@ -68,7 +68,7 @@ class AccountBankStatementImport(models.TransientModel): def _check_paypal(self, data_file): try: data_file = self._get_paypal_str_data(data_file) - except Exception as e: + except UnicodeDecodeError as e: _logger.debug(e) return False if not self.paypal_map_id: From d6c08d021289a5f18c6cef27c9e821f454c166bf Mon Sep 17 00:00:00 2001 From: Vincent Barrier Date: Wed, 3 Jul 2019 23:12:20 +0200 Subject: [PATCH 3/3] refactoring --- .../wizards/account_bank_statement_import_paypal.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/account_bank_statement_import_paypal/wizards/account_bank_statement_import_paypal.py b/account_bank_statement_import_paypal/wizards/account_bank_statement_import_paypal.py index 76018dc..a6db902 100644 --- a/account_bank_statement_import_paypal/wizards/account_bank_statement_import_paypal.py +++ b/account_bank_statement_import_paypal/wizards/account_bank_statement_import_paypal.py @@ -66,13 +66,13 @@ class AccountBankStatementImport(models.TransientModel): @api.model def _check_paypal(self, data_file): + if not self.paypal_map_id: + return False try: data_file = self._get_paypal_str_data(data_file) except UnicodeDecodeError as e: _logger.debug(e) return False - if not self.paypal_map_id: - return False headers = self.mapped('paypal_map_id.map_line_ids.name') file_headers = data_file.split('\n', 1)[0] if any(item not in file_headers for item in headers):