worker-automate-hub 0.5.761__py3-none-any.whl → 0.5.762__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.
@@ -117,10 +117,11 @@ async def extracao_saldo_estoque(task: RpaProcessoEntradaDTO):
117
117
  while tentativa <= max_tentativas and not sucesso:
118
118
  console.print(f"Tentativa {tentativa} de {max_tentativas}", style="bold cyan")
119
119
 
120
+ # 1) Abrir o picker de formatos pelo botão (imagem)
120
121
  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)
122
+ caminho_img = r'assets\\extracao_relatorios\\btn_salvar.png'
123
+ if os.path.isfile(caminho_img):
124
+ pos = pyautogui.locateCenterOnScreen(caminho_img, confidence=0.9)
124
125
  if pos:
125
126
  pyautogui.click(pos)
126
127
  console.print("Clique realizado no botão salvar", style="bold green")
@@ -131,49 +132,139 @@ async def extracao_saldo_estoque(task: RpaProcessoEntradaDTO):
131
132
 
132
133
  await worker_sleep(8)
133
134
 
135
+ # 2) Selecionar formato "Excel" na janela TFrmRelatorioFormato
134
136
  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)
140
-
141
- await worker_sleep(5)
142
-
143
- console.print("Confirmando salvar...", style="bold cyan")
144
- main_window.child_window(class_name="TBitBtn", found_index=1).click_input()
137
+ try:
138
+ app_fmt = Application().connect(class_name="TFrmRelatorioFormato", timeout=10)
139
+ win_fmt = app_fmt["TFrmRelatorioFormato"]
140
+ win_fmt.wait("visible", timeout=10)
141
+
142
+ combo = win_fmt.ComboBox
143
+ textos = combo.texts()
144
+ console.print(f"Itens do ComboBox: {textos}", style="bold yellow")
145
+
146
+ # Se souber o índice correto, mantenha. Caso contrário, tente por texto contendo 'Excel'
147
+ try:
148
+ combo.select(8)
149
+ except Exception:
150
+ alvo = None
151
+ for i, t in enumerate(textos):
152
+ if "EXCEL" in str(t).upper() or "XLSX" in str(t).upper():
153
+ alvo = i
154
+ break
155
+ if alvo is not None:
156
+ combo.select(alvo)
157
+ else:
158
+ console.print("Não foi possível localizar a opção de Excel no ComboBox.", style="bold red")
159
+ tentativa += 1
160
+ await worker_sleep(2)
161
+ continue
162
+
163
+ await worker_sleep(1)
164
+
165
+ # Botão OK/Confirmar na janela de formato
166
+ # Em muitos Delphi VCL, TBitBtn com found_index=1 costuma ser OK.
167
+ win_fmt.child_window(class_name="TBitBtn", found_index=1).wait("enabled", timeout=5)
168
+ win_fmt.child_window(class_name="TBitBtn", found_index=1).click_input()
169
+ except Exception as e:
170
+ console.print(f"Falha ao selecionar formato: {e}", style="bold red")
171
+ tentativa += 1
172
+ await worker_sleep(3)
173
+ continue
145
174
 
146
175
  await worker_sleep(5)
147
176
 
177
+ # 3) Janela "Salvar para arquivo"
148
178
  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")
179
+ try:
180
+ app_save = Application().connect(title_re="Salvar para arquivo", timeout=30)
181
+ win_save = app_save.window(title_re="Salvar para arquivo")
182
+ win_save.wait("visible", timeout=30)
183
+ except Exception as e:
184
+ console.print(f"Não achou a janela 'Salvar para arquivo': {e}", style="bold red")
185
+ tentativa += 1
186
+ await worker_sleep(3)
187
+ continue
151
188
 
189
+ # Caminho do arquivo a salvar
152
190
  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")
191
+
192
+ # Se já existe, removemos para evitar pop-up de confirmação
193
+ if os.path.exists(caminho_arquivo):
194
+ try:
195
+ os.remove(caminho_arquivo)
196
+ console.print("Arquivo existente removido para evitar prompt de sobrescrita.", style="bold yellow")
197
+ except Exception as e:
198
+ console.print(f"Não foi possível remover o arquivo existente: {e}", style="bold red")
199
+
200
+ try:
201
+ # Campo "Nome" (Edit, control_id=1148)
202
+ campo_nome = win_save.child_window(class_name="Edit", control_id=1148).wrapper_object()
203
+ campo_nome.set_focus()
204
+ # limpa conteúdo
205
+ try:
206
+ campo_nome.set_edit_text("")
207
+ except Exception:
208
+ # fallback limpando com Ctrl+A + Delete
209
+ campo_nome.type_keys("^a{DELETE}", pause=0.02)
210
+
211
+ # digita caminho
212
+ campo_nome.type_keys(caminho_arquivo, with_spaces=True, pause=0.01)
213
+ console.print(f"Arquivo configurado para: {caminho_arquivo}", style="bold green")
214
+
215
+ await worker_sleep(1)
216
+
217
+ # Botão Salvar (primeiro Button)
218
+ btn_salvar = win_save.child_window(class_name="Button", found_index=0)
219
+ btn_salvar.wait("enabled", timeout=10)
220
+ btn_salvar.click_input()
221
+ except Exception as e:
222
+ console.print(f"Erro ao confirmar salvar: {e}", style="bold red")
223
+ tentativa += 1
224
+ await worker_sleep(3)
225
+ continue
156
226
 
157
227
  await worker_sleep(2)
158
-
159
- main_window.child_window(class_name="Button", found_index=0).click_input()
160
228
 
161
- await worker_sleep(4)
229
+ # 3.1) Tratar confirmação de sobrescrita, se aparecer
230
+ try:
231
+ # Pode vir em PT/EN dependendo do SO
232
+ # Título comum: "Confirm Save As" (EN) ou "Confirmar Salvar Como" (PT)
233
+ try:
234
+ app_conf = Application().connect(title_re="Confirm(ar)?( )?Salvar( )?Como|Confirm Save As", timeout=3)
235
+ win_conf = app_conf.window(title_re="Confirm(ar)?( )?Salvar( )?Como|Confirm Save As")
236
+ win_conf.wait("visible", timeout=3)
237
+ # Botões costumam ser "Sim"/"Yes" como class_name="Button"
238
+ # Tente o primeiro botão (Yes/Sim)
239
+ win_conf.child_window(class_name="Button", found_index=0).click_input()
240
+ console.print("Confirmação de sobrescrita respondida.", style="bold yellow")
241
+ except Exception:
242
+ pass
243
+ except Exception:
244
+ pass
245
+
246
+ await worker_sleep(2)
162
247
 
248
+ # 4) Aguardar o processamento/Printing encerrar
163
249
  console.print("Aguardando finalização do processo de impressão/salvamento...", style="bold cyan")
164
250
  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")
251
+ app_print = Application().connect(title_re="Printing", timeout=5)
252
+ win_print = app_print.window(title_re="Printing")
253
+ try:
254
+ win_print.wait_not("visible", timeout=60)
255
+ console.print("Janela 'Printing' fechada.", style="bold green")
256
+ except Exception:
257
+ console.print("Janela 'Printing' não fechou no tempo esperado. Seguindo.", style="bold yellow")
169
258
  except findwindows.ElementNotFoundError:
170
259
  console.print("Janela 'Printing' não apareceu.", style="bold yellow")
260
+ except Exception as e:
261
+ console.print(f"Erro ao aguardar 'Printing': {e}", style="bold yellow")
171
262
 
172
- # Verifica se o arquivo foi salvo
263
+ # 5) Validar arquivo salvo
173
264
  if os.path.exists(caminho_arquivo):
174
265
  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())
266
+ with open(caminho_arquivo, "rb") as f:
267
+ file_bytes = io.BytesIO(f.read())
177
268
  sucesso = True
178
269
  else:
179
270
  console.print("Arquivo não encontrado, tentando novamente...", style="bold red")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: worker-automate-hub
3
- Version: 0.5.761
3
+ Version: 0.5.762
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=nFAv5Bvwwo2Mhy69q5BqR-XsKtg4KIqAunrUmGeW1S0,9173
73
+ worker_automate_hub/tasks/jobs/extracao_saldo_estoque.py,sha256=_tmKYCKqd05xueln-nfd3yVhwpkpsflNQY1BDtyzEZQ,13726
74
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
@@ -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.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,,
104
+ worker_automate_hub-0.5.762.dist-info/entry_points.txt,sha256=sddyhjx57I08RY8X7UxcTpdoOsWULAWNKN9Xr6pp_Kw,54
105
+ worker_automate_hub-0.5.762.dist-info/METADATA,sha256=BEbaURlGZPVFULs8hLkai5d3PzlMyahZkrGyc-YfmyI,3049
106
+ worker_automate_hub-0.5.762.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
107
+ worker_automate_hub-0.5.762.dist-info/RECORD,,