worker-automate-hub 0.5.759__py3-none-any.whl → 0.5.761__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/tasks/jobs/extracao_saldo_estoque_fiscal.py +154 -68
- {worker_automate_hub-0.5.759.dist-info → worker_automate_hub-0.5.761.dist-info}/METADATA +1 -1
- {worker_automate_hub-0.5.759.dist-info → worker_automate_hub-0.5.761.dist-info}/RECORD +5 -5
- {worker_automate_hub-0.5.759.dist-info → worker_automate_hub-0.5.761.dist-info}/WHEEL +0 -0
- {worker_automate_hub-0.5.759.dist-info → worker_automate_hub-0.5.761.dist-info}/entry_points.txt +0 -0
@@ -282,86 +282,173 @@ async def extracao_saldo_estoque_fiscal(
|
|
282
282
|
|
283
283
|
await worker_sleep(2)
|
284
284
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
if
|
296
|
-
pyautogui.
|
297
|
-
|
285
|
+
max_tentativas = 5
|
286
|
+
tentativa = 1
|
287
|
+
sucesso = False
|
288
|
+
|
289
|
+
while tentativa <= max_tentativas and not sucesso:
|
290
|
+
console.print(f"Tentativa {tentativa} de {max_tentativas}", style="bold cyan")
|
291
|
+
|
292
|
+
# 1) Abrir o picker de formatos pelo botão (imagem)
|
293
|
+
console.print("Procurando botão de salvar (imagem)...", style="bold cyan")
|
294
|
+
caminho_img = r'assets\\extracao_relatorios\\btn_salvar.png'
|
295
|
+
if os.path.isfile(caminho_img):
|
296
|
+
pos = pyautogui.locateCenterOnScreen(caminho_img, confidence=0.9)
|
297
|
+
if pos:
|
298
|
+
pyautogui.click(pos)
|
299
|
+
console.print("Clique realizado no botão salvar", style="bold green")
|
300
|
+
else:
|
301
|
+
console.print("Imagem encontrada mas não está visível na tela", style="bold yellow")
|
298
302
|
else:
|
299
|
-
print("Imagem
|
300
|
-
else:
|
301
|
-
print("A imagem NÃO existe:", caminho)
|
302
|
-
|
303
|
-
await worker_sleep(2)
|
303
|
+
console.print("Imagem do botão salvar NÃO existe", style="bold red")
|
304
304
|
|
305
|
-
|
306
|
-
app = Application().connect(class_name="TFrmRelatorioFormato", found_index=0)
|
307
|
-
main_window = app["TFrmRelatorioFormato"]
|
308
|
-
main_window.set_focus()
|
309
|
-
# Acessa o ComboBox pelo identificador conhecido
|
310
|
-
combo = main_window.ComboBox
|
311
|
-
|
312
|
-
# Garante que existe "Excel" na lista
|
313
|
-
itens = combo.texts()
|
314
|
-
print("Itens do ComboBox:", itens)
|
315
|
-
|
316
|
-
# Seleciona o Excel correto (o segundo da lista, índice 8)
|
317
|
-
combo.select(8)
|
318
|
-
|
319
|
-
await worker_sleep(2)
|
305
|
+
await worker_sleep(8)
|
320
306
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
307
|
+
# 2) Selecionar formato "Excel" na janela TFrmRelatorioFormato
|
308
|
+
console.print("Selecionando formato Excel...", style="bold cyan")
|
309
|
+
try:
|
310
|
+
app_fmt = Application().connect(class_name="TFrmRelatorioFormato", timeout=10)
|
311
|
+
win_fmt = app_fmt["TFrmRelatorioFormato"]
|
312
|
+
win_fmt.wait("visible", timeout=10)
|
313
|
+
|
314
|
+
combo = win_fmt.ComboBox
|
315
|
+
textos = combo.texts()
|
316
|
+
console.print(f"Itens do ComboBox: {textos}", style="bold yellow")
|
317
|
+
|
318
|
+
# Se souber o índice correto, mantenha. Caso contrário, tente por texto contendo 'Excel'
|
319
|
+
try:
|
320
|
+
combo.select(8)
|
321
|
+
except Exception:
|
322
|
+
alvo = None
|
323
|
+
for i, t in enumerate(textos):
|
324
|
+
if "EXCEL" in str(t).upper() or "XLSX" in str(t).upper():
|
325
|
+
alvo = i
|
326
|
+
break
|
327
|
+
if alvo is not None:
|
328
|
+
combo.select(alvo)
|
329
|
+
else:
|
330
|
+
console.print("Não foi possível localizar a opção de Excel no ComboBox.", style="bold red")
|
331
|
+
tentativa += 1
|
332
|
+
await worker_sleep(2)
|
333
|
+
continue
|
334
|
+
|
335
|
+
await worker_sleep(1)
|
336
|
+
|
337
|
+
# Botão OK/Confirmar na janela de formato
|
338
|
+
win_fmt.child_window(class_name="TBitBtn", found_index=1).wait("enabled", timeout=5)
|
339
|
+
win_fmt.child_window(class_name="TBitBtn", found_index=1).click_input()
|
340
|
+
except Exception as e:
|
341
|
+
console.print(f"Falha ao selecionar formato: {e}", style="bold red")
|
342
|
+
tentativa += 1
|
343
|
+
await worker_sleep(3)
|
344
|
+
continue
|
331
345
|
|
332
|
-
|
333
|
-
campo_nome = main_window.child_window(
|
334
|
-
class_name="Edit", control_id=1148
|
335
|
-
).wrapper_object()
|
336
|
-
caminho_arquivo = rf"C:\Users\automatehub\Downloads\saldo_estoque_fiscal_{periodo_format}_{filial}.xlsx"
|
337
|
-
campo_nome.set_focus()
|
338
|
-
campo_nome.set_edit_text(caminho_arquivo)
|
346
|
+
await worker_sleep(5)
|
339
347
|
|
340
|
-
|
348
|
+
# 3) Janela "Salvar para arquivo"
|
349
|
+
console.print("Abrindo janela de salvar arquivo...", style="bold cyan")
|
350
|
+
try:
|
351
|
+
app_save = Application().connect(title_re="Salvar para arquivo", timeout=30)
|
352
|
+
win_save = app_save.window(title_re="Salvar para arquivo")
|
353
|
+
win_save.wait("visible", timeout=30)
|
354
|
+
except Exception as e:
|
355
|
+
console.print(f"Não achou a janela 'Salvar para arquivo': {e}", style="bold red")
|
356
|
+
tentativa += 1
|
357
|
+
await worker_sleep(3)
|
358
|
+
continue
|
359
|
+
|
360
|
+
# Caminho do arquivo a salvar
|
361
|
+
caminho_arquivo = rf"C:\Users\automatehub\Downloads\saldo_estoque_fiscal_{periodo_format}_{filial}.xlsx"
|
362
|
+
|
363
|
+
# Se já existe, removemos para evitar pop-up de confirmação
|
364
|
+
if os.path.exists(caminho_arquivo):
|
365
|
+
try:
|
366
|
+
os.remove(caminho_arquivo)
|
367
|
+
console.print("Arquivo existente removido para evitar prompt de sobrescrita.", style="bold yellow")
|
368
|
+
except Exception as e:
|
369
|
+
console.print(f"Não foi possível remover o arquivo existente: {e}", style="bold red")
|
341
370
|
|
342
|
-
|
371
|
+
try:
|
372
|
+
# Campo "Nome" (Edit, control_id=1148)
|
373
|
+
campo_nome = win_save.child_window(class_name="Edit", control_id=1148).wrapper_object()
|
374
|
+
campo_nome.set_focus()
|
375
|
+
# limpa conteúdo
|
376
|
+
try:
|
377
|
+
campo_nome.set_edit_text("")
|
378
|
+
except Exception:
|
379
|
+
# fallback limpando com Ctrl+A + Delete
|
380
|
+
campo_nome.type_keys("^a{DELETE}", pause=0.02)
|
381
|
+
|
382
|
+
# digita caminho
|
383
|
+
campo_nome.type_keys(caminho_arquivo, with_spaces=True, pause=0.01)
|
384
|
+
console.print(f"Arquivo configurado para: {caminho_arquivo}", style="bold green")
|
385
|
+
|
386
|
+
await worker_sleep(1)
|
387
|
+
|
388
|
+
# Botão Salvar (primeiro Button)
|
389
|
+
btn_salvar = win_save.child_window(class_name="Button", found_index=0)
|
390
|
+
btn_salvar.wait("enabled", timeout=10)
|
391
|
+
btn_salvar.click_input()
|
392
|
+
except Exception as e:
|
393
|
+
console.print(f"Erro ao confirmar salvar: {e}", style="bold red")
|
394
|
+
tentativa += 1
|
395
|
+
await worker_sleep(3)
|
396
|
+
continue
|
343
397
|
|
344
|
-
|
345
|
-
keyboard.send_keys("{TAB}{TAB}{ENTER}", pause=0.3)
|
398
|
+
await worker_sleep(2)
|
346
399
|
|
347
|
-
|
400
|
+
# 3.1) Tratar confirmação de sobrescrita, se aparecer
|
401
|
+
try:
|
402
|
+
# Pode vir em PT/EN dependendo do SO
|
403
|
+
# Título comum: "Confirm Save As" (EN) ou "Confirmar Salvar Como" (PT)
|
404
|
+
try:
|
405
|
+
app_conf = Application().connect(title_re="Confirm(ar)?( )?Salvar( )?Como|Confirm Save As", timeout=3)
|
406
|
+
win_conf = app_conf.window(title_re="Confirm(ar)?( )?Salvar( )?Como|Confirm Save As")
|
407
|
+
win_conf.wait("visible", timeout=3)
|
408
|
+
# Botões costumam ser "Sim"/"Yes" como class_name="Button"
|
409
|
+
# Tente o primeiro botão (Yes/Sim)
|
410
|
+
win_conf.child_window(class_name="Button", found_index=0).click_input()
|
411
|
+
console.print("Confirmação de sobrescrita respondida.", style="bold yellow")
|
412
|
+
except Exception:
|
413
|
+
pass
|
414
|
+
except Exception:
|
415
|
+
pass
|
348
416
|
|
349
|
-
|
417
|
+
await worker_sleep(2)
|
350
418
|
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
419
|
+
# 4) Aguardar o processamento/Printing encerrar
|
420
|
+
console.print("Aguardando finalização do processo de impressão/salvamento...", style="bold cyan")
|
421
|
+
try:
|
422
|
+
app_print = Application().connect(title_re="Printing", timeout=5)
|
423
|
+
win_print = app_print.window(title_re="Printing")
|
424
|
+
try:
|
425
|
+
win_print.wait_not("visible", timeout=60)
|
426
|
+
console.print("Janela 'Printing' fechada.", style="bold green")
|
427
|
+
except Exception:
|
428
|
+
console.print("Janela 'Printing' não fechou no tempo esperado. Seguindo.", style="bold yellow")
|
429
|
+
except findwindows.ElementNotFoundError:
|
430
|
+
console.print("Janela 'Printing' não apareceu.", style="bold yellow")
|
431
|
+
except Exception as e:
|
432
|
+
console.print(f"Erro ao aguardar 'Printing': {e}", style="bold yellow")
|
433
|
+
|
434
|
+
# 5) Validar arquivo salvo
|
435
|
+
if os.path.exists(caminho_arquivo):
|
436
|
+
console.print(f"Arquivo encontrado: {caminho_arquivo}", style="bold green")
|
437
|
+
with open(caminho_arquivo, "rb") as f:
|
438
|
+
file_bytes = io.BytesIO(f.read())
|
439
|
+
sucesso = True
|
440
|
+
else:
|
441
|
+
console.print("Arquivo não encontrado, tentando novamente...", style="bold red")
|
442
|
+
tentativa += 1
|
443
|
+
await worker_sleep(3)
|
355
444
|
|
356
|
-
|
357
|
-
|
358
|
-
print("Janela 'Printing' fechada.")
|
445
|
+
if not sucesso:
|
446
|
+
console.print("Falha após 5 tentativas. Arquivo não foi gerado.", style="bold red")
|
359
447
|
|
360
|
-
except findwindows.ElementNotFoundError:
|
361
|
-
print("Janela 'Printing' não estava aberta.")
|
362
448
|
|
363
449
|
nome_com_extensao = f"saldo_estoque_fiscal_{periodo_format}_{filial}.xlsx"
|
364
450
|
# lê o arquivo
|
451
|
+
print(caminho_arquivo)
|
365
452
|
with open(f"{caminho_arquivo}", "rb") as file:
|
366
453
|
file_bytes = io.BytesIO(file.read())
|
367
454
|
|
@@ -378,7 +465,7 @@ async def extracao_saldo_estoque_fiscal(
|
|
378
465
|
os.remove(f"{caminho_arquivo}")
|
379
466
|
return RpaRetornoProcessoDTO(
|
380
467
|
sucesso=True,
|
381
|
-
retorno="Relatório
|
468
|
+
retorno="Relatório gerado com sucesso",
|
382
469
|
status=RpaHistoricoStatusEnum.Sucesso,
|
383
470
|
)
|
384
471
|
|
@@ -391,8 +478,6 @@ async def extracao_saldo_estoque_fiscal(
|
|
391
478
|
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)],
|
392
479
|
)
|
393
480
|
|
394
|
-
print("")
|
395
|
-
|
396
481
|
except Exception as ex:
|
397
482
|
retorno = f"Erro Processo Saldo Estoque Fiscal: {str(ex)}"
|
398
483
|
logger.error(retorno)
|
@@ -403,3 +488,4 @@ async def extracao_saldo_estoque_fiscal(
|
|
403
488
|
status=RpaHistoricoStatusEnum.Falha,
|
404
489
|
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)],
|
405
490
|
)
|
491
|
+
|
@@ -71,7 +71,7 @@ worker_automate_hub/tasks/jobs/exemplo_processo.py,sha256=nV0iLoip2FH2-FhLmhX3nP
|
|
71
71
|
worker_automate_hub/tasks/jobs/extracao_fechamento_contabil.py,sha256=6Kr5DKjKLqtFvGzyiXtt7xrQsuU898l8pQXDq9C6AX8,19567
|
72
72
|
worker_automate_hub/tasks/jobs/extracao_fechamento_emsys.py,sha256=-T2nZUDiFrUGm_KLxJd_4qcrageDxVpWW3KAAniLFC4,21448
|
73
73
|
worker_automate_hub/tasks/jobs/extracao_saldo_estoque.py,sha256=nFAv5Bvwwo2Mhy69q5BqR-XsKtg4KIqAunrUmGeW1S0,9173
|
74
|
-
worker_automate_hub/tasks/jobs/extracao_saldo_estoque_fiscal.py,sha256=
|
74
|
+
worker_automate_hub/tasks/jobs/extracao_saldo_estoque_fiscal.py,sha256=d4ckXWJ2sZmE8femwVsGpy6YRIqcleEUOyhLDpjoidM,20010
|
75
75
|
worker_automate_hub/tasks/jobs/fechar_conexao_rdp.py,sha256=UWAKCS2dbfgDlSQOBdjmVJXfD1MMuUrOi3weDgB0CAc,5718
|
76
76
|
worker_automate_hub/tasks/jobs/fidc_exportacao_docs_portal_b2b.py,sha256=tWUmYy3Zhi3JEt8AoqTsWpU-wbf5-OxhCrTOooh1WH4,15616
|
77
77
|
worker_automate_hub/tasks/jobs/fidc_gerar_nosso_numero.py,sha256=FAmcCqKVjedf7wIped8XRLIZ9S3oWc6fakF-r1Zm0kg,12637
|
@@ -101,7 +101,7 @@ worker_automate_hub/utils/updater.py,sha256=en2FCGhI8aZ-JNP3LQm64NJDc4awCNW7UhbV
|
|
101
101
|
worker_automate_hub/utils/util.py,sha256=V2WtWoETdTrAtGA8UgeqAAVphUj9KkGSZFzYsHJFATA,210055
|
102
102
|
worker_automate_hub/utils/utils_nfe_entrada.py,sha256=TOXKSHOPxy8N3-ROpTGjNIHstX0i2b8qekcj1tRvjG8,38174
|
103
103
|
worker_automate_hub/worker.py,sha256=uhZ3f-iaQ1i8cANbljp50vkYl-Xm0_sHtjwwF_2y72o,7191
|
104
|
-
worker_automate_hub-0.5.
|
105
|
-
worker_automate_hub-0.5.
|
106
|
-
worker_automate_hub-0.5.
|
107
|
-
worker_automate_hub-0.5.
|
104
|
+
worker_automate_hub-0.5.761.dist-info/entry_points.txt,sha256=sddyhjx57I08RY8X7UxcTpdoOsWULAWNKN9Xr6pp_Kw,54
|
105
|
+
worker_automate_hub-0.5.761.dist-info/METADATA,sha256=QkyzB7A1SY7-XUnJpdV0SyGi78QauZQ6N1-rjyb2T_U,3049
|
106
|
+
worker_automate_hub-0.5.761.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
107
|
+
worker_automate_hub-0.5.761.dist-info/RECORD,,
|
File without changes
|
{worker_automate_hub-0.5.759.dist-info → worker_automate_hub-0.5.761.dist-info}/entry_points.txt
RENAMED
File without changes
|