worker-automate-hub 0.5.749__py3-none-any.whl → 0.5.912__py3-none-any.whl
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/api/client.py +186 -68
- worker_automate_hub/api/rpa_historico_service.py +1 -0
- worker_automate_hub/cli.py +91 -111
- worker_automate_hub/tasks/jobs/abertura_livros_fiscais.py +112 -229
- worker_automate_hub/tasks/jobs/descartes.py +91 -77
- worker_automate_hub/tasks/jobs/devolucao_produtos.py +1386 -0
- worker_automate_hub/tasks/jobs/entrada_de_notas_15.py +3 -46
- worker_automate_hub/tasks/jobs/entrada_de_notas_22.py +833 -0
- worker_automate_hub/tasks/jobs/entrada_de_notas_36.py +29 -9
- worker_automate_hub/tasks/jobs/entrada_de_notas_37.py +619 -0
- worker_automate_hub/tasks/jobs/entrada_de_notas_39.py +1 -1
- worker_automate_hub/tasks/jobs/entrada_de_notas_9.py +63 -16
- worker_automate_hub/tasks/jobs/extracao_dados_nielsen.py +504 -0
- worker_automate_hub/tasks/jobs/extracao_saldo_estoque.py +242 -108
- worker_automate_hub/tasks/jobs/extracao_saldo_estoque_fiscal.py +688 -0
- worker_automate_hub/tasks/jobs/fidc_gerar_nosso_numero.py +2 -2
- worker_automate_hub/tasks/jobs/fidc_remessa_cobranca_cnab240.py +25 -16
- worker_automate_hub/tasks/jobs/geracao_balancetes_filial.py +330 -0
- worker_automate_hub/tasks/jobs/importacao_extratos.py +538 -0
- worker_automate_hub/tasks/jobs/importacao_extratos_748.py +800 -0
- worker_automate_hub/tasks/jobs/inclusao_pedidos_ipiranga.py +222 -0
- worker_automate_hub/tasks/jobs/inclusao_pedidos_raizen.py +174 -0
- worker_automate_hub/tasks/jobs/inclusao_pedidos_vibra.py +327 -0
- worker_automate_hub/tasks/jobs/notas_faturamento_sap.py +438 -157
- worker_automate_hub/tasks/jobs/opex_capex.py +540 -326
- worker_automate_hub/tasks/jobs/sped_fiscal.py +8 -8
- worker_automate_hub/tasks/jobs/transferencias.py +52 -41
- worker_automate_hub/tasks/task_definitions.py +46 -1
- worker_automate_hub/tasks/task_executor.py +11 -0
- worker_automate_hub/utils/util.py +252 -215
- worker_automate_hub/utils/utils_nfe_entrada.py +1 -1
- worker_automate_hub/worker.py +1 -9
- {worker_automate_hub-0.5.749.dist-info → worker_automate_hub-0.5.912.dist-info}/METADATA +4 -2
- {worker_automate_hub-0.5.749.dist-info → worker_automate_hub-0.5.912.dist-info}/RECORD +36 -25
- {worker_automate_hub-0.5.749.dist-info → worker_automate_hub-0.5.912.dist-info}/WHEEL +1 -1
- {worker_automate_hub-0.5.749.dist-info → worker_automate_hub-0.5.912.dist-info}/entry_points.txt +0 -0
|
@@ -210,7 +210,7 @@ async def gerar_nosso_numero(task: RpaProcessoEntradaDTO) -> RpaRetornoProcessoD
|
|
|
210
210
|
return RpaRetornoProcessoDTO(
|
|
211
211
|
sucesso=False, retorno=log_msg, status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
|
212
212
|
)
|
|
213
|
-
|
|
213
|
+
await worker_sleep(60)
|
|
214
214
|
app = Application().connect(title="Seleciona Cobrança Bancária")
|
|
215
215
|
main_window = app["Seleciona Cobrança Bancária"]
|
|
216
216
|
code = main_window.child_window(class_name="TDBIEditCode", found_index=0)
|
|
@@ -226,7 +226,7 @@ async def gerar_nosso_numero(task: RpaProcessoEntradaDTO) -> RpaRetornoProcessoD
|
|
|
226
226
|
button_ok.click()
|
|
227
227
|
pyautogui.click(855, 740)
|
|
228
228
|
|
|
229
|
-
await worker_sleep(
|
|
229
|
+
await worker_sleep(120)
|
|
230
230
|
boleto_argenta = None
|
|
231
231
|
max_trys = 5
|
|
232
232
|
trys = 0
|
|
@@ -6,7 +6,7 @@ import shutil
|
|
|
6
6
|
import warnings
|
|
7
7
|
from datetime import datetime, timedelta
|
|
8
8
|
from decimal import ROUND_HALF_UP, Decimal
|
|
9
|
-
|
|
9
|
+
import win32wnet
|
|
10
10
|
import pyperclip
|
|
11
11
|
import pyautogui
|
|
12
12
|
from pywinauto.application import Application
|
|
@@ -58,7 +58,10 @@ async def remessa_cobranca_cnab240(task: RpaProcessoEntradaDTO) -> RpaRetornoPro
|
|
|
58
58
|
temp_folder = temp_folder +'\\'
|
|
59
59
|
#Pega Config para logar no Emsys
|
|
60
60
|
config = await get_config_by_name("login_emsys")
|
|
61
|
+
user_folder_login = await get_config_by_name("user_credentials")
|
|
62
|
+
user_folder_login = user_folder_login.conConfiguracao
|
|
61
63
|
folders_paths = await get_config_by_name("Folders_Fidc")
|
|
64
|
+
folders_paths = folders_paths.conConfiguracao
|
|
62
65
|
|
|
63
66
|
#Abre um novo emsys
|
|
64
67
|
await kill_all_emsys()
|
|
@@ -110,7 +113,6 @@ async def remessa_cobranca_cnab240(task: RpaProcessoEntradaDTO) -> RpaRetornoPro
|
|
|
110
113
|
|
|
111
114
|
field_arquivo.double_click_input()
|
|
112
115
|
field_arquivo.set_edit_text("")
|
|
113
|
-
# field_arquivo.type_keys(folders_paths.conConfiguracao['remessa_cobranca_path'] + new_text_field_arquivo, with_spaces=True)
|
|
114
116
|
field_arquivo.type_keys(temp_folder + new_text_field_arquivo, with_spaces=True)
|
|
115
117
|
|
|
116
118
|
await worker_sleep(2)
|
|
@@ -165,7 +167,7 @@ async def remessa_cobranca_cnab240(task: RpaProcessoEntradaDTO) -> RpaRetornoPro
|
|
|
165
167
|
#clcica em OK
|
|
166
168
|
pyautogui.click(1100, 660)
|
|
167
169
|
|
|
168
|
-
await worker_sleep(
|
|
170
|
+
await worker_sleep(180)
|
|
169
171
|
|
|
170
172
|
try:
|
|
171
173
|
app = Application().connect(title="Informação", backend="uia")
|
|
@@ -230,9 +232,7 @@ async def remessa_cobranca_cnab240(task: RpaProcessoEntradaDTO) -> RpaRetornoPro
|
|
|
230
232
|
sucesso=False, retorno=log_msg, status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)])
|
|
231
233
|
|
|
232
234
|
# # Substituindo arquivo original e fazedno upload (feito logo apos gerar para garaintir que o arquivo não se perca)
|
|
233
|
-
# origem = folders_paths.conConfiguracao['remessa_cobranca_path'] + new_text_field_arquivo
|
|
234
235
|
origem = temp_folder + new_text_field_arquivo
|
|
235
|
-
|
|
236
236
|
# Abrindo o arquivo original para leitura
|
|
237
237
|
file = open(origem, 'r')
|
|
238
238
|
file_text = file.read()
|
|
@@ -247,7 +247,9 @@ async def remessa_cobranca_cnab240(task: RpaProcessoEntradaDTO) -> RpaRetornoPro
|
|
|
247
247
|
file = open(origem, 'w')
|
|
248
248
|
file.write(file_text)
|
|
249
249
|
file.close()
|
|
250
|
-
|
|
250
|
+
|
|
251
|
+
await worker_sleep(5)
|
|
252
|
+
|
|
251
253
|
console.print(f"Substituições realizadas com sucesso no arquivo original: {origem}")
|
|
252
254
|
try:
|
|
253
255
|
with open(origem, 'rb') as file:
|
|
@@ -260,7 +262,6 @@ async def remessa_cobranca_cnab240(task: RpaProcessoEntradaDTO) -> RpaRetornoPro
|
|
|
260
262
|
return RpaRetornoProcessoDTO(
|
|
261
263
|
sucesso=False, retorno=log_msg, status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)])
|
|
262
264
|
|
|
263
|
-
|
|
264
265
|
# Clica em 'Yes' imprimir listagem
|
|
265
266
|
await worker_sleep(10)
|
|
266
267
|
try:
|
|
@@ -293,7 +294,6 @@ async def remessa_cobranca_cnab240(task: RpaProcessoEntradaDTO) -> RpaRetornoPro
|
|
|
293
294
|
|
|
294
295
|
await worker_sleep(10)
|
|
295
296
|
|
|
296
|
-
# await save_pdf_emsys(folders_paths.conConfiguracao['remessa_cobranca_path'] + new_text_field_arquivo +" (PDF)")
|
|
297
297
|
await save_pdf_emsys(temp_folder + new_text_field_arquivo + PDF_SUFFIX)
|
|
298
298
|
|
|
299
299
|
await worker_sleep(5)
|
|
@@ -324,12 +324,22 @@ async def remessa_cobranca_cnab240(task: RpaProcessoEntradaDTO) -> RpaRetornoPro
|
|
|
324
324
|
|
|
325
325
|
try:
|
|
326
326
|
#Mover para pasta correta
|
|
327
|
-
shutil.move(origem, folders_paths
|
|
328
|
-
except
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
327
|
+
shutil.move(origem, folders_paths["remessa_cobranca_path_prod"])
|
|
328
|
+
except:
|
|
329
|
+
try:
|
|
330
|
+
win32wnet.WNetAddConnection2(0, None, folders_paths["remessa_cobranca_path_prod_ip"], None, user_folder_login.get("usuario"), user_folder_login.get("senha"))
|
|
331
|
+
if os.path.exists(origem):
|
|
332
|
+
shutil.move(origem, folders_paths["remessa_cobranca_path_prod_ip"])
|
|
333
|
+
else:
|
|
334
|
+
log_msg=(f"Erro ao mover o arquivo para pasta de remessa: {origem} na pasta {folders_paths['remessa_cobranca_path_prod_ip']}")
|
|
335
|
+
console.print(log_msg, style="bold red")
|
|
336
|
+
return RpaRetornoProcessoDTO(
|
|
337
|
+
sucesso=False, retorno=log_msg, status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)])
|
|
338
|
+
except Exception as e:
|
|
339
|
+
log_msg=(f"Erro ao mover o arquivo para pasta de remessa: {e}")
|
|
340
|
+
console.print(log_msg, style="bold red")
|
|
341
|
+
return RpaRetornoProcessoDTO(
|
|
342
|
+
sucesso=False, retorno=log_msg, status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)])
|
|
333
343
|
|
|
334
344
|
#Delete temp folder
|
|
335
345
|
await delete_folder(nome_pasta)
|
|
@@ -343,5 +353,4 @@ async def remessa_cobranca_cnab240(task: RpaProcessoEntradaDTO) -> RpaRetornoPro
|
|
|
343
353
|
log_msg = f"Erro Processo Remessa de Cobranca CNAB240: {str(ex)}"
|
|
344
354
|
console.print(log_msg, style="bold red")
|
|
345
355
|
return RpaRetornoProcessoDTO(
|
|
346
|
-
sucesso=False, retorno=log_msg, status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)])
|
|
347
|
-
|
|
356
|
+
sucesso=False, retorno=log_msg, status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)])
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import numpy
|
|
2
|
+
import asyncio
|
|
3
|
+
import sys
|
|
4
|
+
import os
|
|
5
|
+
import io
|
|
6
|
+
from pywinauto.keyboard import send_keys
|
|
7
|
+
|
|
8
|
+
# sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..')))
|
|
9
|
+
from worker_automate_hub.models.dto.rpa_historico_request_dto import (
|
|
10
|
+
RpaHistoricoStatusEnum,
|
|
11
|
+
RpaRetornoProcessoDTO,
|
|
12
|
+
RpaTagDTO,
|
|
13
|
+
RpaTagEnum,
|
|
14
|
+
)
|
|
15
|
+
from worker_automate_hub.models.dto.rpa_processo_entrada_dto import (
|
|
16
|
+
RpaProcessoEntradaDTO,
|
|
17
|
+
)
|
|
18
|
+
from worker_automate_hub.utils.util import (
|
|
19
|
+
kill_all_emsys,
|
|
20
|
+
worker_sleep,
|
|
21
|
+
)
|
|
22
|
+
from rich.console import Console
|
|
23
|
+
import pyautogui
|
|
24
|
+
from datetime import datetime
|
|
25
|
+
|
|
26
|
+
# from dateutil.relativedelta import relativedelta
|
|
27
|
+
from PIL import ImageFilter, ImageEnhance
|
|
28
|
+
from pytesseract import image_to_string
|
|
29
|
+
from pywinauto import Application, Desktop
|
|
30
|
+
import subprocess
|
|
31
|
+
import os
|
|
32
|
+
from worker_automate_hub.api.client import get_config_by_name, send_file
|
|
33
|
+
from worker_automate_hub.utils.utils_nfe_entrada import EMSys
|
|
34
|
+
import psutil
|
|
35
|
+
from time import sleep
|
|
36
|
+
|
|
37
|
+
pyautogui.PAUSE = 0.5
|
|
38
|
+
console = Console()
|
|
39
|
+
emsys = EMSys()
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def get_text_from_window(window, relative_coords, value=None):
|
|
43
|
+
try:
|
|
44
|
+
screenshot = window.capture_as_image()
|
|
45
|
+
imagem = screenshot.convert("L")
|
|
46
|
+
imagem = imagem.filter(ImageFilter.SHARPEN)
|
|
47
|
+
imagem = ImageEnhance.Contrast(imagem).enhance(2)
|
|
48
|
+
cropped_screenshot = imagem.crop(relative_coords)
|
|
49
|
+
texto = image_to_string(cropped_screenshot, lang="por")
|
|
50
|
+
return (value.upper() in texto.upper()) if value != None else texto.lower()
|
|
51
|
+
except Exception as error:
|
|
52
|
+
console.print(f"Error: {error}")
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
async def open_contabil_processes():
|
|
56
|
+
try:
|
|
57
|
+
console.print("Abrindo EMSys Contabil...")
|
|
58
|
+
os.startfile("C:\\Users\\automatehub\\Desktop\\Contabil\\contabil1.lnk")
|
|
59
|
+
await worker_sleep(3)
|
|
60
|
+
os.startfile("C:\\Users\\automatehub\\Desktop\\Contabil\\contabil2.lnk")
|
|
61
|
+
await worker_sleep(30)
|
|
62
|
+
os.startfile("C:\\Users\\automatehub\\Desktop\\Contabil\\contabil3.lnk")
|
|
63
|
+
await worker_sleep(20)
|
|
64
|
+
pyautogui.hotkey("win", "d")
|
|
65
|
+
await worker_sleep(4)
|
|
66
|
+
os.startfile("C:\\Users\\automatehub\\Desktop\\Contabil\\contabil4.lnk")
|
|
67
|
+
await worker_sleep(2)
|
|
68
|
+
except Exception as error:
|
|
69
|
+
console.print(f"Error: {error}")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
async def geracao_balancetes_filial(
|
|
73
|
+
task: RpaProcessoEntradaDTO,
|
|
74
|
+
) -> RpaRetornoProcessoDTO:
|
|
75
|
+
try:
|
|
76
|
+
await kill_all_emsys()
|
|
77
|
+
await open_contabil_processes()
|
|
78
|
+
config = await get_config_by_name("login_emsys_contabil")
|
|
79
|
+
filial = task.configEntrada.get("filialEmpresaOrigem")
|
|
80
|
+
periodo_inicial = task.configEntrada.get("periodoInicial")
|
|
81
|
+
periodo_final = task.configEntrada.get("periodoFinal")
|
|
82
|
+
historico_id = task.historico_id
|
|
83
|
+
if historico_id:
|
|
84
|
+
console.print("Historico ID recuperado com sucesso...\n")
|
|
85
|
+
app = None
|
|
86
|
+
max_attempts = 30
|
|
87
|
+
console.print("Tentando encontrar janela de login...")
|
|
88
|
+
for attempt in range(max_attempts):
|
|
89
|
+
try:
|
|
90
|
+
app = Application(backend="win32").connect(
|
|
91
|
+
title="Selecione o Usuário para autenticação"
|
|
92
|
+
)
|
|
93
|
+
console.print("Janela encontrada!")
|
|
94
|
+
break
|
|
95
|
+
except:
|
|
96
|
+
console.print("Janela ainda nao encontrada...")
|
|
97
|
+
await worker_sleep(1)
|
|
98
|
+
if not app:
|
|
99
|
+
console.print("Nao foi possivel encontrar a janela de login...")
|
|
100
|
+
return RpaRetornoProcessoDTO(
|
|
101
|
+
sucesso=False,
|
|
102
|
+
retorno="Erro durante tentativa localizacao de janelas...",
|
|
103
|
+
status=RpaHistoricoStatusEnum.Falha,
|
|
104
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)],
|
|
105
|
+
)
|
|
106
|
+
await emsys.verify_warning_and_error("Erro", "&Ok")
|
|
107
|
+
await worker_sleep(4)
|
|
108
|
+
pyautogui.click(x=1021, y=127)
|
|
109
|
+
console.print("Logando...")
|
|
110
|
+
await emsys.verify_warning_and_error("Erro", "&Ok")
|
|
111
|
+
pyautogui.write(config.conConfiguracao.get("user"))
|
|
112
|
+
pyautogui.press("enter")
|
|
113
|
+
|
|
114
|
+
await worker_sleep(4)
|
|
115
|
+
pyautogui.write(config.conConfiguracao.get("pass"))
|
|
116
|
+
pyautogui.press("enter")
|
|
117
|
+
|
|
118
|
+
await worker_sleep(10)
|
|
119
|
+
|
|
120
|
+
main_window = None
|
|
121
|
+
for attempt in range(max_attempts):
|
|
122
|
+
main_window = Application().connect(title="EMSys [Contabil]")
|
|
123
|
+
main_window = main_window.top_window()
|
|
124
|
+
if main_window.exists():
|
|
125
|
+
console.print("Janela encontrada!")
|
|
126
|
+
break
|
|
127
|
+
console.print("Janela ainda nao encontrada...")
|
|
128
|
+
await worker_sleep(1)
|
|
129
|
+
|
|
130
|
+
if not main_window:
|
|
131
|
+
return RpaRetornoProcessoDTO(
|
|
132
|
+
sucesso=False,
|
|
133
|
+
retorno="Erro durante tentativa localizacao de janelas....",
|
|
134
|
+
status=RpaHistoricoStatusEnum.Falha,
|
|
135
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)],
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
# Adicionando foco
|
|
139
|
+
try:
|
|
140
|
+
main_window.set_focus()
|
|
141
|
+
console.print(f"Ativando janela: {main_window}")
|
|
142
|
+
except Exception as error:
|
|
143
|
+
console.print(f"Erro ao setar foco na janela: {main_window}")
|
|
144
|
+
|
|
145
|
+
await worker_sleep(4)
|
|
146
|
+
console.print("Cicar em BAL")
|
|
147
|
+
pyautogui.click(x=453, y=96)
|
|
148
|
+
await worker_sleep(4)
|
|
149
|
+
|
|
150
|
+
console.print("Preenchendo campo periodo...")
|
|
151
|
+
|
|
152
|
+
app = Application(backend="win32").connect(class_name="TFrmBalancete")
|
|
153
|
+
win = app.window(class_name="TFrmBalancete")
|
|
154
|
+
|
|
155
|
+
# Seus índices: inicial = found_index=1, final = found_index=0
|
|
156
|
+
ctrl_inicial = win.child_window(
|
|
157
|
+
class_name="TRzEditDate", found_index=1
|
|
158
|
+
).wrapper_object()
|
|
159
|
+
ctrl_final = win.child_window(
|
|
160
|
+
class_name="TRzEditDate", found_index=0
|
|
161
|
+
).wrapper_object()
|
|
162
|
+
|
|
163
|
+
# ---- Inicial ----
|
|
164
|
+
try:
|
|
165
|
+
ctrl_inicial.set_edit_text(periodo_inicial) # tenta via WM_SETTEXT
|
|
166
|
+
except Exception:
|
|
167
|
+
ctrl_inicial.set_focus()
|
|
168
|
+
ctrl_inicial.click_input()
|
|
169
|
+
send_keys("^a{DELETE}")
|
|
170
|
+
send_keys(
|
|
171
|
+
periodo_inicial.replace("/", "")
|
|
172
|
+
) # fallback: digita só dígitos (máscara)
|
|
173
|
+
|
|
174
|
+
# ---- Final ----
|
|
175
|
+
try:
|
|
176
|
+
ctrl_final.set_edit_text(periodo_final)
|
|
177
|
+
except Exception:
|
|
178
|
+
ctrl_final.set_focus()
|
|
179
|
+
ctrl_final.click_input()
|
|
180
|
+
send_keys("^a{DELETE}")
|
|
181
|
+
send_keys(periodo_final.replace("/", ""))
|
|
182
|
+
|
|
183
|
+
await worker_sleep(4)
|
|
184
|
+
|
|
185
|
+
console.print("Selecionar detalhada por centro de custo..")
|
|
186
|
+
detalhada = win.child_window(class_name="TRzComboBox", found_index=0)
|
|
187
|
+
detalhada.select("Centro de Custo")
|
|
188
|
+
|
|
189
|
+
await worker_sleep(6)
|
|
190
|
+
|
|
191
|
+
console.print("Selecionar considerar contas analíticas zerada")
|
|
192
|
+
contas_analit_zeradas = win.child_window(
|
|
193
|
+
class_name="TRzCheckBox", found_index=2
|
|
194
|
+
).click()
|
|
195
|
+
|
|
196
|
+
await worker_sleep(4)
|
|
197
|
+
|
|
198
|
+
console.print("Selecionar considerar contas sintéticas zerada")
|
|
199
|
+
contas_sint_zeradas = win.child_window(
|
|
200
|
+
class_name="TRzCheckBox", found_index=0
|
|
201
|
+
).click()
|
|
202
|
+
|
|
203
|
+
await worker_sleep(4)
|
|
204
|
+
|
|
205
|
+
console.print("Selecionar por filiais")
|
|
206
|
+
selec_filiais = win.child_window(
|
|
207
|
+
class_name="TRzCheckBox", found_index=3
|
|
208
|
+
).click()
|
|
209
|
+
|
|
210
|
+
await worker_sleep(4)
|
|
211
|
+
|
|
212
|
+
console.print("Selecionar CSV")
|
|
213
|
+
selec_csv = win.child_window(class_name="TRzComboBox", found_index=1)
|
|
214
|
+
selec_csv.select("Arquivo CSV")
|
|
215
|
+
|
|
216
|
+
await worker_sleep(4)
|
|
217
|
+
|
|
218
|
+
console.print("Clicar em gerar relatório")
|
|
219
|
+
btn_gerar_relatorio = win.child_window(
|
|
220
|
+
class_name="TBitBtn", found_index=0
|
|
221
|
+
).click()
|
|
222
|
+
|
|
223
|
+
# Selecionar filial
|
|
224
|
+
app = Application(backend="win32").connect(
|
|
225
|
+
title="Seleção de Empresas", timeout=10
|
|
226
|
+
)
|
|
227
|
+
dlg = app.window(title="Seleção de Empresas")
|
|
228
|
+
edit = dlg.child_window(class_name="TEdit", found_index=0).wrapper_object()
|
|
229
|
+
|
|
230
|
+
# Tenta via WM_SETTEXT
|
|
231
|
+
try:
|
|
232
|
+
edit.set_focus()
|
|
233
|
+
edit.set_edit_text("") # limpa
|
|
234
|
+
edit.set_edit_text(filial) # escreve
|
|
235
|
+
except Exception:
|
|
236
|
+
# Fallback: digita como teclado
|
|
237
|
+
edit.set_focus()
|
|
238
|
+
edit.click_input()
|
|
239
|
+
send_keys("^a{DELETE}")
|
|
240
|
+
send_keys("3", with_spaces=True)
|
|
241
|
+
|
|
242
|
+
await worker_sleep(3)
|
|
243
|
+
|
|
244
|
+
# Marcar filial
|
|
245
|
+
imagem_alvo = "assets\\geracao_bal_filial\\btn_selec_uma_filial.png"
|
|
246
|
+
|
|
247
|
+
btn_sect_uma = pyautogui.locateCenterOnScreen(
|
|
248
|
+
imagem_alvo, confidence=0.9
|
|
249
|
+
) # requer opencv-python
|
|
250
|
+
if btn_sect_uma: # se achou, clica
|
|
251
|
+
pyautogui.click(btn_sect_uma)
|
|
252
|
+
|
|
253
|
+
btn_ok = dlg.child_window(class_name="TBitBtn", title="&OK").click()
|
|
254
|
+
|
|
255
|
+
# aguarda até a janela "Gera Arquivo CSV (Excel)" existir (ou ficar visível)
|
|
256
|
+
csv_win = Desktop(backend="win32").window(title="Gera Arquivo CSV (Excel)")
|
|
257
|
+
csv_win.wait("exists", timeout=3600)
|
|
258
|
+
|
|
259
|
+
app_csv = Application(backend="win32").connect(title="Gera Arquivo CSV (Excel)")
|
|
260
|
+
dlg_csv = app_csv.window(title="Gera Arquivo CSV (Excel)")
|
|
261
|
+
edit = dlg_csv.child_window(class_name="Edit", found_index=0)
|
|
262
|
+
# Tenta via WM_SETTEXT (mais estável)
|
|
263
|
+
try:
|
|
264
|
+
periodo_inicial = periodo_inicial.replace("/", "")
|
|
265
|
+
periodo_final = periodo_final.replace("/", "")
|
|
266
|
+
edit.set_focus()
|
|
267
|
+
edit.set_edit_text("") # limpa
|
|
268
|
+
edit.set_edit_text(
|
|
269
|
+
rf"C:\Users\automatehub\Downloads\balancete_{periodo_inicial}_{periodo_final}_{filial}"
|
|
270
|
+
)
|
|
271
|
+
except Exception:
|
|
272
|
+
# Fallback: digita como teclado
|
|
273
|
+
edit.set_focus()
|
|
274
|
+
edit.click_input()
|
|
275
|
+
send_keys("^a{DELETE}")
|
|
276
|
+
send_keys(
|
|
277
|
+
rf"C:\Users\automatehub\Downloads\balancete_{periodo_inicial}_{periodo_final}_{filial}",
|
|
278
|
+
with_spaces=True,
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
# Clicar em salvar
|
|
282
|
+
app = Application(backend="win32").connect(
|
|
283
|
+
title="Gera Arquivo CSV (Excel)", timeout=10
|
|
284
|
+
)
|
|
285
|
+
dlg = app.window(title="Gera Arquivo CSV (Excel)")
|
|
286
|
+
btn_salvar = dlg.child_window(class_name="Button", found_index=0).click()
|
|
287
|
+
|
|
288
|
+
await worker_sleep(6)
|
|
289
|
+
|
|
290
|
+
# Janela confirmação clicar em OK
|
|
291
|
+
app = Application(backend="win32").connect(title="Informação", timeout=10)
|
|
292
|
+
dlg = app.window(title="Informação")
|
|
293
|
+
btn_ok = dlg.child_window(class_name="Button", found_index=0).click()
|
|
294
|
+
|
|
295
|
+
console.print("Arquivo salvo com sucesso...\n")
|
|
296
|
+
await worker_sleep(3)
|
|
297
|
+
path_to_txt = rf"C:\Users\automatehub\Downloads\balancete_{periodo_inicial}_{periodo_final}_{filial}"
|
|
298
|
+
|
|
299
|
+
with open(f"{path_to_txt}.csv", "rb") as file:
|
|
300
|
+
file_bytes = io.BytesIO(file.read())
|
|
301
|
+
|
|
302
|
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
303
|
+
desArquivo = f"balancete_{periodo_inicial}_{periodo_final}_{filial}.csv"
|
|
304
|
+
try:
|
|
305
|
+
await send_file(
|
|
306
|
+
historico_id, desArquivo, "csv", file_bytes, file_extension="csv"
|
|
307
|
+
)
|
|
308
|
+
os.remove(path_to_txt + ".csv")
|
|
309
|
+
return RpaRetornoProcessoDTO(
|
|
310
|
+
sucesso=True,
|
|
311
|
+
retorno="Balancete gerado com sucesso",
|
|
312
|
+
status=RpaHistoricoStatusEnum.Sucesso,
|
|
313
|
+
)
|
|
314
|
+
except Exception as e:
|
|
315
|
+
result = f"Arquivo balancete gerado com sucesso, porém gerou erro ao realizar o envio para o backoffice {e} - Arquivo ainda salvo na dispositivo utilizado no diretório {path_to_txt}!"
|
|
316
|
+
console.print(result, style="bold red")
|
|
317
|
+
return RpaRetornoProcessoDTO(
|
|
318
|
+
sucesso=False,
|
|
319
|
+
retorno=result,
|
|
320
|
+
status=RpaHistoricoStatusEnum.Falha,
|
|
321
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)],
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
except Exception as erro:
|
|
325
|
+
return RpaRetornoProcessoDTO(
|
|
326
|
+
sucesso=False,
|
|
327
|
+
retorno=f"Erro durante o processo integração contabil, erro : {erro}",
|
|
328
|
+
status=RpaHistoricoStatusEnum.Falha,
|
|
329
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)],
|
|
330
|
+
)
|