From 3664c9dd66bf20006de8f068e54fba1aa4a064b9 Mon Sep 17 00:00:00 2001 From: ikapasi Date: Wed, 25 May 2022 09:54:00 +0530 Subject: [PATCH] [MIG] account_bank_statement_import_online_paypal: Migration to 15.0 --- .../__manifest__.py | 2 +- .../online_bank_statement_provider_paypal.py | 18 +++++++++++++----- .../readme/CONTRIBUTORS.rst | 1 + ...t_account_statement_import_online_paypal.py | 16 ++++++++++++---- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/account_statement_import_online_paypal/__manifest__.py b/account_statement_import_online_paypal/__manifest__.py index 49547705..df2e9a19 100644 --- a/account_statement_import_online_paypal/__manifest__.py +++ b/account_statement_import_online_paypal/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Online Bank Statements: PayPal.com", - "version": "14.0.1.0.0", + "version": "15.0.1.0.0", "author": "CorporateHub, Odoo Community Association (OCA)", "maintainers": ["alexey-pelykh"], "website": "https://github.com/OCA/bank-statement-import", diff --git a/account_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py b/account_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py index 388a167f..8665ac5c 100644 --- a/account_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py +++ b/account_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py @@ -230,8 +230,12 @@ class OnlineBankStatementProviderPayPal(models.Model): ) if not first_transaction: raise UserError( - _("Failed to resolve transaction %s (%s)") - % (first_transaction_id, first_transaction_date) + _( + "Failed to resolve transaction %(first_transaction_id)s " + "(%(first_transaction_date)s)", + first_transaction_id=first_transaction_id, + first_transaction_date=first_transaction_date, + ) ) balance_start = self._paypal_get_transaction_ending_balance(first_transaction) balance_start -= self._paypal_get_transaction_total_amount(first_transaction) @@ -245,8 +249,12 @@ class OnlineBankStatementProviderPayPal(models.Model): ) if not last_transaction: raise UserError( - _("Failed to resolve transaction %s (%s)") - % (last_transaction_id, last_transaction_date) + _( + "Failed to resolve transaction %(last_transaction_id)s " + "(%(last_transaction_date)s)", + last_transaction_id=last_transaction_id, + last_transaction_date=last_transaction_date, + ) ) balance_end = self._paypal_get_transaction_ending_balance(last_transaction) @@ -496,7 +504,7 @@ class OnlineBankStatementProviderPayPal(models.Model): "total_pages": 0, } - raise self._paypal_decode_error(content) or e + raise self._paypal_decode_error(content) or e from None return json.loads(content) @api.model diff --git a/account_statement_import_online_paypal/readme/CONTRIBUTORS.rst b/account_statement_import_online_paypal/readme/CONTRIBUTORS.rst index bbb62dfd..084cff53 100644 --- a/account_statement_import_online_paypal/readme/CONTRIBUTORS.rst +++ b/account_statement_import_online_paypal/readme/CONTRIBUTORS.rst @@ -2,3 +2,4 @@ * Alexey Pelykh * Omar CastiƱeira +* isufi kapasi diff --git a/account_statement_import_online_paypal/tests/test_account_statement_import_online_paypal.py b/account_statement_import_online_paypal/tests/test_account_statement_import_online_paypal.py index 8515cf9e..ac082705 100644 --- a/account_statement_import_online_paypal/tests/test_account_statement_import_online_paypal.py +++ b/account_statement_import_online_paypal/tests/test_account_statement_import_online_paypal.py @@ -144,7 +144,9 @@ class TestAccountBankAccountStatementImportOnlinePayPal(common.TransactionCase): _provider_class + "._paypal_retrieve", return_value=mocked_response, ): - with self.assertRaises(Exception): + with self.assertRaisesRegex( + UserError, "PayPal App features are configured incorrectly!" + ): provider._paypal_get_token() def test_bad_token_type(self): @@ -175,7 +177,7 @@ class TestAccountBankAccountStatementImportOnlinePayPal(common.TransactionCase): _provider_class + "._paypal_retrieve", return_value=mocked_response, ): - with self.assertRaises(Exception): + with self.assertRaisesRegex(UserError, "Invalid token type!"): provider._paypal_get_token() def test_no_token(self): @@ -205,7 +207,9 @@ class TestAccountBankAccountStatementImportOnlinePayPal(common.TransactionCase): _provider_class + "._paypal_retrieve", return_value=mocked_response, ): - with self.assertRaises(Exception): + with self.assertRaisesRegex( + UserError, "Failed to acquire token using Client ID and Secret!" + ): provider._paypal_get_token() def test_no_data_on_monday(self): @@ -434,7 +438,11 @@ class TestAccountBankAccountStatementImportOnlinePayPal(common.TransactionCase): _provider_class + "._paypal_retrieve", return_value=mocked_response, ), self.mock_token(): - with self.assertRaises(Exception): + with self.assertRaisesRegex( + UserError, + "PayPal allows retrieving transactions only up to 3 years in " + "the past. Please import older transactions manually.", + ): provider._obtain_statement_data( self.now - relativedelta(years=5), self.now,