worker-automate-hub 0.5.753__tar.gz → 0.5.838__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/PKG-INFO +4 -2
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/pyproject.toml +2 -1
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/api/client.py +123 -35
- worker_automate_hub-0.5.838/worker_automate_hub/cli.py +212 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/abertura_livros_fiscais.py +110 -224
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/descartes.py +83 -69
- worker_automate_hub-0.5.838/worker_automate_hub/tasks/jobs/devolucao_produtos.py +1386 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/entrada_de_notas_15.py +3 -46
- worker_automate_hub-0.5.838/worker_automate_hub/tasks/jobs/entrada_de_notas_22.py +833 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/entrada_de_notas_36.py +29 -9
- worker_automate_hub-0.5.838/worker_automate_hub/tasks/jobs/entrada_de_notas_37.py +619 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/entrada_de_notas_39.py +1 -1
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/entrada_de_notas_9.py +63 -16
- worker_automate_hub-0.5.838/worker_automate_hub/tasks/jobs/extracao_saldo_estoque.py +369 -0
- worker_automate_hub-0.5.838/worker_automate_hub/tasks/jobs/extracao_saldo_estoque_fiscal.py +688 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/fidc_remessa_cobranca_cnab240.py +25 -16
- worker_automate_hub-0.5.838/worker_automate_hub/tasks/jobs/geracao_balancetes_filial.py +330 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/opex_capex.py +112 -29
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/sped_fiscal.py +8 -8
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/transferencias.py +52 -41
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/task_definitions.py +24 -1
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/task_executor.py +11 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/utils/util.py +74 -36
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/utils/utils_nfe_entrada.py +1 -1
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/worker.py +1 -9
- worker_automate_hub-0.5.753/worker_automate_hub/cli.py +0 -232
- worker_automate_hub-0.5.753/worker_automate_hub/tasks/jobs/extracao_saldo_estoque.py +0 -236
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/README.md +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/__init__.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/api/__init__.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/api/ahead_service.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/api/datalake_service.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/api/helpers/__init__.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/api/helpers/api_helpers.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/api/rdp_service.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/api/rpa_fila_service.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/api/rpa_historico_service.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/api/webhook_service.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/config/__init__.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/config/settings.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/config.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/core/so_manipulation.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/decorators/__init__.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/decorators/deprecation.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/decorators/rate_limit.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/decorators/repeat.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/decorators/retry.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/decorators/singleton.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/decorators/timeit.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/models/__init__.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/models/dao/__init__.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/models/dao/rpa_configuracao.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/models/dao/rpa_fila.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/models/dao/rpa_historico.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/models/dao/rpa_processo.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/models/dao/rpa_robo.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/models/dto/__init__.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/models/dto/rpa_historico_request_dto.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/models/dto/rpa_processo_entrada_dto.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/models/dto/rpa_processo_rdp_dto.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/models/dto/rpa_sap_dto.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/models/dto/rpa_sistema_dto.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/__init__.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/__init__.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/coleta_dje_process.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/conexao_rdp.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/cte_manual.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/cte_xml.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/devolucao_ctf.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/devolucao_ctf_35.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/devolucao_prazo_a_faturar.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/ecac_estadual_go.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/ecac_estadual_main.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/ecac_estadual_mt.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/ecac_estadual_sc.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/ecac_estadual_sp.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/ecac_federal.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/entrada_cte_1353.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/entrada_cte_333.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/entrada_de_notas_16.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/entrada_de_notas_207.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/entrada_de_notas_32.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/entrada_de_notas_33.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/entrada_de_notas_34.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/entrada_de_notas_500.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/entrada_de_notas_503.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/entrada_de_notas_505.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/entrada_de_notas_7139.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/entrada_de_notas_9000.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/exemplo_processo.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/extracao_fechamento_contabil.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/extracao_fechamento_emsys.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/fechar_conexao_rdp.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/fidc_exportacao_docs_portal_b2b.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/fidc_gerar_nosso_numero.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/fidc_retorno_cobranca.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/geracao_aprovacao_pedidos.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/geracao_aprovacao_pedidos_novo.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/integracao_contabil.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/integracao_contabil_generica.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/lancamento_pis_cofins.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/lancamento_rateio.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/login_emsys.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/login_emsys_versao_especifica.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/notas_faturamento_sap.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/tasks/jobs/playground.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/utils/__init__.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/utils/env.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/utils/get_creds_gworkspace.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/utils/logger.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/utils/toast.py +0 -0
- {worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/utils/updater.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: worker-automate-hub
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.838
|
|
4
4
|
Summary: Worker Automate HUB é uma aplicação para automatizar rotinas de RPA nos ambientes Argenta.
|
|
5
5
|
Author: Joel Paim
|
|
6
6
|
Requires-Python: >=3.12,<4.0
|
|
@@ -10,6 +10,7 @@ Classifier: Natural Language :: Portuguese (Brazilian)
|
|
|
10
10
|
Classifier: Programming Language :: Python :: 3
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.12
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
13
14
|
Classifier: Topic :: Utilities
|
|
14
15
|
Requires-Dist: aiohttp (>=3.9.5,<4.0.0)
|
|
15
16
|
Requires-Dist: beautifulsoup4 (>=4.12.3,<5.0.0)
|
|
@@ -49,6 +50,7 @@ Requires-Dist: timedelta (>=2020.12.3,<2021.0.0)
|
|
|
49
50
|
Requires-Dist: toml (>=0.10.2,<0.11.0)
|
|
50
51
|
Requires-Dist: torch (>=2.4.0,<3.0.0)
|
|
51
52
|
Requires-Dist: typer (>=0.12.3,<0.13.0)
|
|
53
|
+
Requires-Dist: unidecode (>=1.4.0,<2.0.0)
|
|
52
54
|
Requires-Dist: webdriver-manager (>=4.0.2,<5.0.0)
|
|
53
55
|
Requires-Dist: win10toast (>=0.9,<0.10)
|
|
54
56
|
Requires-Dist: xhtml2pdf (>=0.2.16,<0.3.0)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "worker-automate-hub"
|
|
3
|
-
version = "0.5.
|
|
3
|
+
version = "0.5.838"
|
|
4
4
|
description = "Worker Automate HUB é uma aplicação para automatizar rotinas de RPA nos ambientes Argenta."
|
|
5
5
|
authors = ["Joel Paim"]
|
|
6
6
|
readme = "README.md"
|
|
@@ -61,6 +61,7 @@ gitpython = "^3.1.43"
|
|
|
61
61
|
selenium = "^4.27.1"
|
|
62
62
|
webdriver-manager = "^4.0.2"
|
|
63
63
|
xlrd = "^2.0.1"
|
|
64
|
+
unidecode = "^1.4.0"
|
|
64
65
|
|
|
65
66
|
[tool.poetry.group.dev.dependencies]
|
|
66
67
|
pytest = "^8.2.2"
|
{worker_automate_hub-0.5.753 → worker_automate_hub-0.5.838}/worker_automate_hub/api/client.py
RENAMED
|
@@ -2,12 +2,13 @@ from decimal import ROUND_HALF_UP, Decimal
|
|
|
2
2
|
import threading
|
|
3
3
|
from typing import Optional
|
|
4
4
|
import aiohttp
|
|
5
|
-
|
|
5
|
+
import re
|
|
6
|
+
from collections import defaultdict
|
|
6
7
|
import aiohttp
|
|
7
8
|
import requests
|
|
8
9
|
from aiohttp import ClientSession
|
|
9
10
|
from rich.console import Console
|
|
10
|
-
|
|
11
|
+
from typing import List, Dict, Any
|
|
11
12
|
from worker_automate_hub.api.helpers.api_helpers import handle_api_response
|
|
12
13
|
from worker_automate_hub.config.settings import load_env_config
|
|
13
14
|
from worker_automate_hub.models.dao.rpa_configuracao import RpaConfiguracao
|
|
@@ -144,41 +145,42 @@ async def get_processo(uuidProcesso: str) -> RpaProcesso:
|
|
|
144
145
|
RpaProcesso: O processo caso tenha sido encontrado.
|
|
145
146
|
"""
|
|
146
147
|
env_config, _ = load_env_config()
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
x = 0
|
|
149
|
+
while x < 10:
|
|
150
|
+
try:
|
|
151
|
+
if not uuidProcesso:
|
|
152
|
+
raise ValueError("O uuid do processo deve ser informado")
|
|
150
153
|
|
|
151
|
-
|
|
152
|
-
|
|
154
|
+
headers_basic = {"Authorization": f"Basic {env_config["API_AUTHORIZATION"]}"}
|
|
155
|
+
timeout = aiohttp.ClientTimeout(total=600)
|
|
153
156
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
157
|
+
async with aiohttp.ClientSession(
|
|
158
|
+
connector=aiohttp.TCPConnector(verify_ssl=True), timeout=timeout
|
|
159
|
+
) as session:
|
|
160
|
+
async with session.get(
|
|
161
|
+
f"{env_config["API_BASE_URL"]}/processo/{uuidProcesso}",
|
|
162
|
+
headers=headers_basic,
|
|
163
|
+
) as response:
|
|
164
|
+
if response.status != 200:
|
|
165
|
+
x += 1
|
|
166
|
+
console.print(f"Erro ao obter o processo: {response.content}")
|
|
167
|
+
continue
|
|
168
|
+
else:
|
|
169
|
+
res = await response.json()
|
|
170
|
+
if type(res["campos"]) == str and res["campos"] == "{}":
|
|
171
|
+
res["campos"] = {}
|
|
172
|
+
return RpaProcesso(**res)
|
|
168
173
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
except Exception as e:
|
|
176
|
-
logger.error(f"Erro ao obter o processo: {str(e)}")
|
|
177
|
-
console.print(
|
|
178
|
-
f"{e}\n",
|
|
179
|
-
style="bold red",
|
|
174
|
+
except ValueError as e:
|
|
175
|
+
x += 1
|
|
176
|
+
logger.error(f"Erro ao obter o processo: {str(e)}")
|
|
177
|
+
console.print(
|
|
178
|
+
f"{e}\n",
|
|
179
|
+
style="bold red",
|
|
180
180
|
)
|
|
181
|
-
|
|
181
|
+
continue
|
|
182
|
+
|
|
183
|
+
return None
|
|
182
184
|
|
|
183
185
|
|
|
184
186
|
async def get_workers():
|
|
@@ -497,6 +499,89 @@ async def get_valor_remessa_cobranca(date: str):
|
|
|
497
499
|
logger.info(err_msg)
|
|
498
500
|
|
|
499
501
|
|
|
502
|
+
async def get_notas_produtos(codFornecedor: int, codEmpresa: int, itens: List[Dict[str, Any]]) -> Dict[str, Any]:
|
|
503
|
+
"""
|
|
504
|
+
Função única:
|
|
505
|
+
- Converte itens (aceita chaves codigo/codigoProduto e quantidade/qtd)
|
|
506
|
+
- Chama /nf-supplier/checker com Authorization: Basic
|
|
507
|
+
- Normaliza tipos do retorno
|
|
508
|
+
- Entrega:
|
|
509
|
+
{
|
|
510
|
+
"lista": [ {codItem, qtdTotal, notas, valorUnitario}, ... ],
|
|
511
|
+
"por_codigo": { codItem: {...}, ... }
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
Retorno esperado da API (ex):
|
|
515
|
+
[
|
|
516
|
+
{"codItem": 19969, "qtdTotal": 15, "notas": ["1418727","1410744"], "valorUnitario": 5.29},
|
|
517
|
+
{"codItem": 29272, "qtdTotal": 10, "notas": ["1418727"], "valorUnitario": 7.12}
|
|
518
|
+
]
|
|
519
|
+
"""
|
|
520
|
+
# --- Carrega config
|
|
521
|
+
env_config, _ = load_env_config()
|
|
522
|
+
url_base = env_config["API_BASE_URL"].rstrip("/")
|
|
523
|
+
url = f"{url_base}/nf-supplier/checker"
|
|
524
|
+
|
|
525
|
+
# --- Header Basic (aceita token puro ou já "Basic ...")
|
|
526
|
+
token = (env_config.get("API_AUTHORIZATION") or "").strip()
|
|
527
|
+
auth_header = token if token.lower().startswith("basic ") else f"Basic {token}"
|
|
528
|
+
|
|
529
|
+
# --- Converte itens de entrada
|
|
530
|
+
itens_convertidos: List[Dict[str, int]] = []
|
|
531
|
+
for it in itens or []:
|
|
532
|
+
codigo = re.findall(r"\d+", it.get("descricaoProduto"))[0]
|
|
533
|
+
quantidade = it.get("quantidade", it.get("qtd"))
|
|
534
|
+
if codigo is None or quantidade is None:
|
|
535
|
+
logger.warning(f"Item incompleto: {it}")
|
|
536
|
+
console.print(f"⚠️ Item incompleto: {it}", style="yellow")
|
|
537
|
+
continue
|
|
538
|
+
try:
|
|
539
|
+
itens_convertidos.append({"codigo": int(codigo), "quantidade": int(quantidade)})
|
|
540
|
+
except Exception:
|
|
541
|
+
logger.warning(f"Item inválido (não numérico): {it}")
|
|
542
|
+
console.print(f"⚠️ Item inválido (não numérico): {it}", style="yellow")
|
|
543
|
+
|
|
544
|
+
body = {
|
|
545
|
+
"codFornecedor": int(codFornecedor),
|
|
546
|
+
"codEmpresa": int(codEmpresa),
|
|
547
|
+
"itens": itens_convertidos,
|
|
548
|
+
}
|
|
549
|
+
headers = {"Authorization": auth_header, "Content-Type": "application/json"}
|
|
550
|
+
|
|
551
|
+
# --- Chamada HTTP
|
|
552
|
+
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(verify_ssl=False)) as session:
|
|
553
|
+
async with session.post(url, json=body, headers=headers) as resp:
|
|
554
|
+
text = await resp.text()
|
|
555
|
+
if resp.status != 200:
|
|
556
|
+
raise RuntimeError(f"HTTP {resp.status} ao chamar {url}: {text}")
|
|
557
|
+
try:
|
|
558
|
+
data = await resp.json()
|
|
559
|
+
except Exception:
|
|
560
|
+
raise RuntimeError(f"Resposta não-JSON do servidor: {text[:600]}")
|
|
561
|
+
|
|
562
|
+
console.print(f"✅ Resposta da API: {data}", style="bold green")
|
|
563
|
+
logger.info(f"nf-supplier/checker -> {data}")
|
|
564
|
+
|
|
565
|
+
if not isinstance(data, list):
|
|
566
|
+
raise ValueError(f"Formato inesperado da API: {type(data)} -> {data}")
|
|
567
|
+
|
|
568
|
+
# --- Normaliza tipos e monta índices
|
|
569
|
+
lista_norm: List[Dict[str, Any]] = []
|
|
570
|
+
por_codigo: Dict[int, Dict[str, Any]] = {}
|
|
571
|
+
|
|
572
|
+
for row in data:
|
|
573
|
+
cod = int(row.get("codItem"))
|
|
574
|
+
item_norm = {
|
|
575
|
+
"codItem": cod,
|
|
576
|
+
"qtdTotal": int(row.get("qtdTotal", 0)),
|
|
577
|
+
"notas": [str(n) for n in (row.get("notas") or [])],
|
|
578
|
+
"valorUnitario": float(row.get("valorUnitario", 0.0)),
|
|
579
|
+
}
|
|
580
|
+
lista_norm.append(item_norm)
|
|
581
|
+
por_codigo[cod] = item_norm
|
|
582
|
+
|
|
583
|
+
return {"lista": lista_norm, "por_codigo": por_codigo}
|
|
584
|
+
|
|
500
585
|
async def get_status_nf_emsys(chave: int):
|
|
501
586
|
"""
|
|
502
587
|
Procura o status de nota fiscal no EMSYS.
|
|
@@ -581,8 +666,9 @@ async def get_dados_nf_emsys(
|
|
|
581
666
|
) as session:
|
|
582
667
|
async with session.get(url, headers=headers_basic, params=params) as response:
|
|
583
668
|
if response.status != 200:
|
|
669
|
+
body = await response.text() # ✅ lê o conteúdo do body
|
|
584
670
|
raise Exception(
|
|
585
|
-
f"
|
|
671
|
+
f"({response.status}): {body}"
|
|
586
672
|
)
|
|
587
673
|
|
|
588
674
|
data = await response.json()
|
|
@@ -655,7 +741,7 @@ async def get_dados_nf_emsys(
|
|
|
655
741
|
return resultado
|
|
656
742
|
|
|
657
743
|
except Exception as e:
|
|
658
|
-
raise Exception(f"
|
|
744
|
+
raise Exception(f"{e}")
|
|
659
745
|
|
|
660
746
|
|
|
661
747
|
|
|
@@ -743,6 +829,8 @@ async def send_file(
|
|
|
743
829
|
elif file_extension == "xlsx":
|
|
744
830
|
filename = desArquivo
|
|
745
831
|
content_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
832
|
+
elif file_extension == "csv":
|
|
833
|
+
content_type = "text/csv"
|
|
746
834
|
else:
|
|
747
835
|
raise ValueError(f"Extensão de arquivo não suportada: {file_extension}")
|
|
748
836
|
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import importlib.metadata
|
|
3
|
+
import threading
|
|
4
|
+
|
|
5
|
+
import inquirer
|
|
6
|
+
import psutil
|
|
7
|
+
from inquirer.themes import GreenPassion
|
|
8
|
+
from rich.console import Console
|
|
9
|
+
from typer import Context, Exit, Option, Typer
|
|
10
|
+
|
|
11
|
+
from worker_automate_hub.api.client import get_workers, load_environments
|
|
12
|
+
from worker_automate_hub.core.so_manipulation import (
|
|
13
|
+
add_worker_config,
|
|
14
|
+
download_tesseract,
|
|
15
|
+
update_assets_v2,
|
|
16
|
+
write_env_config,
|
|
17
|
+
)
|
|
18
|
+
from worker_automate_hub.utils.updater import check_for_update
|
|
19
|
+
from worker_automate_hub.utils.util import (
|
|
20
|
+
add_start_on_boot_to_registry,
|
|
21
|
+
create_worker_bat,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
from .worker import run_worker
|
|
25
|
+
|
|
26
|
+
console = Console()
|
|
27
|
+
app = Typer()
|
|
28
|
+
stop_event = threading.Event() # Evento para parar as threads
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
HELP_MESSAGE = """
|
|
32
|
+
[b]Worker[/] - Grupo Argenta
|
|
33
|
+
|
|
34
|
+
Forma de uso: [b]worker [SUBCOMANDO] [ARGUMENTOS][/]
|
|
35
|
+
|
|
36
|
+
Existem 3 subcomandos disponíveis para essa aplicação
|
|
37
|
+
|
|
38
|
+
- [b]run[/]: Inicializa o Worker na máquina atual e começa a solicitar trabalho para o orquestrador.
|
|
39
|
+
- [b]validate[/]: Verifica se o Worker atual está configurado corretamente e pronto para ser inicializado.
|
|
40
|
+
- [b]assets[/]: Realiza a limpeza e depois download na pasta assets de todos arquivos utilizado pelo worker durante execução.
|
|
41
|
+
|
|
42
|
+
[b]Exemplos de uso:[/]
|
|
43
|
+
[b][blue]RUN[/][/]
|
|
44
|
+
[green][b]worker[/][/] [b]run[/]
|
|
45
|
+
|
|
46
|
+
[b][blue]UPDATE[/][/]
|
|
47
|
+
[green][b]worker[/][/] [b]update[/]
|
|
48
|
+
|
|
49
|
+
[b][blue]VALIDATE[/][/]
|
|
50
|
+
[green][b]worker[/][/] [b]validate[/]
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
[b]Help:[/]
|
|
55
|
+
[b]Para mais informações[/]
|
|
56
|
+
[green][b]worker[/][/] --help
|
|
57
|
+
|
|
58
|
+
[b]Para ver a versão instalada[/]
|
|
59
|
+
[green][b]worker[/][/] --version
|
|
60
|
+
|
|
61
|
+
[b]Para gerar o arquivo de configuração[/]
|
|
62
|
+
[green][b]worker[/][/] configure
|
|
63
|
+
|
|
64
|
+
[b]Para informações detalhadas
|
|
65
|
+
[blue][link=https://github.com/SIM-Rede/worker-automate-hub]Repo no GIT Argenta[/][/] | [blue][link=https://pypi.org/project/worker-automate-hub/]Publicação no PyPI[/][/]
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@app.callback(invoke_without_command=True)
|
|
70
|
+
def main(
|
|
71
|
+
ctx: Context,
|
|
72
|
+
version: bool = Option(
|
|
73
|
+
False,
|
|
74
|
+
"--version",
|
|
75
|
+
help="Mostra a versão instalada",
|
|
76
|
+
is_flag=True,
|
|
77
|
+
),
|
|
78
|
+
):
|
|
79
|
+
"""Comando principal"""
|
|
80
|
+
if ctx.invoked_subcommand:
|
|
81
|
+
return
|
|
82
|
+
|
|
83
|
+
if version:
|
|
84
|
+
console.print(
|
|
85
|
+
importlib.metadata.version("worker-automate-hub"),
|
|
86
|
+
style="bold blue",
|
|
87
|
+
)
|
|
88
|
+
raise Exit(code=0)
|
|
89
|
+
|
|
90
|
+
console.print(HELP_MESSAGE)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@app.command()
|
|
94
|
+
def configure():
|
|
95
|
+
"""Executa o processo interativo de configuração"""
|
|
96
|
+
console.clear()
|
|
97
|
+
environment_names = [
|
|
98
|
+
"local",
|
|
99
|
+
"qa",
|
|
100
|
+
"main",
|
|
101
|
+
]
|
|
102
|
+
q = [
|
|
103
|
+
inquirer.Text("vault_token", "Por favor digite o token do Vault"),
|
|
104
|
+
inquirer.List("env_list", "Selecione o ambiente", environment_names),
|
|
105
|
+
]
|
|
106
|
+
r = inquirer.prompt(q, theme=GreenPassion())
|
|
107
|
+
|
|
108
|
+
env_sel, credentials = load_environments(r["env_list"], r["vault_token"])
|
|
109
|
+
write_env_config(env_sel, credentials)
|
|
110
|
+
workers = asyncio.run(get_workers())
|
|
111
|
+
|
|
112
|
+
if workers is None:
|
|
113
|
+
console.print("\nNenhum worker encontrado.\n", style="yellow")
|
|
114
|
+
raise Exit(code=0)
|
|
115
|
+
|
|
116
|
+
nomes_workers = [worker["nomRobo"] for worker in workers]
|
|
117
|
+
q2 = [inquirer.List("worker_list", "Selecione um Worker", choices=nomes_workers)]
|
|
118
|
+
r2 = inquirer.prompt(q2, theme=GreenPassion())
|
|
119
|
+
worker_sel = next(
|
|
120
|
+
worker for worker in workers if worker["nomRobo"] == r2["worker_list"]
|
|
121
|
+
)
|
|
122
|
+
add_worker_config(worker_sel)
|
|
123
|
+
|
|
124
|
+
q3 = [
|
|
125
|
+
inquirer.Confirm(
|
|
126
|
+
"reg_config",
|
|
127
|
+
message="Adicionar configuração de inicialização aos registros do Windows?",
|
|
128
|
+
)
|
|
129
|
+
]
|
|
130
|
+
r3 = inquirer.prompt(q3, theme=GreenPassion())
|
|
131
|
+
if r3["reg_config"]:
|
|
132
|
+
add_start_on_boot_to_registry()
|
|
133
|
+
|
|
134
|
+
q4 = [
|
|
135
|
+
inquirer.Confirm(
|
|
136
|
+
"assets_config",
|
|
137
|
+
message="Atualizar a pasta assets?",
|
|
138
|
+
)
|
|
139
|
+
]
|
|
140
|
+
r4 = inquirer.prompt(q4, theme=GreenPassion())
|
|
141
|
+
if r4["assets_config"]:
|
|
142
|
+
update_assets_v2()
|
|
143
|
+
|
|
144
|
+
q5 = [inquirer.Confirm("worker_bat", message="Criar o arquivo worker-startup.bat?")]
|
|
145
|
+
r5 = inquirer.prompt(q5, theme=GreenPassion())
|
|
146
|
+
if r5["worker_bat"]:
|
|
147
|
+
create_worker_bat()
|
|
148
|
+
|
|
149
|
+
q6 = [
|
|
150
|
+
inquirer.Confirm(
|
|
151
|
+
"tesseract_install", message="Iniciar a instalação do Tesseract?"
|
|
152
|
+
)
|
|
153
|
+
]
|
|
154
|
+
r6 = inquirer.prompt(q6, theme=GreenPassion())
|
|
155
|
+
if r6["tesseract_install"]:
|
|
156
|
+
asyncio.run(download_tesseract())
|
|
157
|
+
|
|
158
|
+
console.print("\nConfiguração finalizada com sucesso!\n", style="bold green")
|
|
159
|
+
|
|
160
|
+
raise Exit(code=0)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def is_command_running(command):
|
|
164
|
+
"""
|
|
165
|
+
Verifica se um comando CLI está sendo executado em outro terminal.
|
|
166
|
+
"""
|
|
167
|
+
command_str = " ".join(command)
|
|
168
|
+
rep = 0
|
|
169
|
+
for proc in psutil.process_iter(["pid", "name", "cmdline"]):
|
|
170
|
+
try:
|
|
171
|
+
cmdline = proc.info["cmdline"]
|
|
172
|
+
if cmdline and isinstance(cmdline, list):
|
|
173
|
+
cmdline_str = " ".join(cmdline)
|
|
174
|
+
if command_str in cmdline_str:
|
|
175
|
+
rep += 1
|
|
176
|
+
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
|
|
177
|
+
continue
|
|
178
|
+
|
|
179
|
+
return rep > 1
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
@app.command()
|
|
183
|
+
def run(
|
|
184
|
+
force: bool = Option(
|
|
185
|
+
False,
|
|
186
|
+
"--force",
|
|
187
|
+
help="Força a execução mesmo se outro comando já estiver rodando.",
|
|
188
|
+
),
|
|
189
|
+
assets: bool = Option(
|
|
190
|
+
False,
|
|
191
|
+
"--assets",
|
|
192
|
+
help="Executa o download da pasta assets atualizada.",
|
|
193
|
+
),
|
|
194
|
+
):
|
|
195
|
+
"""Inicializa o worker"""
|
|
196
|
+
if assets:
|
|
197
|
+
update_assets_v2()
|
|
198
|
+
|
|
199
|
+
command = ["worker", "run"]
|
|
200
|
+
if not force and is_command_running(command):
|
|
201
|
+
console.print(
|
|
202
|
+
"\nO script já está em execução. Saindo...\n", style="bold yellow"
|
|
203
|
+
)
|
|
204
|
+
raise Exit(code=0)
|
|
205
|
+
|
|
206
|
+
run_worker(stop_event)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
@app.command()
|
|
210
|
+
def update():
|
|
211
|
+
"""Força verificação/atualização do worker"""
|
|
212
|
+
check_for_update(stop_event)
|