From b63debd74747aff819f3953346d9ea19ead38a5e Mon Sep 17 00:00:00 2001 From: Magno Costa Date: Wed, 14 Aug 2024 15:59:15 -0300 Subject: [PATCH] [REF] l10n_br_account_payment_brcobranca: Solve 'E8106(external-request-timeout) Use of external request method without timeout. It could wait for a long time.' --- .../constants/br_cobranca.py | 2 ++ .../models/account_move.py | 9 +++++++-- .../models/account_payment_order.py | 2 ++ .../parser/cnab_file_parser.py | 3 ++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/l10n_br_account_payment_brcobranca/constants/br_cobranca.py b/l10n_br_account_payment_brcobranca/constants/br_cobranca.py index 622c859328b3..2f061a5aee97 100644 --- a/l10n_br_account_payment_brcobranca/constants/br_cobranca.py +++ b/l10n_br_account_payment_brcobranca/constants/br_cobranca.py @@ -11,6 +11,8 @@ from odoo.exceptions import UserError from odoo.tools import config +TIMEOUT = 300 # seconds + DICT_BRCOBRANCA_CNAB_TYPE = { "240": "cnab240", "400": "cnab400", diff --git a/l10n_br_account_payment_brcobranca/models/account_move.py b/l10n_br_account_payment_brcobranca/models/account_move.py index c9c6e8ef8f4a..174035ff2728 100644 --- a/l10n_br_account_payment_brcobranca/models/account_move.py +++ b/l10n_br_account_payment_brcobranca/models/account_move.py @@ -12,7 +12,7 @@ from odoo import _, models from odoo.exceptions import UserError -from ..constants.br_cobranca import get_brcobranca_api_url +from ..constants.br_cobranca import TIMEOUT, get_brcobranca_api_url logger = logging.getLogger(__name__) @@ -71,7 +71,12 @@ def _get_brcobranca_boleto(self, boletos): brcobranca_service_url, self.name, ) - res = requests.post(brcobranca_service_url, data={"type": "pdf"}, files=files) + res = requests.post( + brcobranca_service_url, + data={"type": "pdf"}, + files=files, + timeout=TIMEOUT, + ) if str(res.status_code)[0] == "2": pdf_string = res.content diff --git a/l10n_br_account_payment_brcobranca/models/account_payment_order.py b/l10n_br_account_payment_brcobranca/models/account_payment_order.py index 69b084b24034..7d27ebe3b1ec 100644 --- a/l10n_br_account_payment_brcobranca/models/account_payment_order.py +++ b/l10n_br_account_payment_brcobranca/models/account_payment_order.py @@ -16,6 +16,7 @@ from ..constants.br_cobranca import ( DICT_BRCOBRANCA_CNAB_TYPE, + TIMEOUT, get_brcobranca_api_url, get_brcobranca_bank, ) @@ -182,6 +183,7 @@ def _get_brcobranca_remessa(self, bank_brcobranca, remessa_values, cnab_type): "bank": bank_brcobranca.name, }, files=files, + timeout=TIMEOUT, ) if cnab_type == "240" and "R01" in res.text[242:254]: diff --git a/l10n_br_account_payment_brcobranca/parser/cnab_file_parser.py b/l10n_br_account_payment_brcobranca/parser/cnab_file_parser.py index 955a0896810b..a741df308aee 100644 --- a/l10n_br_account_payment_brcobranca/parser/cnab_file_parser.py +++ b/l10n_br_account_payment_brcobranca/parser/cnab_file_parser.py @@ -13,7 +13,7 @@ from odoo.addons.account_move_base_import.parser.file_parser import FileParser -from ..constants.br_cobranca import get_brcobranca_api_url +from ..constants.br_cobranca import TIMEOUT, get_brcobranca_api_url logger = logging.getLogger(__name__) @@ -91,6 +91,7 @@ def _get_brcobranca_retorno(self, files): "bank": bank_name_brcobranca, }, files=files, + timeout=TIMEOUT, ) if res.status_code != 201: