From 604a32c16ddf938bd347205936fca918cf1587e7 Mon Sep 17 00:00:00 2001 From: "Omar (Comunitea)" Date: Fri, 25 Feb 2022 11:56:14 +0100 Subject: [PATCH] [IMP] account_bank_statement_import_online_paypal: black, isort, prettier --- .../__manifest__.py | 2 +- .../online_bank_statement_provider_paypal.py | 16 +++++-- ...unt_bank_statement_import_online_paypal.py | 46 +++++++++++++------ ...ccount_bank_statement_import_online_paypal | 1 + .../setup.py | 6 +++ 5 files changed, 52 insertions(+), 19 deletions(-) create mode 120000 setup/account_bank_statement_import_online_paypal/odoo/addons/account_bank_statement_import_online_paypal create mode 100644 setup/account_bank_statement_import_online_paypal/setup.py diff --git a/account_bank_statement_import_online_paypal/__manifest__.py b/account_bank_statement_import_online_paypal/__manifest__.py index 1ddf646f..82bab800 100644 --- a/account_bank_statement_import_online_paypal/__manifest__.py +++ b/account_bank_statement_import_online_paypal/__manifest__.py @@ -7,7 +7,7 @@ "version": "13.0.1.0.0", "author": "CorporateHub, Odoo Community Association (OCA)", "maintainers": ["alexey-pelykh"], - "website": "https://github.com/OCA/bank-statement-import/", + "website": "https://github.com/OCA/bank-statement-import", "license": "AGPL-3", "category": "Accounting", "summary": "Online bank statements for PayPal.com", diff --git a/account_bank_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py b/account_bank_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py index 892c8e1c..0d6d9816 100644 --- a/account_bank_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py +++ b/account_bank_statement_import_online_paypal/models/online_bank_statement_provider_paypal.py @@ -180,7 +180,8 @@ class OnlineBankStatementProviderPayPal(models.Model): self.ensure_one() if self.service != "paypal": return super()._obtain_statement_data( - date_since, date_until, + date_since, + date_until, ) # pragma: no cover currency = (self.currency_id or self.company_id.currency_id).name @@ -336,7 +337,8 @@ class OnlineBankStatementProviderPayPal(models.Model): url = ( self.api_base or PAYPAL_API_BASE ) + "/v1/reporting/balances?currency_code={}&as_of_time={}".format( - currency, as_of_timestamp.isoformat() + "Z", + currency, + as_of_timestamp.isoformat() + "Z", ) data = self._paypal_retrieve(url, token) available_balance = data["balances"][0].get("available_balance") @@ -351,7 +353,10 @@ class OnlineBankStatementProviderPayPal(models.Model): (self.api_base or PAYPAL_API_BASE) + "/v1/reporting/transactions" + ("?start_date=%s" "&end_date=%s" "&fields=all") - % (transaction_date, transaction_date,) + % ( + transaction_date, + transaction_date, + ) ) data = self._paypal_retrieve(url, token) transactions = data["transaction_details"] @@ -452,7 +457,10 @@ class OnlineBankStatementProviderPayPal(models.Model): if "name" in content: return UserError( "%s: %s" - % (content["name"], content.get("message", _("Unknown error")),) + % ( + content["name"], + content.get("message", _("Unknown error")), + ) ) if "error" in content: diff --git a/account_bank_statement_import_online_paypal/tests/test_account_bank_statement_import_online_paypal.py b/account_bank_statement_import_online_paypal/tests/test_account_bank_statement_import_online_paypal.py index 87c92e2c..b2842d06 100644 --- a/account_bank_statement_import_online_paypal/tests/test_account_bank_statement_import_online_paypal.py +++ b/account_bank_statement_import_online_paypal/tests/test_account_bank_statement_import_online_paypal.py @@ -65,12 +65,16 @@ class TestAccountBankAccountStatementImportOnlinePayPal(common.TransactionCase): self.paypal_parse_transaction = lambda payload: ( Provider._paypal_transaction_to_lines( Provider._paypal_preparse_transaction( - json.loads(payload, parse_float=Decimal,) + json.loads( + payload, + parse_float=Decimal, + ) ) ) ) self.mock_token = lambda: mock.patch( - _provider_class + "._paypal_get_token", return_value="--TOKEN--", + _provider_class + "._paypal_get_token", + return_value="--TOKEN--", ) def test_good_token(self): @@ -99,7 +103,8 @@ class TestAccountBankAccountStatementImportOnlinePayPal(common.TransactionCase): ) token = None with mock.patch( - _provider_class + "._paypal_retrieve", return_value=mocked_response, + _provider_class + "._paypal_retrieve", + return_value=mocked_response, ): token = provider._paypal_get_token() self.assertEqual(token, "---TOKEN---") @@ -129,7 +134,8 @@ class TestAccountBankAccountStatementImportOnlinePayPal(common.TransactionCase): parse_float=Decimal, ) with mock.patch( - _provider_class + "._paypal_retrieve", return_value=mocked_response, + _provider_class + "._paypal_retrieve", + return_value=mocked_response, ): with self.assertRaises(Exception): provider._paypal_get_token() @@ -159,7 +165,8 @@ class TestAccountBankAccountStatementImportOnlinePayPal(common.TransactionCase): parse_float=Decimal, ) with mock.patch( - _provider_class + "._paypal_retrieve", return_value=mocked_response, + _provider_class + "._paypal_retrieve", + return_value=mocked_response, ): with self.assertRaises(Exception): provider._paypal_get_token() @@ -188,7 +195,8 @@ class TestAccountBankAccountStatementImportOnlinePayPal(common.TransactionCase): parse_float=Decimal, ) with mock.patch( - _provider_class + "._paypal_retrieve", return_value=mocked_response, + _provider_class + "._paypal_retrieve", + return_value=mocked_response, ): with self.assertRaises(Exception): provider._paypal_get_token() @@ -247,7 +255,10 @@ class TestAccountBankAccountStatementImportOnlinePayPal(common.TransactionCase): ), self.mock_token(): data = provider.with_context( test_account_bank_statement_import_online_paypal_monday=True, - )._obtain_statement_data(self.now - relativedelta(hours=1), self.now,) + )._obtain_statement_data( + self.now - relativedelta(hours=1), + self.now, + ) self.assertEqual(data, ([], {"balance_start": 0.75, "balance_end_real": 0.75})) @@ -272,7 +283,8 @@ class TestAccountBankAccountStatementImportOnlinePayPal(common.TransactionCase): throw=True, ) with mock.patch( - _provider_class + "._paypal_urlopen", return_value=mocked_response, + _provider_class + "._paypal_urlopen", + return_value=mocked_response, ): with self.assertRaises(UserError): provider._paypal_retrieve("https://url", "") @@ -298,7 +310,8 @@ class TestAccountBankAccountStatementImportOnlinePayPal(common.TransactionCase): throw=True, ) with mock.patch( - _provider_class + "._paypal_urlopen", return_value=mocked_response, + _provider_class + "._paypal_urlopen", + return_value=mocked_response, ): with self.assertRaises(UserError): provider._paypal_retrieve("https://url", "") @@ -360,7 +373,8 @@ class TestAccountBankAccountStatementImportOnlinePayPal(common.TransactionCase): side_effect=[mocked_response_1, mocked_response_2], ), self.mock_token(): data = provider._obtain_statement_data( - self.now - relativedelta(hours=1), self.now, + self.now - relativedelta(hours=1), + self.now, ) self.assertEqual(data, ([], {"balance_start": 0.75, "balance_end_real": 0.75})) @@ -392,11 +406,13 @@ class TestAccountBankAccountStatementImportOnlinePayPal(common.TransactionCase): parse_float=Decimal, ) with mock.patch( - _provider_class + "._paypal_retrieve", return_value=mocked_response, + _provider_class + "._paypal_retrieve", + return_value=mocked_response, ), self.mock_token(): with self.assertRaises(Exception): provider._obtain_statement_data( - self.now - relativedelta(years=5), self.now, + self.now - relativedelta(years=5), + self.now, ) def test_pull(self): @@ -510,10 +526,12 @@ class TestAccountBankAccountStatementImportOnlinePayPal(common.TransactionCase): parse_float=Decimal, ) with mock.patch( - _provider_class + "._paypal_retrieve", return_value=mocked_response, + _provider_class + "._paypal_retrieve", + return_value=mocked_response, ), self.mock_token(): data = provider._obtain_statement_data( - datetime(2019, 8, 1), datetime(2019, 8, 2), + datetime(2019, 8, 1), + datetime(2019, 8, 2), ) self.assertEqual(len(data[0]), 2) diff --git a/setup/account_bank_statement_import_online_paypal/odoo/addons/account_bank_statement_import_online_paypal b/setup/account_bank_statement_import_online_paypal/odoo/addons/account_bank_statement_import_online_paypal new file mode 120000 index 00000000..10d27dd0 --- /dev/null +++ b/setup/account_bank_statement_import_online_paypal/odoo/addons/account_bank_statement_import_online_paypal @@ -0,0 +1 @@ +../../../../account_bank_statement_import_online_paypal \ No newline at end of file diff --git a/setup/account_bank_statement_import_online_paypal/setup.py b/setup/account_bank_statement_import_online_paypal/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/account_bank_statement_import_online_paypal/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)