From daa143336e58f83f82fefea455314ce2dd0d7d1c Mon Sep 17 00:00:00 2001 From: "Ronald Portier (Therp BV)" Date: Wed, 31 Aug 2022 12:51:28 +0200 Subject: [PATCH] [FIX] *_online_ponto: Backport 4a8f9ac better code organisation --- .../online_bank_statement_provider_ponto.py | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py b/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py index d107ef9..f3c1bff 100644 --- a/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py +++ b/account_bank_statement_import_online_ponto/models/online_bank_statement_provider_ponto.py @@ -159,34 +159,33 @@ class OnlineBankStatementProviderPonto(models.Model): response = requests.get( page_url, params=params, headers=self._ponto_header() ) - if response.status_code == 200: - if params.get("before"): - params.pop("before") - data = json.loads(response.text) - links = data.get("links", {}) - if page_next: - page_url = links.get("next", False) - else: - page_url = links.get("prev", False) - transactions = data.get("data", []) - if transactions: - current_transactions = [] - for transaction in transactions: - date = self._ponto_date_from_string( - transaction.get("attributes", {}).get("executionDate") - ) - if date_since <= date < date_until: - current_transactions.append(transaction) - - if current_transactions: - if not page_next or (page_next and not latest_identifier): - latest_identifier = current_transactions[0].get("id") - transaction_lines.extend(current_transactions) - else: + if response.status_code != 200: raise UserError( _("Error during get transaction.\n\n%s \n\n %s") % (response.status_code, response.text) ) + if params.get("before"): + params.pop("before") + data = json.loads(response.text) + links = data.get("links", {}) + if page_next: + page_url = links.get("next", False) + else: + page_url = links.get("prev", False) + transactions = data.get("data", []) + if transactions: + current_transactions = [] + for transaction in transactions: + date = self._ponto_date_from_string( + transaction.get("attributes", {}).get("executionDate") + ) + if date_since <= date < date_until: + current_transactions.append(transaction) + + if current_transactions: + if not page_next or (page_next and not latest_identifier): + latest_identifier = current_transactions[0].get("id") + transaction_lines.extend(current_transactions) if latest_identifier: self.ponto_last_identifier = latest_identifier return transaction_lines