worker-automate-hub 0.5.758__py3-none-any.whl → 0.5.759__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.
@@ -49,154 +49,142 @@ async def extracao_saldo_estoque(task: RpaProcessoEntradaDTO):
49
49
  periodo_format = periodo.replace("/", "")
50
50
  filial = task.configEntrada["filialEmpresaOrigem"]
51
51
  historico_id = task.historico_id
52
+
53
+ console.print("Finalizando processos antigos do EMSys...", style="bold yellow")
52
54
  await kill_all_emsys()
53
55
 
56
+ console.print("Iniciando EMSys...", style="bold green")
54
57
  app = Application(backend="win32").start("C:\\Rezende\\EMSys3\\EMSys3_35.exe")
55
58
  warnings.filterwarnings(
56
59
  "ignore",
57
60
  category=UserWarning,
58
61
  message="32-bit application should be automated using 32-bit Python",
59
62
  )
60
- console.print("\nEMSys iniciando...", style="bold green")
63
+
64
+ console.print("Fazendo login no EMSys...", style="bold cyan")
61
65
  return_login = await login_emsys(
62
66
  config.conConfiguracao, app, task, filial_origem=filial
63
67
  )
64
68
 
65
- if return_login.sucesso == True:
69
+ if return_login.sucesso:
70
+ console.print("Login realizado com sucesso", style="bold green")
66
71
  type_text_into_field(
67
72
  "Rel. Saldo Estoque ", app["TFrmMenuPrincipal"]["Edit"], True, "50"
68
73
  )
69
74
  pyautogui.press("enter")
70
75
  await worker_sleep(2)
71
76
  pyautogui.press("enter")
72
-
73
77
  else:
74
78
  logger.info(f"\nError Message: {return_login.retorno}")
75
- console.print(f"\nError Message: {return_login.retorno}", style="bold red")
79
+ console.print(f"Erro no login: {return_login.retorno}", style="bold red")
76
80
  return return_login
77
81
 
78
82
  await worker_sleep(2)
79
83
 
80
- ##### Janela Relatório Saldos do Estoque #####
81
- # Marcar check box data
84
+ console.print("Abrindo janela Relatório de Saldo de Estoque...", style="bold cyan")
82
85
  app = Application().connect(class_name="TFrmRelSaldoEstoque", timeout=60)
83
86
  main_window = app["TFrmRelSaldoEstoque"]
84
87
  main_window.set_focus()
85
88
 
86
- # Captura o campo de data
87
- data_chk = main_window.child_window(
88
- class_name="TCheckBox", found_index=3
89
- ).click_input()
89
+ console.print("Marcando campo de data...", style="bold cyan")
90
+ main_window.child_window(class_name="TCheckBox", found_index=3).click_input()
90
91
 
91
92
  await worker_sleep(2)
92
- # Insere a data
93
- data_input = main_window.child_window(class_name="TDBIEditDate", found_index=0)
94
93
 
94
+ console.print(f"Inserindo período: {periodo}", style="bold cyan")
95
+ data_input = main_window.child_window(class_name="TDBIEditDate", found_index=0)
95
96
  data_input.set_edit_text(periodo)
96
97
 
97
- # Clicar em gerar relatório
98
- btn_gerar = main_window.child_window(
99
- class_name="TBitBtn", found_index=0
100
- ).click_input()
98
+ console.print("Gerando relatório...", style="bold cyan")
99
+ main_window.child_window(class_name="TBitBtn", found_index=0).click_input()
101
100
 
102
- # Aguarda até 60 segundos para a janela aparecer
103
101
  timings.wait_until_passes(
104
102
  timeout=1800,
105
103
  retry_interval=1,
106
104
  func=lambda: Application().connect(class_name="TFrmPreviewRelatorio"),
107
105
  )
106
+ await worker_sleep(2)
108
107
 
109
- await worker_sleep(10)
110
-
111
- # Conecta à janela Preview Relatorio
108
+ console.print("Abrindo Preview Relatório...", style="bold cyan")
112
109
  app = Application().connect(class_name="TFrmPreviewRelatorio")
113
110
  main_window = app["TFrmPreviewRelatorio"]
114
111
  main_window.set_focus()
115
112
 
116
- # Clicar em salvar
117
- caminho = r"assets\\extracao_relatorios\\btn_salvar.png"
118
- # Verifica se o arquivo existe
119
- if os.path.isfile(caminho):
120
- print("A imagem existe:", caminho)
121
-
122
- # Procura a imagem na tela
123
- pos = pyautogui.locateCenterOnScreen(
124
- caminho, confidence=0.9
125
- ) # ajuste o confidence se necessário
126
- if pos:
127
- pyautogui.click(pos) # clica no centro da imagem
128
- print("Clique realizado na imagem.")
113
+ max_tentativas = 5
114
+ tentativa = 1
115
+ sucesso = False
116
+
117
+ while tentativa <= max_tentativas and not sucesso:
118
+ console.print(f"Tentativa {tentativa} de {max_tentativas}", style="bold cyan")
119
+
120
+ console.print("Procurando botão de salvar (imagem)...", style="bold cyan")
121
+ caminho = r'assets\\extracao_relatorios\\btn_salvar.png'
122
+ if os.path.isfile(caminho):
123
+ pos = pyautogui.locateCenterOnScreen(caminho, confidence=0.9)
124
+ if pos:
125
+ pyautogui.click(pos)
126
+ console.print("Clique realizado no botão salvar", style="bold green")
127
+ else:
128
+ console.print("Imagem encontrada mas não está visível na tela", style="bold yellow")
129
129
  else:
130
- print("Imagem encontrada no disco, mas não está visível na tela.")
131
- else:
132
- print("A imagem NÃO existe:", caminho)
130
+ console.print("Imagem do botão salvar NÃO existe", style="bold red")
133
131
 
134
- await worker_sleep(2)
132
+ await worker_sleep(8)
135
133
 
136
- # Conecta na janela Configuração para Salvar Arquivo
137
- app = Application().connect(class_name="TFrmRelatorioFormato")
138
- main_window = app["TFrmRelatorioFormato"]
139
- main_window.set_focus()
140
- # Acessa o ComboBox pelo identificador conhecido
141
- combo = main_window.ComboBox
142
-
143
- # Garante que existe "Excel" na lista
144
- itens = combo.texts()
145
- print("Itens do ComboBox:", itens)
146
-
147
- # Seleciona o Excel correto (o segundo da lista, índice 8)
148
- combo.select(8)
134
+ console.print("Selecionando formato Excel...", style="bold cyan")
135
+ app = Application().connect(class_name="TFrmRelatorioFormato")
136
+ main_window = app["TFrmRelatorioFormato"]
137
+ combo = main_window.ComboBox
138
+ console.print(f"Itens do ComboBox: {combo.texts()}", style="bold yellow")
139
+ combo.select(8)
149
140
 
150
- await worker_sleep(2)
151
-
152
- # Clicar em Salvar
153
- main_window.child_window(class_name="TBitBtn", found_index=1).click_input()
141
+ await worker_sleep(5)
154
142
 
155
- await worker_sleep(5)
143
+ console.print("Confirmando salvar...", style="bold cyan")
144
+ main_window.child_window(class_name="TBitBtn", found_index=1).click_input()
156
145
 
157
- # Conecta na janela "Salvar para arquivo"
158
- app = Application().connect(title_re="Salvar para arquivo", timeout=30)
159
- main_window = app.window(title_re="Salvar para arquivo")
146
+ await worker_sleep(5)
160
147
 
161
- # Campo Nome (Edit) - use set_edit_text para evitar problemas de escape
162
- campo_nome = main_window.child_window(
163
- class_name="Edit", control_id=1148
164
- ).wrapper_object()
165
- caminho_arquivo = f"C:\\Users\\automatehub\\Downloads\\saldo_estoque_{periodo_format}_{filial}.xlsx"
166
- campo_nome.set_focus()
167
- campo_nome.set_edit_text(caminho_arquivo)
148
+ console.print("Abrindo janela de salvar arquivo...", style="bold cyan")
149
+ app = Application().connect(title_re="Salvar para arquivo", timeout=30)
150
+ main_window = app.window(title_re="Salvar para arquivo")
168
151
 
169
- print("✅ Texto inserido no campo Nome")
152
+ caminho_arquivo = rf"C:\Users\automatehub\Downloads\saldo_estoque_{periodo_format}_{filial}.xlsx"
153
+ campo_nome = main_window.child_window(class_name="Edit", control_id=1148).wrapper_object()
154
+ campo_nome.set_edit_text(caminho_arquivo)
155
+ console.print(f"Arquivo configurado para: {caminho_arquivo}", style="bold green")
170
156
 
171
- await worker_sleep(2)
172
-
173
- # Clicar em ok para salvar
174
- main_window.child_window(class_name="Button", found_index=0).click_input()
175
-
176
- await worker_sleep(20)
177
-
178
- # caminho_img = r"assets\\extracao_relatorios\\janela_printing.png"
179
-
180
- # Aguarda até a janela com título "Printing" (ou "Salvando...") fechar
181
-
182
- try:
183
- app = Application().connect(title_re="Printing") # conecta se existir
184
- janela = app.window(title_re="Printing")
185
-
186
- print("⏳ Aguardando a janela 'Printing' sumir...")
187
- janela.wait_not("visible", timeout=60) # espera até 60 segundos
188
- print(" Janela 'Printing' fechada.")
189
-
190
- except findwindows.ElementNotFoundError:
191
- print("⚠️ Janela 'Printing' não estava aberta.")
157
+ await worker_sleep(2)
158
+
159
+ main_window.child_window(class_name="Button", found_index=0).click_input()
160
+
161
+ await worker_sleep(4)
162
+
163
+ console.print("Aguardando finalização do processo de impressão/salvamento...", style="bold cyan")
164
+ try:
165
+ app = Application().connect(title_re="Printing")
166
+ janela = app.window(title_re="Printing")
167
+ janela.wait_not("visible", timeout=60)
168
+ console.print("Janela 'Printing' fechada.", style="bold green")
169
+ except findwindows.ElementNotFoundError:
170
+ console.print("Janela 'Printing' não apareceu.", style="bold yellow")
171
+
172
+ # Verifica se o arquivo foi salvo
173
+ if os.path.exists(caminho_arquivo):
174
+ console.print(f"Arquivo encontrado: {caminho_arquivo}", style="bold green")
175
+ with open(caminho_arquivo, "rb") as file:
176
+ file_bytes = io.BytesIO(file.read())
177
+ sucesso = True
178
+ else:
179
+ console.print("Arquivo não encontrado, tentando novamente...", style="bold red")
180
+ tentativa += 1
181
+ await worker_sleep(3)
192
182
 
193
- nome_com_extensao = f"saldo_estoque_{periodo_format}_{filial}.xlsx"
194
- # o arquivo
195
- print(caminho_arquivo)
196
- with open(f"{caminho_arquivo}", "rb") as file:
197
- file_bytes = io.BytesIO(file.read())
183
+ if not sucesso:
184
+ console.print("Falha após 5 tentativas. Arquivo não foi gerado.", style="bold red")
198
185
 
199
- console.print("Enviar Excel para o BOF")
186
+ nome_com_extensao = f'saldo_estoque_{periodo_format}_{filial}.xlsx'
187
+ console.print("Enviando arquivo XLS para o BOF...", style="bold cyan")
200
188
  try:
201
189
  await send_file(
202
190
  historico_id,
@@ -205,11 +193,11 @@ async def extracao_saldo_estoque(task: RpaProcessoEntradaDTO):
205
193
  file_bytes,
206
194
  file_extension="xlsx",
207
195
  )
208
- console.print("Removendo arquivo XLS da pasta downloads")
209
- os.remove(f"{caminho_arquivo}")
196
+ console.print("Removendo arquivo da pasta downloads", style="bold yellow")
197
+ os.remove(caminho_arquivo)
210
198
  return RpaRetornoProcessoDTO(
211
199
  sucesso=True,
212
- retorno="Relatório gerado com sucesso",
200
+ retorno="Relatório enviado com sucesso!",
213
201
  status=RpaHistoricoStatusEnum.Sucesso,
214
202
  )
215
203
 
@@ -221,6 +209,9 @@ async def extracao_saldo_estoque(task: RpaProcessoEntradaDTO):
221
209
  status=RpaHistoricoStatusEnum.Falha,
222
210
  tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)],
223
211
  )
212
+
213
+ console.print("Processo concluído com sucesso!", style="bold green")
214
+
224
215
  except Exception as ex:
225
216
  retorno = f"Erro Processo Fechamento Balancete: {str(ex)}"
226
217
  logger.error(retorno)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: worker-automate-hub
3
- Version: 0.5.758
3
+ Version: 0.5.759
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
@@ -70,7 +70,7 @@ worker_automate_hub/tasks/jobs/entrada_de_notas_9000.py,sha256=0mOmS28tQKF5m7vMz
70
70
  worker_automate_hub/tasks/jobs/exemplo_processo.py,sha256=nV0iLoip2FH2-FhLmhX3nPqsfl_MPufZ3E5Q5krJvdc,3544
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
- worker_automate_hub/tasks/jobs/extracao_saldo_estoque.py,sha256=LocziY74XAKdFyyPJPRt9_zs3J59-kysggjmpASqdxU,8384
73
+ worker_automate_hub/tasks/jobs/extracao_saldo_estoque.py,sha256=nFAv5Bvwwo2Mhy69q5BqR-XsKtg4KIqAunrUmGeW1S0,9173
74
74
  worker_automate_hub/tasks/jobs/extracao_saldo_estoque_fiscal.py,sha256=OJQAkE6mqm7lNodleYRWwJq3syxrTqcPGt27_u6NPPs,14950
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
@@ -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.758.dist-info/entry_points.txt,sha256=sddyhjx57I08RY8X7UxcTpdoOsWULAWNKN9Xr6pp_Kw,54
105
- worker_automate_hub-0.5.758.dist-info/METADATA,sha256=1xkBHjCMiZUphzKk7_pcpyhiQxsr6bHAO9-4ihxnt8M,3049
106
- worker_automate_hub-0.5.758.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
107
- worker_automate_hub-0.5.758.dist-info/RECORD,,
104
+ worker_automate_hub-0.5.759.dist-info/entry_points.txt,sha256=sddyhjx57I08RY8X7UxcTpdoOsWULAWNKN9Xr6pp_Kw,54
105
+ worker_automate_hub-0.5.759.dist-info/METADATA,sha256=tMWbnY_CoFvxTSMsKPGVRbkAsl_HM5XxtbKuLCk0Ajw,3049
106
+ worker_automate_hub-0.5.759.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
107
+ worker_automate_hub-0.5.759.dist-info/RECORD,,