worker-automate-hub 0.5.621__py3-none-any.whl → 0.5.623__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/devolucao_ctf_35.py +4305 -0
- worker_automate_hub/tasks/jobs/devolucao_prazo_a_faturar.py +487 -247
- worker_automate_hub/utils/utils_nfe_entrada.py +29 -11
- {worker_automate_hub-0.5.621.dist-info → worker_automate_hub-0.5.623.dist-info}/METADATA +1 -1
- {worker_automate_hub-0.5.621.dist-info → worker_automate_hub-0.5.623.dist-info}/RECORD +7 -6
- {worker_automate_hub-0.5.621.dist-info → worker_automate_hub-0.5.623.dist-info}/WHEEL +0 -0
- {worker_automate_hub-0.5.621.dist-info → worker_automate_hub-0.5.623.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,4305 @@
|
|
1
|
+
import getpass
|
2
|
+
import warnings
|
3
|
+
import os
|
4
|
+
import re
|
5
|
+
import io
|
6
|
+
import uuid
|
7
|
+
import asyncio
|
8
|
+
import pyautogui
|
9
|
+
import pytesseract
|
10
|
+
from datetime import datetime, timedelta
|
11
|
+
from pywinauto.application import Application
|
12
|
+
from pypdf import PdfReader
|
13
|
+
from PIL import Image, ImageEnhance
|
14
|
+
from pywinauto.keyboard import send_keys
|
15
|
+
from pywinauto.mouse import double_click
|
16
|
+
import win32clipboard
|
17
|
+
from pywinauto_recorder.player import set_combobox
|
18
|
+
from rich.console import Console
|
19
|
+
from worker_automate_hub.api.ahead_service import save_xml_to_downloads
|
20
|
+
from worker_automate_hub.api.client import (
|
21
|
+
get_config_by_name,
|
22
|
+
get_status_nf_emsys,
|
23
|
+
send_file,
|
24
|
+
)
|
25
|
+
from worker_automate_hub.models.dto.rpa_historico_request_dto import (
|
26
|
+
RpaHistoricoStatusEnum,
|
27
|
+
RpaRetornoProcessoDTO,
|
28
|
+
RpaTagDTO,
|
29
|
+
RpaTagEnum,
|
30
|
+
)
|
31
|
+
from worker_automate_hub.models.dto.rpa_processo_entrada_dto import (
|
32
|
+
RpaProcessoEntradaDTO,
|
33
|
+
)
|
34
|
+
from worker_automate_hub.utils.logger import logger
|
35
|
+
from worker_automate_hub.utils.util import (
|
36
|
+
e_ultimo_dia_util,
|
37
|
+
delete_xml,
|
38
|
+
find_nop_divergence,
|
39
|
+
ocr_warnings,
|
40
|
+
ocr_by_class,
|
41
|
+
nf_busca_nf_saida,
|
42
|
+
nf_busca_nf_saida_mais_recente,
|
43
|
+
pessoas_ativa_cliente_fornecedor,
|
44
|
+
nf_devolucao_liquidar_cupom,
|
45
|
+
status_trasmissao,
|
46
|
+
find_warning_nop_divergence,
|
47
|
+
gerenciador_nf_header,
|
48
|
+
gerenciador_nf_header_retransmissao,
|
49
|
+
cadastro_pre_venda_header,
|
50
|
+
incluir_registro,
|
51
|
+
is_window_open,
|
52
|
+
is_window_open_by_class,
|
53
|
+
kill_all_emsys,
|
54
|
+
login_emsys,
|
55
|
+
ocr_title,
|
56
|
+
select_documento_type,
|
57
|
+
set_variable,
|
58
|
+
type_text_into_field,
|
59
|
+
worker_sleep,
|
60
|
+
post_partner,
|
61
|
+
get_text_display_window,
|
62
|
+
)
|
63
|
+
|
64
|
+
pyautogui.PAUSE = 0.5
|
65
|
+
pyautogui.FAILSAFE = False
|
66
|
+
console = Console()
|
67
|
+
|
68
|
+
|
69
|
+
async def devolucao_ctf_35(task: RpaProcessoEntradaDTO) -> RpaRetornoProcessoDTO:
|
70
|
+
"""
|
71
|
+
Processo que relazia entrada de notas no ERP EMSys(Linx).
|
72
|
+
|
73
|
+
"""
|
74
|
+
try:
|
75
|
+
#DEFINIR CONSTANTE DEFAULT PARA O ASSETS
|
76
|
+
ASSETS_PATH = "assets"
|
77
|
+
# Get config from BOF
|
78
|
+
config = await get_config_by_name("login_emsys")
|
79
|
+
try:
|
80
|
+
aliquota_icms = await get_config_by_name("Aliquota_ICMS")
|
81
|
+
conconfig_aliquota_icms = aliquota_icms.conConfiguracao.get("aliquotas")
|
82
|
+
except Exception as e:
|
83
|
+
return RpaRetornoProcessoDTO(
|
84
|
+
sucesso=False,
|
85
|
+
retorno=f"Não foi possivel recuperar o valor da configuração de Aliquota, erro: {e}.",
|
86
|
+
status=RpaHistoricoStatusEnum.Falha,
|
87
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
88
|
+
)
|
89
|
+
console.print(task)
|
90
|
+
|
91
|
+
# Seta config entrada na var nota para melhor entendimento
|
92
|
+
nota = task.configEntrada
|
93
|
+
|
94
|
+
#Definindo Variaveis com Escopo global
|
95
|
+
numero_cupom_fiscal = nota.get("numCupomNotaFiscal")
|
96
|
+
cod_empresa = nota.get("codigoEmpresa")
|
97
|
+
cod_cliente_correto = nota.get("codClienteCorreto")
|
98
|
+
cod_cliente_incorreto = nota.get("codClienteIncorreto")
|
99
|
+
nota_separada = False
|
100
|
+
steps = ""
|
101
|
+
numero_nota_fiscal = ""
|
102
|
+
valor_nota_fiscal = ""
|
103
|
+
item_arla = False
|
104
|
+
cidade_cliente = ""
|
105
|
+
data_hoje = datetime.today().strftime('%d/%m/%Y')
|
106
|
+
multiplicador_timeout = int(float(task.sistemas[0].timeout))
|
107
|
+
set_variable("timeout_multiplicador", multiplicador_timeout)
|
108
|
+
|
109
|
+
#VERIFICANDO ENTRADA
|
110
|
+
historico_id = task.historico_id
|
111
|
+
if historico_id:
|
112
|
+
console.print("Historico ID recuperado com sucesso...\n")
|
113
|
+
else:
|
114
|
+
console.print("Não foi possivel recuperar o histórico do ID, não sendo possivel enviar os arquivo gerados como retorno...\n")
|
115
|
+
return RpaRetornoProcessoDTO(
|
116
|
+
sucesso=False,
|
117
|
+
retorno="Não foi possivel recuperar o histórico do ID, não sendo possivel enviar os arquivo gerados como retorno",
|
118
|
+
status=RpaHistoricoStatusEnum.Falha,
|
119
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
120
|
+
)
|
121
|
+
|
122
|
+
# Fecha a instancia do emsys - caso esteja aberta
|
123
|
+
await kill_all_emsys()
|
124
|
+
|
125
|
+
#Validar se é o ultimo dia
|
126
|
+
# if await e_ultimo_dia_util():
|
127
|
+
# return RpaRetornoProcessoDTO(
|
128
|
+
# sucesso=False,
|
129
|
+
# retorno="Não será possivel processar devido a regra - 'Não deve ser processado nenhuma devolução no último dia útil do mês vigente'",
|
130
|
+
# status=RpaHistoricoStatusEnum.Falha,
|
131
|
+
# tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
132
|
+
# )
|
133
|
+
|
134
|
+
#Realizando o login
|
135
|
+
app = Application(backend="win32").start("C:\\Rezende\\EMSys3\\EMSys3.exe")
|
136
|
+
warnings.filterwarnings("ignore",category=UserWarning,message="32-bit application should be automated using 32-bit Python")
|
137
|
+
console.print("\nEMSys iniciando...", style="bold green")
|
138
|
+
return_login = await login_emsys(config.conConfiguracao, app, task)
|
139
|
+
if return_login.sucesso == True:
|
140
|
+
console.print("Processo de login realizado com sucesso... \n")
|
141
|
+
else:
|
142
|
+
logger.info(f"\nError Message: {return_login.retorno}")
|
143
|
+
console.print(f"\nError Message: {return_login.retorno}", style="bold red")
|
144
|
+
return return_login
|
145
|
+
|
146
|
+
|
147
|
+
#HABILITAR CLIENTE E FORNECEDOR PARA COD INCORRETO
|
148
|
+
console.print("Seguindo com o processo de habilitar Cliente e Fornecedor para andamento do processo.. \n")
|
149
|
+
type_text_into_field("Pessoas", app["TFrmMenuPrincipal"]["Edit"], True, "50")
|
150
|
+
pyautogui.press("enter")
|
151
|
+
await worker_sleep(2)
|
152
|
+
send_keys("{DOWN " + ("1") + "}")
|
153
|
+
await worker_sleep(1)
|
154
|
+
pyautogui.press("enter")
|
155
|
+
|
156
|
+
await worker_sleep(2)
|
157
|
+
console.print("Verificando se o cliente esta ativo como Cliente e como Fornecedor... \n")
|
158
|
+
ativar_cliente_fornecedor = await pessoas_ativa_cliente_fornecedor(cod_cliente_incorreto, True, True)
|
159
|
+
if ativar_cliente_fornecedor.sucesso == True:
|
160
|
+
steps += 'ETAPA 01 - CLIENTE E FORNECEDOR - ATIVADOS COM SUCESSO'
|
161
|
+
console.log(ativar_cliente_fornecedor.retorno, style="bold green")
|
162
|
+
else:
|
163
|
+
return RpaRetornoProcessoDTO(
|
164
|
+
sucesso=False,
|
165
|
+
retorno=ativar_cliente_fornecedor.retorno,
|
166
|
+
status=RpaHistoricoStatusEnum.Falha,
|
167
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
168
|
+
)
|
169
|
+
|
170
|
+
#REALIZAR PROCESSO DE NOTA FISCAL DE SAIDA
|
171
|
+
type_text_into_field("Nota Fiscal de Saida", app["TFrmMenuPrincipal"]["Edit"], True, "50")
|
172
|
+
pyautogui.press("enter")
|
173
|
+
await worker_sleep(2)
|
174
|
+
pyautogui.press('down')
|
175
|
+
pyautogui.press("enter")
|
176
|
+
console.print(f"\nPesquisa: 'Nota Fiscal de Saída' realizada com sucesso",style="bold green")
|
177
|
+
await worker_sleep(6)
|
178
|
+
|
179
|
+
busca_nf_saida = await nf_busca_nf_saida(numero_cupom_fiscal)
|
180
|
+
if busca_nf_saida.sucesso == True:
|
181
|
+
console.log(busca_nf_saida.retorno, style="bold green")
|
182
|
+
else:
|
183
|
+
retorno = f"{busca_nf_saida.retorno} \nEtapas Executadas:\n{steps}"
|
184
|
+
return RpaRetornoProcessoDTO(
|
185
|
+
sucesso=False,
|
186
|
+
retorno=retorno,
|
187
|
+
status=RpaHistoricoStatusEnum.Falha,
|
188
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
189
|
+
)
|
190
|
+
|
191
|
+
|
192
|
+
#VERIFICANDO A EXISTENCIA DE WARNINGS
|
193
|
+
console.print("Verificando a existência de Warning... \n")
|
194
|
+
warning_pop_up = await is_window_open("Warning")
|
195
|
+
if warning_pop_up["IsOpened"] == True:
|
196
|
+
console.print("possui Pop-up de Warning, analisando... \n")
|
197
|
+
ocr_pop_warning = await ocr_warnings(numero_cupom_fiscal)
|
198
|
+
if ocr_pop_warning.sucesso == True:
|
199
|
+
retorno = f"POP UP Warning não mapeado para seguimento do processo, mensagem: {ocr_pop_warning.retorno} \nEtapas Executadas:\n{steps}"
|
200
|
+
return RpaRetornoProcessoDTO(
|
201
|
+
sucesso=False,
|
202
|
+
retorno=retorno,
|
203
|
+
status=RpaHistoricoStatusEnum.Falha,
|
204
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
205
|
+
)
|
206
|
+
else:
|
207
|
+
retorno = f"{ocr_pop_warning.retorno} \nEtapas Executadas:\n{steps}"
|
208
|
+
return RpaRetornoProcessoDTO(
|
209
|
+
sucesso=False,
|
210
|
+
retorno=retorno,
|
211
|
+
status=RpaHistoricoStatusEnum.Falha,
|
212
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
213
|
+
)
|
214
|
+
else:
|
215
|
+
console.print("Não possui pop de Warning...\n")
|
216
|
+
|
217
|
+
|
218
|
+
busca_nf_saida_recente = await nf_busca_nf_saida_mais_recente()
|
219
|
+
if busca_nf_saida_recente.sucesso == True:
|
220
|
+
console.log(busca_nf_saida.retorno, style="bold green")
|
221
|
+
else:
|
222
|
+
retorno = f"{busca_nf_saida_recente.retorno} \nEtapas Executadas:\n{steps}"
|
223
|
+
return RpaRetornoProcessoDTO(
|
224
|
+
sucesso=False,
|
225
|
+
retorno=retorno,
|
226
|
+
status=RpaHistoricoStatusEnum.Falha,
|
227
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
228
|
+
)
|
229
|
+
|
230
|
+
|
231
|
+
#VERIFICANDO SE O BOTÃO IR PARA A NOTA FATURA
|
232
|
+
console.print("Verificando o status do Botão [Ir para Nota Fatura]...\n")
|
233
|
+
try:
|
234
|
+
btn_ir_para_nota = pyautogui.locateOnScreen(ASSETS_PATH +
|
235
|
+
"\\notas_saida\\ir_para_nota_a_fatura_esmaecido.PNG", confidence=0.8)
|
236
|
+
if btn_ir_para_nota:
|
237
|
+
console.print("Botão 'Ir para nota de faturar' inativo, seguindo com o processo...\n")
|
238
|
+
app = Application().connect(class_name="TFrmNotaFiscalSaida", timeout=60)
|
239
|
+
main_window = app["TFrmNotaFiscalSaida"]
|
240
|
+
main_window.set_focus()
|
241
|
+
main_window.close()
|
242
|
+
else:
|
243
|
+
retorno = f"Botão [Ir para nota de faturar] está ativo, impossibilitando realizar a devolução \nEtapas Executadas:\n{steps}"
|
244
|
+
return RpaRetornoProcessoDTO(
|
245
|
+
sucesso=False,
|
246
|
+
retorno=retorno,
|
247
|
+
status=RpaHistoricoStatusEnum.Falha,
|
248
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
249
|
+
)
|
250
|
+
except Exception as e:
|
251
|
+
return RpaRetornoProcessoDTO(
|
252
|
+
sucesso=False,
|
253
|
+
retorno=f"Não foi possivel verificar o botão [Ir para nota de faturar], erro: {e}",
|
254
|
+
status=RpaHistoricoStatusEnum.Falha,
|
255
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
256
|
+
)
|
257
|
+
|
258
|
+
|
259
|
+
#ETAPA 14 A 18
|
260
|
+
#STEP 2 - EMISSAO DA NOTA
|
261
|
+
type_text_into_field("Nota Fiscal de Entrada", app["TFrmMenuPrincipal"]["Edit"], True, "50")
|
262
|
+
pyautogui.press("enter")
|
263
|
+
await worker_sleep(2)
|
264
|
+
pyautogui.press("enter")
|
265
|
+
console.print(f"\nPesquisa: 'Nota Fiscal de Entrada' realizada com sucesso",style="bold green",
|
266
|
+
)
|
267
|
+
|
268
|
+
# Procura campo documento
|
269
|
+
console.print("Navegando pela Janela de Nota Fiscal de Entrada...\n")
|
270
|
+
document_type = await select_documento_type("NFe - NOTA FISCAL ELETRONICA PROPRIA - DANFE SERIE 077")
|
271
|
+
if document_type.sucesso == True:
|
272
|
+
console.log(document_type.retorno, style="bold green")
|
273
|
+
else:
|
274
|
+
retorno = f"{document_type.retorno} \nEtapas Executadas:\n{steps}"
|
275
|
+
return RpaRetornoProcessoDTO(
|
276
|
+
sucesso=False,
|
277
|
+
retorno=retorno,
|
278
|
+
status=RpaHistoricoStatusEnum.Falha,
|
279
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
280
|
+
)
|
281
|
+
|
282
|
+
await worker_sleep(4)
|
283
|
+
|
284
|
+
app = Application().connect(class_name="TFrmNotaFiscalEntrada", timeout=60)
|
285
|
+
main_window = app["TFrmNotaFiscalEntrada"]
|
286
|
+
|
287
|
+
main_window.set_focus()
|
288
|
+
await worker_sleep(3)
|
289
|
+
|
290
|
+
console.print("Controles encontrados na janela 'Nota Fiscal de Entrada, navegando entre eles...\n")
|
291
|
+
panel_TNotebook = main_window.child_window(class_name="TNotebook", found_index=0)
|
292
|
+
panel_TPage = panel_TNotebook.child_window(class_name="TPage", found_index=0)
|
293
|
+
panel_TPageControl = panel_TPage.child_window(class_name="TPageControl", found_index=0)
|
294
|
+
panel_TTabSheet = panel_TPageControl.child_window(class_name="TTabSheet", found_index=0)
|
295
|
+
|
296
|
+
#SELECIONANDO O TIPO NOTA
|
297
|
+
console.print("SELECIONANDO O TIPO NOTA...\n")
|
298
|
+
radio_nota_devolucao = main_window.child_window(class_name="TDBIRadioButton", found_index=1)
|
299
|
+
radio_nota_devolucao.click()
|
300
|
+
await worker_sleep(1)
|
301
|
+
|
302
|
+
#INSERINDO A ENTRADA E EMISSÃO
|
303
|
+
console.print("INSERINDO A ENTRADA E EMISSÃO ...\n")
|
304
|
+
field_entrada = main_window.child_window(class_name="TDBIEditDate", found_index=1)
|
305
|
+
field_emissao = main_window.child_window(class_name="TDBIEditDate", found_index=2)
|
306
|
+
field_entrada.set_edit_text(data_hoje)
|
307
|
+
await worker_sleep(1)
|
308
|
+
field_emissao.set_edit_text(data_hoje)
|
309
|
+
await worker_sleep(1)
|
310
|
+
|
311
|
+
#INSERINDO CODIGO DO FORNECEDOR
|
312
|
+
console.print("INSERINDO CODIGO DO FORNECEDOR ...\n")
|
313
|
+
field_fornecedor = main_window.child_window(class_name="TDBIEditCode", found_index=0)
|
314
|
+
field_fornecedor.click()
|
315
|
+
|
316
|
+
if cod_cliente_incorreto != "140552":
|
317
|
+
field_fornecedor.set_edit_text(cod_cliente_incorreto)
|
318
|
+
else:
|
319
|
+
field_fornecedor.set_edit_text(cod_empresa)
|
320
|
+
field_fornecedor.click()
|
321
|
+
pyautogui.press("tab")
|
322
|
+
await worker_sleep(2)
|
323
|
+
|
324
|
+
|
325
|
+
itens = nota.get('itens', [])
|
326
|
+
itens_arla = [item for item in itens if item['descricao'].lower() == 'arla']
|
327
|
+
|
328
|
+
#SELECIONAO A NOP
|
329
|
+
console.print("SELECIONAO A NOP...\n")
|
330
|
+
select_box_nop_select = main_window.child_window(class_name="TDBIComboBox", found_index=0)
|
331
|
+
select_box_nop_select.click()
|
332
|
+
|
333
|
+
itens_to_select = select_box_nop_select.texts()
|
334
|
+
nop_to_be_select = ''
|
335
|
+
|
336
|
+
if len(itens_arla) == len(itens):
|
337
|
+
for item in itens_to_select:
|
338
|
+
if ('1202' in item and ('s/ est' in item.lower() or 's/est' in item.lower()) and ('c/ fin' in item.lower() or 'c/fin' in item.lower())):
|
339
|
+
nop_to_be_select = item
|
340
|
+
break
|
341
|
+
elif '2202' in item and (('s/ est' in item.lower() or 's/est' in item.lower()) and ('c/ fin' in item.lower() or 'c/fin' in item.lower())):
|
342
|
+
nop_to_be_select = item
|
343
|
+
break
|
344
|
+
else:
|
345
|
+
for item in itens_to_select:
|
346
|
+
if '1662' in item and (('c/fi' in item.lower() or 'c /fi' in item.lower())):
|
347
|
+
nop_to_be_select = item
|
348
|
+
break
|
349
|
+
|
350
|
+
if nop_to_be_select != '':
|
351
|
+
set_combobox("||List", nop_to_be_select)
|
352
|
+
else:
|
353
|
+
retorno = f"Não foi possivel encontrar a nop \nEtapas Executadas:\n{steps}"
|
354
|
+
return RpaRetornoProcessoDTO(
|
355
|
+
sucesso=False,
|
356
|
+
retorno=retorno,
|
357
|
+
status=RpaHistoricoStatusEnum.Falha,
|
358
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
359
|
+
)
|
360
|
+
|
361
|
+
|
362
|
+
try:
|
363
|
+
pesquisar_icon = pyautogui.locateOnScreen(ASSETS_PATH + "\\emsys\\selecionar_venda.png", confidence=0.8)
|
364
|
+
pyautogui.click(pesquisar_icon)
|
365
|
+
await worker_sleep(5)
|
366
|
+
except Exception as e:
|
367
|
+
retorno = f"Não foi possivel clicar no botão Selecionar Venda, erro: {e} \nEtapas Executadas:\n{steps}"
|
368
|
+
return RpaRetornoProcessoDTO(
|
369
|
+
sucesso=False,
|
370
|
+
retorno=retorno,
|
371
|
+
status=RpaHistoricoStatusEnum.Falha,
|
372
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
373
|
+
)
|
374
|
+
|
375
|
+
await worker_sleep(2)
|
376
|
+
pesquisar_venda_devolucao = await is_window_open_by_class("TFrmPesquisarVendaDevolucao", "TFrmPesquisarVendaDevolucao")
|
377
|
+
if pesquisar_venda_devolucao["IsOpened"] == True:
|
378
|
+
app = Application().connect(class_name="TFrmPesquisarVendaDevolucao", timeout=60)
|
379
|
+
main_window = app["TFrmPesquisarVendaDevolucao"]
|
380
|
+
main_window.set_focus()
|
381
|
+
|
382
|
+
panel_filtro = main_window.child_window(class_name="TGroupBox", found_index=0)
|
383
|
+
#INSERINDO O NUMERO VENDA
|
384
|
+
console.print("INSERINDO O NUMERO VENDA...\n")
|
385
|
+
field_num_venda = panel_filtro.child_window(class_name="TDBIEditString", found_index=0)
|
386
|
+
field_num_venda.set_edit_text(numero_cupom_fiscal)
|
387
|
+
await worker_sleep(1)
|
388
|
+
|
389
|
+
#INSERINDO O CODIGO DO CLIENTE
|
390
|
+
console.print("INSERINDO O CODIGO DO CLIENTE...\n")
|
391
|
+
field_cliente = panel_filtro.child_window(class_name="TDBIEditCode", found_index=0)
|
392
|
+
field_cliente.set_edit_text(cod_cliente_incorreto)
|
393
|
+
await worker_sleep(1)
|
394
|
+
field_cliente.click()
|
395
|
+
await worker_sleep(1)
|
396
|
+
pyautogui.press('tab')
|
397
|
+
await worker_sleep(3)
|
398
|
+
|
399
|
+
try:
|
400
|
+
pesquisar_icon = pyautogui.locateOnScreen(ASSETS_PATH + "\\notas_saida\\icon_pesquisa_nota_saida.png", confidence=0.8)
|
401
|
+
pyautogui.click(pesquisar_icon)
|
402
|
+
await worker_sleep(5)
|
403
|
+
except Exception as e:
|
404
|
+
retorno = f"Não foi possivel clicar na Lupa para buscar a nota fiscal, erro: {e} \nEtapas Executadas:\n{steps}"
|
405
|
+
return RpaRetornoProcessoDTO(
|
406
|
+
sucesso=False,
|
407
|
+
retorno=retorno,
|
408
|
+
status=RpaHistoricoStatusEnum.Falha,
|
409
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
410
|
+
)
|
411
|
+
|
412
|
+
i = 0
|
413
|
+
max_attempts = 17
|
414
|
+
|
415
|
+
while i < max_attempts:
|
416
|
+
i += 1
|
417
|
+
console.print("Verificando se a nota foi encontrada...\n")
|
418
|
+
try:
|
419
|
+
main_window.set_focus()
|
420
|
+
no_data_full_path = "assets\\entrada_notas\\no_data_display.png"
|
421
|
+
img_no_data = pyautogui.locateCenterOnScreen(no_data_full_path, confidence=0.6)
|
422
|
+
if img_no_data:
|
423
|
+
console.print("'No data display' ainda aparente. Tentando novamente...")
|
424
|
+
await worker_sleep(10)
|
425
|
+
except pyautogui.ImageNotFoundException:
|
426
|
+
console.print("'No data display' não encontrado na tela!")
|
427
|
+
break
|
428
|
+
|
429
|
+
except Exception as e:
|
430
|
+
console.print(f"Ocorreu um erro: {e}")
|
431
|
+
|
432
|
+
|
433
|
+
await worker_sleep(5)
|
434
|
+
# VERIFICANDO A EXISTENCIA DE ERRO
|
435
|
+
erro_pop_up = await is_window_open_by_class("TMessageForm","TMessageForm")
|
436
|
+
if erro_pop_up["IsOpened"] == True:
|
437
|
+
retorno = f"Nota não encontrada no EMsys na tela de Pesquisa Vendas para Devolução \nEtapas Executadas:\n{steps}"
|
438
|
+
return RpaRetornoProcessoDTO(
|
439
|
+
sucesso=False,
|
440
|
+
retorno=retorno,
|
441
|
+
status=RpaHistoricoStatusEnum.Falha,
|
442
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
443
|
+
)
|
444
|
+
|
445
|
+
main_window.set_focus()
|
446
|
+
try:
|
447
|
+
selecionar_todos_itens = pyautogui.locateOnScreen(ASSETS_PATH + "\\emsys\\selecinar_todos_itens_quadro_azul.png", confidence=0.8)
|
448
|
+
pyautogui.click(selecionar_todos_itens)
|
449
|
+
await worker_sleep(5)
|
450
|
+
except Exception as e:
|
451
|
+
retorno = f"Não foi possivel clicar em selecionar todos os itens na tela de Pesquisar Vendas para Devolução, erro: {e} \nEtapas Executadas:\n{steps}"
|
452
|
+
return RpaRetornoProcessoDTO(
|
453
|
+
sucesso=False,
|
454
|
+
retorno=retorno,
|
455
|
+
status=RpaHistoricoStatusEnum.Falha,
|
456
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
457
|
+
)
|
458
|
+
|
459
|
+
try:
|
460
|
+
pesquisar_icon = pyautogui.locateOnScreen(ASSETS_PATH + "\\emsys\\inserir.png", confidence=0.8)
|
461
|
+
pyautogui.click(pesquisar_icon)
|
462
|
+
await worker_sleep(5)
|
463
|
+
except Exception as e:
|
464
|
+
retorno = f"Não foi possivel clicar em Inserir para selecionar a nota fiscal, erro: {e} \nEtapas Executadas:\n{steps}"
|
465
|
+
return RpaRetornoProcessoDTO(
|
466
|
+
sucesso=False,
|
467
|
+
retorno=retorno,
|
468
|
+
status=RpaHistoricoStatusEnum.Falha,
|
469
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
470
|
+
)
|
471
|
+
|
472
|
+
await worker_sleep(5)
|
473
|
+
console.print("Navegando pela Janela de Nota Fiscal de Entrada...\n")
|
474
|
+
app = Application().connect(class_name="TFrmNotaFiscalEntrada")
|
475
|
+
main_window = app["TFrmNotaFiscalEntrada"]
|
476
|
+
|
477
|
+
main_window.set_focus()
|
478
|
+
console.print("Acessando os itens da nota... \n")
|
479
|
+
panel_TPage = main_window.child_window(class_name="TPage", title="Formulario")
|
480
|
+
panel_TTabSheet = panel_TPage.child_window(class_name="TcxCustomInnerTreeView")
|
481
|
+
panel_TTabSheet.wait("visible")
|
482
|
+
panel_TTabSheet.click()
|
483
|
+
send_keys("^({HOME})")
|
484
|
+
await worker_sleep(1)
|
485
|
+
send_keys("{DOWN " + ("5") + "}")
|
486
|
+
|
487
|
+
# CONFIRMANDO SE A ABA DE ITENS FOI ACESSADA COM SUCESSO
|
488
|
+
panel_TPage = main_window.child_window(class_name="TPage", title="Formulario")
|
489
|
+
panel_TPage.wait("visible")
|
490
|
+
panel_TTabSheet = panel_TPage.child_window(class_name="TTabSheet")
|
491
|
+
title_n_serie = panel_TPage.child_window(title="N° Série")
|
492
|
+
|
493
|
+
console.print("Verificando se os itens foram abertos com sucesso... \n")
|
494
|
+
if not title_n_serie:
|
495
|
+
retorno = f"Não foi possivel acessar a aba de 'Itens da nota \nEtapas Executadas:\n{steps}"
|
496
|
+
console.print(f"Não foi possivel acessar a aba de 'Itens da nota...\n")
|
497
|
+
return RpaRetornoProcessoDTO(
|
498
|
+
sucesso=False,
|
499
|
+
retorno=retorno,
|
500
|
+
status=RpaHistoricoStatusEnum.Falha,
|
501
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
502
|
+
)
|
503
|
+
|
504
|
+
await worker_sleep(2)
|
505
|
+
|
506
|
+
console.print("Acessando os itens indivualmente... \n")
|
507
|
+
send_keys("{TAB 2}", pause=0.1)
|
508
|
+
await worker_sleep(2)
|
509
|
+
|
510
|
+
itens_nota = []
|
511
|
+
|
512
|
+
index = 0
|
513
|
+
last_line_item_emsys = 'x'
|
514
|
+
|
515
|
+
try:
|
516
|
+
while True:
|
517
|
+
await worker_sleep(2)
|
518
|
+
send_keys("^({HOME})")
|
519
|
+
await worker_sleep(1)
|
520
|
+
send_keys("{DOWN " + str(index) + "}", pause=0.1)
|
521
|
+
await worker_sleep(3)
|
522
|
+
|
523
|
+
with pyautogui.hold('ctrl'):
|
524
|
+
pyautogui.press('c')
|
525
|
+
await worker_sleep(1)
|
526
|
+
with pyautogui.hold('ctrl'):
|
527
|
+
pyautogui.press('c')
|
528
|
+
|
529
|
+
win32clipboard.OpenClipboard()
|
530
|
+
line_itens_emsys = win32clipboard.GetClipboardData().strip()
|
531
|
+
win32clipboard.CloseClipboard()
|
532
|
+
console.print(f"Linha atual copiada do Emsys: {line_itens_emsys}\nUltima Linha copiada: {last_line_item_emsys}")
|
533
|
+
|
534
|
+
if bool(line_itens_emsys):
|
535
|
+
if last_line_item_emsys == line_itens_emsys:
|
536
|
+
break
|
537
|
+
else:
|
538
|
+
last_line_item_emsys = line_itens_emsys
|
539
|
+
|
540
|
+
send_keys("+{F10}")
|
541
|
+
await worker_sleep(1)
|
542
|
+
send_keys("{DOWN 2}")
|
543
|
+
await worker_sleep(1)
|
544
|
+
send_keys("{ENTER}")
|
545
|
+
await worker_sleep(4)
|
546
|
+
|
547
|
+
app = Application().connect(title="Alteração de Item")
|
548
|
+
main_window = app["Alteração de Item"]
|
549
|
+
main_window.set_focus()
|
550
|
+
|
551
|
+
#RETRIVE ITENS NOTA
|
552
|
+
|
553
|
+
tcx_page = main_window.child_window(class_name="TcxPageControl", found_index=0)
|
554
|
+
tab_sheet = tcx_page.child_window(class_name="TcxTabSheet", found_index=0)
|
555
|
+
|
556
|
+
quantidade_index = tab_sheet.child_window(class_name="TDBIEditNumber", found_index=42)
|
557
|
+
vl_unitario_index = tab_sheet.child_window(class_name="TCurrencyEdit", found_index=0)
|
558
|
+
vl_desconto_index = tab_sheet.child_window(class_name="TDBIEditNumber", found_index=41)
|
559
|
+
|
560
|
+
|
561
|
+
quantidade = quantidade_index.window_text()
|
562
|
+
vl_unitario = vl_unitario_index.window_text()
|
563
|
+
vl_desconto = vl_desconto_index.window_text()
|
564
|
+
|
565
|
+
# ITERAGINDO COM O IPI
|
566
|
+
tpage_ipi = main_window.child_window(class_name="TPanel", found_index=0)
|
567
|
+
|
568
|
+
#RETRIVE COD E DESC ITEM
|
569
|
+
cod_item_index = tpage_ipi.child_window(class_name="TDBIEditNumber", found_index=0)
|
570
|
+
cod_item = cod_item_index.window_text()
|
571
|
+
|
572
|
+
desc_item_index = tpage_ipi.child_window(class_name="TDBIEditString", found_index=1)
|
573
|
+
desc_item = desc_item_index.window_text()
|
574
|
+
|
575
|
+
|
576
|
+
item_a_ser_devolvido = False
|
577
|
+
for item in nota.get('itens'):
|
578
|
+
if desc_item.lower() in item['descricao'].lower():
|
579
|
+
item_a_ser_devolvido = True
|
580
|
+
|
581
|
+
|
582
|
+
if not item_a_ser_devolvido:
|
583
|
+
itens_nota_dict = {
|
584
|
+
"codigo": cod_item,
|
585
|
+
"descricao": desc_item,
|
586
|
+
"quantidade": quantidade,
|
587
|
+
"valor_unitario": vl_unitario,
|
588
|
+
"desconto": vl_desconto
|
589
|
+
}
|
590
|
+
itens_nota.append(itens_nota_dict)
|
591
|
+
|
592
|
+
|
593
|
+
ipi = tpage_ipi.child_window(class_name="TDBIComboBox", found_index=2)
|
594
|
+
ipi_value = ipi.window_text()
|
595
|
+
|
596
|
+
console.print(f"Trabalhando com os itens, valor do IP {ipi_value}... \n")
|
597
|
+
if "IPI - ENTRADAS OUTROS" in ipi_value:
|
598
|
+
console.print(f"Iten selecionado com sucesso, clicando em Cancelar ...\n")
|
599
|
+
try:
|
600
|
+
btn_alterar = main_window.child_window(title="&Cancelar")
|
601
|
+
btn_alterar.click()
|
602
|
+
except:
|
603
|
+
btn_alterar = main_window.child_window(title="Cancelar")
|
604
|
+
btn_alterar.click()
|
605
|
+
await worker_sleep(3)
|
606
|
+
else:
|
607
|
+
console.print(f"Trabalhando com os itens, valor do IP em branco, selecionando IPI 0% ... \n")
|
608
|
+
ipi.click_input()
|
609
|
+
set_combobox("||List", "IPI - ENTRADAS OUTROS")
|
610
|
+
|
611
|
+
await worker_sleep(4)
|
612
|
+
tpage_ipi = main_window.child_window(class_name="TPanel", found_index=0)
|
613
|
+
ipi = tpage_ipi.child_window(class_name="TDBIComboBox", found_index=2)
|
614
|
+
ipi_value = ipi.window_text()
|
615
|
+
|
616
|
+
if "IPI - ENTRADAS OUTROS" in ipi_value:
|
617
|
+
console.print(f"Trabalhando com os itens, sucesso ao selecionar o valor do IPI ... \n")
|
618
|
+
else:
|
619
|
+
return RpaRetornoProcessoDTO(
|
620
|
+
sucesso=False,
|
621
|
+
retorno=f"Erro ao selecionar o IPI de unidade nos itens, IPI: {ipi_value}",
|
622
|
+
status=RpaHistoricoStatusEnum.Falha,
|
623
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
624
|
+
)
|
625
|
+
|
626
|
+
await worker_sleep(4)
|
627
|
+
|
628
|
+
console.print(f"Iten selecionado com sucesso, clicando em alterar ...\n")
|
629
|
+
try:
|
630
|
+
btn_alterar = main_window.child_window(title="&Alterar")
|
631
|
+
btn_alterar.click()
|
632
|
+
except:
|
633
|
+
btn_alterar = main_window.child_window(title="Alterar")
|
634
|
+
btn_alterar.click()
|
635
|
+
await worker_sleep(3)
|
636
|
+
|
637
|
+
confirm_pop_up = await is_window_open_by_class("TMessageForm","TMessageForm")
|
638
|
+
if confirm_pop_up["IsOpened"] == True:
|
639
|
+
app_confirm = Application().connect(
|
640
|
+
class_name="TMessageForm"
|
641
|
+
)
|
642
|
+
main_window_confirm = app_confirm["TMessageForm"]
|
643
|
+
|
644
|
+
btn_yes = main_window_confirm["&Yes"]
|
645
|
+
try:
|
646
|
+
btn_yes.click()
|
647
|
+
await worker_sleep(3)
|
648
|
+
console.print("O botão Yes foi clicado com sucesso.", style="green")
|
649
|
+
main_window.close()
|
650
|
+
except:
|
651
|
+
return RpaRetornoProcessoDTO(
|
652
|
+
sucesso=False,
|
653
|
+
retorno=f"Não foi possivel clicar em Yes durante a alteração da tributação IPI",
|
654
|
+
status=RpaHistoricoStatusEnum.Falha,
|
655
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
656
|
+
)
|
657
|
+
index = index+1
|
658
|
+
except Exception as e:
|
659
|
+
retorno = f"Erro ao trabalhar nas alterações dos itens, erro: {e} \nEtapas Executadas:\n{steps}"
|
660
|
+
return RpaRetornoProcessoDTO(
|
661
|
+
sucesso=False,
|
662
|
+
retorno=retorno,
|
663
|
+
status=RpaHistoricoStatusEnum.Falha,
|
664
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
665
|
+
)
|
666
|
+
|
667
|
+
await worker_sleep(5)
|
668
|
+
console.print("Navegando pela Janela de Nota Fiscal de Entrada - Acessando a Janela de Pagamento...\n")
|
669
|
+
app = Application().connect(class_name="TFrmNotaFiscalEntrada")
|
670
|
+
main_window = app["TFrmNotaFiscalEntrada"]
|
671
|
+
|
672
|
+
main_window.set_focus()
|
673
|
+
console.log("Seleciona Pagamento", style="bold yellow")
|
674
|
+
pyautogui.click(624, 422)
|
675
|
+
await worker_sleep(2)
|
676
|
+
|
677
|
+
console.print(f"Adicionando pagamento... \n")
|
678
|
+
try:
|
679
|
+
panel_TPage = main_window.child_window(class_name="TPage", title="Formulario")
|
680
|
+
panel_TTabSheet = panel_TPage.child_window(class_name="TPageControl")
|
681
|
+
panel_TabPagamento = panel_TTabSheet.child_window(class_name="TTabSheet")
|
682
|
+
panel_TabPagamentoCaixa = panel_TTabSheet.child_window(title="Pagamento Pelo Caixa")
|
683
|
+
tipo_cobranca = panel_TabPagamentoCaixa.child_window(class_name="TDBIComboBox", found_index=0)
|
684
|
+
|
685
|
+
console.print(f"Selecionando a Especie de Caixa... \n")
|
686
|
+
tipo_cobranca.click()
|
687
|
+
await worker_sleep(1)
|
688
|
+
especie_caixa = main_window.child_window(class_name="TDBIComboBox", found_index=1).click()
|
689
|
+
especie_caixa.select("13 - DEVOLUCAO DE VENDA")
|
690
|
+
send_keys('{ENTER}')
|
691
|
+
|
692
|
+
await worker_sleep(2)
|
693
|
+
|
694
|
+
console.print(f"Capturando o valor em Valores Restante... \n")
|
695
|
+
tab_valores = panel_TabPagamento.child_window(title="Valores")
|
696
|
+
valores_restantes = tab_valores.child_window(
|
697
|
+
class_name="TDBIEditNumber", found_index=1
|
698
|
+
)
|
699
|
+
valores_restantes_text = valores_restantes.window_text()
|
700
|
+
valor_nota_fiscal = valores_restantes_text
|
701
|
+
console.print(f"Valor capturado {valores_restantes_text}, inserindo no campo Valor em Pagamento pelo Caixa... \n")
|
702
|
+
|
703
|
+
valor = panel_TabPagamentoCaixa.child_window(class_name="TDBIEditNumber", found_index=0)
|
704
|
+
valor.set_edit_text(valores_restantes_text)
|
705
|
+
except Exception as e:
|
706
|
+
retorno = f"Não foi possivel realizar as atividades na aba de 'Pagamento', erro: {e} \nEtapas Executadas:\n{steps}"
|
707
|
+
return RpaRetornoProcessoDTO(
|
708
|
+
sucesso=False,
|
709
|
+
retorno=retorno,
|
710
|
+
status=RpaHistoricoStatusEnum.Falha,
|
711
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
712
|
+
)
|
713
|
+
|
714
|
+
|
715
|
+
# Inclui registro
|
716
|
+
console.print(f"Incluindo registro...\n")
|
717
|
+
try:
|
718
|
+
ASSETS_PATH = "assets"
|
719
|
+
inserir_registro = pyautogui.locateOnScreen(ASSETS_PATH + "\\entrada_notas\\IncluirRegistro.png", confidence=0.8)
|
720
|
+
pyautogui.click(inserir_registro)
|
721
|
+
except Exception as e:
|
722
|
+
console.print(
|
723
|
+
f"Não foi possivel incluir o registro utilizando reconhecimento de imagem, Error: {e}...\n tentando inserir via posição...\n"
|
724
|
+
)
|
725
|
+
await incluir_registro()
|
726
|
+
|
727
|
+
|
728
|
+
await worker_sleep(5)
|
729
|
+
console.print("Verificando a existencia de POP-UP de Itens que Ultrapassam a Variação Máxima de Custo ...\n")
|
730
|
+
itens_variacao_maxima = await is_window_open_by_class("TFrmTelaSelecao", "TFrmTelaSelecao")
|
731
|
+
if itens_variacao_maxima["IsOpened"] == True:
|
732
|
+
app = Application().connect(class_name="TFrmTelaSelecao")
|
733
|
+
main_window = app["TFrmTelaSelecao"]
|
734
|
+
send_keys("%o")
|
735
|
+
|
736
|
+
|
737
|
+
#VERIFICANDO SE A NOTA FOI INCLUIDA COM SUCESSO
|
738
|
+
console.print("Verificando a se a Nota foi incluida com sucesso... \n")
|
739
|
+
try:
|
740
|
+
app = Application().connect(title="Information", timeout=180)
|
741
|
+
main_window = app["Information"]
|
742
|
+
main_window.set_focus()
|
743
|
+
|
744
|
+
#EXTRAINDO O NUMERO DA NOTA
|
745
|
+
window_rect = main_window.rectangle()
|
746
|
+
screenshot = pyautogui.screenshot(
|
747
|
+
region=(
|
748
|
+
window_rect.left,
|
749
|
+
window_rect.top,
|
750
|
+
window_rect.width(),
|
751
|
+
window_rect.height(),
|
752
|
+
)
|
753
|
+
)
|
754
|
+
username = getpass.getuser()
|
755
|
+
short_uuid = str(uuid.uuid4()).replace('-', '')[:6]
|
756
|
+
path_to_png = f"C:\\Users\\{username}\\Downloads\\aviso_popup_{short_uuid}.png"
|
757
|
+
screenshot.save(path_to_png)
|
758
|
+
console.print(f"Print salvo em {path_to_png}...\n")
|
759
|
+
|
760
|
+
console.print(
|
761
|
+
f"Preparando a imagem para maior resolução e assertividade no OCR...\n"
|
762
|
+
)
|
763
|
+
image = Image.open(path_to_png)
|
764
|
+
image = image.convert("L")
|
765
|
+
enhancer = ImageEnhance.Contrast(image)
|
766
|
+
image = enhancer.enhance(2.0)
|
767
|
+
image.save(path_to_png)
|
768
|
+
console.print(f"Imagem preparada com sucesso...\n")
|
769
|
+
console.print(f"Realizando OCR...\n")
|
770
|
+
captured_text = pytesseract.image_to_string(Image.open(path_to_png))
|
771
|
+
console.print(f"Texto Full capturado {captured_text}...\n")
|
772
|
+
os.remove(path_to_png)
|
773
|
+
pattern = r"sequ[êe]ncia:\s*(\d+)"
|
774
|
+
match = re.search(pattern, captured_text)
|
775
|
+
|
776
|
+
if match:
|
777
|
+
numero_nota_fiscal = match.group(1)
|
778
|
+
|
779
|
+
|
780
|
+
app = Application().connect(title="Information", timeout=180)
|
781
|
+
main_window = app["Information"]
|
782
|
+
main_window.set_focus()
|
783
|
+
try:
|
784
|
+
btn_ok = main_window.child_window(class_name="TButton", found_index=0)
|
785
|
+
btn_ok.click()
|
786
|
+
except Exception as e:
|
787
|
+
pyautogui.press('enter')
|
788
|
+
finally:
|
789
|
+
pyautogui.press('enter')
|
790
|
+
|
791
|
+
|
792
|
+
await worker_sleep(3)
|
793
|
+
steps += 'ETAPA 02 - Nota fiscal de Entrada Incluida com sucesso'
|
794
|
+
except Exception as e:
|
795
|
+
retorno = f"Não foi possivel obter a confirmação de Nota fiscal incluida com sucesso, erro {e} \nEtapas Executadas:\n{steps}"
|
796
|
+
return RpaRetornoProcessoDTO(
|
797
|
+
sucesso=False,
|
798
|
+
retorno=retorno,
|
799
|
+
status=RpaHistoricoStatusEnum.Falha,
|
800
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
801
|
+
)
|
802
|
+
|
803
|
+
else:
|
804
|
+
retorno = f"Não foi possivel abrir a tela de Pesquisar Venda para Devolução \nEtapas Executadas:\n{steps}"
|
805
|
+
return RpaRetornoProcessoDTO(
|
806
|
+
sucesso=False,
|
807
|
+
retorno=retorno,
|
808
|
+
status=RpaHistoricoStatusEnum.Falha,
|
809
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
810
|
+
)
|
811
|
+
pyautogui.click(1321, 247)
|
812
|
+
|
813
|
+
await worker_sleep(4)
|
814
|
+
#STEP 3
|
815
|
+
type_text_into_field("Gerenciador de Notas Fiscais", app["TFrmMenuPrincipal"]["Edit"], True, "50")
|
816
|
+
pyautogui.press("enter")
|
817
|
+
await worker_sleep(2)
|
818
|
+
pyautogui.press("enter")
|
819
|
+
await worker_sleep(5)
|
820
|
+
console.print(f"\nPesquisa: 'Gerenciador de Notas Fiscais' realizada com sucesso",style="bold green")
|
821
|
+
pesquisar_venda_devolucao = await is_window_open_by_class("TFrmGerenciadorNFe2", "TFrmGerenciadorNFe2")
|
822
|
+
if pesquisar_venda_devolucao["IsOpened"] == True:
|
823
|
+
console.print(f"\n'Gerenciador de Notas Fiscais'aberta com sucesso",style="bold green")
|
824
|
+
|
825
|
+
if cod_cliente_incorreto != "140552":
|
826
|
+
selecionar_itens_gerenciador_nfe = await gerenciador_nf_header(data_hoje, cod_cliente_incorreto)
|
827
|
+
else:
|
828
|
+
selecionar_itens_gerenciador_nfe = await gerenciador_nf_header(data_hoje, cod_empresa)
|
829
|
+
|
830
|
+
|
831
|
+
if selecionar_itens_gerenciador_nfe.sucesso:
|
832
|
+
console.print("PROCESSO EXECUTADO COM SUCESSO, SEGUINDO COM O PROCESSO PARA TRANSMITIR A NF-E...\n")
|
833
|
+
app = Application().connect(class_name="TFrmGerenciadorNFe2", timeout=10)
|
834
|
+
main_window = app["TFrmGerenciadorNFe2"]
|
835
|
+
main_window.set_focus()
|
836
|
+
|
837
|
+
console.print("Obtendo informacao da tela para o botao Transfimitir\n")
|
838
|
+
tpanel_footer = main_window.child_window(class_name="TPanel", found_index=1)
|
839
|
+
btn_transmitir = tpanel_footer.child_window(class_name="TBitBtn", found_index=5)
|
840
|
+
btn_transmitir.click()
|
841
|
+
pyautogui.click(595, 746)
|
842
|
+
console.print("Transmitir clicado com sucesso...\n")
|
843
|
+
await worker_sleep(3)
|
844
|
+
|
845
|
+
max_attempts = 15
|
846
|
+
i = 0
|
847
|
+
console.print("Aguardando pop de operacação concluida \n")
|
848
|
+
while i < max_attempts:
|
849
|
+
try:
|
850
|
+
app = Application().connect(class_name="TFrmProcessamentoNFe2", timeout=10)
|
851
|
+
main_window = app["TFrmProcessamentoNFe2"]
|
852
|
+
|
853
|
+
await worker_sleep(5)
|
854
|
+
information_pop_up = await is_window_open_by_class("TMessageForm", "TMessageForm")
|
855
|
+
if information_pop_up["IsOpened"] == True:
|
856
|
+
msg_pop_up = await ocr_by_class(numero_nota_fiscal, "TMessageForm", "TMessageForm")
|
857
|
+
if msg_pop_up.sucesso:
|
858
|
+
if 'concl' in msg_pop_up.retorno.lower():
|
859
|
+
try:
|
860
|
+
information_operacao_concluida = main_window.child_window(class_name="TMessageForm")
|
861
|
+
btn_ok = information_operacao_concluida.child_window(class_name="TButton")
|
862
|
+
btn_ok.click()
|
863
|
+
await worker_sleep(4)
|
864
|
+
except:
|
865
|
+
pyautogui.press('enter')
|
866
|
+
await worker_sleep(4)
|
867
|
+
finally:
|
868
|
+
pyautogui.press('enter')
|
869
|
+
break
|
870
|
+
else:
|
871
|
+
retorno = f"Pop up nao mapeado para seguimento do robo {msg_pop_up} \nEtapas Executadas:\n{steps}"
|
872
|
+
return RpaRetornoProcessoDTO(
|
873
|
+
sucesso=False,
|
874
|
+
retorno=retorno,
|
875
|
+
status=RpaHistoricoStatusEnum.Falha,
|
876
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
877
|
+
)
|
878
|
+
else:
|
879
|
+
retorno = f"Não foi possivel realizar a confirmação do msg do OCR \nEtapas Executadas:\n{steps}"
|
880
|
+
return RpaRetornoProcessoDTO(
|
881
|
+
sucesso=False,
|
882
|
+
retorno=retorno,
|
883
|
+
status=RpaHistoricoStatusEnum.Falha,
|
884
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
885
|
+
)
|
886
|
+
except Exception as e:
|
887
|
+
pass
|
888
|
+
|
889
|
+
|
890
|
+
i += 1
|
891
|
+
await worker_sleep(10)
|
892
|
+
|
893
|
+
|
894
|
+
if i == max_attempts:
|
895
|
+
console.print("Número máximo de tentativas atingido. Encerrando...")
|
896
|
+
retorno = f"Tempo esgotado e numero de tentativas atingido, não foi possivel obter o retorno de conclusão para transmissão na tela de Gerenciador NF-e \nEtapas Executadas:\n{steps}"
|
897
|
+
return RpaRetornoProcessoDTO(
|
898
|
+
sucesso=False,
|
899
|
+
retorno=retorno,
|
900
|
+
status=RpaHistoricoStatusEnum.Falha,
|
901
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
902
|
+
)
|
903
|
+
|
904
|
+
|
905
|
+
pop_up_status = await status_trasmissao()
|
906
|
+
console.print(f"Status copiado: {pop_up_status}")
|
907
|
+
|
908
|
+
|
909
|
+
if "autorizado o uso da nf-e" in pop_up_status.lower():
|
910
|
+
console.print("Sucesso ao transmitir...\n")
|
911
|
+
app = Application().connect(class_name="TFrmProcessamentoNFe2", timeout=15)
|
912
|
+
main_window = app["TFrmProcessamentoNFe2"]
|
913
|
+
main_window.set_focus()
|
914
|
+
await worker_sleep(3)
|
915
|
+
console.print(f"Fechando tela de processamento...\n")
|
916
|
+
fechar_tela_processamento = "assets\\emsys\\button_fechar.PNG"
|
917
|
+
try:
|
918
|
+
button_location = pyautogui.locateCenterOnScreen(
|
919
|
+
fechar_tela_processamento, confidence=0.6
|
920
|
+
)
|
921
|
+
if button_location:
|
922
|
+
pyautogui.click(button_location)
|
923
|
+
console.print("Botão 'Fechar' clicado com sucesso!")
|
924
|
+
except pyautogui.ImageNotFoundException:
|
925
|
+
window_rect = main_window.rectangle()
|
926
|
+
console.print(f"Area que sera utulizada para o recorte {window_rect}...\n")
|
927
|
+
try:
|
928
|
+
button_location = pyautogui.locateCenterOnScreen(
|
929
|
+
fechar_tela_processamento,
|
930
|
+
region=(
|
931
|
+
window_rect.left,
|
932
|
+
window_rect.top,
|
933
|
+
window_rect.width(),
|
934
|
+
window_rect.height(),
|
935
|
+
),
|
936
|
+
)
|
937
|
+
if button_location:
|
938
|
+
button_location = (
|
939
|
+
button_location.x + window_rect.left,
|
940
|
+
button_location.y + window_rect.top,
|
941
|
+
)
|
942
|
+
console.print(
|
943
|
+
f"Botão encontrado nas coordenadas: {button_location}"
|
944
|
+
)
|
945
|
+
pyautogui.click(button_location)
|
946
|
+
except pyautogui.ImageNotFoundException:
|
947
|
+
retorno = f"Não foi possivel fechar a tela de processamento, Error: {e} \nEtapas Executadas:\n{steps}"
|
948
|
+
console.print(f"Não foi possivel fechar a tela de processamento, Error: {e}...\n tentando inserir via posição...\n")
|
949
|
+
return RpaRetornoProcessoDTO(
|
950
|
+
sucesso=False,
|
951
|
+
retorno=retorno,
|
952
|
+
status=RpaHistoricoStatusEnum.Falha,
|
953
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
954
|
+
)
|
955
|
+
except Exception as e:
|
956
|
+
retorno = f"Não foi possivel fechar a tela de processamento, Error:{e} \nEtapas Executadas:\n{steps}"
|
957
|
+
console.print(f"Não foi possivel fechar a tela de processamento, Error:{e}...\n tentando inserir via posição...\n")
|
958
|
+
return RpaRetornoProcessoDTO(
|
959
|
+
sucesso=False,
|
960
|
+
retorno=retorno,
|
961
|
+
status=RpaHistoricoStatusEnum.Falha,
|
962
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
963
|
+
)
|
964
|
+
else:
|
965
|
+
x = 0
|
966
|
+
while x <= 2:
|
967
|
+
app = Application().connect(class_name="TFrmGerenciadorNFe2")
|
968
|
+
main_window = app["TFrmGerenciadorNFe2"]
|
969
|
+
main_window.close()
|
970
|
+
await worker_sleep(3)
|
971
|
+
|
972
|
+
|
973
|
+
type_text_into_field("Gerenciador de Notas Fiscais", app["TFrmMenuPrincipal"]["Edit"], True, "50")
|
974
|
+
pyautogui.press("enter")
|
975
|
+
await worker_sleep(2)
|
976
|
+
pyautogui.press("enter")
|
977
|
+
await worker_sleep(5)
|
978
|
+
console.print(f"\nPesquisa: 'Gerenciador de Notas Fiscais' realizada com sucesso",style="bold green")
|
979
|
+
pesquisar_venda_devolucao = await is_window_open_by_class("TFrmGerenciadorNFe2", "TFrmGerenciadorNFe2")
|
980
|
+
if pesquisar_venda_devolucao["IsOpened"] == True:
|
981
|
+
console.print(f"\n'Gerenciador de Notas Fiscais'aberta com sucesso",style="bold green")
|
982
|
+
selecionar_itens_gerenciador_nfe = await gerenciador_nf_header_retransmissao(data_hoje, cod_cliente_incorreto, "Rejeitada")
|
983
|
+
if selecionar_itens_gerenciador_nfe.sucesso:
|
984
|
+
console.print("PROCESSO EXECUTADO COM SUCESSO, SEGUINDO COM O PROCESSO PARA TRANSMITIR A NF-E...\n")
|
985
|
+
app = Application().connect(class_name="TFrmGerenciadorNFe2", timeout=10)
|
986
|
+
main_window = app["TFrmGerenciadorNFe2"]
|
987
|
+
main_window.set_focus()
|
988
|
+
|
989
|
+
|
990
|
+
console.print("Obtendo informacao da tela para o botao Transfimitir\n")
|
991
|
+
tpanel_footer = main_window.child_window(class_name="TPanel", found_index=1)
|
992
|
+
btn_transmitir = tpanel_footer.child_window(class_name="TBitBtn", found_index=5)
|
993
|
+
btn_transmitir.click()
|
994
|
+
pyautogui.click(595, 746)
|
995
|
+
console.print("Transmitir clicado com sucesso...\n")
|
996
|
+
await worker_sleep(3)
|
997
|
+
|
998
|
+
max_attempts = 15
|
999
|
+
i = 0
|
1000
|
+
console.print("Aguardando pop de operacação concluida \n")
|
1001
|
+
while i < max_attempts:
|
1002
|
+
try:
|
1003
|
+
app = Application().connect(class_name="TFrmProcessamentoNFe2", timeout=10)
|
1004
|
+
main_window = app["TFrmProcessamentoNFe2"]
|
1005
|
+
|
1006
|
+
await worker_sleep(5)
|
1007
|
+
information_pop_up = await is_window_open_by_class("TMessageForm", "TMessageForm")
|
1008
|
+
if information_pop_up["IsOpened"] == True:
|
1009
|
+
msg_pop_up = await ocr_by_class(numero_nota_fiscal, "TMessageForm", "TMessageForm")
|
1010
|
+
if msg_pop_up.sucesso:
|
1011
|
+
if 'concl' in msg_pop_up.retorno.lower():
|
1012
|
+
try:
|
1013
|
+
information_operacao_concluida = main_window.child_window(class_name="TMessageForm")
|
1014
|
+
btn_ok = information_operacao_concluida.child_window(class_name="TButton")
|
1015
|
+
btn_ok.click()
|
1016
|
+
await worker_sleep(4)
|
1017
|
+
except:
|
1018
|
+
pyautogui.press('enter')
|
1019
|
+
await worker_sleep(4)
|
1020
|
+
finally:
|
1021
|
+
pyautogui.press('enter')
|
1022
|
+
break
|
1023
|
+
else:
|
1024
|
+
retorno = f"Pop up nao mapeado para seguimento do robo {msg_pop_up} \nEtapas Executadas:\n{steps}"
|
1025
|
+
return RpaRetornoProcessoDTO(
|
1026
|
+
sucesso=False,
|
1027
|
+
retorno=retorno,
|
1028
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1029
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
1030
|
+
)
|
1031
|
+
else:
|
1032
|
+
retorno = f"Não foi possivel realizar a confirmação do msg do OCR \nEtapas Executadas:\n{steps}"
|
1033
|
+
return RpaRetornoProcessoDTO(
|
1034
|
+
sucesso=False,
|
1035
|
+
retorno=retorno,
|
1036
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1037
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
1038
|
+
)
|
1039
|
+
except Exception as e:
|
1040
|
+
pass
|
1041
|
+
|
1042
|
+
|
1043
|
+
i += 1
|
1044
|
+
await worker_sleep(10)
|
1045
|
+
|
1046
|
+
|
1047
|
+
if i == max_attempts:
|
1048
|
+
console.print("Número máximo de tentativas atingido. Encerrando...")
|
1049
|
+
retorno = f"Tempo esgotado e numero de tentativas atingido, não foi possivel obter o retorno de conclusão para transmissão na tela de Gerenciador NF-e \nEtapas Executadas:\n{steps}"
|
1050
|
+
return RpaRetornoProcessoDTO(
|
1051
|
+
sucesso=False,
|
1052
|
+
retorno=retorno,
|
1053
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1054
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
1055
|
+
)
|
1056
|
+
|
1057
|
+
|
1058
|
+
pop_up_status = await status_trasmissao()
|
1059
|
+
console.print(f"Status copiado: {pop_up_status}")
|
1060
|
+
|
1061
|
+
if "autorizado o uso da nf-e" in pop_up_status.lower():
|
1062
|
+
console.print("Sucesso ao transmitir...\n")
|
1063
|
+
app = Application().connect(class_name="TFrmProcessamentoNFe2", timeout=15)
|
1064
|
+
main_window = app["TFrmProcessamentoNFe2"]
|
1065
|
+
main_window.set_focus()
|
1066
|
+
await worker_sleep(3)
|
1067
|
+
console.print(f"Fechando tela de processamento...\n")
|
1068
|
+
fechar_tela_processamento = "assets\\emsys\\button_fechar.PNG"
|
1069
|
+
button_location = pyautogui.locateCenterOnScreen(
|
1070
|
+
fechar_tela_processamento, confidence=0.6
|
1071
|
+
)
|
1072
|
+
if button_location:
|
1073
|
+
pyautogui.click(button_location)
|
1074
|
+
console.print("Botão 'Fechar' clicado com sucesso!")
|
1075
|
+
|
1076
|
+
break
|
1077
|
+
elif 'duplicidade' in pop_up_status.lower():
|
1078
|
+
console.print("Duplicidade de NF...\n")
|
1079
|
+
app = Application().connect(class_name="TFrmProcessamentoNFe2", timeout=15)
|
1080
|
+
main_window = app["TFrmProcessamentoNFe2"]
|
1081
|
+
main_window.set_focus()
|
1082
|
+
await worker_sleep(3)
|
1083
|
+
console.print(f"Fechando tela de processamento...\n")
|
1084
|
+
fechar_tela_processamento = "assets\\emsys\\button_fechar.PNG"
|
1085
|
+
button_location = pyautogui.locateCenterOnScreen(
|
1086
|
+
fechar_tela_processamento, confidence=0.6
|
1087
|
+
)
|
1088
|
+
if button_location:
|
1089
|
+
pyautogui.click(button_location)
|
1090
|
+
console.print("Botão 'Fechar' clicado com sucesso!")
|
1091
|
+
|
1092
|
+
await worker_sleep(20)
|
1093
|
+
|
1094
|
+
try:
|
1095
|
+
app = Application().connect(class_name="TFrmGerenciadorNFe2", timeout=10)
|
1096
|
+
main_window = app["TFrmGerenciadorNFe2"]
|
1097
|
+
main_window.set_focus()
|
1098
|
+
|
1099
|
+
|
1100
|
+
console.print("Obtendo informacao da tela para o botao Transfimitir\n")
|
1101
|
+
tpanel_footer = main_window.child_window(class_name="TPanel", found_index=1)
|
1102
|
+
btn_consultar_sefaz = tpanel_footer.child_window(class_name="TBitBtn", found_index=4)
|
1103
|
+
btn_consultar_sefaz.click()
|
1104
|
+
|
1105
|
+
await worker_sleep(3)
|
1106
|
+
|
1107
|
+
max_attempts = 15
|
1108
|
+
i = 0
|
1109
|
+
console.print("Aguardando pop de operacação concluida \n")
|
1110
|
+
while i < max_attempts:
|
1111
|
+
try:
|
1112
|
+
app = Application().connect(class_name="TFrmProcessamentoNFe2", timeout=10)
|
1113
|
+
main_window = app["TFrmProcessamentoNFe2"]
|
1114
|
+
|
1115
|
+
await worker_sleep(5)
|
1116
|
+
information_pop_up = await is_window_open_by_class("TMessageForm", "TMessageForm")
|
1117
|
+
if information_pop_up["IsOpened"] == True:
|
1118
|
+
msg_pop_up = await ocr_by_class(numero_nota_fiscal, "TMessageForm", "TMessageForm")
|
1119
|
+
if msg_pop_up.sucesso:
|
1120
|
+
if 'concl' in msg_pop_up.retorno.lower():
|
1121
|
+
try:
|
1122
|
+
information_operacao_concluida = main_window.child_window(class_name="TMessageForm")
|
1123
|
+
btn_ok = information_operacao_concluida.child_window(class_name="TButton")
|
1124
|
+
btn_ok.click()
|
1125
|
+
await worker_sleep(4)
|
1126
|
+
except:
|
1127
|
+
pyautogui.press('enter')
|
1128
|
+
await worker_sleep(4)
|
1129
|
+
finally:
|
1130
|
+
pyautogui.press('enter')
|
1131
|
+
break
|
1132
|
+
else:
|
1133
|
+
retorno = f"Pop up nao mapeado para seguimento do robo {msg_pop_up} \nEtapas Executadas:\n{steps}"
|
1134
|
+
return RpaRetornoProcessoDTO(
|
1135
|
+
sucesso=False,
|
1136
|
+
retorno=retorno,
|
1137
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1138
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
1139
|
+
)
|
1140
|
+
else:
|
1141
|
+
retorno = f"Não foi possivel realizar a confirmação do msg do OCR \nEtapas Executadas:\n{steps}"
|
1142
|
+
return RpaRetornoProcessoDTO(
|
1143
|
+
sucesso=False,
|
1144
|
+
retorno=retorno,
|
1145
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1146
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
1147
|
+
)
|
1148
|
+
except Exception as e:
|
1149
|
+
pass
|
1150
|
+
|
1151
|
+
|
1152
|
+
i += 1
|
1153
|
+
await worker_sleep(10)
|
1154
|
+
|
1155
|
+
|
1156
|
+
if i == max_attempts:
|
1157
|
+
console.print("Número máximo de tentativas atingido. Encerrando...")
|
1158
|
+
retorno = f"Tempo esgotado e numero de tentativas atingido, não foi possivel obter o retorno de conclusão para transmissão na tela de Gerenciador NF-e \nEtapas Executadas:\n{steps}"
|
1159
|
+
return RpaRetornoProcessoDTO(
|
1160
|
+
sucesso=False,
|
1161
|
+
retorno=retorno,
|
1162
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1163
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
1164
|
+
)
|
1165
|
+
|
1166
|
+
|
1167
|
+
pop_up_status = await status_trasmissao()
|
1168
|
+
console.print(f"Status copiado: {pop_up_status}")
|
1169
|
+
|
1170
|
+
if "autorizado o uso da nf-e" in pop_up_status.lower():
|
1171
|
+
console.print("Sucesso ao transmitir...\n")
|
1172
|
+
app = Application().connect(class_name="TFrmProcessamentoNFe2", timeout=15)
|
1173
|
+
main_window = app["TFrmProcessamentoNFe2"]
|
1174
|
+
main_window.set_focus()
|
1175
|
+
await worker_sleep(3)
|
1176
|
+
console.print(f"Fechando tela de processamento...\n")
|
1177
|
+
fechar_tela_processamento = "assets\\emsys\\button_fechar.PNG"
|
1178
|
+
button_location = pyautogui.locateCenterOnScreen(
|
1179
|
+
fechar_tela_processamento, confidence=0.6
|
1180
|
+
)
|
1181
|
+
if button_location:
|
1182
|
+
pyautogui.click(button_location)
|
1183
|
+
console.print("Botão 'Fechar' clicado com sucesso!")
|
1184
|
+
|
1185
|
+
else:
|
1186
|
+
get_error_msg = await get_text_display_window(pop_up_status)
|
1187
|
+
console.print(f"Mensagem Rejeição: {get_error_msg}")
|
1188
|
+
retorno = f"Erro ao transmitir, mensagem de rejeição {get_error_msg} \nEtapas Executadas:\n{steps}"
|
1189
|
+
return RpaRetornoProcessoDTO(
|
1190
|
+
sucesso=False,
|
1191
|
+
retorno=retorno,
|
1192
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1193
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
1194
|
+
)
|
1195
|
+
except Exception as e:
|
1196
|
+
retorno = f"Erro ao retransmitir, erro {e}, \nEtapas Executadas:\n{steps}"
|
1197
|
+
return RpaRetornoProcessoDTO(
|
1198
|
+
sucesso=False,
|
1199
|
+
retorno=retorno,
|
1200
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1201
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
1202
|
+
)
|
1203
|
+
else:
|
1204
|
+
console.print(f"Mensagem de Rejeição: {pop_up_status.lower()}")
|
1205
|
+
|
1206
|
+
x = x + 1
|
1207
|
+
if x == 2:
|
1208
|
+
retorno = f"Erro ao transmitir, \nEtapas Executadas:\n{steps}"
|
1209
|
+
return RpaRetornoProcessoDTO(
|
1210
|
+
sucesso=False,
|
1211
|
+
retorno=retorno,
|
1212
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1213
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
1214
|
+
)
|
1215
|
+
|
1216
|
+
|
1217
|
+
|
1218
|
+
#PROCESSO DE IMPRESSÃO
|
1219
|
+
console.print("Conectando a janela para seguir com o processo de impressão...\n")
|
1220
|
+
app = Application().connect(class_name="TFrmGerenciadorNFe2", timeout=60)
|
1221
|
+
main_window = app["TFrmGerenciadorNFe2"]
|
1222
|
+
main_window.set_focus()
|
1223
|
+
console.print("Obtendo informações do btn para imprimir...\n")
|
1224
|
+
tpanel_footer = main_window.child_window(class_name="TPanel", found_index=1)
|
1225
|
+
btn_imprimir_danfe = tpanel_footer.child_window(class_name="TBitBtn", found_index=0)
|
1226
|
+
btn_imprimir_danfe.click()
|
1227
|
+
await worker_sleep(5)
|
1228
|
+
|
1229
|
+
|
1230
|
+
i = 0
|
1231
|
+
while i < 3:
|
1232
|
+
try:
|
1233
|
+
imprimir_screen_opened = await is_window_open_by_class("TFrmConfiguraTemplateDANF2","TFrmConfiguraTemplateDANF2")
|
1234
|
+
if imprimir_screen_opened["IsOpened"] == True:
|
1235
|
+
break
|
1236
|
+
else:
|
1237
|
+
btn_imprimir_danfe.click()
|
1238
|
+
await worker_sleep(5)
|
1239
|
+
i = i+1
|
1240
|
+
except Exception as e:
|
1241
|
+
await worker_sleep(5)
|
1242
|
+
i = i+1
|
1243
|
+
console.print(e)
|
1244
|
+
|
1245
|
+
await worker_sleep(5)
|
1246
|
+
try:
|
1247
|
+
console.print("Obtendo informações do btn selecionar PDF...\n")
|
1248
|
+
app = Application().connect(class_name="TFrmConfiguraTemplateDANF2", timeout=60)
|
1249
|
+
main_window = app["TFrmConfiguraTemplateDANF2"]
|
1250
|
+
main_window.set_focus()
|
1251
|
+
console.print("Selecionando PDF...\n")
|
1252
|
+
btn_selecionar_pdf = main_window.child_window(class_name="TRadioButton", found_index=1)
|
1253
|
+
btn_selecionar_pdf.click()
|
1254
|
+
await worker_sleep(3)
|
1255
|
+
|
1256
|
+
i = 0
|
1257
|
+
while i < 3:
|
1258
|
+
btn_selecionar_pdf = main_window.child_window(class_name="TRadioButton", found_index=1)
|
1259
|
+
if btn_selecionar_pdf.is_checked():
|
1260
|
+
console.print("O botão 'PDF' está selecionado.")
|
1261
|
+
break
|
1262
|
+
else:
|
1263
|
+
await worker_sleep(2)
|
1264
|
+
i = i+1
|
1265
|
+
|
1266
|
+
await worker_sleep(2)
|
1267
|
+
except Exception as e:
|
1268
|
+
result = f"Erro ao imprimir o arquivo \nEtapas Executadas:\n{steps}"
|
1269
|
+
console.print(result, style="bold red")
|
1270
|
+
return RpaRetornoProcessoDTO(
|
1271
|
+
sucesso=False,
|
1272
|
+
retorno=result,
|
1273
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1274
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
1275
|
+
)
|
1276
|
+
|
1277
|
+
|
1278
|
+
i = 0
|
1279
|
+
while i < 6:
|
1280
|
+
try:
|
1281
|
+
salvar_file_opened = await is_window_open("Salvar par arquivo")
|
1282
|
+
if salvar_file_opened["IsOpened"] == True:
|
1283
|
+
break
|
1284
|
+
else:
|
1285
|
+
console.print("BTN Gerar ...\n")
|
1286
|
+
btn_gerar = main_window.child_window(title="Gerar")
|
1287
|
+
btn_gerar.click()
|
1288
|
+
console.print("BTN Gerar - Clicado com sucesso...\n")
|
1289
|
+
await worker_sleep(5)
|
1290
|
+
i = i+1
|
1291
|
+
except Exception as e:
|
1292
|
+
await worker_sleep(5)
|
1293
|
+
i = i+1
|
1294
|
+
console.print(e)
|
1295
|
+
|
1296
|
+
|
1297
|
+
await worker_sleep(4)
|
1298
|
+
steps += 'ETAPA 03 - PROCESSO DE TRANSMITIR NF-e EXECUTADO COM SUCESSO '
|
1299
|
+
|
1300
|
+
|
1301
|
+
app = Application().connect(title="Salvar par arquivo")
|
1302
|
+
main_window = app["Salvar par arquivo"]
|
1303
|
+
console.print("Tela 'Salvar' encontrada!")
|
1304
|
+
|
1305
|
+
console.print("Interagindo com a tela 'Salvar'...\n")
|
1306
|
+
username = getpass.getuser()
|
1307
|
+
path_to_txt = f"C:\\Users\\{username}\\Downloads\\DEVOLUCAO PRAZO A FATURAR {numero_cupom_fiscal}"
|
1308
|
+
|
1309
|
+
main_window.type_keys("%n")
|
1310
|
+
pyautogui.write(path_to_txt)
|
1311
|
+
await worker_sleep(1)
|
1312
|
+
main_window.type_keys("%l")
|
1313
|
+
console.print("Arquivo salvo com sucesso...\n")
|
1314
|
+
await worker_sleep(6)
|
1315
|
+
|
1316
|
+
with open(f"{path_to_txt}.pdf", 'rb') as file:
|
1317
|
+
file_bytes = io.BytesIO(file.read())
|
1318
|
+
|
1319
|
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
1320
|
+
desArquivo = f"DEVOLUCAO PRAZO A FATURAR {numero_cupom_fiscal}.pdf"
|
1321
|
+
try:
|
1322
|
+
await send_file(historico_id, desArquivo, "pdf", file_bytes, file_extension="pdf")
|
1323
|
+
os.remove(path_to_txt+".pdf")
|
1324
|
+
except Exception as e:
|
1325
|
+
result = f"Arquivo DEVOLUÇÃO PRAZO A FATURAR 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}! \nEtapas Executadas:\n{steps}"
|
1326
|
+
console.print(result, style="bold red")
|
1327
|
+
return RpaRetornoProcessoDTO(
|
1328
|
+
sucesso=False,
|
1329
|
+
retorno=result,
|
1330
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1331
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
1332
|
+
)
|
1333
|
+
|
1334
|
+
app = Application().connect(class_name="TFrmConfiguraTemplateDANF2", timeout=10)
|
1335
|
+
main_window = app["TFrmConfiguraTemplateDANF2"]
|
1336
|
+
main_window.close()
|
1337
|
+
await worker_sleep(5)
|
1338
|
+
|
1339
|
+
|
1340
|
+
i = 0
|
1341
|
+
while i < 7:
|
1342
|
+
try:
|
1343
|
+
processamento_nf_opened = await is_window_open_by_class("TFrmProcessamentoNFe2", "TFrmProcessamentoNFe2")
|
1344
|
+
if processamento_nf_opened["IsOpened"] == True:
|
1345
|
+
app = Application().connect(class_name="TFrmProcessamentoNFe2", timeout=10)
|
1346
|
+
main_window = app["TFrmProcessamentoNFe2"]
|
1347
|
+
main_window.set_focus()
|
1348
|
+
main_window.close()
|
1349
|
+
await worker_sleep(1)
|
1350
|
+
else:
|
1351
|
+
break
|
1352
|
+
except:
|
1353
|
+
console.print("Não foi possivel fechar a tela com retorno do processamento", style="bold red")
|
1354
|
+
finally:
|
1355
|
+
i = i+1
|
1356
|
+
|
1357
|
+
|
1358
|
+
app = Application().connect(class_name="TFrmGerenciadorNFe2", timeout=15)
|
1359
|
+
main_window = app["TFrmGerenciadorNFe2"]
|
1360
|
+
main_window.set_focus()
|
1361
|
+
main_window.close()
|
1362
|
+
await worker_sleep(10)
|
1363
|
+
|
1364
|
+
i = 0
|
1365
|
+
while i < 7:
|
1366
|
+
try:
|
1367
|
+
gerenciandor_nf_opened = await is_window_open_by_class("TFrmGerenciadorNFe2", "TFrmGerenciadorNFe2")
|
1368
|
+
if gerenciandor_nf_opened["IsOpened"] == True:
|
1369
|
+
app = Application().connect(class_name="TFrmGerenciadorNFe2", timeout=60)
|
1370
|
+
main_window = app["TFrmGerenciadorNFe2"]
|
1371
|
+
main_window.set_focus()
|
1372
|
+
send_keys('alt+{F4}')
|
1373
|
+
#main_window.close()
|
1374
|
+
await worker_sleep(1)
|
1375
|
+
else:
|
1376
|
+
break
|
1377
|
+
except:
|
1378
|
+
console.print("Não foi possivel fechar a tela com retorno de gerencimaneto de nf", style="bold red")
|
1379
|
+
finally:
|
1380
|
+
i = i+1
|
1381
|
+
|
1382
|
+
|
1383
|
+
else:
|
1384
|
+
retorno = f"{selecionar_itens_gerenciador_nfe} \nEtapas Executadas:\n{steps}"
|
1385
|
+
return RpaRetornoProcessoDTO(
|
1386
|
+
sucesso=False,
|
1387
|
+
retorno=retorno,
|
1388
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1389
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
1390
|
+
)
|
1391
|
+
else:
|
1392
|
+
retorno = f"Não foi possivel abrir a tela de Gerenciador de Notas Fiscais \nEtapas Executadas:\n{steps}"
|
1393
|
+
return RpaRetornoProcessoDTO(
|
1394
|
+
sucesso=False,
|
1395
|
+
retorno=retorno,
|
1396
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1397
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
1398
|
+
)
|
1399
|
+
|
1400
|
+
|
1401
|
+
await worker_sleep(2)
|
1402
|
+
gerenciandor_nf_opened = await is_window_open_by_class("TFrmGerenciadorNFe2", "TFrmGerenciadorNFe2")
|
1403
|
+
if gerenciandor_nf_opened["IsOpened"] == True:
|
1404
|
+
app = Application().connect(class_name="TFrmGerenciadorNFe2", timeout=60)
|
1405
|
+
main_window = app["TFrmGerenciadorNFe2"]
|
1406
|
+
main_window.close()
|
1407
|
+
await worker_sleep(1)
|
1408
|
+
|
1409
|
+
|
1410
|
+
|
1411
|
+
#STEP 4
|
1412
|
+
#PRE VENDA
|
1413
|
+
itens_nota_separada = []
|
1414
|
+
itens_nota_conjunta = []
|
1415
|
+
for item in nota.get('itens'):
|
1416
|
+
if item['notaSeparada']:
|
1417
|
+
itens_nota_separada.append(item)
|
1418
|
+
else:
|
1419
|
+
itens_nota_conjunta.append(item)
|
1420
|
+
|
1421
|
+
|
1422
|
+
if len(itens_nota_separada) > 0:
|
1423
|
+
console.print(itens_nota_separada)
|
1424
|
+
for nf in itens_nota_separada:
|
1425
|
+
type_text_into_field("Cadastro Pré venda", app["TFrmMenuPrincipal"]["Edit"], True, "50")
|
1426
|
+
pyautogui.press("enter")
|
1427
|
+
await worker_sleep(2)
|
1428
|
+
pyautogui.press("enter")
|
1429
|
+
await worker_sleep(4)
|
1430
|
+
console.print(f"\nPesquisa: 'Cadastro Pré venda' realizada com sucesso",style="bold green")
|
1431
|
+
await worker_sleep(2)
|
1432
|
+
cadastro_pre_venda = await is_window_open_by_class("TFrmPreVenda", "TFrmPreVenda")
|
1433
|
+
#preenchimento_header_pre_venda = await cadastro_pre_venda_header("5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC", cod_cliente_correto, "A VISTA", "5656 - VENDA DE COMB OU LUB ADQ DE TERCEIRO C/ FIN S/ ESTOQUE")
|
1434
|
+
if not item_arla:
|
1435
|
+
preenchimento_header_pre_venda = await cadastro_pre_venda_header("5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC", cod_cliente_correto, "A VISTA", "5656 - VENDA DE COMB OU LUB ADQ DE TERCEIRO C/ FIN S/ ESTOQUE")
|
1436
|
+
else:
|
1437
|
+
#PRECISA DO ESPAÇO NO FINAL!!!
|
1438
|
+
preenchimento_header_pre_venda = await cadastro_pre_venda_header("5102 - VENDA MERCAD. ADQ. DE TERCEIRO- 5.102 S/ ESTOQ C/ FINAN ", cod_cliente_correto, "A VISTA", "5102 - VENDA MERCAD. ADQ. DE TERCEIRO- 5.102 S/ESTOQ C/ FINAN FE")
|
1439
|
+
|
1440
|
+
if preenchimento_header_pre_venda.sucesso:
|
1441
|
+
try:
|
1442
|
+
cidade_cliente = preenchimento_header_pre_venda.retorno
|
1443
|
+
console.print(f"\nPreenchimento cabeçalho da pre venda preenchido com sucesso, seguindo com o processo.. ",style="bold green")
|
1444
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=60)
|
1445
|
+
main_window = app["TFrmPreVenda"]
|
1446
|
+
main_window.set_focus()
|
1447
|
+
|
1448
|
+
console.print("Navegando nos elementos...\n")
|
1449
|
+
panel_TPage= main_window.child_window(class_name="TPage", found_index=0)
|
1450
|
+
panel_menu_itens= main_window.child_window(class_name="TcxCustomInnerTreeView", found_index=0)
|
1451
|
+
|
1452
|
+
console.print("Acessando a janela de Itens...\n")
|
1453
|
+
panel_menu_itens.click()
|
1454
|
+
await worker_sleep(1)
|
1455
|
+
pyautogui.press('home')
|
1456
|
+
await worker_sleep(1)
|
1457
|
+
pyautogui.press('down')
|
1458
|
+
#console.print(nota.get('itens'))
|
1459
|
+
item_devolvido = ''
|
1460
|
+
quantidade = nf['novaQuantidade']
|
1461
|
+
preco = nf['novoPreco']
|
1462
|
+
descricao = nf['descricao']
|
1463
|
+
descricao = 'Diesel Comum' if descricao == 'Diesel S500' else descricao
|
1464
|
+
quantidade = str(quantidade)
|
1465
|
+
preco = str(preco)
|
1466
|
+
#descricao = descricao.replace(".",",")
|
1467
|
+
console.print(quantidade, preco, descricao)
|
1468
|
+
item_devolvido = descricao
|
1469
|
+
item_arla = False
|
1470
|
+
|
1471
|
+
if 'arla' in descricao.lower():
|
1472
|
+
item_arla = True
|
1473
|
+
|
1474
|
+
if 'gasolina' in descricao.lower() or 'diesel' in descricao.lower() or 'gnv' in descricao.lower() or 'etanol' in descricao.lower() or 'arla' in descricao.lower():
|
1475
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=60)
|
1476
|
+
main_window = app["TFrmPreVenda"]
|
1477
|
+
main_window.set_focus()
|
1478
|
+
|
1479
|
+
console.print("Itens acessado com sucesso, clicando em Incluir...\n")
|
1480
|
+
panel_TGroup_Box= panel_TPage.child_window(class_name="TGroupBox", found_index=0)
|
1481
|
+
btn_incluir = panel_TGroup_Box.child_window(class_name="TDBIBitBtn", found_index=4)
|
1482
|
+
btn_incluir.click()
|
1483
|
+
await worker_sleep(2)
|
1484
|
+
console.print("Incluir clicado com sucesso...\n")
|
1485
|
+
|
1486
|
+
#VERIFICANDO A EXISTENCIA DE WARNINGS
|
1487
|
+
console.print("Verificando a existência de Warning... \n")
|
1488
|
+
warning_pop_up = await is_window_open("Warning")
|
1489
|
+
if warning_pop_up["IsOpened"] == True:
|
1490
|
+
console.print("possui Pop-up de Warning, analisando... \n")
|
1491
|
+
ocr_pop_warning = await ocr_warnings(numero_cupom_fiscal)
|
1492
|
+
if ocr_pop_warning.sucesso == True:
|
1493
|
+
return RpaRetornoProcessoDTO(
|
1494
|
+
sucesso=False,
|
1495
|
+
retorno=f"POP UP Warning não mapeado para seguimento do processo, mensagem: {ocr_pop_warning.retorno}",
|
1496
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1497
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
1498
|
+
)
|
1499
|
+
else:
|
1500
|
+
return RpaRetornoProcessoDTO(
|
1501
|
+
sucesso=False,
|
1502
|
+
retorno=f"POP UP Warning não mapeado para seguimento do processo",
|
1503
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1504
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
1505
|
+
)
|
1506
|
+
|
1507
|
+
|
1508
|
+
i = 0
|
1509
|
+
while i <= 7:
|
1510
|
+
try:
|
1511
|
+
console.print("Clicando sobre a lupa para inserir o almoxarifado...\n")
|
1512
|
+
app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=130)
|
1513
|
+
main_window = app["TFrmIncluiItemPreVenda"]
|
1514
|
+
main_window.set_focus()
|
1515
|
+
panel_TGroup_Box= main_window.child_window(class_name="TPanel", found_index=2)
|
1516
|
+
lupa_almoxarifaco = panel_TGroup_Box.child_window(class_name="TDBIBitBtn", found_index=1)
|
1517
|
+
lupa_almoxarifaco.click()
|
1518
|
+
console.print("Lupa clicado com sucesso inserindo a descrição do almoxarifado...\n")
|
1519
|
+
await worker_sleep(2)
|
1520
|
+
|
1521
|
+
dialog_buscar = await is_window_open_by_class("TfrmDialogBuscaGeral", "TfrmDialogBuscaGeral")
|
1522
|
+
if dialog_buscar["IsOpened"] == True:
|
1523
|
+
break
|
1524
|
+
else:
|
1525
|
+
console.print("Não foi possivel abrir a janela de Busca Geral")
|
1526
|
+
i = i+1
|
1527
|
+
except Exception as e:
|
1528
|
+
console.print(f"Erro ao abrir a janela de Busca Geral: {e}")
|
1529
|
+
i = i+1
|
1530
|
+
|
1531
|
+
|
1532
|
+
if i == 7:
|
1533
|
+
retorno = f"Não foi possivel abrir a tela para buscar pelo item do produto na seleção do almoxarifado - \nEtapas Executadas:\n{steps}"
|
1534
|
+
return RpaRetornoProcessoDTO(
|
1535
|
+
sucesso=False,
|
1536
|
+
retorno=retorno,
|
1537
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1538
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
1539
|
+
)
|
1540
|
+
|
1541
|
+
app = Application().connect(class_name="TfrmDialogBuscaGeral", timeout=60)
|
1542
|
+
main_window = app["TfrmDialogBuscaGeral"]
|
1543
|
+
main_window.set_focus()
|
1544
|
+
|
1545
|
+
console.print("Buscando a mercadoria baseado na descrição...\n")
|
1546
|
+
rect = main_window.rectangle()
|
1547
|
+
center_x = (rect.left + rect.right) // 2
|
1548
|
+
center_y = (rect.top + rect.bottom) // 2
|
1549
|
+
|
1550
|
+
#pyautogui.moveTo(center_x, center_y)
|
1551
|
+
await worker_sleep(1)
|
1552
|
+
pyautogui.click(center_x, center_y)
|
1553
|
+
await worker_sleep(1)
|
1554
|
+
send_keys("^({HOME})")
|
1555
|
+
item_arla_founded = False
|
1556
|
+
|
1557
|
+
last_line = ''
|
1558
|
+
max_attempts = 12
|
1559
|
+
attempts = 0
|
1560
|
+
|
1561
|
+
while attempts < max_attempts:
|
1562
|
+
with pyautogui.hold('ctrl'):
|
1563
|
+
pyautogui.press('c')
|
1564
|
+
await worker_sleep(1)
|
1565
|
+
with pyautogui.hold('ctrl'):
|
1566
|
+
pyautogui.press('c')
|
1567
|
+
|
1568
|
+
win32clipboard.OpenClipboard()
|
1569
|
+
descricao_item = win32clipboard.GetClipboardData().strip()
|
1570
|
+
win32clipboard.CloseClipboard()
|
1571
|
+
|
1572
|
+
if last_line == descricao_item:
|
1573
|
+
if item_arla:
|
1574
|
+
console.print("Todos os itens percorridos e o item é Arla...\n")
|
1575
|
+
main_window.set_focus()
|
1576
|
+
send_keys("%r")
|
1577
|
+
await worker_sleep(1)
|
1578
|
+
|
1579
|
+
app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=60)
|
1580
|
+
main_window = app["TFrmIncluiItemPreVenda"]
|
1581
|
+
main_window.set_focus()
|
1582
|
+
panel_TGroup_Box= main_window.child_window(class_name="TPanel", found_index=2)
|
1583
|
+
almoxarificado_index = panel_TGroup_Box.child_window(class_name="TDBIEditNumber", found_index=1)
|
1584
|
+
cod_almoxarificado = str(cod_empresa)+"50"
|
1585
|
+
almoxarificado_index.click()
|
1586
|
+
await worker_sleep(1)
|
1587
|
+
for _ in range(5):
|
1588
|
+
pyautogui.press("del")
|
1589
|
+
pyautogui.press("backspace")
|
1590
|
+
await worker_sleep(1)
|
1591
|
+
pyautogui.write(str(cod_almoxarificado))
|
1592
|
+
await worker_sleep(1)
|
1593
|
+
pyautogui.press('tab')
|
1594
|
+
await worker_sleep(4)
|
1595
|
+
|
1596
|
+
cod_item_index = panel_TGroup_Box.child_window(class_name="TDBIEditNumber", found_index=0)
|
1597
|
+
cod_item_index.click()
|
1598
|
+
await worker_sleep(1)
|
1599
|
+
for _ in range(5):
|
1600
|
+
pyautogui.press("del")
|
1601
|
+
pyautogui.press("backspace")
|
1602
|
+
pyautogui.write("1420")
|
1603
|
+
await worker_sleep(1)
|
1604
|
+
pyautogui.press('tab')
|
1605
|
+
await worker_sleep(3)
|
1606
|
+
console.print("Cod do item e Almoxarifado inserido com sucesso, saindo...\n")
|
1607
|
+
break
|
1608
|
+
else:
|
1609
|
+
retorno = f"Todos os itens percorridos e não foi possivel encontrar a descrição condizente a {descricao} \nEtapas Executadas:\n{steps}"
|
1610
|
+
return RpaRetornoProcessoDTO(
|
1611
|
+
sucesso=False,
|
1612
|
+
retorno=retorno,
|
1613
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1614
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
1615
|
+
)
|
1616
|
+
else:
|
1617
|
+
if descricao.lower() in descricao_item.lower():
|
1618
|
+
console.print("Descrição do item encontrada, saindo...\n")
|
1619
|
+
item_arla_founded = True
|
1620
|
+
main_window.set_focus()
|
1621
|
+
send_keys("%o")
|
1622
|
+
break
|
1623
|
+
else:
|
1624
|
+
console.print("Descrição do item não encontrada, saindo...\n")
|
1625
|
+
last_line = descricao_item
|
1626
|
+
pyautogui.press('down')
|
1627
|
+
attempts += 1
|
1628
|
+
|
1629
|
+
|
1630
|
+
await worker_sleep(10)
|
1631
|
+
console.print("Processo finalizado com sucesso, seguindo com a seleção da natureza...\n")
|
1632
|
+
|
1633
|
+
app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=60)
|
1634
|
+
main_window = app["TFrmIncluiItemPreVenda"]
|
1635
|
+
main_window.set_focus()
|
1636
|
+
panel_TGroup_Box= main_window.child_window(class_name="TPanel", found_index=2)
|
1637
|
+
natureza_oper_select = panel_TGroup_Box.child_window(class_name="TDBIComboBox", found_index=0)
|
1638
|
+
nop_selected = natureza_oper_select.window_text()
|
1639
|
+
nop_selected_value = nop_selected[:4]
|
1640
|
+
await worker_sleep(1)
|
1641
|
+
|
1642
|
+
itens_to_select = natureza_oper_select.texts()
|
1643
|
+
nop_to_be_select = ''
|
1644
|
+
|
1645
|
+
for item in itens_to_select:
|
1646
|
+
if nop_selected_value in item and (('c/' in item.lower() or 'c /' in item.lower()) and ('s/' in item.lower() or 's /' in item.lower())):
|
1647
|
+
nop_to_be_select = item
|
1648
|
+
break
|
1649
|
+
|
1650
|
+
# natureza_oper_select.click()
|
1651
|
+
await worker_sleep(1)
|
1652
|
+
|
1653
|
+
console.print(f"Descrição: {descricao}")
|
1654
|
+
if 'gasolina' in descricao.lower() or 'diesel' in descricao.lower() or 'gnv' in descricao.lower() or 'etanol' in descricao.lower():
|
1655
|
+
try:
|
1656
|
+
console.print("Selecionando NOP do item: '5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC'")
|
1657
|
+
natureza_oper_select.select("5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC")
|
1658
|
+
except:
|
1659
|
+
console.print("Selecionando NOP: 5656 - VENDA DE COMB OU LUB ADQ DE TERCEIRO C/ FIN S/ ESTOQUE")
|
1660
|
+
natureza_oper_select.select("5656 - VENDA DE COMB OU LUB ADQ DE TERCEIRO C/ FIN S/ ESTOQUE")
|
1661
|
+
elif 'arla' in descricao.lower():
|
1662
|
+
try:
|
1663
|
+
#PRECISA DO ESPAÇO NO FINAL!!
|
1664
|
+
console.print("Selecionando NOP do item: '5102 - VENDA MERCAD. ADQ. DE TERCEIRO- 5.102 S/ ESTOQ C/ FINAN '")
|
1665
|
+
natureza_oper_select.select("5102 - VENDA MERCAD. ADQ. DE TERCEIRO- 5.102 S/ ESTOQ C/ FINAN ")
|
1666
|
+
except:
|
1667
|
+
console.print("Selecionando NOP do item: '5102 - VENDA MERCAD. ADQ. DE TERCEIRO- 5.102 S/ ESTOQ C/ FINAN FE'")
|
1668
|
+
natureza_oper_select.select("5102 - VENDA MERCAD. ADQ. DE TERCEIRO- 5.102 S/ ESTOQ C/ FINAN FE")
|
1669
|
+
else:
|
1670
|
+
retorno = f"Não é combustivel {nop_selected} \nEtapas Executadas:\n{steps}"
|
1671
|
+
return RpaRetornoProcessoDTO(
|
1672
|
+
sucesso=False,
|
1673
|
+
retorno=retorno,
|
1674
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1675
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
1676
|
+
)
|
1677
|
+
# console.print("Selecionando NOP do item: '5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC'")
|
1678
|
+
# natureza_oper_select.select("5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC")
|
1679
|
+
|
1680
|
+
|
1681
|
+
await worker_sleep(1)
|
1682
|
+
console.print("Natureza da operação selecionado com sucesso, preenchendo os itens...\n")
|
1683
|
+
|
1684
|
+
#INSERINDO A QUANTIDADE
|
1685
|
+
main_window.set_focus()
|
1686
|
+
panel_TPage_Control= main_window.child_window(class_name="TcxPageControl", found_index=0)
|
1687
|
+
panel_tabSheet = panel_TPage_Control.child_window(class_name="TcxTabSheet", found_index=0)
|
1688
|
+
|
1689
|
+
field_quantidade = panel_tabSheet.child_window(class_name="TDBIEditNumber", found_index=8)
|
1690
|
+
console.print("Inserindo a quantidade de Itens...\n")
|
1691
|
+
field_quantidade.click()
|
1692
|
+
await worker_sleep(1)
|
1693
|
+
pyautogui.press('del')
|
1694
|
+
await worker_sleep(1)
|
1695
|
+
pyautogui.press('backspace')
|
1696
|
+
await worker_sleep(1)
|
1697
|
+
pyautogui.write(quantidade)
|
1698
|
+
#field_quantidade.set_edit_text(quantidade)
|
1699
|
+
await worker_sleep(1)
|
1700
|
+
pyautogui.press('tab')
|
1701
|
+
await worker_sleep(2)
|
1702
|
+
|
1703
|
+
#INSERINDO O VALOR INDIVIDUAL DO ITEM
|
1704
|
+
console.print("Inserindo o valor indivual do Item...\n")
|
1705
|
+
i = 0
|
1706
|
+
while i < 3:
|
1707
|
+
btn_valor_unitario = panel_tabSheet.child_window(class_name="TDBIBitBtn", found_index=0)
|
1708
|
+
btn_valor_unitario.click()
|
1709
|
+
console.print("Garantindo o click em valor individual")
|
1710
|
+
pyautogui.click(973, 658)
|
1711
|
+
await worker_sleep(3)
|
1712
|
+
|
1713
|
+
caixa_valor_aberta = await is_window_open_by_class("TFrmInputBoxNumero", "TFrmInputBoxNumero")
|
1714
|
+
if caixa_valor_aberta["IsOpened"] == True:
|
1715
|
+
break
|
1716
|
+
else:
|
1717
|
+
i = i + 1
|
1718
|
+
|
1719
|
+
console.print("Conectado a caixa para inserir o valor ")
|
1720
|
+
app = Application().connect(class_name="TFrmInputBoxNumero", timeout=60)
|
1721
|
+
main_window = app["TFrmInputBoxNumero"]
|
1722
|
+
main_window.set_focus()
|
1723
|
+
console.print("Caixa para inserir o valor conectada corretamento ")
|
1724
|
+
|
1725
|
+
field_valor = main_window.child_window(class_name="TDBIEditNumber", found_index=0)
|
1726
|
+
field_valor.click()
|
1727
|
+
await worker_sleep(1)
|
1728
|
+
for _ in range(10):
|
1729
|
+
pyautogui.press("del")
|
1730
|
+
pyautogui.press("backspace")
|
1731
|
+
pyautogui.write(preco)
|
1732
|
+
#field_valor.set_edit_text(preco)
|
1733
|
+
await worker_sleep(2)
|
1734
|
+
|
1735
|
+
main_window.set_focus()
|
1736
|
+
send_keys("%o")
|
1737
|
+
await worker_sleep(2)
|
1738
|
+
console.print("Valor inserido com sucesso...\n")
|
1739
|
+
|
1740
|
+
console.print("Fechando tela de incluir item pre venda...\n")
|
1741
|
+
app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=60)
|
1742
|
+
main_window = app["TFrmIncluiItemPreVenda"]
|
1743
|
+
main_window.set_focus()
|
1744
|
+
send_keys("%i")
|
1745
|
+
await worker_sleep(2)
|
1746
|
+
#Divergencia de nop na capa e no item
|
1747
|
+
await find_nop_divergence()
|
1748
|
+
await worker_sleep(5)
|
1749
|
+
main_window.close()
|
1750
|
+
|
1751
|
+
|
1752
|
+
#INSERINDO O VALOR
|
1753
|
+
console.print(f"\nNavegando para inserir o valor... ",style="bold green")
|
1754
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=60)
|
1755
|
+
main_window = app["TFrmPreVenda"]
|
1756
|
+
main_window.set_focus()
|
1757
|
+
|
1758
|
+
console.print("Navegando nos elementos...\n")
|
1759
|
+
panel_TPage= main_window.child_window(class_name="TPage", found_index=0)
|
1760
|
+
panel_menu_itens= main_window.child_window(class_name="TcxCustomInnerTreeView", found_index=0)
|
1761
|
+
|
1762
|
+
console.print("Acessando a janela de Itens...\n")
|
1763
|
+
panel_menu_itens.click()
|
1764
|
+
await worker_sleep(1)
|
1765
|
+
pyautogui.press('home')
|
1766
|
+
await worker_sleep(1)
|
1767
|
+
send_keys("{DOWN " + ("3") + "}")
|
1768
|
+
await worker_sleep(3)
|
1769
|
+
|
1770
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=60)
|
1771
|
+
main_window = app["TFrmPreVenda"]
|
1772
|
+
main_window.set_focus()
|
1773
|
+
|
1774
|
+
console.print("Navegando nos elementos...\n")
|
1775
|
+
panel_TNotebook = main_window.child_window(class_name="TNotebook", found_index=0)
|
1776
|
+
recebimento_caixa_panel = panel_TNotebook.child_window(title="Recebimento Pelo Caixa")
|
1777
|
+
especie_btn = recebimento_caixa_panel.child_window(class_name="TDBIComboBox", found_index=0)
|
1778
|
+
especie_btn.select("13 - DEVOLUCAO DE VENDA")
|
1779
|
+
|
1780
|
+
await worker_sleep(2)
|
1781
|
+
|
1782
|
+
totais_panel = panel_TNotebook.child_window(title="Totais")
|
1783
|
+
totais_panel.set_focus()
|
1784
|
+
|
1785
|
+
total_pre_venda_field = totais_panel.child_window(class_name="TDBIEditNumber", found_index=4)
|
1786
|
+
valor_total_value = total_pre_venda_field.window_text()
|
1787
|
+
|
1788
|
+
console.print(f'Valor capturado: {valor_total_value}')
|
1789
|
+
|
1790
|
+
await worker_sleep(1)
|
1791
|
+
|
1792
|
+
recebimento_caixa_panel = panel_TNotebook.child_window(title="Recebimento Pelo Caixa")
|
1793
|
+
valor_field = recebimento_caixa_panel.child_window(class_name="TDBIEditNumber", found_index=0)
|
1794
|
+
valor_field.click()
|
1795
|
+
await worker_sleep(1)
|
1796
|
+
|
1797
|
+
valor_field.set_edit_text(valor_total_value)
|
1798
|
+
|
1799
|
+
console.print(f'Valor inserido: {valor_total_value}')
|
1800
|
+
|
1801
|
+
await worker_sleep(2)
|
1802
|
+
|
1803
|
+
console.print(f'Incluindo registro')
|
1804
|
+
|
1805
|
+
incluir_registro_btn = recebimento_caixa_panel.child_window(class_name="TDBIBitBtn", found_index=2)
|
1806
|
+
incluir_registro_btn.click()
|
1807
|
+
|
1808
|
+
await worker_sleep(2)
|
1809
|
+
|
1810
|
+
|
1811
|
+
#VERIFICANDO A EXISTENCIA DE WARNINGS
|
1812
|
+
console.print("Verificando a existência de Warning... \n")
|
1813
|
+
warning_pop_up = await is_window_open("Warning")
|
1814
|
+
if warning_pop_up["IsOpened"] == True:
|
1815
|
+
console.print("possui Pop-up de Warning, analisando... \n")
|
1816
|
+
ocr_pop_warning = await ocr_warnings(numero_cupom_fiscal)
|
1817
|
+
if ocr_pop_warning.sucesso == True:
|
1818
|
+
retorno = f"POP UP Warning não mapeado para seguimento do processo, mensagem: {ocr_pop_warning.retorno} \nEtapas Executadas:\n{steps}"
|
1819
|
+
return RpaRetornoProcessoDTO(
|
1820
|
+
sucesso=False,
|
1821
|
+
retorno=retorno,
|
1822
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1823
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
1824
|
+
)
|
1825
|
+
else:
|
1826
|
+
retorno = f"{ocr_pop_warning.retorno} \nEtapas Executadas:\n{steps}"
|
1827
|
+
return RpaRetornoProcessoDTO(
|
1828
|
+
sucesso=False,
|
1829
|
+
retorno=retorno,
|
1830
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1831
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
1832
|
+
)
|
1833
|
+
else:
|
1834
|
+
console.print("Não possui pop de Warning...\n")
|
1835
|
+
|
1836
|
+
|
1837
|
+
# #CONFIRMANDO NA TELA DE PRE VENDA
|
1838
|
+
# try:
|
1839
|
+
# console.print("CLICANDO EM CONFIRMAR... \n")
|
1840
|
+
# app = Application().connect(class_name="TFrmPreVenda", timeout=60)
|
1841
|
+
# main_window = app["TFrmPreVenda"]
|
1842
|
+
# main_window.set_focus()
|
1843
|
+
|
1844
|
+
# panel_Tnotebook = main_window.child_window(class_name="TNotebook", found_index=0)
|
1845
|
+
# panel_Tnotebook = panel_Tnotebook.child_window(class_name="TPage", found_index=0)
|
1846
|
+
# btn_confirmar = panel_Tnotebook.child_window(class_name="TBitBtn", found_index=11)
|
1847
|
+
# btn_confirmar.click()
|
1848
|
+
# console.print("CONFIRMAR CLICADO COM SUCESSO... \n")
|
1849
|
+
# await worker_sleep(3)
|
1850
|
+
# except Exception as e:
|
1851
|
+
# retorno = f"Não foi possivel clicar em Confirma na tela de Pre Venda \nEtapas Executadas:\n{steps}"
|
1852
|
+
# return RpaRetornoProcessoDTO(
|
1853
|
+
# sucesso=False,
|
1854
|
+
# retorno=retorno,
|
1855
|
+
# status=RpaHistoricoStatusEnum.Falha,
|
1856
|
+
# tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
1857
|
+
# )
|
1858
|
+
|
1859
|
+
|
1860
|
+
# Inclui registro
|
1861
|
+
console.print(f"Incluindo registro...\n")
|
1862
|
+
try:
|
1863
|
+
ASSETS_PATH = "assets"
|
1864
|
+
inserir_registro = pyautogui.locateOnScreen(ASSETS_PATH + "\\entrada_notas\\IncluirRegistro.png", confidence=0.8)
|
1865
|
+
pyautogui.click(inserir_registro)
|
1866
|
+
|
1867
|
+
except Exception as e:
|
1868
|
+
console.print(
|
1869
|
+
f"Não foi possivel incluir o registro utilizando reconhecimento de imagem, Error: {e}...\n tentando inserir via posição...\n"
|
1870
|
+
)
|
1871
|
+
await incluir_registro()
|
1872
|
+
await worker_sleep(5)
|
1873
|
+
|
1874
|
+
|
1875
|
+
await worker_sleep(10)
|
1876
|
+
#VERIFICANDO A EXISTENCIA DE WARNINGS
|
1877
|
+
console.print("Verificando a existência de Warning... \n")
|
1878
|
+
warning_pop_up = await is_window_open("Warning")
|
1879
|
+
if warning_pop_up["IsOpened"] == True:
|
1880
|
+
console.print("possui Pop-up de Warning, analisando... \n")
|
1881
|
+
ocr_pop_warning = await ocr_warnings(numero_cupom_fiscal)
|
1882
|
+
if ocr_pop_warning.sucesso == True:
|
1883
|
+
retorno = f"POP UP Warning não mapeado para seguimento do processo, mensagem: {ocr_pop_warning.retorno} \nEtapas Executadas:\n{steps}"
|
1884
|
+
return RpaRetornoProcessoDTO(
|
1885
|
+
sucesso=False,
|
1886
|
+
retorno=retorno,
|
1887
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1888
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
1889
|
+
)
|
1890
|
+
else:
|
1891
|
+
retorno = f"POP UP Warning não mapeado para seguimento do processo \nEtapas Executadas:\n{steps}"
|
1892
|
+
return RpaRetornoProcessoDTO(
|
1893
|
+
sucesso=False,
|
1894
|
+
retorno=retorno,
|
1895
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1896
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
1897
|
+
)
|
1898
|
+
await worker_sleep(10)
|
1899
|
+
#VERIFICANDO SE A PRÉ VENDA FOI INCLUIDA COM SUCESSO
|
1900
|
+
console.print("VERIFICANDO SE A PRÉ VENDA FOI INCLUIDA COM SUCESSO... \n")
|
1901
|
+
information_pop_up = await is_window_open("Informação")
|
1902
|
+
if information_pop_up["IsOpened"] == True:
|
1903
|
+
msg_pop_up = await ocr_title(numero_nota_fiscal, "Informação")
|
1904
|
+
console.print(f'retorno:{msg_pop_up.sucesso}')
|
1905
|
+
console.print(f'retorno:{msg_pop_up}')
|
1906
|
+
if msg_pop_up.sucesso == True:
|
1907
|
+
msg_retorno = msg_pop_up.retorno
|
1908
|
+
console.print(msg_retorno)
|
1909
|
+
if 'venda' in msg_retorno.lower():
|
1910
|
+
try:
|
1911
|
+
information_operacao_concluida = main_window.child_window(title="Informação")
|
1912
|
+
btn_ok = information_operacao_concluida.child_window(class_name="TButton")
|
1913
|
+
btn_ok.click()
|
1914
|
+
await worker_sleep(4)
|
1915
|
+
except:
|
1916
|
+
pyautogui.press('enter')
|
1917
|
+
await worker_sleep(4)
|
1918
|
+
else:
|
1919
|
+
retorno = f"Pop up nao mapeado para seguimento do robo {msg_pop_up.retorno} \nEtapas Executadas:\n{steps}"
|
1920
|
+
return RpaRetornoProcessoDTO(
|
1921
|
+
sucesso=False,
|
1922
|
+
retorno=retorno,
|
1923
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1924
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
1925
|
+
)
|
1926
|
+
else:
|
1927
|
+
retorno = f"Não foi possivel realizar a confirmação do msg do OCR \nEtapas Executadas:\n{steps}"
|
1928
|
+
return RpaRetornoProcessoDTO(
|
1929
|
+
sucesso=False,
|
1930
|
+
retorno=retorno,
|
1931
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1932
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
1933
|
+
)
|
1934
|
+
else:
|
1935
|
+
retorno = f"Janela de confirmação de pre venda incluida nao encontrada \nEtapas Executadas:\n{steps}"
|
1936
|
+
return RpaRetornoProcessoDTO(
|
1937
|
+
sucesso=False,
|
1938
|
+
retorno=retorno,
|
1939
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1940
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
1941
|
+
)
|
1942
|
+
|
1943
|
+
|
1944
|
+
steps += ' ETAPA 04 - PRE VENDA INCLUIDA COM SUCESSO'
|
1945
|
+
#CONFIRMANDO POP UP DE PRÉ VENDA - PESQUISAR PRE VENDA
|
1946
|
+
try:
|
1947
|
+
console.print("CONFIRMANDO POP UP DE PRÉ VENDA - PESQUISAR PRE VENDA... \n")
|
1948
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=10)
|
1949
|
+
main_window = app["Confirm"]
|
1950
|
+
main_window.set_focus()
|
1951
|
+
|
1952
|
+
btn_yes = main_window.child_window(class_name="TButton", found_index=1)
|
1953
|
+
btn_yes.click()
|
1954
|
+
await worker_sleep(3)
|
1955
|
+
except Exception as e:
|
1956
|
+
retorno = f"Pop Up de Confirm (Deseja pesquisar a Pré Venda ?) não encontrado \nEtapas Executadas:\n{steps}"
|
1957
|
+
return RpaRetornoProcessoDTO(
|
1958
|
+
sucesso=False,
|
1959
|
+
retorno=retorno,
|
1960
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1961
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
1962
|
+
)
|
1963
|
+
|
1964
|
+
|
1965
|
+
#CONFIRMANDO NA TELA DE PRE VENDA
|
1966
|
+
try:
|
1967
|
+
console.print("CLICANDO EM CONFIRMAR... \n")
|
1968
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=60)
|
1969
|
+
main_window = app["TFrmPreVenda"]
|
1970
|
+
main_window.set_focus()
|
1971
|
+
|
1972
|
+
panel_Tnotebook = main_window.child_window(class_name="TNotebook", found_index=0)
|
1973
|
+
panel_Tnotebook = panel_Tnotebook.child_window(class_name="TPage", found_index=0)
|
1974
|
+
btn_confirmar = panel_Tnotebook.child_window(class_name="TBitBtn", found_index=11)
|
1975
|
+
btn_confirmar.click()
|
1976
|
+
console.print("CONFIRMAR CLICADO COM SUCESSO... \n")
|
1977
|
+
await worker_sleep(3)
|
1978
|
+
except Exception as e:
|
1979
|
+
retorno = f"Não foi possivel clicar em Confirma na tela de Pre Venda \nEtapas Executadas:\n{steps}"
|
1980
|
+
return RpaRetornoProcessoDTO(
|
1981
|
+
sucesso=False,
|
1982
|
+
retorno=retorno,
|
1983
|
+
status=RpaHistoricoStatusEnum.Falha,
|
1984
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
1985
|
+
)
|
1986
|
+
|
1987
|
+
|
1988
|
+
#CONFIRMANDO NA TELA DE PRE VENDA
|
1989
|
+
try:
|
1990
|
+
console.print("CONFIRMANDO POP UP DE Deseja realmente confirmar esta PRÉ VENDA ... \n")
|
1991
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=10)
|
1992
|
+
main_window = app["Confirm"]
|
1993
|
+
main_window.set_focus()
|
1994
|
+
|
1995
|
+
btn_yes = main_window.child_window(class_name="TButton", found_index=1)
|
1996
|
+
btn_yes.click()
|
1997
|
+
except Exception as e:
|
1998
|
+
retorno = f"Não foi possivel clicar para confirmar a janela 'Deseja realmente confirmar esta pre-venda' \nEtapas Executadas:\n{steps}"
|
1999
|
+
return RpaRetornoProcessoDTO(
|
2000
|
+
sucesso=False,
|
2001
|
+
retorno=retorno,
|
2002
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2003
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
2004
|
+
)
|
2005
|
+
|
2006
|
+
|
2007
|
+
await worker_sleep(5)
|
2008
|
+
app = Application().connect(title="Information", timeout=180)
|
2009
|
+
main_window = app["Information"]
|
2010
|
+
main_window.set_focus()
|
2011
|
+
try:
|
2012
|
+
btn_ok = main_window.child_window(class_name="TButton", found_index=0)
|
2013
|
+
btn_ok.click()
|
2014
|
+
except Exception as e:
|
2015
|
+
pyautogui.press('enter')
|
2016
|
+
finally:
|
2017
|
+
pyautogui.press('enter')
|
2018
|
+
|
2019
|
+
|
2020
|
+
#FATURAR
|
2021
|
+
try:
|
2022
|
+
console.print("FATURAR... \n")
|
2023
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=10)
|
2024
|
+
main_window = app["TFrmPreVenda"]
|
2025
|
+
main_window.set_focus()
|
2026
|
+
|
2027
|
+
panel_Tnotebook = main_window.child_window(class_name="TNotebook", found_index=0)
|
2028
|
+
panel_Tnotebook = panel_Tnotebook.child_window(class_name="TPage", found_index=0)
|
2029
|
+
btn_faturar = panel_Tnotebook.child_window(class_name="TBitBtn", found_index=7)
|
2030
|
+
btn_faturar.click()
|
2031
|
+
console.print("BOTAO FATURAR CLICADO COM SUCESSO... \n")
|
2032
|
+
await worker_sleep(5)
|
2033
|
+
except Exception as e:
|
2034
|
+
retorno = f"Não foi possivel clicar em Faturar na tela de pre venda, erro: {e} \nEtapas Executadas:\n{steps}"
|
2035
|
+
return RpaRetornoProcessoDTO(
|
2036
|
+
sucesso=False,
|
2037
|
+
retorno=retorno,
|
2038
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2039
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
2040
|
+
)
|
2041
|
+
|
2042
|
+
|
2043
|
+
await worker_sleep(10)
|
2044
|
+
warning_pop = await is_window_open_by_class("TFrmPreVenda", "Warning")
|
2045
|
+
if warning_pop["IsOpened"] == True:
|
2046
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=10)
|
2047
|
+
try:
|
2048
|
+
main_window = app["Warning"]
|
2049
|
+
main_window.set_focus()
|
2050
|
+
retorno = f"Cliente Cliente sem permissão para realizar a emissão da nota fiscal, por favor verificar o cadastro do mesmo \nEtapas Executadas:\n{steps}"
|
2051
|
+
return RpaRetornoProcessoDTO(
|
2052
|
+
sucesso=False,
|
2053
|
+
retorno=retorno,
|
2054
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2055
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
2056
|
+
)
|
2057
|
+
except Exception as e:
|
2058
|
+
console.print('Não possui tela de Warning')
|
2059
|
+
else:
|
2060
|
+
console.print("Nenhum pop-up de Warning Encontrado... \n")
|
2061
|
+
|
2062
|
+
|
2063
|
+
information_pop_up = await is_window_open("Information")
|
2064
|
+
if information_pop_up["IsOpened"] == True:
|
2065
|
+
app = Application().connect(title="Information", timeout=30)
|
2066
|
+
main_window = app["Information"]
|
2067
|
+
main_window.set_focus()
|
2068
|
+
btn_ok = main_window.child_window(class_name="TButton", found_index=0)
|
2069
|
+
btn_ok.click()
|
2070
|
+
|
2071
|
+
|
2072
|
+
await worker_sleep(15)
|
2073
|
+
#FATURAMENTO PRÉ-VENDA
|
2074
|
+
try:
|
2075
|
+
console.print("FATURAMENTO PRÉ-VENDA... \n")
|
2076
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
|
2077
|
+
main_window = app["TFrmDadosFaturamentoPreVenda"]
|
2078
|
+
main_window.set_focus()
|
2079
|
+
except Exception as e:
|
2080
|
+
retorno = f"Não foi encontrada a Janela Faturamento de Pré Venda \nEtapas Executadas:\n{steps}"
|
2081
|
+
return RpaRetornoProcessoDTO(
|
2082
|
+
sucesso=False,
|
2083
|
+
retorno=result,
|
2084
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2085
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
2086
|
+
)
|
2087
|
+
|
2088
|
+
await find_warning_nop_divergence()
|
2089
|
+
await worker_sleep(2)
|
2090
|
+
#VERIFICANDO SE POSSUI POP UP WARNING
|
2091
|
+
console.print("Verificando a presença de Warning... \n")
|
2092
|
+
warning_boo = False
|
2093
|
+
try:
|
2094
|
+
try:
|
2095
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=10)
|
2096
|
+
main_window = app["Warning"]
|
2097
|
+
main_window.set_focus()
|
2098
|
+
except:
|
2099
|
+
console.print('Except')
|
2100
|
+
app = Application().connect(class_name="Warning", timeout=10)
|
2101
|
+
main_window = app["Warning"]
|
2102
|
+
main_window.set_focus()
|
2103
|
+
console.print("Possui Warning... \n")
|
2104
|
+
await find_warning_nop_divergence()
|
2105
|
+
btn_ok = main_window.child_window(class_name="TButton", found_index=0)
|
2106
|
+
btn_ok.click()
|
2107
|
+
await worker_sleep(3)
|
2108
|
+
warning_boo = True
|
2109
|
+
except:
|
2110
|
+
console.print("Não Possui Warning... \n")
|
2111
|
+
|
2112
|
+
await find_warning_nop_divergence()
|
2113
|
+
await worker_sleep(2)
|
2114
|
+
#ALTERANDO TRIBUTO DOS ITENS
|
2115
|
+
if warning_boo:
|
2116
|
+
try:
|
2117
|
+
console.print('Acessando a tela de Itens')
|
2118
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
|
2119
|
+
main_window = app["TFrmDadosFaturamentoPreVenda"]
|
2120
|
+
main_window.set_focus()
|
2121
|
+
send_keys("%i")
|
2122
|
+
await worker_sleep(2)
|
2123
|
+
send_keys("%g")
|
2124
|
+
await worker_sleep(2)
|
2125
|
+
|
2126
|
+
await find_warning_nop_divergence()
|
2127
|
+
await worker_sleep(2)
|
2128
|
+
console.print("Conectando para realizar a alteração da tributação do produto... \n")
|
2129
|
+
app = Application().connect(class_name="TFrmDadosTributacaoProdutoPreVenda", timeout=60)
|
2130
|
+
main_window = app["TFrmDadosTributacaoProdutoPreVenda"]
|
2131
|
+
|
2132
|
+
tpanel_dados_tributacao = main_window.child_window(class_name="TPanel", found_index=1)
|
2133
|
+
tributacao_icms_select = tpanel_dados_tributacao.child_window(class_name="TDBIComboBox", found_index=4)
|
2134
|
+
|
2135
|
+
|
2136
|
+
if not item_arla:
|
2137
|
+
console.print("Não é item Arla ajustando tributacao... \n")
|
2138
|
+
tributacao_icms_select.click()
|
2139
|
+
await worker_sleep(1)
|
2140
|
+
set_combobox("||List", "061 - 061- MONOFASICO")
|
2141
|
+
else:
|
2142
|
+
console.print("Item Arla buscando pela aliquota do estado... \n")
|
2143
|
+
aliquota = None
|
2144
|
+
for item in conconfig_aliquota_icms:
|
2145
|
+
if cidade_cliente in item["estado"]:
|
2146
|
+
aliquota = item["aliquota"]
|
2147
|
+
break
|
2148
|
+
|
2149
|
+
if aliquota:
|
2150
|
+
console.print(f"A alíquota para o estado {cidade_cliente} é: {aliquota}")
|
2151
|
+
tributacao_icms_select.click()
|
2152
|
+
await worker_sleep(1)
|
2153
|
+
tributacao = f"000 - 000- ICMS - {aliquota}%"
|
2154
|
+
set_combobox("||List", tributacao)
|
2155
|
+
else:
|
2156
|
+
retorno = f"Estado {cidade_cliente} não encontrado \nEtapas Executadas:\n{steps}"
|
2157
|
+
return RpaRetornoProcessoDTO(
|
2158
|
+
sucesso=False,
|
2159
|
+
retorno=retorno,
|
2160
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2161
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
2162
|
+
)
|
2163
|
+
main_window.set_focus()
|
2164
|
+
send_keys("%o")
|
2165
|
+
except Exception as e:
|
2166
|
+
retorno = f"Não foi possivel corrigir a tributação do itens na Janela Faturamento de Pré Venda, erro {e} \nEtapas Executadas:\n{steps}"
|
2167
|
+
return RpaRetornoProcessoDTO(
|
2168
|
+
sucesso=False,
|
2169
|
+
retorno=result,
|
2170
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2171
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
2172
|
+
)
|
2173
|
+
|
2174
|
+
|
2175
|
+
console.print("Processo de ajustar aliquota realizado com sucesso, adicionando a mensagem... \n")
|
2176
|
+
try:
|
2177
|
+
console.print("Conectando a janela de pre venda... \n")
|
2178
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
|
2179
|
+
main_window = app["TFrmDadosFaturamentoPreVenda"]
|
2180
|
+
main_window.set_focus()
|
2181
|
+
send_keys("%m")
|
2182
|
+
await worker_sleep(2)
|
2183
|
+
|
2184
|
+
mensagem_tab = pyautogui.locateOnScreen(ASSETS_PATH + "\\notas_saida\\icon_mensagem.png", confidence=0.7)
|
2185
|
+
if mensagem_tab:
|
2186
|
+
pyautogui.click(mensagem_tab)
|
2187
|
+
await worker_sleep(4)
|
2188
|
+
else:
|
2189
|
+
retorno = f"Não foi possivel localizar o campo 'Mensagem' \nEtapas Executadas:\n{steps}"
|
2190
|
+
return RpaRetornoProcessoDTO(
|
2191
|
+
sucesso=False,
|
2192
|
+
retorno=retorno,
|
2193
|
+
status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
2194
|
+
)
|
2195
|
+
|
2196
|
+
|
2197
|
+
panel_tab_sheet = main_window.child_window(class_name="TcxTabSheet", found_index=0)
|
2198
|
+
field_observacao = panel_tab_sheet.child_window(class_name="TDBIMemo", found_index=0)
|
2199
|
+
console.print(f"Mensagem a ser adicionada\n")
|
2200
|
+
text_campo_observacao = f"Nome do Motorista: {nota.get("nomeMotorista")} - Placa: {nota.get("placaClienteCorreto")} - Quilometragem do Veículo: {nota.get("quilometragemVeiculo")}"
|
2201
|
+
console.print(f"{text_campo_observacao}\n")
|
2202
|
+
field_observacao.click()
|
2203
|
+
await worker_sleep(2)
|
2204
|
+
pyautogui.write(text_campo_observacao)
|
2205
|
+
await worker_sleep(2)
|
2206
|
+
|
2207
|
+
try:
|
2208
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
|
2209
|
+
main_window = app["TFrmDadosFaturamentoPreVenda"]
|
2210
|
+
main_window.set_focus()
|
2211
|
+
btn_ok = main_window.child_window(class_name="TBitBtn", found_index=1)
|
2212
|
+
btn_ok.click()
|
2213
|
+
except:
|
2214
|
+
btn_ok = main_window.child_window(title="&Ok")
|
2215
|
+
btn_ok.click()
|
2216
|
+
await worker_sleep(5)
|
2217
|
+
|
2218
|
+
await worker_sleep(10)
|
2219
|
+
await find_warning_nop_divergence()
|
2220
|
+
await worker_sleep(2)
|
2221
|
+
warning_pop_up = await is_window_open("Warning")
|
2222
|
+
if warning_pop_up["IsOpened"] == True:
|
2223
|
+
console.print("possui Pop-up de Warning, analisando... \n")
|
2224
|
+
app = Application().connect(title="Warning")
|
2225
|
+
main_window = app["Warning"]
|
2226
|
+
await worker_sleep(2)
|
2227
|
+
main_window.set_focus()
|
2228
|
+
console.print("Clicando em OK, para andamento do processo...\n")
|
2229
|
+
btn_ok = main_window.child_window(title="OK", class_name="TButton")
|
2230
|
+
if btn_ok.exists() and btn_ok.is_enabled():
|
2231
|
+
btn_ok.click()
|
2232
|
+
#Este click pode ser desnecessário, é apanas uma garantia
|
2233
|
+
pyautogui.click(961, 562)
|
2234
|
+
await worker_sleep(2)
|
2235
|
+
else:
|
2236
|
+
log_msg = "Warning - Erro ao clicar em Ok, na tela de warning...\n"
|
2237
|
+
console.print(log_msg, style="bold red")
|
2238
|
+
return RpaRetornoProcessoDTO(
|
2239
|
+
sucesso=False, retorno=log_msg, status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
2240
|
+
)
|
2241
|
+
await worker_sleep(1)
|
2242
|
+
#SELECIONANDO O TIPO DE DOCUMENTO
|
2243
|
+
try:
|
2244
|
+
console.print("Conectando a janela de pre venda para colocar modelo \n")
|
2245
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=10)
|
2246
|
+
main_window = app["TFrmDadosFaturamentoPreVenda"]
|
2247
|
+
main_window.set_focus()
|
2248
|
+
send_keys("%p")
|
2249
|
+
await worker_sleep(2)
|
2250
|
+
|
2251
|
+
panel_TPage= main_window.child_window(class_name="TPageControl", found_index=0)
|
2252
|
+
panel_Ttabsheet= panel_TPage.child_window(class_name="TTabSheet", found_index=0)
|
2253
|
+
modelo_select = panel_Ttabsheet.child_window(class_name="TDBIComboBox", found_index=1)
|
2254
|
+
modelo_select.click()
|
2255
|
+
await worker_sleep(1)
|
2256
|
+
set_combobox("||List", "NFe - NOTA FISCAL ELETRONICA PROPRIA - DANFE SERIE 077")
|
2257
|
+
await worker_sleep(3)
|
2258
|
+
console.print("Verificando se o tipo de nota foi selecionado corretamente \n")
|
2259
|
+
modelo_select = panel_Ttabsheet.child_window(class_name="TDBIComboBox", found_index=1)
|
2260
|
+
tipo_selecionado = modelo_select.window_text()
|
2261
|
+
if "077" in tipo_selecionado.lower():
|
2262
|
+
console.print(f"Tipo de cobrança corretamente selecionado {tipo_selecionado}... \n")
|
2263
|
+
else:
|
2264
|
+
retorno = f"Não foi possivel selecionar o modelo do documento, tipo selecionado {tipo_selecionado}' \nEtapas Executadas:\n{steps}"
|
2265
|
+
return RpaRetornoProcessoDTO(
|
2266
|
+
sucesso=False,
|
2267
|
+
retorno=retorno,
|
2268
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2269
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
2270
|
+
)
|
2271
|
+
|
2272
|
+
main_window.set_focus()
|
2273
|
+
try:
|
2274
|
+
#Clcica no OK para seguir a transmissão da pré-venda
|
2275
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
|
2276
|
+
main_window = app["TFrmDadosFaturamentoPreVenda"]
|
2277
|
+
main_window.set_focus()
|
2278
|
+
btn_ok = main_window.child_window(class_name="TBitBtn", found_index=1)
|
2279
|
+
btn_ok.click()
|
2280
|
+
except:
|
2281
|
+
btn_ok = main_window.child_window(title="&Ok")
|
2282
|
+
btn_ok.click()
|
2283
|
+
await worker_sleep(5)
|
2284
|
+
|
2285
|
+
except Exception as e:
|
2286
|
+
retorno = f"Não foi possivel selecionar o modelo do documento {e}' \nEtapas Executadas:\n{steps}"
|
2287
|
+
return RpaRetornoProcessoDTO(
|
2288
|
+
sucesso=False,
|
2289
|
+
retorno=retorno,
|
2290
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2291
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
2292
|
+
)
|
2293
|
+
else:
|
2294
|
+
console.print("Não possui pop de Warning...\n")
|
2295
|
+
|
2296
|
+
|
2297
|
+
await find_warning_nop_divergence()
|
2298
|
+
await worker_sleep(2)
|
2299
|
+
#VERIFICANDO SE POSSUI POP UP WARNING
|
2300
|
+
console.print("Verificando a presença de Warning... \n")
|
2301
|
+
warning_boo = False
|
2302
|
+
try:
|
2303
|
+
try:
|
2304
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=30)
|
2305
|
+
main_window = app["Warning"]
|
2306
|
+
main_window.set_focus()
|
2307
|
+
except:
|
2308
|
+
console.print('Except')
|
2309
|
+
app = Application().connect(class_name="Warning", timeout=10)
|
2310
|
+
main_window = app["Warning"]
|
2311
|
+
main_window.set_focus()
|
2312
|
+
console.print("Possui Warning... \n")
|
2313
|
+
await find_warning_nop_divergence()
|
2314
|
+
btn_ok = main_window.child_window(class_name="TButton", found_index=0)
|
2315
|
+
btn_ok.click()
|
2316
|
+
await worker_sleep(3)
|
2317
|
+
warning_boo = True
|
2318
|
+
except:
|
2319
|
+
console.print("Não Possui Warning... \n")
|
2320
|
+
|
2321
|
+
|
2322
|
+
#ALTERANDO TRIBUTO DOS ITENS
|
2323
|
+
if warning_boo:
|
2324
|
+
try:
|
2325
|
+
console.print('Acessando a tela de Itens')
|
2326
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
|
2327
|
+
main_window = app["TFrmDadosFaturamentoPreVenda"]
|
2328
|
+
main_window.set_focus()
|
2329
|
+
send_keys("%i")
|
2330
|
+
await worker_sleep(2)
|
2331
|
+
send_keys("%g")
|
2332
|
+
await worker_sleep(2)
|
2333
|
+
|
2334
|
+
|
2335
|
+
console.print("Conectando para realizar a alteração da tributação do produto... \n")
|
2336
|
+
app = Application().connect(class_name="TFrmDadosTributacaoProdutoPreVenda", timeout=60)
|
2337
|
+
main_window = app["TFrmDadosTributacaoProdutoPreVenda"]
|
2338
|
+
|
2339
|
+
tpanel_dados_tributacao = main_window.child_window(class_name="TPanel", found_index=1)
|
2340
|
+
tributacao_icms_select = tpanel_dados_tributacao.child_window(class_name="TDBIComboBox", found_index=4)
|
2341
|
+
|
2342
|
+
|
2343
|
+
if not item_arla:
|
2344
|
+
console.print("Não é item Arla ajustando tributacao... \n")
|
2345
|
+
tributacao_icms_select.click()
|
2346
|
+
await worker_sleep(1)
|
2347
|
+
set_combobox("||List", "061 - 061- MONOFASICO")
|
2348
|
+
else:
|
2349
|
+
console.print("Item Arla buscando pela aliquota do estado... \n")
|
2350
|
+
aliquota = None
|
2351
|
+
for item in conconfig_aliquota_icms:
|
2352
|
+
if cidade_cliente in item["estado"]:
|
2353
|
+
aliquota = item["aliquota"]
|
2354
|
+
break
|
2355
|
+
|
2356
|
+
if aliquota:
|
2357
|
+
console.print(f"A alíquota para o estado {cidade_cliente} é: {aliquota}")
|
2358
|
+
tributacao_icms_select.click()
|
2359
|
+
await worker_sleep(1)
|
2360
|
+
tributacao = f"000 - 000- ICMS - {aliquota}%"
|
2361
|
+
set_combobox("||List", tributacao)
|
2362
|
+
else:
|
2363
|
+
retorno = f"Estado {cidade_cliente} não encontrado \nEtapas Executadas:\n{steps}"
|
2364
|
+
return RpaRetornoProcessoDTO(
|
2365
|
+
sucesso=False,
|
2366
|
+
retorno=retorno,
|
2367
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2368
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
2369
|
+
)
|
2370
|
+
main_window.set_focus()
|
2371
|
+
send_keys("%o")
|
2372
|
+
except Exception as e:
|
2373
|
+
retorno = f"Não foi possivel corrigir a tributação do itens na Janela Faturamento de Pré Venda, erro {e} \nEtapas Executadas:\n{steps}"
|
2374
|
+
return RpaRetornoProcessoDTO(
|
2375
|
+
sucesso=False,
|
2376
|
+
retorno=result,
|
2377
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2378
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
2379
|
+
)
|
2380
|
+
else:
|
2381
|
+
console.print("Não possui warning para alterar tributação... \n")
|
2382
|
+
|
2383
|
+
#ADICIONANDO MENSAGEM
|
2384
|
+
await worker_sleep(5)
|
2385
|
+
try:
|
2386
|
+
console.print("Identificando - TFrmDadosFaturamentoPreVenda 1")
|
2387
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=10)
|
2388
|
+
main_window = app["Confirm"]
|
2389
|
+
main_window.set_focus()
|
2390
|
+
except:
|
2391
|
+
console.print("Identificando - TMessageForm 1")
|
2392
|
+
app = Application().connect(class_name="TMessageForm", timeout=10, title='Confirm')
|
2393
|
+
main_window = app["TMessageForm"]
|
2394
|
+
main_window.set_focus()
|
2395
|
+
|
2396
|
+
btn_yes = main_window.child_window(class_name="TButton", title="&Yes")
|
2397
|
+
btn_yes.click()
|
2398
|
+
|
2399
|
+
await worker_sleep(5)
|
2400
|
+
|
2401
|
+
try:
|
2402
|
+
console.print('Identificando - TFrmDadosFaturamentoPreVenda 1')
|
2403
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=10)
|
2404
|
+
main_window = app["TMessageForm"]
|
2405
|
+
except Exception as ex:
|
2406
|
+
console.print(f'{ex} - TMessageForm 4')
|
2407
|
+
app = Application().connect(class_name="TMessageForm", timeout=10)
|
2408
|
+
main_window = app["TMessageForm"]
|
2409
|
+
|
2410
|
+
main_window.set_focus()
|
2411
|
+
send_keys("%i")
|
2412
|
+
await worker_sleep(15)
|
2413
|
+
|
2414
|
+
except Exception as e:
|
2415
|
+
retorno = f"Não foi possivel adicionar a 'Mensagem' na tela de Faturamento de pre venda, erro {e} \nEtapas Executadas:\n{steps}"
|
2416
|
+
return RpaRetornoProcessoDTO(
|
2417
|
+
sucesso=False,
|
2418
|
+
retorno=retorno,
|
2419
|
+
status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
2420
|
+
)
|
2421
|
+
|
2422
|
+
try:
|
2423
|
+
app = Application().connect(class_name="TFrmAguarde", timeout=60)
|
2424
|
+
main_window = app["TppPrintDialog"]
|
2425
|
+
tpanel_btn_ok = main_window.child_window(class_name="TPanel", found_index=1)
|
2426
|
+
btn_ok_print_screen = tpanel_btn_ok.child_window(class_name="TButton", found_index=1)
|
2427
|
+
btn_ok_print_screen.click()
|
2428
|
+
await worker_sleep(3)
|
2429
|
+
except Exception as e:
|
2430
|
+
retorno = f"Não foi encontrada a para a impressão da nova venda \nEtapas Executadas:\n{steps}"
|
2431
|
+
return RpaRetornoProcessoDTO(
|
2432
|
+
sucesso=False,
|
2433
|
+
retorno=result,
|
2434
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2435
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
2436
|
+
)
|
2437
|
+
|
2438
|
+
|
2439
|
+
console.print(f"NAVEGANDO NA TELA DE SALVAR RELATORIO\n")
|
2440
|
+
#INSERINDO O DIRETORIO E SALVANDO O ARQUIVO
|
2441
|
+
try:
|
2442
|
+
app = Application().connect(title="Salvar Saída de Impressão como")
|
2443
|
+
main_window = app["Dialog"]
|
2444
|
+
console.print("Tela 'Salvar' encontrada!")
|
2445
|
+
|
2446
|
+
console.print("Interagindo com a tela 'Salvar'...\n")
|
2447
|
+
username = getpass.getuser()
|
2448
|
+
path_to_txt = f"C:\\Users\\{username}\\Downloads\\NOVA VENDA {numero_cupom_fiscal}"
|
2449
|
+
|
2450
|
+
main_window.type_keys("%n")
|
2451
|
+
pyautogui.write(path_to_txt)
|
2452
|
+
await worker_sleep(1)
|
2453
|
+
main_window.type_keys("%l")
|
2454
|
+
console.print("Arquivo salvo com sucesso...\n")
|
2455
|
+
await worker_sleep(8)
|
2456
|
+
except Exception as e:
|
2457
|
+
retorno = f"Não foi salvar o arquivo com a nova venda, erro {e} \nEtapas Executadas:\n{steps}"
|
2458
|
+
return RpaRetornoProcessoDTO(
|
2459
|
+
sucesso=False,
|
2460
|
+
retorno=result,
|
2461
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2462
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
2463
|
+
)
|
2464
|
+
|
2465
|
+
with open(f"{path_to_txt}.pdf", 'rb') as file:
|
2466
|
+
file_bytes = io.BytesIO(file.read())
|
2467
|
+
|
2468
|
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
2469
|
+
desArquivo = f"NOVA VENDA {numero_cupom_fiscal}.pdf"
|
2470
|
+
try:
|
2471
|
+
await send_file(historico_id, desArquivo, "pdf", file_bytes, file_extension="pdf")
|
2472
|
+
os.remove(f"{path_to_txt}.pdf")
|
2473
|
+
except Exception as e:
|
2474
|
+
result = f"Arquivo NOVA VENDA 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} !"
|
2475
|
+
console.print(result, style="bold red")
|
2476
|
+
return RpaRetornoProcessoDTO(
|
2477
|
+
sucesso=False,
|
2478
|
+
retorno=result,
|
2479
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2480
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
2481
|
+
)
|
2482
|
+
|
2483
|
+
information_pop_up = await is_window_open("Information")
|
2484
|
+
if information_pop_up["IsOpened"] == True:
|
2485
|
+
app = Application().connect(title="Information", timeout=30)
|
2486
|
+
main_window = app["Information"]
|
2487
|
+
main_window.set_focus()
|
2488
|
+
btn_ok = main_window.child_window(class_name="TButton", found_index=0)
|
2489
|
+
btn_ok.click()
|
2490
|
+
|
2491
|
+
|
2492
|
+
try:
|
2493
|
+
app = Application().connect(class_name="TFrmProcessamentoFEe2", timeout=10)
|
2494
|
+
main_window = app["TFrmProcessamentoFEe2"]
|
2495
|
+
main_window.close()
|
2496
|
+
except Exception as e:
|
2497
|
+
console.print("Janela TFrmDadosFaturamentoPreVenda ja fechada")
|
2498
|
+
|
2499
|
+
|
2500
|
+
await worker_sleep(5)
|
2501
|
+
is_confirm_pop_up = False
|
2502
|
+
try:
|
2503
|
+
app = Application().connect(class_name="TFrmGerenciadorNFe2", timeout=10)
|
2504
|
+
main_window = app["Confirm"]
|
2505
|
+
is_confirm_pop_up = True
|
2506
|
+
except:
|
2507
|
+
pass
|
2508
|
+
|
2509
|
+
|
2510
|
+
if is_confirm_pop_up == True:
|
2511
|
+
msg_text = await ocr_by_class(numero_cupom_fiscal,"TFrmGerenciadorNFe2", "Confirm")
|
2512
|
+
if 'imprimir' in msg_text.retorno.lower():
|
2513
|
+
app = Application().connect(class_name="TFrmGerenciadorNFe2", timeout=10)
|
2514
|
+
main_window = app["Confirm"]
|
2515
|
+
main_window.set_focus()
|
2516
|
+
send_keys("%n")
|
2517
|
+
|
2518
|
+
|
2519
|
+
#Fechar telas Antes de fazer nova pesquisa
|
2520
|
+
await worker_sleep(10)
|
2521
|
+
try:
|
2522
|
+
app = Application().connect(class_name="TFrmProcessamentoNFe2", timeout=10)
|
2523
|
+
window_lancando_nota = app["TFrmProcessamentoNFe2"]
|
2524
|
+
window_lancando_nota.set_focus()
|
2525
|
+
fechar_tela_processamento = "assets\\emsys\\button_fechar.PNG"
|
2526
|
+
try:
|
2527
|
+
button_location = pyautogui.locateCenterOnScreen(
|
2528
|
+
fechar_tela_processamento, confidence=0.6
|
2529
|
+
)
|
2530
|
+
if button_location:
|
2531
|
+
pyautogui.click(button_location)
|
2532
|
+
console.print("Botão 'Fechar' clicado com sucesso!")
|
2533
|
+
except pyautogui.ImageNotFoundException:
|
2534
|
+
window_rect = main_window.rectangle()
|
2535
|
+
console.print(f"Area que sera utulizada para o recorte {window_rect}...\n")
|
2536
|
+
try:
|
2537
|
+
button_location = pyautogui.locateCenterOnScreen(
|
2538
|
+
fechar_tela_processamento,
|
2539
|
+
region=(
|
2540
|
+
window_rect.left,
|
2541
|
+
window_rect.top,
|
2542
|
+
window_rect.width(),
|
2543
|
+
window_rect.height(),
|
2544
|
+
),
|
2545
|
+
)
|
2546
|
+
if button_location:
|
2547
|
+
button_location = (
|
2548
|
+
button_location.x + window_rect.left,
|
2549
|
+
button_location.y + window_rect.top,
|
2550
|
+
)
|
2551
|
+
console.print(
|
2552
|
+
f"Botão encontrado nas coordenadas: {button_location}"
|
2553
|
+
)
|
2554
|
+
pyautogui.click(button_location)
|
2555
|
+
await worker_sleep(10)
|
2556
|
+
except pyautogui.ImageNotFoundException:
|
2557
|
+
retorno = f"Não foi possivel fechar a tela de processamento, Error: {e} \nEtapas Executadas:\n{steps}"
|
2558
|
+
console.print(f"Não foi possivel fechar a tela de processamento, Error: {e}...\n tentando inserir via posição...\n")
|
2559
|
+
return RpaRetornoProcessoDTO(
|
2560
|
+
sucesso=False,
|
2561
|
+
retorno=retorno,
|
2562
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2563
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
2564
|
+
)
|
2565
|
+
except Exception as e:
|
2566
|
+
retorno = f"Não foi possivel fechar a tela de processamento, Error:{e} \nEtapas Executadas:\n{steps}"
|
2567
|
+
console.print(f"Não foi possivel fechar a tela de processamento, Error:{e}...\n tentando inserir via posição...\n")
|
2568
|
+
return RpaRetornoProcessoDTO(
|
2569
|
+
sucesso=False,
|
2570
|
+
retorno=retorno,
|
2571
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2572
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
2573
|
+
)
|
2574
|
+
except:
|
2575
|
+
console.print("Janela TFrmProcessamentoNFe2 ja fechada")
|
2576
|
+
|
2577
|
+
await worker_sleep(10)
|
2578
|
+
console.print("Verificando se possui pop-up imprimir boleta")
|
2579
|
+
boleta_screen = await is_window_open("Confirm")
|
2580
|
+
if boleta_screen["IsOpened"] == True:
|
2581
|
+
console.print("Janela aberta, fechando")
|
2582
|
+
try:
|
2583
|
+
console.print("Confirm")
|
2584
|
+
app = Application().connect(title="Confirm", timeout=10)
|
2585
|
+
main_window = app["Confirm"]
|
2586
|
+
main_window.set_focus()
|
2587
|
+
except:
|
2588
|
+
console.print("Identificando - TMessageForm 5")
|
2589
|
+
app = Application().connect(class_name="TMessageForm", timeout=10, title='Confirm')
|
2590
|
+
main_window = app["TMessageForm"]
|
2591
|
+
main_window.set_focus()
|
2592
|
+
|
2593
|
+
btn_no = main_window.child_window(class_name="TButton", title="&No")
|
2594
|
+
btn_no.click()
|
2595
|
+
|
2596
|
+
|
2597
|
+
await worker_sleep(7)
|
2598
|
+
erro_screen = await is_window_open_by_class("TFrmDadosFaturamentoPreVenda","Confirm")
|
2599
|
+
if erro_screen["IsOpened"] == True:
|
2600
|
+
console.print("Janela aberta, fechando")
|
2601
|
+
try:
|
2602
|
+
console.print("Identificando - TFrmDadosFaturamentoPreVenda 2")
|
2603
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=10)
|
2604
|
+
main_window = app["Confirm"]
|
2605
|
+
main_window.set_focus()
|
2606
|
+
except:
|
2607
|
+
console.print("Identificando - TMessageForm 3")
|
2608
|
+
app = Application().connect(class_name="TMessageForm", timeout=10, title='Confirm')
|
2609
|
+
main_window = app["TMessageForm"]
|
2610
|
+
main_window.set_focus()
|
2611
|
+
|
2612
|
+
btn_no = main_window.child_window(class_name="TButton", title="&No")
|
2613
|
+
btn_no.click()
|
2614
|
+
|
2615
|
+
|
2616
|
+
await worker_sleep(10)
|
2617
|
+
console.print("Verificando se a tela de Mensagem esta aberta")
|
2618
|
+
erro_screen = await is_window_open_by_class("TMemo","TMemo")
|
2619
|
+
if erro_screen["IsOpened"] == True:
|
2620
|
+
console.print("Janela aberta, fechando")
|
2621
|
+
app = Application().connect(class_name="TMemo", timeout=10)
|
2622
|
+
main_window = app["TMemo"]
|
2623
|
+
main_window.set_focus()
|
2624
|
+
await worker_sleep(5)
|
2625
|
+
main_window.close()
|
2626
|
+
|
2627
|
+
await worker_sleep(5)
|
2628
|
+
console.print("Verificando se a tela de Faturamento Pre venda esta aberta")
|
2629
|
+
close_dados_faturamento = await is_window_open_by_class("TFrmDadosFaturamentoPreVenda","TFrmDadosFaturamentoPreVenda")
|
2630
|
+
if close_dados_faturamento["IsOpened"] == True:
|
2631
|
+
console.print("Janela aberta, fechando")
|
2632
|
+
try:
|
2633
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
|
2634
|
+
main_window = app["TFrmDadosFaturamentoPreVenda"]
|
2635
|
+
main_window.set_focus()
|
2636
|
+
btn_cancelar = main_window.child_window(class_name="TBitBtn", found_index=0)
|
2637
|
+
btn_cancelar.click()
|
2638
|
+
except:
|
2639
|
+
btn_cancelar = main_window.child_window(title="&Cancela")
|
2640
|
+
btn_cancelar.click()
|
2641
|
+
|
2642
|
+
|
2643
|
+
await worker_sleep(10)
|
2644
|
+
console.print("Verificando se a tela de Faturamento Pre venda esta aberta")
|
2645
|
+
close_dados_faturamento = await is_window_open_by_class("TFrmDadosFaturamentoPreVenda","TFrmDadosFaturamentoPreVenda")
|
2646
|
+
if close_dados_faturamento["IsOpened"] == True:
|
2647
|
+
console.print("Janela aberta, fechando")
|
2648
|
+
try:
|
2649
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=180)
|
2650
|
+
main_window = app["TFrmDadosFaturamentoPreVenda"]
|
2651
|
+
main_window.set_focus()
|
2652
|
+
await worker_sleep(2)
|
2653
|
+
main_window.close()
|
2654
|
+
except Exception as e:
|
2655
|
+
console.print(f"Erro ao fechar a janela de dados faturamento pre venda {e}")
|
2656
|
+
|
2657
|
+
|
2658
|
+
await worker_sleep(10)
|
2659
|
+
console.print("Verificando se a tela de Gerenciador esta aberta")
|
2660
|
+
window_gerenciador_screen = await is_window_open_by_class("TFrmGerenciadorNFe2","TFrmGerenciadorNFe2")
|
2661
|
+
if window_gerenciador_screen["IsOpened"] == True:
|
2662
|
+
app = Application().connect(class_name="TFrmGerenciadorNFe2", timeout=10)
|
2663
|
+
window_gerenciador = app["TFrmGerenciadorNFe2"]
|
2664
|
+
window_gerenciador.set_focus()
|
2665
|
+
await worker_sleep(2)
|
2666
|
+
window_gerenciador.close()
|
2667
|
+
else:
|
2668
|
+
console.print("Janela TFrmGerenciadorNFe2 ja fechada")
|
2669
|
+
|
2670
|
+
|
2671
|
+
await worker_sleep(10)
|
2672
|
+
console.print("Verificando se a tela de Pre venda esta aberta")
|
2673
|
+
window_gerenciador_screen = await is_window_open_by_class("TFrmPreVenda","TFrmPreVenda")
|
2674
|
+
if window_gerenciador_screen["IsOpened"] == True:
|
2675
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=10)
|
2676
|
+
window_gerenciador = app["TFrmPreVenda"]
|
2677
|
+
window_gerenciador.set_focus()
|
2678
|
+
await worker_sleep(2)
|
2679
|
+
window_gerenciador.close()
|
2680
|
+
else:
|
2681
|
+
console.print("Janela TFrmPreVenda ja fechada")
|
2682
|
+
else:
|
2683
|
+
console.print("Não é combustivel")
|
2684
|
+
|
2685
|
+
|
2686
|
+
except Exception as e:
|
2687
|
+
retorno = f"Não foi possivel concluir o processo de pré venda {e} \nEtapas Executadas:\n{steps}"
|
2688
|
+
return RpaRetornoProcessoDTO(
|
2689
|
+
sucesso=False,
|
2690
|
+
retorno=retorno,
|
2691
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2692
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
2693
|
+
)
|
2694
|
+
else:
|
2695
|
+
retorno = f"{preenchimento_header_pre_venda.retorno} \nEtapas Executadas:\n{steps}"
|
2696
|
+
return RpaRetornoProcessoDTO(
|
2697
|
+
sucesso=False,
|
2698
|
+
retorno=retorno,
|
2699
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2700
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
2701
|
+
)
|
2702
|
+
else:
|
2703
|
+
console.print(f"\nPesquisa: 'Não possui item para nota separada",style="bold green")
|
2704
|
+
|
2705
|
+
|
2706
|
+
if len(itens_nota_conjunta) > 0:
|
2707
|
+
console.print(itens_nota_conjunta)
|
2708
|
+
type_text_into_field("Cadastro Pré venda", app["TFrmMenuPrincipal"]["Edit"], True, "50")
|
2709
|
+
pyautogui.press("enter")
|
2710
|
+
await worker_sleep(2)
|
2711
|
+
pyautogui.press("enter")
|
2712
|
+
await worker_sleep(4)
|
2713
|
+
console.print(f"\nPesquisa: 'Cadastro Pré venda' realizada com sucesso",style="bold green")
|
2714
|
+
cadastro_pre_venda = await is_window_open_by_class("TFrmPreVenda", "TFrmPreVenda")
|
2715
|
+
if not item_arla:
|
2716
|
+
preenchimento_header_pre_venda = await cadastro_pre_venda_header("5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC", cod_cliente_correto, "A VISTA", "5656 - VENDA DE COMB OU LUB ADQ DE TERCEIRO C/ FIN S/ ESTOQUE")
|
2717
|
+
else:
|
2718
|
+
#PRECISA DO ESPAÇO NO FINAL!!!
|
2719
|
+
preenchimento_header_pre_venda = await cadastro_pre_venda_header("5102 - VENDA MERCAD. ADQ. DE TERCEIRO- 5.102 S/ ESTOQ C/ FINAN ", cod_cliente_correto, "A VISTA", "5102 - VENDA MERCAD. ADQ. DE TERCEIRO- 5.102 S/ESTOQ C/ FINAN FE")
|
2720
|
+
#preenchimento_header_pre_venda = await cadastro_pre_venda_header("5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC", cod_cliente_correto, "A VISTA", "5656 - VENDA DE COMB OU LUB ADQ DE TERCEIRO C/ FIN S/ ESTOQUE")
|
2721
|
+
|
2722
|
+
if preenchimento_header_pre_venda.sucesso:
|
2723
|
+
try:
|
2724
|
+
cidade_cliente = preenchimento_header_pre_venda.retorno
|
2725
|
+
console.print(f"\nPreenchimento cabeçalho da pre venda preenchido com sucesso, seguindo com o processo.. ",style="bold green")
|
2726
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=60)
|
2727
|
+
main_window = app["TFrmPreVenda"]
|
2728
|
+
main_window.set_focus()
|
2729
|
+
|
2730
|
+
console.print("Navegando nos elementos...\n")
|
2731
|
+
panel_TPage= main_window.child_window(class_name="TPage", found_index=0)
|
2732
|
+
panel_menu_itens= main_window.child_window(class_name="TcxCustomInnerTreeView", found_index=0)
|
2733
|
+
|
2734
|
+
console.print("Acessando a janela de Itens...\n")
|
2735
|
+
panel_menu_itens.click()
|
2736
|
+
await worker_sleep(1)
|
2737
|
+
pyautogui.press('home')
|
2738
|
+
await worker_sleep(1)
|
2739
|
+
pyautogui.press('down')
|
2740
|
+
#console.print(nota.get('itens'))
|
2741
|
+
item_devolvido = ''
|
2742
|
+
|
2743
|
+
#FOR ITENS ENTRADA BACKOFFICE - Nota Conjunta
|
2744
|
+
for item in itens_nota_conjunta:
|
2745
|
+
quantidade = item['novaQuantidade']
|
2746
|
+
preco = item['novoPreco']
|
2747
|
+
descricao = item['descricao']
|
2748
|
+
descricao = 'Diesel Comum' if descricao == 'Diesel S500' else descricao
|
2749
|
+
quantidade = str(quantidade)
|
2750
|
+
preco = str(preco)
|
2751
|
+
#descricao = descricao.replace(".",",")
|
2752
|
+
console.print(quantidade, preco, descricao)
|
2753
|
+
item_devolvido = descricao
|
2754
|
+
|
2755
|
+
if 'arla' in descricao.lower():
|
2756
|
+
item_arla = True
|
2757
|
+
|
2758
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=60)
|
2759
|
+
main_window = app["TFrmPreVenda"]
|
2760
|
+
main_window.set_focus()
|
2761
|
+
|
2762
|
+
console.print("Itens acessado com sucesso, clicando em Incluir...\n")
|
2763
|
+
panel_TGroup_Box= panel_TPage.child_window(class_name="TGroupBox", found_index=0)
|
2764
|
+
btn_incluir = panel_TGroup_Box.child_window(class_name="TDBIBitBtn", found_index=4)
|
2765
|
+
btn_incluir.click()
|
2766
|
+
await worker_sleep(2)
|
2767
|
+
console.print("Incluir clicado com sucesso...\n")
|
2768
|
+
|
2769
|
+
#VERIFICANDO A EXISTENCIA DE WARNINGS
|
2770
|
+
console.print("Verificando a existência de Warning... \n")
|
2771
|
+
warning_pop_up = await is_window_open("Warning")
|
2772
|
+
if warning_pop_up["IsOpened"] == True:
|
2773
|
+
console.print("possui Pop-up de Warning, analisando... \n")
|
2774
|
+
ocr_pop_warning = await ocr_warnings(numero_cupom_fiscal)
|
2775
|
+
if ocr_pop_warning.sucesso == True:
|
2776
|
+
return RpaRetornoProcessoDTO(
|
2777
|
+
sucesso=False,
|
2778
|
+
retorno=f"POP UP Warning não mapeado para seguimento do processo, mensagem: {ocr_pop_warning.retorno}",
|
2779
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2780
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
2781
|
+
)
|
2782
|
+
else:
|
2783
|
+
return RpaRetornoProcessoDTO(
|
2784
|
+
sucesso=False,
|
2785
|
+
retorno=f"POP UP Warning não mapeado para seguimento do processo",
|
2786
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2787
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
2788
|
+
)
|
2789
|
+
|
2790
|
+
|
2791
|
+
i = 0
|
2792
|
+
while i < 7:
|
2793
|
+
try:
|
2794
|
+
console.print("Clicando sobre a lupa para inserir o almoxarifado...\n")
|
2795
|
+
app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=130)
|
2796
|
+
main_window = app["TFrmIncluiItemPreVenda"]
|
2797
|
+
main_window.set_focus()
|
2798
|
+
panel_TGroup_Box= main_window.child_window(class_name="TPanel", found_index=2)
|
2799
|
+
lupa_almoxarifaco = panel_TGroup_Box.child_window(class_name="TDBIBitBtn", found_index=1)
|
2800
|
+
lupa_almoxarifaco.click()
|
2801
|
+
console.print("Lupa clicado com sucesso inserindo a descrição do almoxarifado...\n")
|
2802
|
+
await worker_sleep(2)
|
2803
|
+
|
2804
|
+
dialog_buscar = await is_window_open_by_class("TfrmDialogBuscaGeral", "TfrmDialogBuscaGeral")
|
2805
|
+
if dialog_buscar["IsOpened"] == True:
|
2806
|
+
break
|
2807
|
+
else:
|
2808
|
+
console.print("Não foi possivel abrir a janela de Busca Geral")
|
2809
|
+
i = i+1
|
2810
|
+
except Exception as e:
|
2811
|
+
console.print(f"Erro ao abrir a janela de Busca Geral: {e}")
|
2812
|
+
i = i+1
|
2813
|
+
|
2814
|
+
|
2815
|
+
if i == 7:
|
2816
|
+
retorno = f"Não foi possivel abrir a tela para buscar pelo item do produto na seleção do almoxarifado - \nEtapas Executadas:\n{steps}"
|
2817
|
+
return RpaRetornoProcessoDTO(
|
2818
|
+
sucesso=False,
|
2819
|
+
retorno=retorno,
|
2820
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2821
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
2822
|
+
)
|
2823
|
+
|
2824
|
+
app = Application().connect(class_name="TfrmDialogBuscaGeral", timeout=60)
|
2825
|
+
main_window = app["TfrmDialogBuscaGeral"]
|
2826
|
+
main_window.set_focus()
|
2827
|
+
|
2828
|
+
console.print("Buscando a mercadoria baseado na descrição...\n")
|
2829
|
+
rect = main_window.rectangle()
|
2830
|
+
center_x = (rect.left + rect.right) // 2
|
2831
|
+
center_y = (rect.top + rect.bottom) // 2
|
2832
|
+
|
2833
|
+
#pyautogui.moveTo(center_x, center_y)
|
2834
|
+
await worker_sleep(1)
|
2835
|
+
pyautogui.click(center_x, center_y)
|
2836
|
+
await worker_sleep(1)
|
2837
|
+
send_keys("^({HOME})")
|
2838
|
+
item_arla_founded = False
|
2839
|
+
|
2840
|
+
last_line = ''
|
2841
|
+
max_attempts = 12
|
2842
|
+
attempts = 0
|
2843
|
+
|
2844
|
+
while attempts < max_attempts:
|
2845
|
+
with pyautogui.hold('ctrl'):
|
2846
|
+
pyautogui.press('c')
|
2847
|
+
await worker_sleep(1)
|
2848
|
+
with pyautogui.hold('ctrl'):
|
2849
|
+
pyautogui.press('c')
|
2850
|
+
|
2851
|
+
win32clipboard.OpenClipboard()
|
2852
|
+
descricao_item = win32clipboard.GetClipboardData().strip()
|
2853
|
+
win32clipboard.CloseClipboard()
|
2854
|
+
|
2855
|
+
if last_line == descricao_item:
|
2856
|
+
if item_arla:
|
2857
|
+
main_window.set_focus()
|
2858
|
+
send_keys("%r")
|
2859
|
+
await worker_sleep(1)
|
2860
|
+
|
2861
|
+
app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=60)
|
2862
|
+
main_window = app["TFrmIncluiItemPreVenda"]
|
2863
|
+
main_window.set_focus()
|
2864
|
+
panel_TGroup_Box= main_window.child_window(class_name="TPanel", found_index=2)
|
2865
|
+
almoxarificado_index = panel_TGroup_Box.child_window(class_name="TDBIEditNumber", found_index=1)
|
2866
|
+
cod_almoxarificado = str(cod_empresa)+"50"
|
2867
|
+
almoxarificado_index.click()
|
2868
|
+
await worker_sleep(1)
|
2869
|
+
for _ in range(5):
|
2870
|
+
pyautogui.press("del")
|
2871
|
+
pyautogui.press("backspace")
|
2872
|
+
await worker_sleep(1)
|
2873
|
+
pyautogui.write(str(cod_almoxarificado))
|
2874
|
+
pyautogui.press('tab')
|
2875
|
+
await worker_sleep(1)
|
2876
|
+
|
2877
|
+
cod_item_index = panel_TGroup_Box.child_window(class_name="TDBIEditNumber", found_index=0)
|
2878
|
+
cod_item_index.click()
|
2879
|
+
await worker_sleep(1)
|
2880
|
+
for _ in range(5):
|
2881
|
+
pyautogui.press("del")
|
2882
|
+
pyautogui.press("backspace")
|
2883
|
+
await worker_sleep(1)
|
2884
|
+
pyautogui.write("1420")
|
2885
|
+
pyautogui.press('tab')
|
2886
|
+
await worker_sleep(1)
|
2887
|
+
break
|
2888
|
+
else:
|
2889
|
+
retorno = f"Todos os itens percorridos e não foi possivel encontrar a descrição condizente a {descricao} \nEtapas Executadas:\n{steps}"
|
2890
|
+
return RpaRetornoProcessoDTO(
|
2891
|
+
sucesso=False,
|
2892
|
+
retorno=retorno,
|
2893
|
+
status=RpaHistoricoStatusEnum.Falha,
|
2894
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
2895
|
+
)
|
2896
|
+
else:
|
2897
|
+
if descricao.lower() in descricao_item.lower():
|
2898
|
+
item_arla_founded = True
|
2899
|
+
main_window.set_focus()
|
2900
|
+
send_keys("%o")
|
2901
|
+
break
|
2902
|
+
else:
|
2903
|
+
last_line = descricao_item
|
2904
|
+
pyautogui.press('down')
|
2905
|
+
|
2906
|
+
|
2907
|
+
await worker_sleep(10)
|
2908
|
+
console.print("Processo finalizado com sucesso, seguindo com a seleção da natureza...\n")
|
2909
|
+
|
2910
|
+
app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=60)
|
2911
|
+
main_window = app["TFrmIncluiItemPreVenda"]
|
2912
|
+
main_window.set_focus()
|
2913
|
+
panel_TGroup_Box= main_window.child_window(class_name="TPanel", found_index=2)
|
2914
|
+
natureza_oper_select = panel_TGroup_Box.child_window(class_name="TDBIComboBox", found_index=0)
|
2915
|
+
# natureza_oper_select.click()
|
2916
|
+
|
2917
|
+
console.print(f"É item arla: {item_arla}")
|
2918
|
+
try:
|
2919
|
+
if item_arla:
|
2920
|
+
#PRECISA DO ESPAÇO NO FINAL!!!
|
2921
|
+
console.print("Selecionando NOP do item: '5102 - VENDA MERCAD. ADQ. DE TERCEIRO- 5.102 S/ ESTOQ C/ FINAN '")
|
2922
|
+
natureza_oper_select.select("5102 - VENDA MERCAD. ADQ. DE TERCEIRO- 5.102 S/ ESTOQ C/ FINAN ")
|
2923
|
+
else:
|
2924
|
+
console.print("Selecionando NOP do item: '5656 - VENDA DE COMB OU LUB ADQ DE TERCEIRO C/ FIN S/ ESTOQUE'")
|
2925
|
+
natureza_oper_select.select("5656 - VENDA DE COMB OU LUB ADQ DE TERCEIRO C/ FIN S/ ESTOQUE")
|
2926
|
+
except:
|
2927
|
+
if item_arla:
|
2928
|
+
console.print("Selecionando NOP: '5102 - VENDA MERCAD. ADQ. DE TERCEIRO- 5.102 S/ ESTOQ C/ FINAN FE'")
|
2929
|
+
natureza_oper_select.select("5102 - VENDA MERCAD. ADQ. DE TERCEIRO- 5.102 S/ ESTOQ C/ FINAN FE")
|
2930
|
+
else:
|
2931
|
+
console.print("Selecionando NOP: '5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC'")
|
2932
|
+
natureza_oper_select.select("5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC")
|
2933
|
+
|
2934
|
+
# console.print("Selecionando NOP: '5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC'")
|
2935
|
+
# natureza_oper_select.select("5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC")
|
2936
|
+
|
2937
|
+
|
2938
|
+
await worker_sleep(3)
|
2939
|
+
console.print("Natureza da operação selecionado com sucesso, preenchendo os itens...\n")
|
2940
|
+
|
2941
|
+
#INSERINDO A QUANTIDADE
|
2942
|
+
main_window.set_focus()
|
2943
|
+
panel_TPage_Control= main_window.child_window(class_name="TcxPageControl", found_index=0)
|
2944
|
+
panel_tabSheet = panel_TPage_Control.child_window(class_name="TcxTabSheet", found_index=0)
|
2945
|
+
|
2946
|
+
field_quantidade = panel_tabSheet.child_window(class_name="TDBIEditNumber", found_index=8)
|
2947
|
+
console.print("Inserindo a quantidade de Itens...\n")
|
2948
|
+
field_quantidade.click()
|
2949
|
+
await worker_sleep(1)
|
2950
|
+
pyautogui.press('del')
|
2951
|
+
await worker_sleep(1)
|
2952
|
+
pyautogui.press('backspace')
|
2953
|
+
await worker_sleep(1)
|
2954
|
+
pyautogui.write(quantidade)
|
2955
|
+
#field_quantidade.set_edit_text(quantidade)
|
2956
|
+
await worker_sleep(1)
|
2957
|
+
pyautogui.press('tab')
|
2958
|
+
await worker_sleep(2)
|
2959
|
+
|
2960
|
+
#INSERINDO O VALOR INDIVIDUAL DO ITEM
|
2961
|
+
console.print("Inserindo o valor indivual do Item...\n")
|
2962
|
+
i = 0
|
2963
|
+
while i < 3:
|
2964
|
+
btn_valor_unitario = panel_tabSheet.child_window(class_name="TDBIBitBtn", found_index=0)
|
2965
|
+
btn_valor_unitario.click()
|
2966
|
+
console.print("Garantindo o click em valor individual")
|
2967
|
+
pyautogui.click(973, 658)
|
2968
|
+
await worker_sleep(3)
|
2969
|
+
|
2970
|
+
caixa_valor_aberta = await is_window_open_by_class("TFrmInputBoxNumero", "TFrmInputBoxNumero")
|
2971
|
+
if caixa_valor_aberta["IsOpened"] == True:
|
2972
|
+
break
|
2973
|
+
else:
|
2974
|
+
i = i + 1
|
2975
|
+
|
2976
|
+
|
2977
|
+
console.print("Conectado a caixa para inserir o valor ")
|
2978
|
+
app = Application().connect(class_name="TFrmInputBoxNumero", timeout=60)
|
2979
|
+
main_window = app["TFrmInputBoxNumero"]
|
2980
|
+
main_window.set_focus()
|
2981
|
+
console.print("Caixa para inserir o valor conectada corretamento ")
|
2982
|
+
|
2983
|
+
|
2984
|
+
field_valor = main_window.child_window(class_name="TDBIEditNumber", found_index=0)
|
2985
|
+
field_valor.click()
|
2986
|
+
await worker_sleep(1)
|
2987
|
+
for _ in range(10):
|
2988
|
+
pyautogui.press("del")
|
2989
|
+
pyautogui.press("backspace")
|
2990
|
+
pyautogui.write(preco)
|
2991
|
+
#field_valor.set_edit_text(preco)
|
2992
|
+
await worker_sleep(2)
|
2993
|
+
|
2994
|
+
main_window.set_focus()
|
2995
|
+
send_keys("%o")
|
2996
|
+
await worker_sleep(2)
|
2997
|
+
console.print("Valor inserido com sucesso...\n")
|
2998
|
+
|
2999
|
+
app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=60)
|
3000
|
+
main_window = app["TFrmIncluiItemPreVenda"]
|
3001
|
+
main_window.set_focus()
|
3002
|
+
send_keys("%i")
|
3003
|
+
await worker_sleep(2)
|
3004
|
+
#Divergencia de nop na capa e no item
|
3005
|
+
await find_nop_divergence()
|
3006
|
+
await worker_sleep(5)
|
3007
|
+
main_window.close()
|
3008
|
+
await worker_sleep(5) #FIM DO LOOP ITENS NOTA CONJUNTA
|
3009
|
+
|
3010
|
+
|
3011
|
+
#FOR OUTROS ITENS NOTA
|
3012
|
+
# for item in itens_nota:
|
3013
|
+
# quantidade = item['quantidade']
|
3014
|
+
# preco = item['valor_unitario']
|
3015
|
+
# descricao = item['descricao']
|
3016
|
+
# descricao = 'Diesel Comum' if descricao == 'Diesel S500' else descricao
|
3017
|
+
# item_cod = item['codigo']
|
3018
|
+
# #descricao = descricao.replace(".",",")
|
3019
|
+
|
3020
|
+
# if 'arla' in descricao.lower():
|
3021
|
+
# item_arla = True
|
3022
|
+
# continue #continue para pular o item arla
|
3023
|
+
|
3024
|
+
# console.print(quantidade, preco, descricao)
|
3025
|
+
|
3026
|
+
# app = Application().connect(class_name="TFrmPreVenda", timeout=60)
|
3027
|
+
# main_window = app["TFrmPreVenda"]
|
3028
|
+
# main_window.set_focus()
|
3029
|
+
|
3030
|
+
# console.print("Itens acessado com sucesso, clicando em Incluir...\n")
|
3031
|
+
# panel_TGroup_Box= panel_TPage.child_window(class_name="TGroupBox", found_index=0)
|
3032
|
+
# btn_incluir = panel_TGroup_Box.child_window(class_name="TDBIBitBtn", found_index=4)
|
3033
|
+
# btn_incluir.click()
|
3034
|
+
# await worker_sleep(5)
|
3035
|
+
# console.print("Incluir clicado com sucesso...\n")
|
3036
|
+
|
3037
|
+
# #VERIFICANDO A EXISTENCIA DE WARNINGS
|
3038
|
+
# console.print("Verificando a existência de Warning... \n")
|
3039
|
+
# warning_pop_up = await is_window_open("Warning")
|
3040
|
+
# if warning_pop_up["IsOpened"] == True:
|
3041
|
+
# console.print("possui Pop-up de Warning, analisando... \n")
|
3042
|
+
# ocr_pop_warning = await ocr_warnings(numero_cupom_fiscal)
|
3043
|
+
# if ocr_pop_warning.sucesso == True:
|
3044
|
+
# return RpaRetornoProcessoDTO(
|
3045
|
+
# sucesso=False,
|
3046
|
+
# retorno=f"POP UP Warning não mapeado para seguimento do processo, mensagem: {ocr_pop_warning.retorno}",
|
3047
|
+
# status=RpaHistoricoStatusEnum.Falha,
|
3048
|
+
# tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
3049
|
+
# )
|
3050
|
+
# else:
|
3051
|
+
# return RpaRetornoProcessoDTO(
|
3052
|
+
# sucesso=False,
|
3053
|
+
# retorno=f"POP UP Warning não mapeado para seguimento do processo",
|
3054
|
+
# status=RpaHistoricoStatusEnum.Falha,
|
3055
|
+
# tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
3056
|
+
# )
|
3057
|
+
|
3058
|
+
# app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=60)
|
3059
|
+
# main_window = app["TFrmIncluiItemPreVenda"]
|
3060
|
+
# main_window.set_focus()
|
3061
|
+
# panel_TGroup_Box= main_window.child_window(class_name="TPanel", found_index=2)
|
3062
|
+
# almoxarificado_index = panel_TGroup_Box.child_window(class_name="TDBIEditNumber", found_index=1)
|
3063
|
+
# cod_almoxarificado = str(cod_empresa)+"50"
|
3064
|
+
# almoxarificado_index.click()
|
3065
|
+
# await worker_sleep(1)
|
3066
|
+
# for _ in range(5):
|
3067
|
+
# pyautogui.press("del")
|
3068
|
+
# pyautogui.press("backspace")
|
3069
|
+
# await worker_sleep(1)
|
3070
|
+
# pyautogui.write(cod_almoxarificado)
|
3071
|
+
# pyautogui.press('tab')
|
3072
|
+
# await worker_sleep(3)
|
3073
|
+
|
3074
|
+
# cod_item_index = panel_TGroup_Box.child_window(class_name="TDBIEditNumber", found_index=0)
|
3075
|
+
# cod_item_index.click()
|
3076
|
+
# await worker_sleep(1)
|
3077
|
+
|
3078
|
+
# for _ in range(5):
|
3079
|
+
# pyautogui.press("del")
|
3080
|
+
# pyautogui.press("backspace")
|
3081
|
+
|
3082
|
+
# await worker_sleep(1)
|
3083
|
+
# pyautogui.write(str(item_cod))
|
3084
|
+
# pyautogui.press('tab')
|
3085
|
+
# await worker_sleep(3)
|
3086
|
+
|
3087
|
+
|
3088
|
+
# natureza_oper_select = panel_TGroup_Box.child_window(class_name="TDBIComboBox", found_index=0)
|
3089
|
+
# nop_selected = natureza_oper_select.window_text()
|
3090
|
+
# nop_selected_value = nop_selected[:4]
|
3091
|
+
|
3092
|
+
# itens_to_select = natureza_oper_select.texts()
|
3093
|
+
# nop_to_be_select = ''
|
3094
|
+
|
3095
|
+
# for item in itens_to_select:
|
3096
|
+
# if nop_selected_value in item and (('c/' in item.lower() or 'c /' in item.lower()) and ('s/' in item.lower() or 's /' in item.lower())):
|
3097
|
+
# nop_to_be_select = item
|
3098
|
+
# break
|
3099
|
+
|
3100
|
+
# natureza_oper_select.click()
|
3101
|
+
# await worker_sleep(1)
|
3102
|
+
# console.print(f"Descrição: {descricao}")
|
3103
|
+
# console.print("Selecionando NOP do item: '5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC'")
|
3104
|
+
# natureza_oper_select.select("5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC")
|
3105
|
+
|
3106
|
+
# await worker_sleep(1)
|
3107
|
+
# console.print("Natureza da operação selecionado com sucesso, preenchendo os itens...\n")
|
3108
|
+
|
3109
|
+
# #INSERINDO A QUANTIDADE
|
3110
|
+
# main_window.set_focus()
|
3111
|
+
# panel_TPage_Control= main_window.child_window(class_name="TcxPageControl", found_index=0)
|
3112
|
+
# panel_tabSheet = panel_TPage_Control.child_window(class_name="TcxTabSheet", found_index=0)
|
3113
|
+
|
3114
|
+
# field_quantidade = panel_tabSheet.child_window(class_name="TDBIEditNumber", found_index=8)
|
3115
|
+
# console.print("Inserindo a quantidade de Itens...\n")
|
3116
|
+
# field_quantidade.click()
|
3117
|
+
# await worker_sleep(1)
|
3118
|
+
# pyautogui.press('del')
|
3119
|
+
# await worker_sleep(1)
|
3120
|
+
# pyautogui.press('backspace')
|
3121
|
+
# await worker_sleep(1)
|
3122
|
+
# pyautogui.write(quantidade)
|
3123
|
+
# #field_quantidade.set_edit_text(quantidade)
|
3124
|
+
# await worker_sleep(1)
|
3125
|
+
# pyautogui.press('tab')
|
3126
|
+
# await worker_sleep(2)
|
3127
|
+
|
3128
|
+
# console.print("Verificando inclui itiem Pre Venda")
|
3129
|
+
# app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=60)
|
3130
|
+
# main_window = app["TFrmIncluiItemPreVenda"]
|
3131
|
+
# main_window.set_focus()
|
3132
|
+
# send_keys("%i")
|
3133
|
+
# await worker_sleep(2)
|
3134
|
+
# #Divergencia de nop na capa e no item
|
3135
|
+
# await find_nop_divergence()
|
3136
|
+
# await worker_sleep(5)
|
3137
|
+
# main_window.close()
|
3138
|
+
|
3139
|
+
|
3140
|
+
#INSERINDO O VALOR
|
3141
|
+
console.print(f"\nNavegando para inserir o valor... ",style="bold green")
|
3142
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=60)
|
3143
|
+
main_window = app["TFrmPreVenda"]
|
3144
|
+
main_window.set_focus()
|
3145
|
+
|
3146
|
+
console.print("Navegando nos elementos...\n")
|
3147
|
+
panel_TPage= main_window.child_window(class_name="TPage", found_index=0)
|
3148
|
+
panel_menu_itens= main_window.child_window(class_name="TcxCustomInnerTreeView", found_index=0)
|
3149
|
+
|
3150
|
+
console.print("Acessando a janela de Itens...\n")
|
3151
|
+
panel_menu_itens.click()
|
3152
|
+
await worker_sleep(1)
|
3153
|
+
pyautogui.press('home')
|
3154
|
+
await worker_sleep(1)
|
3155
|
+
send_keys("{DOWN " + ("3") + "}")
|
3156
|
+
await worker_sleep(3)
|
3157
|
+
|
3158
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=60)
|
3159
|
+
main_window = app["TFrmPreVenda"]
|
3160
|
+
main_window.set_focus()
|
3161
|
+
|
3162
|
+
console.print("Navegando nos elementos...\n")
|
3163
|
+
panel_TNotebook = main_window.child_window(class_name="TNotebook", found_index=0)
|
3164
|
+
recebimento_caixa_panel = panel_TNotebook.child_window(title="Recebimento Pelo Caixa")
|
3165
|
+
especie_btn = recebimento_caixa_panel.child_window(class_name="TDBIComboBox", found_index=0)
|
3166
|
+
especie_btn.select("13 - DEVOLUCAO DE VENDA")
|
3167
|
+
|
3168
|
+
await worker_sleep(2)
|
3169
|
+
|
3170
|
+
totais_panel = panel_TNotebook.child_window(title="Totais")
|
3171
|
+
totais_panel.set_focus()
|
3172
|
+
|
3173
|
+
total_pre_venda_field = totais_panel.child_window(class_name="TDBIEditNumber", found_index=4)
|
3174
|
+
valor_total_value = total_pre_venda_field.window_text()
|
3175
|
+
|
3176
|
+
console.print(f'Valor capturado: {valor_total_value}')
|
3177
|
+
|
3178
|
+
await worker_sleep(1)
|
3179
|
+
|
3180
|
+
recebimento_caixa_panel = panel_TNotebook.child_window(title="Recebimento Pelo Caixa")
|
3181
|
+
valor_field = recebimento_caixa_panel.child_window(class_name="TDBIEditNumber", found_index=0)
|
3182
|
+
valor_field.click()
|
3183
|
+
await worker_sleep(1)
|
3184
|
+
valor_field.set_edit_text(valor_total_value)
|
3185
|
+
|
3186
|
+
console.print(f'Valor inserido: {valor_total_value}')
|
3187
|
+
|
3188
|
+
await worker_sleep(2)
|
3189
|
+
|
3190
|
+
console.print(f'Incluindo registro')
|
3191
|
+
|
3192
|
+
incluir_registro_btn = recebimento_caixa_panel.child_window(class_name="TDBIBitBtn", found_index=2)
|
3193
|
+
incluir_registro_btn.click()
|
3194
|
+
|
3195
|
+
await worker_sleep(2)
|
3196
|
+
|
3197
|
+
|
3198
|
+
#VERIFICANDO A EXISTENCIA DE WARNINGS
|
3199
|
+
console.print("Verificando a existência de Warning... \n")
|
3200
|
+
warning_pop_up = await is_window_open("Warning")
|
3201
|
+
if warning_pop_up["IsOpened"] == True:
|
3202
|
+
console.print("possui Pop-up de Warning, analisando... \n")
|
3203
|
+
ocr_pop_warning = await ocr_warnings(numero_cupom_fiscal)
|
3204
|
+
if ocr_pop_warning.sucesso == True:
|
3205
|
+
retorno = f"POP UP Warning não mapeado para seguimento do processo, mensagem: {ocr_pop_warning.retorno} \nEtapas Executadas:\n{steps}"
|
3206
|
+
return RpaRetornoProcessoDTO(
|
3207
|
+
sucesso=False,
|
3208
|
+
retorno=retorno,
|
3209
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3210
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
3211
|
+
)
|
3212
|
+
else:
|
3213
|
+
retorno = f"{ocr_pop_warning.retorno} \nEtapas Executadas:\n{steps}"
|
3214
|
+
return RpaRetornoProcessoDTO(
|
3215
|
+
sucesso=False,
|
3216
|
+
retorno=retorno,
|
3217
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3218
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3219
|
+
)
|
3220
|
+
else:
|
3221
|
+
console.print("Não possui pop de Warning...\n")
|
3222
|
+
|
3223
|
+
|
3224
|
+
|
3225
|
+
# Inclui registro
|
3226
|
+
console.print(f"Incluindo registro...\n")
|
3227
|
+
try:
|
3228
|
+
ASSETS_PATH = "assets"
|
3229
|
+
inserir_registro = pyautogui.locateOnScreen(ASSETS_PATH + "\\entrada_notas\\IncluirRegistro.png", confidence=0.8)
|
3230
|
+
pyautogui.click(inserir_registro)
|
3231
|
+
|
3232
|
+
except Exception as e:
|
3233
|
+
console.print(
|
3234
|
+
f"Não foi possivel incluir o registro utilizando reconhecimento de imagem, Error: {e}...\n tentando inserir via posição...\n"
|
3235
|
+
)
|
3236
|
+
await incluir_registro()
|
3237
|
+
await worker_sleep(5)
|
3238
|
+
|
3239
|
+
await worker_sleep(8)
|
3240
|
+
#VERIFICANDO A EXISTENCIA DE WARNINGS
|
3241
|
+
console.print("Verificando a existência de Warning... \n")
|
3242
|
+
warning_pop_up = await is_window_open("Warning")
|
3243
|
+
if warning_pop_up["IsOpened"] == True:
|
3244
|
+
console.print("possui Pop-up de Warning, analisando... \n")
|
3245
|
+
ocr_pop_warning = await ocr_warnings(numero_cupom_fiscal)
|
3246
|
+
if ocr_pop_warning.sucesso == True:
|
3247
|
+
retorno = f"POP UP Warning não mapeado para seguimento do processo, mensagem: {ocr_pop_warning.retorno} \nEtapas Executadas:\n{steps}"
|
3248
|
+
return RpaRetornoProcessoDTO(
|
3249
|
+
sucesso=False,
|
3250
|
+
retorno=retorno,
|
3251
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3252
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
3253
|
+
)
|
3254
|
+
else:
|
3255
|
+
retorno = f"POP UP Warning não mapeado para seguimento do processo \nEtapas Executadas:\n{steps}"
|
3256
|
+
return RpaRetornoProcessoDTO(
|
3257
|
+
sucesso=False,
|
3258
|
+
retorno=retorno,
|
3259
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3260
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
3261
|
+
)
|
3262
|
+
await worker_sleep(5)
|
3263
|
+
#VERIFICANDO SE A PRÉ VENDA FOI INCLUIDA COM SUCESSO
|
3264
|
+
console.print("VERIFICANDO SE A PRÉ VENDA FOI INCLUIDA COM SUCESSO... \n")
|
3265
|
+
information_pop_up = await is_window_open("Informação")
|
3266
|
+
if information_pop_up["IsOpened"] == True:
|
3267
|
+
msg_pop_up = await ocr_title(numero_nota_fiscal, "Informação")
|
3268
|
+
console.print(f'retorno:{msg_pop_up.sucesso}')
|
3269
|
+
console.print(f'retorno:{msg_pop_up}')
|
3270
|
+
if msg_pop_up.sucesso == True:
|
3271
|
+
msg_retorno = msg_pop_up.retorno
|
3272
|
+
console.print(msg_retorno)
|
3273
|
+
if 'venda' in msg_retorno.lower():
|
3274
|
+
try:
|
3275
|
+
information_operacao_concluida = main_window.child_window(title="Informação")
|
3276
|
+
btn_ok = information_operacao_concluida.child_window(class_name="TButton")
|
3277
|
+
btn_ok.click()
|
3278
|
+
await worker_sleep(4)
|
3279
|
+
except:
|
3280
|
+
pyautogui.press('enter')
|
3281
|
+
await worker_sleep(4)
|
3282
|
+
else:
|
3283
|
+
retorno = f"Pop up nao mapeado para seguimento do robo {msg_pop_up.retorno} \nEtapas Executadas:\n{steps}"
|
3284
|
+
return RpaRetornoProcessoDTO(
|
3285
|
+
sucesso=False,
|
3286
|
+
retorno=retorno,
|
3287
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3288
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
|
3289
|
+
)
|
3290
|
+
else:
|
3291
|
+
retorno = f"Não foi possivel realizar a confirmação do msg do OCR \nEtapas Executadas:\n{steps}"
|
3292
|
+
return RpaRetornoProcessoDTO(
|
3293
|
+
sucesso=False,
|
3294
|
+
retorno=retorno,
|
3295
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3296
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3297
|
+
)
|
3298
|
+
else:
|
3299
|
+
retorno = f"Janela de confirmação de pre venda incluida nao encontrada \nEtapas Executadas:\n{steps}"
|
3300
|
+
return RpaRetornoProcessoDTO(
|
3301
|
+
sucesso=False,
|
3302
|
+
retorno=retorno,
|
3303
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3304
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3305
|
+
)
|
3306
|
+
|
3307
|
+
await worker_sleep(5)
|
3308
|
+
steps += ' ETAPA 04 - PRE VENDA INCLUIDA COM SUCESSO'
|
3309
|
+
#CONFIRMANDO POP UP DE PRÉ VENDA - PESQUISAR PRE VENDA
|
3310
|
+
try:
|
3311
|
+
console.print("CONFIRMANDO POP UP DE PRÉ VENDA - PESQUISAR PRE VENDA... \n")
|
3312
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=10)
|
3313
|
+
main_window = app["Confirm"]
|
3314
|
+
main_window.set_focus()
|
3315
|
+
|
3316
|
+
btn_yes = main_window.child_window(class_name="TButton", found_index=1)
|
3317
|
+
btn_yes.click()
|
3318
|
+
await worker_sleep(3)
|
3319
|
+
except Exception as e:
|
3320
|
+
retorno = f"Pop Up de Confirm (Deseja pesquisar a Pré Venda ?) não encontrado \nEtapas Executadas:\n{steps}"
|
3321
|
+
return RpaRetornoProcessoDTO(
|
3322
|
+
sucesso=False,
|
3323
|
+
retorno=retorno,
|
3324
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3325
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3326
|
+
)
|
3327
|
+
|
3328
|
+
|
3329
|
+
#CONFIRMANDO NA TELA DE PRE VENDA
|
3330
|
+
try:
|
3331
|
+
console.print("CLICANDO EM CONFIRMAR... \n")
|
3332
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=60)
|
3333
|
+
main_window = app["TFrmPreVenda"]
|
3334
|
+
main_window.set_focus()
|
3335
|
+
|
3336
|
+
panel_Tnotebook = main_window.child_window(class_name="TNotebook", found_index=0)
|
3337
|
+
panel_Tnotebook = panel_Tnotebook.child_window(class_name="TPage", found_index=0)
|
3338
|
+
btn_confirmar = panel_Tnotebook.child_window(class_name="TBitBtn", found_index=11)
|
3339
|
+
btn_confirmar.click()
|
3340
|
+
console.print("CONFIRMAR CLICADO COM SUCESSO... \n")
|
3341
|
+
await worker_sleep(3)
|
3342
|
+
except Exception as e:
|
3343
|
+
retorno = f"Não foi possivel clicar em Confirma na tela de Pre Venda \nEtapas Executadas:\n{steps}"
|
3344
|
+
return RpaRetornoProcessoDTO(
|
3345
|
+
sucesso=False,
|
3346
|
+
retorno=retorno,
|
3347
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3348
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3349
|
+
)
|
3350
|
+
|
3351
|
+
|
3352
|
+
#CONFIRMANDO NA TELA DE PRE VENDA
|
3353
|
+
try:
|
3354
|
+
console.print("CONFIRMANDO POP UP DE Deseja realmente confirmar esta PRÉ VENDA ... \n")
|
3355
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=10)
|
3356
|
+
main_window = app["Confirm"]
|
3357
|
+
main_window.set_focus()
|
3358
|
+
|
3359
|
+
btn_yes = main_window.child_window(class_name="TButton", found_index=1)
|
3360
|
+
btn_yes.click()
|
3361
|
+
await worker_sleep(3)
|
3362
|
+
except Exception as e:
|
3363
|
+
retorno = f"Não foi possivel clicar para confirmar a janela 'Deseja realmente confirmar esta pre-venda' \nEtapas Executadas:\n{steps}"
|
3364
|
+
return RpaRetornoProcessoDTO(
|
3365
|
+
sucesso=False,
|
3366
|
+
retorno=retorno,
|
3367
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3368
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3369
|
+
)
|
3370
|
+
|
3371
|
+
|
3372
|
+
await worker_sleep(5)
|
3373
|
+
app = Application().connect(title="Information", timeout=180)
|
3374
|
+
main_window = app["Information"]
|
3375
|
+
main_window.set_focus()
|
3376
|
+
try:
|
3377
|
+
btn_ok = main_window.child_window(class_name="TButton", found_index=0)
|
3378
|
+
btn_ok.click()
|
3379
|
+
except Exception as e:
|
3380
|
+
pyautogui.press('enter')
|
3381
|
+
finally:
|
3382
|
+
pyautogui.press('enter')
|
3383
|
+
|
3384
|
+
|
3385
|
+
#FATURAR
|
3386
|
+
try:
|
3387
|
+
console.print("FATURAR... \n")
|
3388
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=10)
|
3389
|
+
main_window = app["TFrmPreVenda"]
|
3390
|
+
main_window.set_focus()
|
3391
|
+
|
3392
|
+
panel_Tnotebook = main_window.child_window(class_name="TNotebook", found_index=0)
|
3393
|
+
panel_Tnotebook = panel_Tnotebook.child_window(class_name="TPage", found_index=0)
|
3394
|
+
btn_faturar = panel_Tnotebook.child_window(class_name="TBitBtn", found_index=7)
|
3395
|
+
btn_faturar.click()
|
3396
|
+
console.print("BOTAO FATURAR CLICADO COM SUCESSO... \n")
|
3397
|
+
await worker_sleep(5)
|
3398
|
+
except Exception as e:
|
3399
|
+
retorno = f"Não foi possivel clicar em Faturar na tela de pre venda, erro: {e} \nEtapas Executadas:\n{steps}"
|
3400
|
+
return RpaRetornoProcessoDTO(
|
3401
|
+
sucesso=False,
|
3402
|
+
retorno=retorno,
|
3403
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3404
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3405
|
+
)
|
3406
|
+
|
3407
|
+
|
3408
|
+
await worker_sleep(10)
|
3409
|
+
warning_pop = await is_window_open_by_class("TFrmPreVenda", "Warning")
|
3410
|
+
if warning_pop["IsOpened"] == True:
|
3411
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=10)
|
3412
|
+
try:
|
3413
|
+
main_window = app["Warning"]
|
3414
|
+
main_window.set_focus()
|
3415
|
+
retorno = f"Cliente Cliente sem permissão para realizar a emissão da nota fiscal, por favor verificar o cadastro do mesmo \nEtapas Executadas:\n{steps}"
|
3416
|
+
return RpaRetornoProcessoDTO(
|
3417
|
+
sucesso=False,
|
3418
|
+
retorno=retorno,
|
3419
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3420
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3421
|
+
)
|
3422
|
+
except Exception as e:
|
3423
|
+
console.print('Não possui tela de Warning')
|
3424
|
+
else:
|
3425
|
+
console.print("Nenhum pop-up de Warning Encontrado... \n")
|
3426
|
+
|
3427
|
+
|
3428
|
+
information_pop_up = await is_window_open("Information")
|
3429
|
+
if information_pop_up["IsOpened"] == True:
|
3430
|
+
app = Application().connect(title="Information", timeout=30)
|
3431
|
+
main_window = app["Information"]
|
3432
|
+
main_window.set_focus()
|
3433
|
+
btn_ok = main_window.child_window(class_name="TButton", found_index=0)
|
3434
|
+
btn_ok.click()
|
3435
|
+
|
3436
|
+
|
3437
|
+
await worker_sleep(15)
|
3438
|
+
#FATURAMENTO PRÉ-VENDA
|
3439
|
+
try:
|
3440
|
+
console.print("FATURAMENTO PRÉ-VENDA... \n")
|
3441
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
|
3442
|
+
main_window = app["TFrmDadosFaturamentoPreVenda"]
|
3443
|
+
main_window.set_focus()
|
3444
|
+
except Exception as e:
|
3445
|
+
retorno = f"Não foi encontrada a Janela Faturamento de Pré Venda \nEtapas Executadas:\n{steps}"
|
3446
|
+
return RpaRetornoProcessoDTO(
|
3447
|
+
sucesso=False,
|
3448
|
+
retorno=result,
|
3449
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3450
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3451
|
+
)
|
3452
|
+
await worker_sleep(2)
|
3453
|
+
await find_warning_nop_divergence()
|
3454
|
+
await worker_sleep(2)
|
3455
|
+
#VERIFICANDO SE POSSUI POP UP WARNING
|
3456
|
+
console.print("Verificando a presença de Warning... \n")
|
3457
|
+
warning_boo = False
|
3458
|
+
await worker_sleep(5)
|
3459
|
+
try:
|
3460
|
+
try:
|
3461
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=10)
|
3462
|
+
main_window = app["Warning"]
|
3463
|
+
main_window.set_focus()
|
3464
|
+
|
3465
|
+
except:
|
3466
|
+
console.print('Except Verificando warnings... \n')
|
3467
|
+
app = Application().connect(class_name="Warning", timeout=10)
|
3468
|
+
main_window = app["Warning"]
|
3469
|
+
main_window.set_focus()
|
3470
|
+
console.print("Possui Warning... \n")
|
3471
|
+
await worker_sleep(2)
|
3472
|
+
await find_warning_nop_divergence()
|
3473
|
+
btn_ok = main_window.child_window(class_name="TButton", found_index=0)
|
3474
|
+
btn_ok.click()
|
3475
|
+
await worker_sleep(3)
|
3476
|
+
warning_boo = True
|
3477
|
+
except:
|
3478
|
+
console.print("Não Possui Warning... \n")
|
3479
|
+
|
3480
|
+
#ALTERANDO TRIBUTO DOS ITENS
|
3481
|
+
if warning_boo:
|
3482
|
+
try:
|
3483
|
+
console.print('Acessando a tela de Itens')
|
3484
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
|
3485
|
+
main_window = app["TFrmDadosFaturamentoPreVenda"]
|
3486
|
+
main_window.set_focus()
|
3487
|
+
send_keys("%i")
|
3488
|
+
await worker_sleep(2)
|
3489
|
+
send_keys("%g")
|
3490
|
+
await worker_sleep(2)
|
3491
|
+
|
3492
|
+
console.print("Conectando para realizar a alteração da tributação do produto... \n")
|
3493
|
+
app = Application().connect(class_name="TFrmDadosTributacaoProdutoPreVenda", timeout=60)
|
3494
|
+
main_window = app["TFrmDadosTributacaoProdutoPreVenda"]
|
3495
|
+
|
3496
|
+
tpanel_dados_tributacao = main_window.child_window(class_name="TPanel", found_index=1)
|
3497
|
+
tributacao_icms_select = tpanel_dados_tributacao.child_window(class_name="TDBIComboBox", found_index=4)
|
3498
|
+
|
3499
|
+
|
3500
|
+
if not item_arla:
|
3501
|
+
console.print("Não é item Arla ajustando tributacao... \n")
|
3502
|
+
tributacao_icms_select.click()
|
3503
|
+
await worker_sleep(1)
|
3504
|
+
set_combobox("||List", "061 - 061- MONOFASICO")
|
3505
|
+
else:
|
3506
|
+
console.print("Item Arla buscando pela aliquota do estado... \n")
|
3507
|
+
aliquota = None
|
3508
|
+
for item in conconfig_aliquota_icms:
|
3509
|
+
if cidade_cliente in item["estado"]:
|
3510
|
+
aliquota = item["aliquota"]
|
3511
|
+
break
|
3512
|
+
|
3513
|
+
if aliquota:
|
3514
|
+
console.print(f"A alíquota para o estado {cidade_cliente} é: {aliquota}")
|
3515
|
+
tributacao_icms_select.click()
|
3516
|
+
await worker_sleep(1)
|
3517
|
+
tributacao = f"000 - 000- ICMS - {aliquota}%"
|
3518
|
+
set_combobox("||List", tributacao)
|
3519
|
+
else:
|
3520
|
+
retorno = f"Estado {cidade_cliente} não encontrado \nEtapas Executadas:\n{steps}"
|
3521
|
+
return RpaRetornoProcessoDTO(
|
3522
|
+
sucesso=False,
|
3523
|
+
retorno=retorno,
|
3524
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3525
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3526
|
+
)
|
3527
|
+
main_window.set_focus()
|
3528
|
+
send_keys("%o")
|
3529
|
+
except Exception as e:
|
3530
|
+
retorno = f"Não foi possivel corrigir a tributação do itens na Janela Faturamento de Pré Venda, erro {e} \nEtapas Executadas:\n{steps}"
|
3531
|
+
return RpaRetornoProcessoDTO(
|
3532
|
+
sucesso=False,
|
3533
|
+
retorno=result,
|
3534
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3535
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3536
|
+
)
|
3537
|
+
|
3538
|
+
|
3539
|
+
console.print("Processo de ajustar aliquota realizado com sucesso, adicionando a mensagem... \n")
|
3540
|
+
try:
|
3541
|
+
console.print("Conectando a janela de pre venda... \n")
|
3542
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
|
3543
|
+
main_window = app["TFrmDadosFaturamentoPreVenda"]
|
3544
|
+
main_window.set_focus()
|
3545
|
+
send_keys("%m")
|
3546
|
+
await worker_sleep(2)
|
3547
|
+
|
3548
|
+
mensagem_tab = pyautogui.locateOnScreen(ASSETS_PATH + "\\notas_saida\\icon_mensagem.png", confidence=0.7)
|
3549
|
+
if mensagem_tab:
|
3550
|
+
pyautogui.click(mensagem_tab)
|
3551
|
+
await worker_sleep(4)
|
3552
|
+
else:
|
3553
|
+
retorno = f"Não foi possivel localizar o campo 'Mensagem' \nEtapas Executadas:\n{steps}"
|
3554
|
+
return RpaRetornoProcessoDTO(
|
3555
|
+
sucesso=False,
|
3556
|
+
retorno=retorno,
|
3557
|
+
status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3558
|
+
)
|
3559
|
+
|
3560
|
+
|
3561
|
+
panel_tab_sheet = main_window.child_window(class_name="TcxTabSheet", found_index=0)
|
3562
|
+
field_observacao = panel_tab_sheet.child_window(class_name="TDBIMemo", found_index=0)
|
3563
|
+
console.print(f"Mensagem a ser adicionada\n")
|
3564
|
+
text_campo_observacao = f"Nome do Motorista: {nota.get("nomeMotorista")} - Placa: {nota.get("placaClienteCorreto")} - Quilometragem do Veículo: {nota.get("quilometragemVeiculo")}"
|
3565
|
+
console.print(f"{text_campo_observacao}\n")
|
3566
|
+
field_observacao.click()
|
3567
|
+
await worker_sleep(2)
|
3568
|
+
pyautogui.write(text_campo_observacao)
|
3569
|
+
await worker_sleep(2)
|
3570
|
+
|
3571
|
+
try:
|
3572
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
|
3573
|
+
main_window = app["TFrmDadosFaturamentoPreVenda"]
|
3574
|
+
main_window.set_focus()
|
3575
|
+
btn_ok = main_window.child_window(class_name="TBitBtn", found_index=1)
|
3576
|
+
btn_ok.click()
|
3577
|
+
except:
|
3578
|
+
btn_ok = main_window.child_window(title="&Ok")
|
3579
|
+
btn_ok.click()
|
3580
|
+
await worker_sleep(5)
|
3581
|
+
|
3582
|
+
await worker_sleep(10)
|
3583
|
+
await find_warning_nop_divergence()
|
3584
|
+
await worker_sleep(2)
|
3585
|
+
warning_pop_up = await is_window_open("Warning")
|
3586
|
+
if warning_pop_up["IsOpened"] == True:
|
3587
|
+
console.print("possui Pop-up de Warning, analisando... \n")
|
3588
|
+
app = Application().connect(title="Warning")
|
3589
|
+
main_window = app["Warning"]
|
3590
|
+
await worker_sleep(2)
|
3591
|
+
main_window.set_focus()
|
3592
|
+
console.print("Clicando em OK, para andamento do processo...\n")
|
3593
|
+
btn_ok = main_window.child_window(title="OK", class_name="TButton")
|
3594
|
+
if btn_ok.exists() and btn_ok.is_enabled():
|
3595
|
+
btn_ok.click()
|
3596
|
+
#Este click pode ser desnecessário, é apanas uma garantia
|
3597
|
+
pyautogui.click(961, 562)
|
3598
|
+
await worker_sleep(2)
|
3599
|
+
else:
|
3600
|
+
log_msg = "Warning - Erro ao clicar em Ok, na tela de warning...\n"
|
3601
|
+
console.print(log_msg, style="bold red")
|
3602
|
+
return RpaRetornoProcessoDTO(
|
3603
|
+
sucesso=False, retorno=log_msg, status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3604
|
+
)
|
3605
|
+
await worker_sleep(1)
|
3606
|
+
#SELECIONANDO O TIPO DE DOCUMENTO
|
3607
|
+
try:
|
3608
|
+
console.print("Conectando a janela de pre venda para colocar modelo \n")
|
3609
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=10)
|
3610
|
+
main_window = app["TFrmDadosFaturamentoPreVenda"]
|
3611
|
+
main_window.set_focus()
|
3612
|
+
send_keys("%p")
|
3613
|
+
await worker_sleep(2)
|
3614
|
+
|
3615
|
+
panel_TPage= main_window.child_window(class_name="TPageControl", found_index=0)
|
3616
|
+
panel_Ttabsheet= panel_TPage.child_window(class_name="TTabSheet", found_index=0)
|
3617
|
+
modelo_select = panel_Ttabsheet.child_window(class_name="TDBIComboBox", found_index=1)
|
3618
|
+
modelo_select.click()
|
3619
|
+
await worker_sleep(1)
|
3620
|
+
set_combobox("||List", "NFe - NOTA FISCAL ELETRONICA PROPRIA - DANFE SERIE 077")
|
3621
|
+
await worker_sleep(3)
|
3622
|
+
console.print("Verificando se o tipo de nota foi selecionado corretamente \n")
|
3623
|
+
modelo_select = panel_Ttabsheet.child_window(class_name="TDBIComboBox", found_index=1)
|
3624
|
+
tipo_selecionado = modelo_select.window_text()
|
3625
|
+
if "077" in tipo_selecionado.lower():
|
3626
|
+
console.print(f"Tipo de cobrança corretamente selecionado {tipo_selecionado}... \n")
|
3627
|
+
else:
|
3628
|
+
retorno = f"Não foi possivel selecionar o modelo do documento, tipo selecionado {tipo_selecionado}' \nEtapas Executadas:\n{steps}"
|
3629
|
+
return RpaRetornoProcessoDTO(
|
3630
|
+
sucesso=False,
|
3631
|
+
retorno=retorno,
|
3632
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3633
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3634
|
+
)
|
3635
|
+
|
3636
|
+
main_window.set_focus()
|
3637
|
+
try:
|
3638
|
+
#Clcica no OK para seguir a transmissão da pré-venda
|
3639
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
|
3640
|
+
main_window = app["TFrmDadosFaturamentoPreVenda"]
|
3641
|
+
main_window.set_focus()
|
3642
|
+
btn_ok = main_window.child_window(class_name="TBitBtn", found_index=1)
|
3643
|
+
btn_ok.click()
|
3644
|
+
except:
|
3645
|
+
btn_ok = main_window.child_window(title="&Ok")
|
3646
|
+
btn_ok.click()
|
3647
|
+
await worker_sleep(5)
|
3648
|
+
|
3649
|
+
except Exception as e:
|
3650
|
+
retorno = f"Não foi possivel selecionar o modelo do documento {e}' \nEtapas Executadas:\n{steps}"
|
3651
|
+
return RpaRetornoProcessoDTO(
|
3652
|
+
sucesso=False,
|
3653
|
+
retorno=retorno,
|
3654
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3655
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3656
|
+
)
|
3657
|
+
else:
|
3658
|
+
console.print("Não possui pop de Warning...\n")
|
3659
|
+
|
3660
|
+
|
3661
|
+
await worker_sleep(2)
|
3662
|
+
await find_warning_nop_divergence()
|
3663
|
+
await worker_sleep(2)
|
3664
|
+
#VERIFICANDO SE POSSUI POP UP WARNING
|
3665
|
+
console.print("Verificando a presença de Warning... \n")
|
3666
|
+
warning_boo = False
|
3667
|
+
try:
|
3668
|
+
try:
|
3669
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=30)
|
3670
|
+
main_window = app["Warning"]
|
3671
|
+
main_window.set_focus()
|
3672
|
+
except:
|
3673
|
+
console.print('Except')
|
3674
|
+
app = Application().connect(class_name="Warning", timeout=10)
|
3675
|
+
main_window = app["Warning"]
|
3676
|
+
main_window.set_focus()
|
3677
|
+
console.print("Possui Warning... \n")
|
3678
|
+
await find_warning_nop_divergence()
|
3679
|
+
btn_ok = main_window.child_window(class_name="TButton", found_index=0)
|
3680
|
+
btn_ok.click()
|
3681
|
+
await worker_sleep(3)
|
3682
|
+
warning_boo = True
|
3683
|
+
except:
|
3684
|
+
console.print("Não Possui Warning... \n")
|
3685
|
+
|
3686
|
+
|
3687
|
+
#ALTERANDO TRIBUTO DOS ITENS
|
3688
|
+
if warning_boo:
|
3689
|
+
try:
|
3690
|
+
console.print('Acessando a tela de Itens')
|
3691
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
|
3692
|
+
main_window = app["TFrmDadosFaturamentoPreVenda"]
|
3693
|
+
main_window.set_focus()
|
3694
|
+
send_keys("%i")
|
3695
|
+
await worker_sleep(2)
|
3696
|
+
send_keys("%g")
|
3697
|
+
await worker_sleep(2)
|
3698
|
+
|
3699
|
+
await find_warning_nop_divergence()
|
3700
|
+
await worker_sleep(2)
|
3701
|
+
console.print("Conectando para realizar a alteração da tributação do produto... \n")
|
3702
|
+
app = Application().connect(class_name="TFrmDadosTributacaoProdutoPreVenda", timeout=60)
|
3703
|
+
main_window = app["TFrmDadosTributacaoProdutoPreVenda"]
|
3704
|
+
|
3705
|
+
tpanel_dados_tributacao = main_window.child_window(class_name="TPanel", found_index=1)
|
3706
|
+
tributacao_icms_select = tpanel_dados_tributacao.child_window(class_name="TDBIComboBox", found_index=4)
|
3707
|
+
|
3708
|
+
|
3709
|
+
if not item_arla:
|
3710
|
+
console.print("Não é item Arla ajustando tributacao... \n")
|
3711
|
+
tributacao_icms_select.click()
|
3712
|
+
await worker_sleep(1)
|
3713
|
+
set_combobox("||List", "061 - 061- MONOFASICO")
|
3714
|
+
else:
|
3715
|
+
console.print("Item Arla buscando pela aliquota do estado... \n")
|
3716
|
+
aliquota = None
|
3717
|
+
for item in conconfig_aliquota_icms:
|
3718
|
+
if cidade_cliente in item["estado"]:
|
3719
|
+
aliquota = item["aliquota"]
|
3720
|
+
break
|
3721
|
+
|
3722
|
+
if aliquota:
|
3723
|
+
console.print(f"A alíquota para o estado {cidade_cliente} é: {aliquota}")
|
3724
|
+
tributacao_icms_select.click()
|
3725
|
+
await worker_sleep(1)
|
3726
|
+
tributacao = f"000 - 000- ICMS - {aliquota}%"
|
3727
|
+
set_combobox("||List", tributacao)
|
3728
|
+
else:
|
3729
|
+
retorno = f"Estado {cidade_cliente} não encontrado \nEtapas Executadas:\n{steps}"
|
3730
|
+
return RpaRetornoProcessoDTO(
|
3731
|
+
sucesso=False,
|
3732
|
+
retorno=retorno,
|
3733
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3734
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3735
|
+
)
|
3736
|
+
main_window.set_focus()
|
3737
|
+
send_keys("%o")
|
3738
|
+
await worker_sleep(1)
|
3739
|
+
try:
|
3740
|
+
#find Message corrigir tributação
|
3741
|
+
app = Application().connect(title="Corrige tributação", timeout=60)
|
3742
|
+
corrige_tribute = app["Corrige tributação"]
|
3743
|
+
corrige_tribute.child_window(title="&Não").click()
|
3744
|
+
pyautogui.click(1109, 602)
|
3745
|
+
except:
|
3746
|
+
pyautogui.click(1109, 602)
|
3747
|
+
console.print("Não encontrou a mensagem de corrigir tributacao\n")
|
3748
|
+
|
3749
|
+
except Exception as e:
|
3750
|
+
retorno = f"Não foi possivel corrigir a tributação do itens na Janela Faturamento de Pré Venda, erro {e} \nEtapas Executadas:\n{steps}"
|
3751
|
+
return RpaRetornoProcessoDTO(
|
3752
|
+
sucesso=False,
|
3753
|
+
retorno=result,
|
3754
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3755
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3756
|
+
)
|
3757
|
+
else:
|
3758
|
+
console.print("Não possui warning para alterar tributação... \n")
|
3759
|
+
|
3760
|
+
|
3761
|
+
#ADICIONANDO MENSAGEM
|
3762
|
+
await worker_sleep(5)
|
3763
|
+
try:
|
3764
|
+
console.print("Identificando - TFrmDadosFaturamentoPreVenda 3")
|
3765
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=10)
|
3766
|
+
main_window = app["Confirm"]
|
3767
|
+
main_window.set_focus()
|
3768
|
+
except:
|
3769
|
+
console.print("Identificando - TMessageForm 8")
|
3770
|
+
try:
|
3771
|
+
await worker_sleep(3)
|
3772
|
+
app = Application().connect(class_name="TMessageForm", timeout=10, title='Confirm')
|
3773
|
+
main_window = app["TMessageForm"]
|
3774
|
+
main_window.set_focus()
|
3775
|
+
except:
|
3776
|
+
console.print("TMessageForm não encontrado")
|
3777
|
+
|
3778
|
+
try:
|
3779
|
+
btn_yes = main_window.child_window(class_name="TButton", title="&Yes")
|
3780
|
+
btn_yes.click()
|
3781
|
+
console.print("Clicou Yes")
|
3782
|
+
except:
|
3783
|
+
await worker_sleep(3)
|
3784
|
+
console.print("Clicando em 'OK' na tela de faturamente pré-venda")
|
3785
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=10)
|
3786
|
+
main_window = app["TFrmDadosFaturamentoPreVenda"]
|
3787
|
+
main_window.set_focus()
|
3788
|
+
main_window.child_window(title="&OK", class_name="TBitBtn").click()
|
3789
|
+
await find_warning_nop_divergence()
|
3790
|
+
|
3791
|
+
#CONFIRMANDO NA TELA DE PRE VENDA
|
3792
|
+
try:
|
3793
|
+
console.print("CONFIRMANDO POP UP DE Deseja realmente confirmar esta PRÉ VENDA ... \n")
|
3794
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=10)
|
3795
|
+
main_window = app["Confirm"]
|
3796
|
+
main_window.set_focus()
|
3797
|
+
|
3798
|
+
btn_yes = main_window.child_window(class_name="TButton", found_index=1)
|
3799
|
+
btn_yes.click()
|
3800
|
+
await worker_sleep(3)
|
3801
|
+
except Exception as e:
|
3802
|
+
await worker_sleep(6)
|
3803
|
+
app = Application().connect(title="Transmição NF-e!",class_name="TMessageForm", timeout=10)
|
3804
|
+
transmission_window = app["Transmição NF-e!"]
|
3805
|
+
transmission_window.set_focus()
|
3806
|
+
if transmission_window.exists():
|
3807
|
+
console.print("Encontrou a tela de Transmissão da NF-e")
|
3808
|
+
else:
|
3809
|
+
retorno = f"Não foi possivel clicar para confirmar a janela 'Deseja realmente confirmar esta pre-venda' \nEtapas Executadas:\n{steps}"
|
3810
|
+
return RpaRetornoProcessoDTO(
|
3811
|
+
sucesso=False,
|
3812
|
+
retorno=retorno,
|
3813
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3814
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3815
|
+
)
|
3816
|
+
|
3817
|
+
#Transmitir e imprimir
|
3818
|
+
try:
|
3819
|
+
app = Application().connect(title="Transmição NF-e!",class_name="TMessageForm", timeout=10)
|
3820
|
+
transmission_window = app["Transmição NF-e!"]
|
3821
|
+
transmission_window.set_focus()
|
3822
|
+
transmission_window.child_window(title='Transmitir e &Imprimir', class_name="TButton").click()
|
3823
|
+
except Exception as e:
|
3824
|
+
retorno = f"Não encontrou a tela de Transmissão da NF-e, erro {e} \nEtapas Executadas:\n{steps}"
|
3825
|
+
return RpaRetornoProcessoDTO(
|
3826
|
+
sucesso=False,
|
3827
|
+
retorno=retorno,
|
3828
|
+
status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3829
|
+
)
|
3830
|
+
|
3831
|
+
await worker_sleep(25)
|
3832
|
+
|
3833
|
+
except Exception as e:
|
3834
|
+
retorno = f"Não foi possivel adicionar a 'Mensagem' na tela de Faturamento de pre venda, erro {e} \nEtapas Executadas:\n{steps}"
|
3835
|
+
return RpaRetornoProcessoDTO(
|
3836
|
+
sucesso=False,
|
3837
|
+
retorno=retorno,
|
3838
|
+
status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3839
|
+
)
|
3840
|
+
|
3841
|
+
await worker_sleep(20)
|
3842
|
+
|
3843
|
+
try_print=10
|
3844
|
+
current_try_print=0
|
3845
|
+
while current_try_print <= try_print:
|
3846
|
+
try:
|
3847
|
+
app = Application().connect(class_name="TFrmAguarde", timeout=60)
|
3848
|
+
main_window = app["TppPrintDialog"]
|
3849
|
+
tpanel_btn_ok = main_window.child_window(class_name="TPanel", found_index=1)
|
3850
|
+
btn_ok_print_screen = tpanel_btn_ok.child_window(class_name="TButton", found_index=1)
|
3851
|
+
btn_ok_print_screen.click()
|
3852
|
+
await worker_sleep(3)
|
3853
|
+
break
|
3854
|
+
except Exception as e:
|
3855
|
+
console.print(f"Tela 'Print' nao encontrada. Tentativa: {current_try_print+1} de {try_print} \n")
|
3856
|
+
current_try_print+=1
|
3857
|
+
await worker_sleep(25)
|
3858
|
+
|
3859
|
+
|
3860
|
+
if current_try_print >= try_print:
|
3861
|
+
retorno = f"Não foi encontrada a tela para a impressão da nova venda \nEtapas Executadas:\n{steps}"
|
3862
|
+
return RpaRetornoProcessoDTO(
|
3863
|
+
sucesso=False,
|
3864
|
+
retorno=retorno,
|
3865
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3866
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3867
|
+
)
|
3868
|
+
|
3869
|
+
console.print(f"NAVEGANDO NA TELA DE SALVAR RELATORIO\n")
|
3870
|
+
#INSERINDO O DIRETORIO E SALVANDO O ARQUIVO
|
3871
|
+
try:
|
3872
|
+
app = Application().connect(title="Salvar Saída de Impressão como")
|
3873
|
+
main_window = app["Dialog"]
|
3874
|
+
console.print("Tela 'Salvar' encontrada!")
|
3875
|
+
|
3876
|
+
console.print("Interagindo com a tela 'Salvar'...\n")
|
3877
|
+
username = getpass.getuser()
|
3878
|
+
path_to_txt = f"C:\\Users\\{username}\\Downloads\\NOVA VENDA {numero_cupom_fiscal}"
|
3879
|
+
|
3880
|
+
main_window.type_keys("%n")
|
3881
|
+
pyautogui.write(path_to_txt)
|
3882
|
+
await worker_sleep(1)
|
3883
|
+
main_window.type_keys("%l")
|
3884
|
+
console.print("Arquivo salvo com sucesso...\n")
|
3885
|
+
await worker_sleep(8)
|
3886
|
+
except Exception as e:
|
3887
|
+
retorno = f"Não foi salvar o arquivo com a nova venda, erro {e} \nEtapas Executadas:\n{steps}"
|
3888
|
+
return RpaRetornoProcessoDTO(
|
3889
|
+
sucesso=False,
|
3890
|
+
retorno=result,
|
3891
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3892
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3893
|
+
)
|
3894
|
+
|
3895
|
+
with open(f"{path_to_txt}.pdf", 'rb') as file:
|
3896
|
+
file_bytes = io.BytesIO(file.read())
|
3897
|
+
|
3898
|
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
3899
|
+
desArquivo = f"NOVA VENDA {numero_cupom_fiscal}.pdf"
|
3900
|
+
try:
|
3901
|
+
await send_file(historico_id, desArquivo, "pdf", file_bytes, file_extension="pdf")
|
3902
|
+
os.remove(f"{path_to_txt}.pdf")
|
3903
|
+
except Exception as e:
|
3904
|
+
result = f"Arquivo NOVA VENDA 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} !"
|
3905
|
+
console.print(result, style="bold red")
|
3906
|
+
return RpaRetornoProcessoDTO(
|
3907
|
+
sucesso=False,
|
3908
|
+
retorno=result,
|
3909
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3910
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3911
|
+
)
|
3912
|
+
|
3913
|
+
information_pop_up = await is_window_open("Information")
|
3914
|
+
if information_pop_up["IsOpened"] == True:
|
3915
|
+
app = Application().connect(title="Information", timeout=30)
|
3916
|
+
main_window = app["Information"]
|
3917
|
+
main_window.set_focus()
|
3918
|
+
btn_ok = main_window.child_window(class_name="TButton", found_index=0)
|
3919
|
+
btn_ok.click()
|
3920
|
+
|
3921
|
+
|
3922
|
+
try:
|
3923
|
+
app = Application().connect(class_name="TFrmProcessamentoFEe2", timeout=10)
|
3924
|
+
main_window = app["TFrmProcessamentoFEe2"]
|
3925
|
+
main_window.close()
|
3926
|
+
except Exception as e:
|
3927
|
+
console.print("Janela TFrmDadosFaturamentoPreVenda ja fechada")
|
3928
|
+
|
3929
|
+
|
3930
|
+
await worker_sleep(5)
|
3931
|
+
is_confirm_pop_up = False
|
3932
|
+
try:
|
3933
|
+
app = Application().connect(class_name="TFrmGerenciadorNFe2", timeout=10)
|
3934
|
+
main_window = app["Confirm"]
|
3935
|
+
is_confirm_pop_up = True
|
3936
|
+
except:
|
3937
|
+
pass
|
3938
|
+
|
3939
|
+
|
3940
|
+
if is_confirm_pop_up == True:
|
3941
|
+
msg_text = await ocr_by_class(numero_cupom_fiscal,"TFrmGerenciadorNFe2", "Confirm")
|
3942
|
+
if 'imprimir' in msg_text.retorno.lower():
|
3943
|
+
app = Application().connect(class_name="TFrmGerenciadorNFe2", timeout=10)
|
3944
|
+
main_window = app["Confirm"]
|
3945
|
+
main_window.set_focus()
|
3946
|
+
send_keys("%n")
|
3947
|
+
|
3948
|
+
|
3949
|
+
#Fechar telas Antes de fazer nova pesquisa
|
3950
|
+
await worker_sleep(10)
|
3951
|
+
try:
|
3952
|
+
app = Application().connect(class_name="TFrmProcessamentoNFe2", timeout=10)
|
3953
|
+
window_lancando_nota = app["TFrmProcessamentoNFe2"]
|
3954
|
+
window_lancando_nota.set_focus()
|
3955
|
+
fechar_tela_processamento = "assets\\emsys\\button_fechar.PNG"
|
3956
|
+
try:
|
3957
|
+
button_location = pyautogui.locateCenterOnScreen(
|
3958
|
+
fechar_tela_processamento, confidence=0.6
|
3959
|
+
)
|
3960
|
+
if button_location:
|
3961
|
+
pyautogui.click(button_location)
|
3962
|
+
console.print("Botão 'Fechar' clicado com sucesso!")
|
3963
|
+
except pyautogui.ImageNotFoundException:
|
3964
|
+
window_rect = main_window.rectangle()
|
3965
|
+
console.print(f"Area que sera utulizada para o recorte {window_rect}...\n")
|
3966
|
+
try:
|
3967
|
+
button_location = pyautogui.locateCenterOnScreen(
|
3968
|
+
fechar_tela_processamento,
|
3969
|
+
region=(
|
3970
|
+
window_rect.left,
|
3971
|
+
window_rect.top,
|
3972
|
+
window_rect.width(),
|
3973
|
+
window_rect.height(),
|
3974
|
+
),
|
3975
|
+
)
|
3976
|
+
if button_location:
|
3977
|
+
button_location = (
|
3978
|
+
button_location.x + window_rect.left,
|
3979
|
+
button_location.y + window_rect.top,
|
3980
|
+
)
|
3981
|
+
console.print(
|
3982
|
+
f"Botão encontrado nas coordenadas: {button_location}"
|
3983
|
+
)
|
3984
|
+
pyautogui.click(button_location)
|
3985
|
+
await worker_sleep(10)
|
3986
|
+
except pyautogui.ImageNotFoundException:
|
3987
|
+
retorno = f"Não foi possivel fechar a tela de processamento, Error: {e} \nEtapas Executadas:\n{steps}"
|
3988
|
+
console.print(f"Não foi possivel fechar a tela de processamento, Error: {e}...\n tentando inserir via posição...\n")
|
3989
|
+
return RpaRetornoProcessoDTO(
|
3990
|
+
sucesso=False,
|
3991
|
+
retorno=retorno,
|
3992
|
+
status=RpaHistoricoStatusEnum.Falha,
|
3993
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
3994
|
+
)
|
3995
|
+
except Exception as e:
|
3996
|
+
retorno = f"Não foi possivel fechar a tela de processamento, Error:{e} \nEtapas Executadas:\n{steps}"
|
3997
|
+
console.print(f"Não foi possivel fechar a tela de processamento, Error:{e}...\n tentando inserir via posição...\n")
|
3998
|
+
return RpaRetornoProcessoDTO(
|
3999
|
+
sucesso=False,
|
4000
|
+
retorno=retorno,
|
4001
|
+
status=RpaHistoricoStatusEnum.Falha,
|
4002
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
4003
|
+
)
|
4004
|
+
except:
|
4005
|
+
console.print("Janela TFrmProcessamentoNFe2 ja fechada")
|
4006
|
+
|
4007
|
+
|
4008
|
+
console.print("Verificando se possui pop-up imprimir boleta")
|
4009
|
+
boleta_screen = await is_window_open("Confirm")
|
4010
|
+
if boleta_screen["IsOpened"] == True:
|
4011
|
+
console.print("Janela aberta, fechando")
|
4012
|
+
try:
|
4013
|
+
console.print("Confirm")
|
4014
|
+
app = Application().connect(title="Confirm", timeout=10)
|
4015
|
+
main_window = app["Confirm"]
|
4016
|
+
main_window.set_focus()
|
4017
|
+
except:
|
4018
|
+
console.print("Identificando - TMessageForm 7")
|
4019
|
+
app = Application().connect(class_name="TMessageForm", timeout=10, title='Confirm')
|
4020
|
+
main_window = app["TMessageForm"]
|
4021
|
+
main_window.set_focus()
|
4022
|
+
|
4023
|
+
btn_no = main_window.child_window(class_name="TButton", title="&No")
|
4024
|
+
btn_no.click()
|
4025
|
+
|
4026
|
+
|
4027
|
+
await worker_sleep(7)
|
4028
|
+
erro_screen = await is_window_open_by_class("TFrmDadosFaturamentoPreVenda","Confirm")
|
4029
|
+
if erro_screen["IsOpened"] == True:
|
4030
|
+
console.print("Janela aberta, fechando")
|
4031
|
+
try:
|
4032
|
+
console.print("Identificando - TFrmDadosFaturamentoPreVenda 4")
|
4033
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=10)
|
4034
|
+
main_window = app["Confirm"]
|
4035
|
+
main_window.set_focus()
|
4036
|
+
except:
|
4037
|
+
console.print("Identificando - TMessageForm 9")
|
4038
|
+
app = Application().connect(class_name="TMessageForm", timeout=10, title='Confirm')
|
4039
|
+
main_window = app["TMessageForm"]
|
4040
|
+
main_window.set_focus()
|
4041
|
+
|
4042
|
+
btn_no = main_window.child_window(class_name="TButton", title="&No")
|
4043
|
+
btn_no.click()
|
4044
|
+
|
4045
|
+
|
4046
|
+
await worker_sleep(10)
|
4047
|
+
console.print("Verificando se a tela de Mensagem esta aberta")
|
4048
|
+
erro_screen = await is_window_open_by_class("TMemo","TMemo")
|
4049
|
+
if erro_screen["IsOpened"] == True:
|
4050
|
+
console.print("Janela aberta, fechando")
|
4051
|
+
app = Application().connect(class_name="TMemo", timeout=10)
|
4052
|
+
main_window = app["TMemo"]
|
4053
|
+
main_window.set_focus()
|
4054
|
+
await worker_sleep(5)
|
4055
|
+
main_window.close()
|
4056
|
+
|
4057
|
+
|
4058
|
+
console.print("Verificando se a tela de Faturamento Pre venda esta aberta")
|
4059
|
+
close_dados_faturamento = await is_window_open_by_class("TFrmDadosFaturamentoPreVenda","TFrmDadosFaturamentoPreVenda")
|
4060
|
+
if close_dados_faturamento["IsOpened"] == True:
|
4061
|
+
console.print("Janela aberta, fechando")
|
4062
|
+
try:
|
4063
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
|
4064
|
+
main_window = app["TFrmDadosFaturamentoPreVenda"]
|
4065
|
+
main_window.set_focus()
|
4066
|
+
btn_cancelar = main_window.child_window(class_name="TBitBtn", found_index=0)
|
4067
|
+
btn_cancelar.click()
|
4068
|
+
except:
|
4069
|
+
btn_cancelar = main_window.child_window(title="&Cancela")
|
4070
|
+
btn_cancelar.click()
|
4071
|
+
|
4072
|
+
|
4073
|
+
await worker_sleep(10)
|
4074
|
+
console.print("Verificando se a tela de Faturamento Pre venda esta aberta")
|
4075
|
+
close_dados_faturamento = await is_window_open_by_class("TFrmDadosFaturamentoPreVenda","TFrmDadosFaturamentoPreVenda")
|
4076
|
+
if close_dados_faturamento["IsOpened"] == True:
|
4077
|
+
console.print("Janela aberta, fechando")
|
4078
|
+
try:
|
4079
|
+
app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=180)
|
4080
|
+
main_window = app["TFrmDadosFaturamentoPreVenda"]
|
4081
|
+
main_window.set_focus()
|
4082
|
+
await worker_sleep(2)
|
4083
|
+
main_window.close()
|
4084
|
+
except Exception as e:
|
4085
|
+
console.print(f"Erro ao fechar a janela de dados faturamento pre venda {e}")
|
4086
|
+
|
4087
|
+
|
4088
|
+
await worker_sleep(5)
|
4089
|
+
console.print("Verificando se a tela de Gerenciador esta aberta")
|
4090
|
+
window_gerenciador_screen = await is_window_open_by_class("TFrmGerenciadorNFe2","TFrmGerenciadorNFe2")
|
4091
|
+
if window_gerenciador_screen["IsOpened"] == True:
|
4092
|
+
app = Application().connect(class_name="TFrmGerenciadorNFe2", timeout=10)
|
4093
|
+
window_gerenciador = app["TFrmGerenciadorNFe2"]
|
4094
|
+
window_gerenciador.set_focus()
|
4095
|
+
await worker_sleep(2)
|
4096
|
+
window_gerenciador.close()
|
4097
|
+
else:
|
4098
|
+
console.print("Janela TFrmGerenciadorNFe2 ja fechada")
|
4099
|
+
|
4100
|
+
|
4101
|
+
await worker_sleep(10)
|
4102
|
+
console.print("Verificando se a tela de Pre venda esta aberta")
|
4103
|
+
window_gerenciador_screen = await is_window_open_by_class("TFrmPreVenda","TFrmPreVenda")
|
4104
|
+
if window_gerenciador_screen["IsOpened"] == True:
|
4105
|
+
app = Application().connect(class_name="TFrmPreVenda", timeout=10)
|
4106
|
+
window_gerenciador = app["TFrmPreVenda"]
|
4107
|
+
window_gerenciador.set_focus()
|
4108
|
+
await worker_sleep(2)
|
4109
|
+
window_gerenciador.close()
|
4110
|
+
else:
|
4111
|
+
console.print("Janela TFrmPreVenda ja fechada")
|
4112
|
+
|
4113
|
+
|
4114
|
+
except Exception as e:
|
4115
|
+
retorno = f"Não foi possivel concluir o processo de pré venda {e} \nEtapas Executadas:\n{steps}"
|
4116
|
+
return RpaRetornoProcessoDTO(
|
4117
|
+
sucesso=False,
|
4118
|
+
retorno=retorno,
|
4119
|
+
status=RpaHistoricoStatusEnum.Falha,
|
4120
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
4121
|
+
)
|
4122
|
+
else:
|
4123
|
+
retorno = f"{preenchimento_header_pre_venda.retorno} \nEtapas Executadas:\n{steps}"
|
4124
|
+
return RpaRetornoProcessoDTO(
|
4125
|
+
sucesso=False,
|
4126
|
+
retorno=retorno,
|
4127
|
+
status=RpaHistoricoStatusEnum.Falha,
|
4128
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
4129
|
+
)
|
4130
|
+
else:
|
4131
|
+
console.print(f"\nPesquisa: 'Não possui item para nota conjunta",style="bold green")
|
4132
|
+
|
4133
|
+
|
4134
|
+
|
4135
|
+
#GERAR RELATORIO FINAL
|
4136
|
+
await worker_sleep(2)
|
4137
|
+
type_text_into_field("Rel. Boletim Caixa", app["TFrmMenuPrincipal"]["Edit"], True, "50")
|
4138
|
+
pyautogui.press("enter")
|
4139
|
+
await worker_sleep(2)
|
4140
|
+
pyautogui.press("enter")
|
4141
|
+
await worker_sleep(5)
|
4142
|
+
path_to_txt = ''
|
4143
|
+
|
4144
|
+
boletim_caixa_opened = await is_window_open_by_class("TFrmRelBoletimCaixa", "TFrmRelBoletimCaixa")
|
4145
|
+
if boletim_caixa_opened["IsOpened"] == True:
|
4146
|
+
console.print(f"\nRelatório Boletim Caixa esta aberta",style="bold green")
|
4147
|
+
else:
|
4148
|
+
console.print(f"\nPesquisa: 'Relatório Boletim Caixa",style="bold green")
|
4149
|
+
type_text_into_field("Rel. Boletim Caixa", app["TFrmMenuPrincipal"]["Edit"], True, "50")
|
4150
|
+
pyautogui.press("enter")
|
4151
|
+
await worker_sleep(2)
|
4152
|
+
pyautogui.press("tab")
|
4153
|
+
await worker_sleep(1)
|
4154
|
+
pyautogui.press("tab")
|
4155
|
+
await worker_sleep(1)
|
4156
|
+
pyautogui.press("enter")
|
4157
|
+
await worker_sleep(5)
|
4158
|
+
|
4159
|
+
|
4160
|
+
try:
|
4161
|
+
app = Application().connect(class_name="TFrmRelBoletimCaixa", timeout=60)
|
4162
|
+
main_window = app["TFrmRelBoletimCaixa"]
|
4163
|
+
except Exception as e:
|
4164
|
+
retorno = f"Não foi possivel abrir a tela de Rel. Boletim Caixa \nEtapas Executadas:\n{steps}"
|
4165
|
+
return RpaRetornoProcessoDTO(
|
4166
|
+
sucesso=False,
|
4167
|
+
retorno=retorno,
|
4168
|
+
status=RpaHistoricoStatusEnum.Falha,
|
4169
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
4170
|
+
)
|
4171
|
+
|
4172
|
+
console.print(f"\nNavegando entre os elementos do Rel Boletim Caixa ",style="bold green")
|
4173
|
+
try:
|
4174
|
+
tgroup_box = main_window.child_window(class_name="TGroupBox", found_index=0)
|
4175
|
+
|
4176
|
+
dt_inicio = tgroup_box.child_window(class_name="TDBIEditDate", found_index=0)
|
4177
|
+
dt_inicio.set_edit_text(data_hoje)
|
4178
|
+
dt_final = main_window.child_window(class_name="TDBIEditDate", found_index=1)
|
4179
|
+
dt_final.set_edit_text(data_hoje)
|
4180
|
+
|
4181
|
+
#SELECIONANDO A ESPECIE
|
4182
|
+
select_especie = main_window.child_window(class_name="TDBIComboBox", found_index=0)
|
4183
|
+
select_especie.click()
|
4184
|
+
set_combobox("||List", "13 - DEVOLUCAO DE VENDA")
|
4185
|
+
send_keys("%g")
|
4186
|
+
except Exception as e:
|
4187
|
+
retorno = f"Não foi possivel filtar Devolução de Venda na tela de Rel. Boletim Caixa \nEtapas Executadas:\n{steps}"
|
4188
|
+
return RpaRetornoProcessoDTO(
|
4189
|
+
sucesso=False,
|
4190
|
+
retorno=retorno,
|
4191
|
+
status=RpaHistoricoStatusEnum.Falha,
|
4192
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
4193
|
+
)
|
4194
|
+
|
4195
|
+
#CLICANDO NO ICONE DE IMPRIMIR
|
4196
|
+
await worker_sleep(10)
|
4197
|
+
screen_width, screen_height = pyautogui.size()
|
4198
|
+
x = 10
|
4199
|
+
y = screen_height - 280 - (96 * 2) / .254
|
4200
|
+
pyautogui.click(x,y)
|
4201
|
+
|
4202
|
+
#INTERAGINDO COM A TELA DE PRINT
|
4203
|
+
try:
|
4204
|
+
console.print("Interagindo com a tela 'PRINT'...\n")
|
4205
|
+
app = Application().connect(class_name="TppPrintDialog", timeout=20)
|
4206
|
+
main_window = app["TppPrintDialog"]
|
4207
|
+
tpanel_btn_ok = main_window.child_window(class_name="TPanel", found_index=1)
|
4208
|
+
btn_ok_print_screen = tpanel_btn_ok.child_window(class_name="TButton", found_index=1)
|
4209
|
+
btn_ok_print_screen.click()
|
4210
|
+
await worker_sleep(5)
|
4211
|
+
|
4212
|
+
|
4213
|
+
#INSERINDO O DIRETORIO E SALVANDO O ARQUIVO
|
4214
|
+
app = Application().connect(title="Salvar Saída de Impressão como")
|
4215
|
+
main_window = app["Dialog"]
|
4216
|
+
console.print("Tela 'Salvar' encontrada!")
|
4217
|
+
|
4218
|
+
console.print("Interagindo com a tela 'Salvar'...\n")
|
4219
|
+
username = getpass.getuser()
|
4220
|
+
path_to_txt = f"C:\\Users\\{username}\\Downloads\\CAIXA 13 DEVOLUCAO {numero_cupom_fiscal}"
|
4221
|
+
|
4222
|
+
main_window.type_keys("%n")
|
4223
|
+
pyautogui.write(path_to_txt)
|
4224
|
+
await worker_sleep(1)
|
4225
|
+
main_window.type_keys("%l")
|
4226
|
+
console.print("Arquivo salvo com sucesso...\n")
|
4227
|
+
await worker_sleep(10)
|
4228
|
+
except Exception as e:
|
4229
|
+
retorno = f"Não foi possivel salvar o relatorio referente ao Boletim Caixa, erro {e}, \nEtapas Executadas:\n{steps}"
|
4230
|
+
return RpaRetornoProcessoDTO(
|
4231
|
+
sucesso=False,
|
4232
|
+
retorno=retorno,
|
4233
|
+
status=RpaHistoricoStatusEnum.Falha,
|
4234
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
4235
|
+
)
|
4236
|
+
|
4237
|
+
|
4238
|
+
with open(f"{path_to_txt}.pdf", 'rb') as file:
|
4239
|
+
file_bytes = io.BytesIO(file.read())
|
4240
|
+
|
4241
|
+
|
4242
|
+
desArquivo = f"CAIXA 13 DEVOLUCAO {numero_cupom_fiscal}.pdf"
|
4243
|
+
try:
|
4244
|
+
await send_file(historico_id, desArquivo, "pdf", file_bytes, file_extension="pdf")
|
4245
|
+
os.remove(f"{path_to_txt}.pdf")
|
4246
|
+
retorno = f"Processo de devolução executado com sucesso \nEtapas Executadas:\n{steps}"
|
4247
|
+
|
4248
|
+
try:
|
4249
|
+
url_retorno = nota.get("urlRetorno")
|
4250
|
+
identificador = nota.get("identificador")
|
4251
|
+
|
4252
|
+
if url_retorno and identificador:
|
4253
|
+
await post_partner(url_retorno, identificador, numero_nota_fiscal, valor_nota_fiscal)
|
4254
|
+
else:
|
4255
|
+
console.print("Não foi possivel obter o valor de urlRetorno/identificador")
|
4256
|
+
except:
|
4257
|
+
console.print(f"Erro ao obter os dados ou enviar a requisição: {e}")
|
4258
|
+
|
4259
|
+
return RpaRetornoProcessoDTO(
|
4260
|
+
sucesso=True,
|
4261
|
+
retorno=retorno,
|
4262
|
+
status=RpaHistoricoStatusEnum.Sucesso)
|
4263
|
+
except Exception as e:
|
4264
|
+
result = f"Arquivo CAIXA 13 DEVOLUÇÃO 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} !"
|
4265
|
+
console.print(result, style="bold red")
|
4266
|
+
return RpaRetornoProcessoDTO(
|
4267
|
+
sucesso=False,
|
4268
|
+
retorno=result,
|
4269
|
+
status=RpaHistoricoStatusEnum.Falha,
|
4270
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
4271
|
+
)
|
4272
|
+
|
4273
|
+
|
4274
|
+
except Exception as ex:
|
4275
|
+
retorno = f"Erro Processo Devolução CTF: {str(ex)} \nEtapas Executadas:\n{steps}"
|
4276
|
+
logger.error(retorno)
|
4277
|
+
console.print(retorno, style="bold red")
|
4278
|
+
return RpaRetornoProcessoDTO(
|
4279
|
+
sucesso=False,
|
4280
|
+
retorno=retorno,
|
4281
|
+
status=RpaHistoricoStatusEnum.Falha,
|
4282
|
+
tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
|
4283
|
+
)
|
4284
|
+
|
4285
|
+
if __name__ == "__main__":
|
4286
|
+
|
4287
|
+
task = RpaProcessoEntradaDTO(
|
4288
|
+
datEntradaFila= datetime.now(),
|
4289
|
+
configEntrada= {"":"","anexo":"https://portalintegra.grupoargenta.com.br/customSim/process/temp/attach/98357_154,80.png","itens":[{"descricao":"Gasolina Comum","novoPreco":6.08,"notaSeparada":False,"novaQuantidade":25.461}],"Empresa":"1","processo":"cf25b3f3-b9f1-45b5-a8d2-8c087024afdc","urlRetorno":"https://portalintegra.grupoargenta.com.br/customSim/process/response.php/WS_NFDEVOLUCAO/cdchamado/98357","nomeEmpresa":"LAGUNA CAMARAO","codigoEmpresa":"80","identificador":"98357","nomeMotorista":"N/A","cscCupomFiscal":"...","codClienteCorreto":"4476","docClienteCorreto":"72840002000108","duvidaSolicitante":"...","nomeClienteCorreto":"CTF","numCupomNotaFiscal":"1144479","codClienteIncorreto":"140552","docClienteIncorreto":"07473735008085","placaClienteCorreto":"0","nomeClienteIncorreto":"SIM REDE DE POSTOS LTDA- LAGUNA","quilometragemVeiculo":"0"},
|
4290
|
+
uuidProcesso='def194c2-ffa0-4b9e-b95c-920fb4ad4150',
|
4291
|
+
nomProcesso='extracao_fechamento_emsys',
|
4292
|
+
uuidFila="",
|
4293
|
+
sistemas=[
|
4294
|
+
{
|
4295
|
+
"sistema": "EMSys",
|
4296
|
+
"timeout": "1.0"
|
4297
|
+
},
|
4298
|
+
{
|
4299
|
+
"sistema": "AutoSystem",
|
4300
|
+
"timeout": "1.0"
|
4301
|
+
}
|
4302
|
+
],
|
4303
|
+
historico_id='2c4429c8-26ae-4ec6-b775-21583992e82f'
|
4304
|
+
)
|
4305
|
+
asyncio.run(devolucao_ctf_35(task))
|