worker-automate-hub 0.5.455__py3-none-any.whl → 0.5.456__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.
@@ -1160,7 +1160,7 @@ async def devolucao_ctf(task: RpaProcessoEntradaDTO) -> RpaRetornoProcessoDTO:
1160
1160
  #STEP 4
1161
1161
  #PRE VENDA
1162
1162
  itens_nota_separada = []
1163
- itens_nota_conjunta = []
1163
+ itens_nota_conjunta = []
1164
1164
  for item in nota.get('itens'):
1165
1165
  if item['notaSeparada']:
1166
1166
  itens_nota_separada.append(item)
@@ -2449,417 +2449,299 @@ async def devolucao_ctf(task: RpaProcessoEntradaDTO) -> RpaRetornoProcessoDTO:
2449
2449
 
2450
2450
 
2451
2451
  if len(itens_nota_conjunta) > 0:
2452
- console.print(itens_nota_separada)
2453
- for nf in itens_nota_separada:
2454
- type_text_into_field("Cadastro Pré venda", app["TFrmMenuPrincipal"]["Edit"], True, "50")
2455
- pyautogui.press("enter")
2456
- await worker_sleep(2)
2457
- pyautogui.press("enter")
2458
- await worker_sleep(4)
2459
- console.print(f"\nPesquisa: 'Cadastro Pré venda' realizada com sucesso",style="bold green")
2460
- await worker_sleep(2)
2461
- cadastro_pre_venda = await is_window_open_by_class("TFrmPreVenda", "TFrmPreVenda")
2462
- 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")
2452
+ console.print(itens_nota_conjunta)
2453
+ type_text_into_field("Cadastro Pré venda", app["TFrmMenuPrincipal"]["Edit"], True, "50")
2454
+ pyautogui.press("enter")
2455
+ await worker_sleep(2)
2456
+ pyautogui.press("enter")
2457
+ await worker_sleep(4)
2458
+ console.print(f"\nPesquisa: 'Cadastro Pré venda' realizada com sucesso",style="bold green")
2459
+ cadastro_pre_venda = await is_window_open_by_class("TFrmPreVenda", "TFrmPreVenda")
2460
+ 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")
2461
+
2462
+ if preenchimento_header_pre_venda.sucesso:
2463
+ try:
2464
+ cidade_cliente = preenchimento_header_pre_venda.retorno
2465
+ console.print(f"\nPreenchimento cabeçalho da pre venda preenchido com sucesso, seguindo com o processo.. ",style="bold green")
2466
+ app = Application().connect(class_name="TFrmPreVenda", timeout=60)
2467
+ main_window = app["TFrmPreVenda"]
2468
+ main_window.set_focus()
2469
+
2470
+ console.print("Navegando nos elementos...\n")
2471
+ panel_TPage= main_window.child_window(class_name="TPage", found_index=0)
2472
+ panel_menu_itens= main_window.child_window(class_name="TcxCustomInnerTreeView", found_index=0)
2473
+
2474
+ console.print("Acessando a janela de Itens...\n")
2475
+ panel_menu_itens.click()
2476
+ await worker_sleep(1)
2477
+ pyautogui.press('home')
2478
+ await worker_sleep(1)
2479
+ pyautogui.press('down')
2480
+ #console.print(nota.get('itens'))
2481
+ item_devolvido = ''
2482
+
2483
+ #FOR ITENS ENTRADA BACKOFFICE - Nota Conjunta
2484
+ for item in itens_nota_conjunta:
2485
+ quantidade = item['novaQuantidade']
2486
+ preco = item['novoPreco']
2487
+ descricao = item['descricao']
2488
+ descricao = 'Diesel Comum' if descricao == 'Diesel S500' else descricao
2489
+ quantidade = str(quantidade)
2490
+ preco = str(preco)
2491
+ #descricao = descricao.replace(".",",")
2492
+ console.print(quantidade, preco, descricao)
2493
+ item_devolvido = descricao
2494
+
2495
+ if 'arla' in descricao.lower():
2496
+ item_arla = True
2463
2497
 
2464
- if preenchimento_header_pre_venda.sucesso:
2465
- try:
2466
- cidade_cliente = preenchimento_header_pre_venda.retorno
2467
- console.print(f"\nPreenchimento cabeçalho da pre venda preenchido com sucesso, seguindo com o processo.. ",style="bold green")
2468
2498
  app = Application().connect(class_name="TFrmPreVenda", timeout=60)
2469
2499
  main_window = app["TFrmPreVenda"]
2470
2500
  main_window.set_focus()
2471
2501
 
2472
- console.print("Navegando nos elementos...\n")
2473
- panel_TPage= main_window.child_window(class_name="TPage", found_index=0)
2474
- panel_menu_itens= main_window.child_window(class_name="TcxCustomInnerTreeView", found_index=0)
2475
-
2476
- console.print("Acessando a janela de Itens...\n")
2477
- panel_menu_itens.click()
2478
- await worker_sleep(1)
2479
- pyautogui.press('home')
2480
- await worker_sleep(1)
2481
- pyautogui.press('down')
2482
- #console.print(nota.get('itens'))
2483
- item_devolvido = ''
2484
-
2485
- #FOR ITENS ENTRADA BACKOFFICE - Nota Conjunta
2486
- for item in itens_nota_conjunta:
2487
- quantidade = item['novaQuantidade']
2488
- preco = item['novoPreco']
2489
- descricao = item['descricao']
2490
- descricao = 'Diesel Comum' if descricao == 'Diesel S500' else descricao
2491
- quantidade = str(quantidade)
2492
- preco = str(preco)
2493
- #descricao = descricao.replace(".",",")
2494
- console.print(quantidade, preco, descricao)
2495
- item_devolvido = descricao
2496
-
2497
- if 'arla' in descricao.lower():
2498
- item_arla = True
2499
-
2500
- app = Application().connect(class_name="TFrmPreVenda", timeout=60)
2501
- main_window = app["TFrmPreVenda"]
2502
- main_window.set_focus()
2503
-
2504
- console.print("Itens acessado com sucesso, clicando em Incluir...\n")
2505
- panel_TGroup_Box= panel_TPage.child_window(class_name="TGroupBox", found_index=0)
2506
- btn_incluir = panel_TGroup_Box.child_window(class_name="TDBIBitBtn", found_index=4)
2507
- btn_incluir.click()
2508
- await worker_sleep(2)
2509
- console.print("Incluir clicado com sucesso...\n")
2510
-
2511
- #VERIFICANDO A EXISTENCIA DE WARNINGS
2512
- console.print("Verificando a existência de Warning... \n")
2513
- warning_pop_up = await is_window_open("Warning")
2514
- if warning_pop_up["IsOpened"] == True:
2515
- console.print("possui Pop-up de Warning, analisando... \n")
2516
- ocr_pop_warning = await ocr_warnings(numero_cupom_fiscal)
2517
- if ocr_pop_warning.sucesso == True:
2518
- return RpaRetornoProcessoDTO(
2519
- sucesso=False,
2520
- retorno=f"POP UP Warning não mapeado para seguimento do processo, mensagem: {ocr_pop_warning.retorno}",
2521
- status=RpaHistoricoStatusEnum.Falha,
2522
- tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
2523
- )
2524
- else:
2525
- return RpaRetornoProcessoDTO(
2526
- sucesso=False,
2527
- retorno=f"POP UP Warning não mapeado para seguimento do processo",
2528
- status=RpaHistoricoStatusEnum.Falha,
2529
- tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
2530
- )
2531
-
2532
-
2533
- i = 0
2534
- while i < 7:
2535
- try:
2536
- console.print("Clicando sobre a lupa para inserir o almoxarifado...\n")
2537
- app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=130)
2538
- main_window = app["TFrmIncluiItemPreVenda"]
2539
- main_window.set_focus()
2540
- panel_TGroup_Box= main_window.child_window(class_name="TPanel", found_index=2)
2541
- lupa_almoxarifaco = panel_TGroup_Box.child_window(class_name="TDBIBitBtn", found_index=1)
2542
- lupa_almoxarifaco.click()
2543
- console.print("Lupa clicado com sucesso inserindo a descrição do almoxarifado...\n")
2544
- await worker_sleep(2)
2545
-
2546
- dialog_buscar = await is_window_open_by_class("TfrmDialogBuscaGeral", "TfrmDialogBuscaGeral")
2547
- if dialog_buscar["IsOpened"] == True:
2548
- break
2549
- else:
2550
- console.print("Não foi possivel abrir a janela de Busca Geral")
2551
- i = i+1
2552
- except Exception as e:
2553
- console.print(f"Erro ao abrir a janela de Busca Geral: {e}")
2554
- i = i+1
2502
+ console.print("Itens acessado com sucesso, clicando em Incluir...\n")
2503
+ panel_TGroup_Box= panel_TPage.child_window(class_name="TGroupBox", found_index=0)
2504
+ btn_incluir = panel_TGroup_Box.child_window(class_name="TDBIBitBtn", found_index=4)
2505
+ btn_incluir.click()
2506
+ await worker_sleep(2)
2507
+ console.print("Incluir clicado com sucesso...\n")
2555
2508
 
2556
-
2557
- if i == 7:
2558
- retorno = f"Não foi possivel abrir a tela para buscar pelo item do produto na seleção do almoxarifado - \nEtapas Executadas:\n{steps}"
2509
+ #VERIFICANDO A EXISTENCIA DE WARNINGS
2510
+ console.print("Verificando a existência de Warning... \n")
2511
+ warning_pop_up = await is_window_open("Warning")
2512
+ if warning_pop_up["IsOpened"] == True:
2513
+ console.print("possui Pop-up de Warning, analisando... \n")
2514
+ ocr_pop_warning = await ocr_warnings(numero_cupom_fiscal)
2515
+ if ocr_pop_warning.sucesso == True:
2559
2516
  return RpaRetornoProcessoDTO(
2560
2517
  sucesso=False,
2561
- retorno=retorno,
2518
+ retorno=f"POP UP Warning não mapeado para seguimento do processo, mensagem: {ocr_pop_warning.retorno}",
2519
+ status=RpaHistoricoStatusEnum.Falha,
2520
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
2521
+ )
2522
+ else:
2523
+ return RpaRetornoProcessoDTO(
2524
+ sucesso=False,
2525
+ retorno=f"POP UP Warning não mapeado para seguimento do processo",
2562
2526
  status=RpaHistoricoStatusEnum.Falha,
2563
2527
  tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
2564
2528
  )
2565
2529
 
2566
- app = Application().connect(class_name="TfrmDialogBuscaGeral", timeout=60)
2567
- main_window = app["TfrmDialogBuscaGeral"]
2568
- main_window.set_focus()
2569
-
2570
- console.print("Buscando a mercadoria baseado na descrição...\n")
2571
- rect = main_window.rectangle()
2572
- center_x = (rect.left + rect.right) // 2
2573
- center_y = (rect.top + rect.bottom) // 2
2574
-
2575
- #pyautogui.moveTo(center_x, center_y)
2576
- await worker_sleep(1)
2577
- pyautogui.click(center_x, center_y)
2578
- await worker_sleep(1)
2579
- send_keys("^({HOME})")
2580
- item_arla_founded = False
2581
-
2582
- last_line = ''
2583
- max_attempts = 12
2584
- attempts = 0
2585
-
2586
- while attempts < max_attempts:
2587
- with pyautogui.hold('ctrl'):
2588
- pyautogui.press('c')
2589
- await worker_sleep(1)
2590
- with pyautogui.hold('ctrl'):
2591
- pyautogui.press('c')
2592
-
2593
- win32clipboard.OpenClipboard()
2594
- descricao_item = win32clipboard.GetClipboardData().strip()
2595
- win32clipboard.CloseClipboard()
2596
-
2597
- if last_line == descricao_item:
2598
- if item_arla:
2599
- main_window.set_focus()
2600
- send_keys("%r")
2601
- await worker_sleep(1)
2602
2530
 
2603
- app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=60)
2604
- main_window = app["TFrmIncluiItemPreVenda"]
2605
- main_window.set_focus()
2606
- panel_TGroup_Box= main_window.child_window(class_name="TPanel", found_index=2)
2607
- almoxarificado_index = panel_TGroup_Box.child_window(class_name="TDBIEditNumber", found_index=1)
2608
- cod_almoxarificado = str(cod_empresa)+"50"
2609
- almoxarificado_index.click()
2610
- await worker_sleep(1)
2611
- for _ in range(5):
2612
- pyautogui.press("del")
2613
- pyautogui.press("backspace")
2614
- await worker_sleep(1)
2615
- pyautogui.write(str(cod_almoxarificado))
2616
- pyautogui.press('tab')
2617
- await worker_sleep(1)
2531
+ i = 0
2532
+ while i < 7:
2533
+ try:
2534
+ console.print("Clicando sobre a lupa para inserir o almoxarifado...\n")
2535
+ app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=130)
2536
+ main_window = app["TFrmIncluiItemPreVenda"]
2537
+ main_window.set_focus()
2538
+ panel_TGroup_Box= main_window.child_window(class_name="TPanel", found_index=2)
2539
+ lupa_almoxarifaco = panel_TGroup_Box.child_window(class_name="TDBIBitBtn", found_index=1)
2540
+ lupa_almoxarifaco.click()
2541
+ console.print("Lupa clicado com sucesso inserindo a descrição do almoxarifado...\n")
2542
+ await worker_sleep(2)
2618
2543
 
2619
- cod_item_index = panel_TGroup_Box.child_window(class_name="TDBIEditNumber", found_index=0)
2620
- cod_item_index.click()
2621
- await worker_sleep(1)
2622
- for _ in range(5):
2623
- pyautogui.press("del")
2624
- pyautogui.press("backspace")
2625
- await worker_sleep(1)
2626
- pyautogui.write("1420")
2627
- pyautogui.press('tab')
2628
- await worker_sleep(1)
2629
- break
2630
- else:
2631
- retorno = f"Todos os itens percorridos e não foi possivel encontrar a descrição condizente a {descricao} \nEtapas Executadas:\n{steps}"
2632
- return RpaRetornoProcessoDTO(
2633
- sucesso=False,
2634
- retorno=retorno,
2635
- status=RpaHistoricoStatusEnum.Falha,
2636
- tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
2637
- )
2544
+ dialog_buscar = await is_window_open_by_class("TfrmDialogBuscaGeral", "TfrmDialogBuscaGeral")
2545
+ if dialog_buscar["IsOpened"] == True:
2546
+ break
2638
2547
  else:
2639
- if descricao.lower() in descricao_item.lower():
2640
- item_arla_founded = True
2641
- main_window.set_focus()
2642
- send_keys("%o")
2643
- break
2644
- else:
2645
- last_line = descricao_item
2646
- pyautogui.press('down')
2647
-
2648
-
2649
- await worker_sleep(10)
2650
- console.print("Processo finalizado com sucesso, seguindo com a seleção da natureza...\n")
2651
-
2652
- app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=60)
2653
- main_window = app["TFrmIncluiItemPreVenda"]
2654
- main_window.set_focus()
2655
- panel_TGroup_Box= main_window.child_window(class_name="TPanel", found_index=2)
2656
- natureza_oper_select = panel_TGroup_Box.child_window(class_name="TDBIComboBox", found_index=0)
2657
- # natureza_oper_select.click()
2658
-
2659
- console.print("Selecionando NOP: '5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC'")
2660
- natureza_oper_select.select("5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC")
2661
-
2548
+ console.print("Não foi possivel abrir a janela de Busca Geral")
2549
+ i = i+1
2550
+ except Exception as e:
2551
+ console.print(f"Erro ao abrir a janela de Busca Geral: {e}")
2552
+ i = i+1
2662
2553
 
2663
- console.print("Natureza da operação selecionado com sucesso, preenchendo os itens...\n")
2554
+
2555
+ if i == 7:
2556
+ retorno = f"Não foi possivel abrir a tela para buscar pelo item do produto na seleção do almoxarifado - \nEtapas Executadas:\n{steps}"
2557
+ return RpaRetornoProcessoDTO(
2558
+ sucesso=False,
2559
+ retorno=retorno,
2560
+ status=RpaHistoricoStatusEnum.Falha,
2561
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
2562
+ )
2664
2563
 
2665
- #INSERINDO A QUANTIDADE
2666
- main_window.set_focus()
2667
- panel_TPage_Control= main_window.child_window(class_name="TcxPageControl", found_index=0)
2668
- panel_tabSheet = panel_TPage_Control.child_window(class_name="TcxTabSheet", found_index=0)
2564
+ app = Application().connect(class_name="TfrmDialogBuscaGeral", timeout=60)
2565
+ main_window = app["TfrmDialogBuscaGeral"]
2566
+ main_window.set_focus()
2669
2567
 
2670
- field_quantidade = panel_tabSheet.child_window(class_name="TDBIEditNumber", found_index=8)
2671
- console.print("Inserindo a quantidade de Itens...\n")
2672
- field_quantidade.click()
2673
- await worker_sleep(1)
2674
- pyautogui.press('del')
2675
- await worker_sleep(1)
2676
- pyautogui.press('backspace')
2677
- await worker_sleep(1)
2678
- pyautogui.write(quantidade)
2679
- #field_quantidade.set_edit_text(quantidade)
2680
- await worker_sleep(1)
2681
- pyautogui.press('tab')
2682
- await worker_sleep(2)
2568
+ console.print("Buscando a mercadoria baseado na descrição...\n")
2569
+ rect = main_window.rectangle()
2570
+ center_x = (rect.left + rect.right) // 2
2571
+ center_y = (rect.top + rect.bottom) // 2
2683
2572
 
2684
- #INSERINDO O VALOR INDIVIDUAL DO ITEM
2685
- console.print("Inserindo o valor indivual do Item...\n")
2686
- btn_valor_unitario = panel_tabSheet.child_window(class_name="TDBIBitBtn", found_index=0)
2687
- btn_valor_unitario.click()
2688
- await worker_sleep(2)
2573
+ #pyautogui.moveTo(center_x, center_y)
2574
+ await worker_sleep(1)
2575
+ pyautogui.click(center_x, center_y)
2576
+ await worker_sleep(1)
2577
+ send_keys("^({HOME})")
2578
+ item_arla_founded = False
2689
2579
 
2690
- app = Application().connect(class_name="TFrmInputBoxNumero", timeout=60)
2691
- main_window = app["TFrmInputBoxNumero"]
2692
- main_window.set_focus()
2580
+ last_line = ''
2581
+ max_attempts = 12
2582
+ attempts = 0
2693
2583
 
2694
- field_valor = main_window.child_window(class_name="TDBIEditNumber", found_index=0)
2695
- field_valor.click()
2584
+ while attempts < max_attempts:
2585
+ with pyautogui.hold('ctrl'):
2586
+ pyautogui.press('c')
2696
2587
  await worker_sleep(1)
2697
- for _ in range(10):
2698
- pyautogui.press("del")
2699
- pyautogui.press("backspace")
2700
- pyautogui.write(preco)
2701
- #field_valor.set_edit_text(preco)
2702
- await worker_sleep(2)
2703
-
2704
- main_window.set_focus()
2705
- send_keys("%o")
2706
- await worker_sleep(2)
2707
- console.print("Valor inserido com sucesso...\n")
2708
-
2709
- app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=60)
2710
- main_window = app["TFrmIncluiItemPreVenda"]
2711
- main_window.set_focus()
2712
- send_keys("%i")
2713
- await worker_sleep(2)
2714
- #Divergencia de nop na capa e no item
2715
- await find_nop_divergence()
2716
- await worker_sleep(5)
2717
- main_window.close()
2718
- await worker_sleep(5) #FIM DO LOOP ITENS NOTA CONJUNTA
2719
-
2720
- #FOR OUTROS ITENS NOTA
2721
- for item in itens_nota:
2722
- quantidade = item['quantidade']
2723
- preco = item['valor_unitario']
2724
- descricao = item['descricao']
2725
- descricao = 'Diesel Comum' if descricao == 'Diesel S500' else descricao
2726
- item_cod = item['codigo']
2727
- #descricao = descricao.replace(".",",")
2588
+ with pyautogui.hold('ctrl'):
2589
+ pyautogui.press('c')
2728
2590
 
2729
- if 'arla' in descricao.lower():
2730
- item_arla = True
2731
- continue #continue para pular o item arla
2591
+ win32clipboard.OpenClipboard()
2592
+ descricao_item = win32clipboard.GetClipboardData().strip()
2593
+ win32clipboard.CloseClipboard()
2732
2594
 
2733
- console.print(quantidade, preco, descricao)
2595
+ if last_line == descricao_item:
2596
+ if item_arla:
2597
+ main_window.set_focus()
2598
+ send_keys("%r")
2599
+ await worker_sleep(1)
2734
2600
 
2735
- app = Application().connect(class_name="TFrmPreVenda", timeout=60)
2736
- main_window = app["TFrmPreVenda"]
2737
- main_window.set_focus()
2738
-
2739
- console.print("Itens acessado com sucesso, clicando em Incluir...\n")
2740
- panel_TGroup_Box= panel_TPage.child_window(class_name="TGroupBox", found_index=0)
2741
- btn_incluir = panel_TGroup_Box.child_window(class_name="TDBIBitBtn", found_index=4)
2742
- btn_incluir.click()
2743
- await worker_sleep(5)
2744
- console.print("Incluir clicado com sucesso...\n")
2601
+ app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=60)
2602
+ main_window = app["TFrmIncluiItemPreVenda"]
2603
+ main_window.set_focus()
2604
+ panel_TGroup_Box= main_window.child_window(class_name="TPanel", found_index=2)
2605
+ almoxarificado_index = panel_TGroup_Box.child_window(class_name="TDBIEditNumber", found_index=1)
2606
+ cod_almoxarificado = str(cod_empresa)+"50"
2607
+ almoxarificado_index.click()
2608
+ await worker_sleep(1)
2609
+ for _ in range(5):
2610
+ pyautogui.press("del")
2611
+ pyautogui.press("backspace")
2612
+ await worker_sleep(1)
2613
+ pyautogui.write(str(cod_almoxarificado))
2614
+ pyautogui.press('tab')
2615
+ await worker_sleep(1)
2745
2616
 
2746
- #VERIFICANDO A EXISTENCIA DE WARNINGS
2747
- console.print("Verificando a existência de Warning... \n")
2748
- warning_pop_up = await is_window_open("Warning")
2749
- if warning_pop_up["IsOpened"] == True:
2750
- console.print("possui Pop-up de Warning, analisando... \n")
2751
- ocr_pop_warning = await ocr_warnings(numero_cupom_fiscal)
2752
- if ocr_pop_warning.sucesso == True:
2617
+ cod_item_index = panel_TGroup_Box.child_window(class_name="TDBIEditNumber", found_index=0)
2618
+ cod_item_index.click()
2619
+ await worker_sleep(1)
2620
+ for _ in range(5):
2621
+ pyautogui.press("del")
2622
+ pyautogui.press("backspace")
2623
+ await worker_sleep(1)
2624
+ pyautogui.write("1420")
2625
+ pyautogui.press('tab')
2626
+ await worker_sleep(1)
2627
+ break
2628
+ else:
2629
+ retorno = f"Todos os itens percorridos e não foi possivel encontrar a descrição condizente a {descricao} \nEtapas Executadas:\n{steps}"
2753
2630
  return RpaRetornoProcessoDTO(
2754
2631
  sucesso=False,
2755
- retorno=f"POP UP Warning não mapeado para seguimento do processo, mensagem: {ocr_pop_warning.retorno}",
2756
- status=RpaHistoricoStatusEnum.Falha,
2757
- tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
2758
- )
2759
- else:
2760
- return RpaRetornoProcessoDTO(
2761
- sucesso=False,
2762
- retorno=f"POP UP Warning não mapeado para seguimento do processo",
2632
+ retorno=retorno,
2763
2633
  status=RpaHistoricoStatusEnum.Falha,
2764
2634
  tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
2765
2635
  )
2636
+ else:
2637
+ if descricao.lower() in descricao_item.lower():
2638
+ item_arla_founded = True
2639
+ main_window.set_focus()
2640
+ send_keys("%o")
2641
+ break
2642
+ else:
2643
+ last_line = descricao_item
2644
+ pyautogui.press('down')
2766
2645
 
2767
- app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=60)
2768
- main_window = app["TFrmIncluiItemPreVenda"]
2769
- main_window.set_focus()
2770
- panel_TGroup_Box= main_window.child_window(class_name="TPanel", found_index=2)
2771
- almoxarificado_index = panel_TGroup_Box.child_window(class_name="TDBIEditNumber", found_index=1)
2772
- cod_almoxarificado = str(cod_empresa)+"50"
2773
- almoxarificado_index.click()
2774
- await worker_sleep(1)
2775
- for _ in range(5):
2776
- pyautogui.press("del")
2777
- pyautogui.press("backspace")
2778
- await worker_sleep(1)
2779
- pyautogui.write(cod_almoxarificado)
2780
- pyautogui.press('tab')
2781
- await worker_sleep(3)
2782
2646
 
2783
- cod_item_index = panel_TGroup_Box.child_window(class_name="TDBIEditNumber", found_index=0)
2784
- cod_item_index.click()
2785
- await worker_sleep(1)
2647
+ await worker_sleep(10)
2648
+ console.print("Processo finalizado com sucesso, seguindo com a seleção da natureza...\n")
2786
2649
 
2787
- for _ in range(5):
2788
- pyautogui.press("del")
2789
- pyautogui.press("backspace")
2650
+ app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=60)
2651
+ main_window = app["TFrmIncluiItemPreVenda"]
2652
+ main_window.set_focus()
2653
+ panel_TGroup_Box= main_window.child_window(class_name="TPanel", found_index=2)
2654
+ natureza_oper_select = panel_TGroup_Box.child_window(class_name="TDBIComboBox", found_index=0)
2655
+ # natureza_oper_select.click()
2656
+
2657
+ console.print("Selecionando NOP: '5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC'")
2658
+ natureza_oper_select.select("5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC")
2659
+
2790
2660
 
2791
- await worker_sleep(1)
2792
- pyautogui.write(str(item_cod))
2793
- pyautogui.press('tab')
2794
- await worker_sleep(3)
2661
+ console.print("Natureza da operação selecionado com sucesso, preenchendo os itens...\n")
2795
2662
 
2663
+ #INSERINDO A QUANTIDADE
2664
+ main_window.set_focus()
2665
+ panel_TPage_Control= main_window.child_window(class_name="TcxPageControl", found_index=0)
2666
+ panel_tabSheet = panel_TPage_Control.child_window(class_name="TcxTabSheet", found_index=0)
2796
2667
 
2797
- natureza_oper_select = panel_TGroup_Box.child_window(class_name="TDBIComboBox", found_index=0)
2798
- nop_selected = natureza_oper_select.window_text()
2799
- nop_selected_value = nop_selected[:4]
2668
+ field_quantidade = panel_tabSheet.child_window(class_name="TDBIEditNumber", found_index=8)
2669
+ console.print("Inserindo a quantidade de Itens...\n")
2670
+ field_quantidade.click()
2671
+ await worker_sleep(1)
2672
+ pyautogui.press('del')
2673
+ await worker_sleep(1)
2674
+ pyautogui.press('backspace')
2675
+ await worker_sleep(1)
2676
+ pyautogui.write(quantidade)
2677
+ #field_quantidade.set_edit_text(quantidade)
2678
+ await worker_sleep(1)
2679
+ pyautogui.press('tab')
2680
+ await worker_sleep(2)
2800
2681
 
2801
- itens_to_select = natureza_oper_select.texts()
2802
- nop_to_be_select = ''
2682
+ #INSERINDO O VALOR INDIVIDUAL DO ITEM
2683
+ console.print("Inserindo o valor indivual do Item...\n")
2684
+ btn_valor_unitario = panel_tabSheet.child_window(class_name="TDBIBitBtn", found_index=0)
2685
+ btn_valor_unitario.click()
2686
+ await worker_sleep(2)
2803
2687
 
2804
- for item in itens_to_select:
2805
- 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())):
2806
- nop_to_be_select = item
2807
- break
2688
+ app = Application().connect(class_name="TFrmInputBoxNumero", timeout=60)
2689
+ main_window = app["TFrmInputBoxNumero"]
2690
+ main_window.set_focus()
2808
2691
 
2809
- natureza_oper_select.click()
2810
- await worker_sleep(1)
2811
- console.print(f"Descrição: {descricao}")
2812
- console.print("Selecionando NOP do item: '5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC'")
2813
- natureza_oper_select.select("5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC")
2814
-
2815
- await worker_sleep(1)
2816
- console.print("Natureza da operação selecionado com sucesso, preenchendo os itens...\n")
2692
+ field_valor = main_window.child_window(class_name="TDBIEditNumber", found_index=0)
2693
+ field_valor.click()
2694
+ await worker_sleep(1)
2695
+ for _ in range(10):
2696
+ pyautogui.press("del")
2697
+ pyautogui.press("backspace")
2698
+ pyautogui.write(preco)
2699
+ #field_valor.set_edit_text(preco)
2700
+ await worker_sleep(2)
2817
2701
 
2818
- #INSERINDO A QUANTIDADE
2819
- main_window.set_focus()
2820
- panel_TPage_Control= main_window.child_window(class_name="TcxPageControl", found_index=0)
2821
- panel_tabSheet = panel_TPage_Control.child_window(class_name="TcxTabSheet", found_index=0)
2702
+ main_window.set_focus()
2703
+ send_keys("%o")
2704
+ await worker_sleep(2)
2705
+ console.print("Valor inserido com sucesso...\n")
2822
2706
 
2823
- field_quantidade = panel_tabSheet.child_window(class_name="TDBIEditNumber", found_index=8)
2824
- console.print("Inserindo a quantidade de Itens...\n")
2825
- field_quantidade.click()
2826
- await worker_sleep(1)
2827
- pyautogui.press('del')
2828
- await worker_sleep(1)
2829
- pyautogui.press('backspace')
2830
- await worker_sleep(1)
2831
- pyautogui.write(quantidade)
2832
- #field_quantidade.set_edit_text(quantidade)
2833
- await worker_sleep(1)
2834
- pyautogui.press('tab')
2835
- await worker_sleep(2)
2707
+ app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=60)
2708
+ main_window = app["TFrmIncluiItemPreVenda"]
2709
+ main_window.set_focus()
2710
+ send_keys("%i")
2711
+ await worker_sleep(2)
2712
+ #Divergencia de nop na capa e no item
2713
+ await find_nop_divergence()
2714
+ await worker_sleep(5)
2715
+ main_window.close()
2716
+ await worker_sleep(5) #FIM DO LOOP ITENS NOTA CONJUNTA
2836
2717
 
2837
- console.print("Verificando inclui itiem Pre Venda")
2838
- app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=60)
2839
- main_window = app["TFrmIncluiItemPreVenda"]
2840
- main_window.set_focus()
2841
- send_keys("%i")
2842
- await worker_sleep(2)
2843
- #Divergencia de nop na capa e no item
2844
- await find_nop_divergence()
2845
- await worker_sleep(5)
2846
- main_window.close()
2718
+
2719
+ #FOR OUTROS ITENS NOTA
2720
+ for item in itens_nota:
2721
+ quantidade = item['quantidade']
2722
+ preco = item['valor_unitario']
2723
+ descricao = item['descricao']
2724
+ descricao = 'Diesel Comum' if descricao == 'Diesel S500' else descricao
2725
+ item_cod = item['codigo']
2726
+ #descricao = descricao.replace(".",",")
2727
+
2728
+ if 'arla' in descricao.lower():
2729
+ item_arla = True
2730
+ continue #continue para pular o item arla
2731
+
2732
+ console.print(quantidade, preco, descricao)
2733
+
2734
+ app = Application().connect(class_name="TFrmPreVenda", timeout=60)
2735
+ main_window = app["TFrmPreVenda"]
2736
+ main_window.set_focus()
2847
2737
 
2848
- # Inclui registro
2849
- console.print(f"Incluindo registro...\n")
2850
- try:
2851
- ASSETS_PATH = "assets"
2852
- inserir_registro = pyautogui.locateOnScreen(ASSETS_PATH + "\\entrada_notas\\IncluirRegistro.png", confidence=0.8)
2853
- pyautogui.click(inserir_registro)
2854
-
2855
- except Exception as e:
2856
- console.print(
2857
- f"Não foi possivel incluir o registro utilizando reconhecimento de imagem, Error: {e}...\n tentando inserir via posição...\n"
2858
- )
2859
- await incluir_registro()
2860
- await worker_sleep(5)
2861
-
2862
- await worker_sleep(8)
2738
+ console.print("Itens acessado com sucesso, clicando em Incluir...\n")
2739
+ panel_TGroup_Box= panel_TPage.child_window(class_name="TGroupBox", found_index=0)
2740
+ btn_incluir = panel_TGroup_Box.child_window(class_name="TDBIBitBtn", found_index=4)
2741
+ btn_incluir.click()
2742
+ await worker_sleep(5)
2743
+ console.print("Incluir clicado com sucesso...\n")
2744
+
2863
2745
  #VERIFICANDO A EXISTENCIA DE WARNINGS
2864
2746
  console.print("Verificando a existência de Warning... \n")
2865
2747
  warning_pop_up = await is_window_open("Warning")
@@ -2867,1034 +2749,1151 @@ async def devolucao_ctf(task: RpaProcessoEntradaDTO) -> RpaRetornoProcessoDTO:
2867
2749
  console.print("possui Pop-up de Warning, analisando... \n")
2868
2750
  ocr_pop_warning = await ocr_warnings(numero_cupom_fiscal)
2869
2751
  if ocr_pop_warning.sucesso == True:
2870
- retorno = f"POP UP Warning não mapeado para seguimento do processo, mensagem: {ocr_pop_warning.retorno} \nEtapas Executadas:\n{steps}"
2871
2752
  return RpaRetornoProcessoDTO(
2872
2753
  sucesso=False,
2873
- retorno=retorno,
2754
+ retorno=f"POP UP Warning não mapeado para seguimento do processo, mensagem: {ocr_pop_warning.retorno}",
2874
2755
  status=RpaHistoricoStatusEnum.Falha,
2875
2756
  tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
2876
2757
  )
2877
2758
  else:
2878
- retorno = f"POP UP Warning não mapeado para seguimento do processo \nEtapas Executadas:\n{steps}"
2879
2759
  return RpaRetornoProcessoDTO(
2880
2760
  sucesso=False,
2881
- retorno=retorno,
2761
+ retorno=f"POP UP Warning não mapeado para seguimento do processo",
2882
2762
  status=RpaHistoricoStatusEnum.Falha,
2883
2763
  tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
2884
2764
  )
2885
- await worker_sleep(5)
2886
- #VERIFICANDO SE A PRÉ VENDA FOI INCLUIDA COM SUCESSO
2887
- console.print("VERIFICANDO SE A PRÉ VENDA FOI INCLUIDA COM SUCESSO... \n")
2888
- information_pop_up = await is_window_open("Informação")
2889
- if information_pop_up["IsOpened"] == True:
2890
- msg_pop_up = await ocr_title(numero_nota_fiscal, "Informação")
2891
- console.print(f'retorno:{msg_pop_up.sucesso}')
2892
- console.print(f'retorno:{msg_pop_up}')
2893
- if msg_pop_up.sucesso == True:
2894
- msg_retorno = msg_pop_up.retorno
2895
- console.print(msg_retorno)
2896
- if 'venda' in msg_retorno.lower():
2897
- try:
2898
- information_operacao_concluida = main_window.child_window(title="Informação")
2899
- btn_ok = information_operacao_concluida.child_window(class_name="TButton")
2900
- btn_ok.click()
2901
- await worker_sleep(4)
2902
- except:
2903
- pyautogui.press('enter')
2904
- await worker_sleep(4)
2905
- else:
2906
- retorno = f"Pop up nao mapeado para seguimento do robo {msg_pop_up.retorno} \nEtapas Executadas:\n{steps}"
2907
- return RpaRetornoProcessoDTO(
2908
- sucesso=False,
2909
- retorno=retorno,
2910
- status=RpaHistoricoStatusEnum.Falha,
2911
- tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
2912
- )
2913
- else:
2914
- retorno = f"Não foi possivel realizar a confirmação do msg do OCR \nEtapas Executadas:\n{steps}"
2915
- return RpaRetornoProcessoDTO(
2916
- sucesso=False,
2917
- retorno=retorno,
2918
- status=RpaHistoricoStatusEnum.Falha,
2919
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
2920
- )
2921
- else:
2922
- retorno = f"Janela de confirmação de pre venda incluida nao encontrada \nEtapas Executadas:\n{steps}"
2923
- return RpaRetornoProcessoDTO(
2924
- sucesso=False,
2925
- retorno=retorno,
2926
- status=RpaHistoricoStatusEnum.Falha,
2927
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
2928
- )
2929
-
2930
- await worker_sleep(5)
2931
- steps += ' ETAPA 04 - PRE VENDA INCLUIDA COM SUCESSO'
2932
- #CONFIRMANDO POP UP DE PRÉ VENDA - PESQUISAR PRE VENDA
2933
- try:
2934
- console.print("CONFIRMANDO POP UP DE PRÉ VENDA - PESQUISAR PRE VENDA... \n")
2935
- app = Application().connect(class_name="TFrmPreVenda", timeout=10)
2936
- main_window = app["Confirm"]
2937
- main_window.set_focus()
2938
2765
 
2939
- btn_yes = main_window.child_window(class_name="TButton", found_index=1)
2940
- btn_yes.click()
2941
- await worker_sleep(3)
2942
- except Exception as e:
2943
- retorno = f"Pop Up de Confirm (Deseja pesquisar a Pré Venda ?) não encontrado \nEtapas Executadas:\n{steps}"
2944
- return RpaRetornoProcessoDTO(
2945
- sucesso=False,
2946
- retorno=retorno,
2947
- status=RpaHistoricoStatusEnum.Falha,
2948
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
2949
- )
2766
+ app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=60)
2767
+ main_window = app["TFrmIncluiItemPreVenda"]
2768
+ main_window.set_focus()
2769
+ panel_TGroup_Box= main_window.child_window(class_name="TPanel", found_index=2)
2770
+ almoxarificado_index = panel_TGroup_Box.child_window(class_name="TDBIEditNumber", found_index=1)
2771
+ cod_almoxarificado = str(cod_empresa)+"50"
2772
+ almoxarificado_index.click()
2773
+ await worker_sleep(1)
2774
+ for _ in range(5):
2775
+ pyautogui.press("del")
2776
+ pyautogui.press("backspace")
2777
+ await worker_sleep(1)
2778
+ pyautogui.write(cod_almoxarificado)
2779
+ pyautogui.press('tab')
2780
+ await worker_sleep(3)
2950
2781
 
2782
+ cod_item_index = panel_TGroup_Box.child_window(class_name="TDBIEditNumber", found_index=0)
2783
+ cod_item_index.click()
2784
+ await worker_sleep(1)
2951
2785
 
2952
- #CONFIRMANDO NA TELA DE PRE VENDA
2953
- try:
2954
- console.print("CLICANDO EM CONFIRMAR... \n")
2955
- app = Application().connect(class_name="TFrmPreVenda", timeout=60)
2956
- main_window = app["TFrmPreVenda"]
2957
- main_window.set_focus()
2786
+ for _ in range(5):
2787
+ pyautogui.press("del")
2788
+ pyautogui.press("backspace")
2958
2789
 
2959
- panel_Tnotebook = main_window.child_window(class_name="TNotebook", found_index=0)
2960
- panel_Tnotebook = panel_Tnotebook.child_window(class_name="TPage", found_index=0)
2961
- btn_confirmar = panel_Tnotebook.child_window(class_name="TBitBtn", found_index=11)
2962
- btn_confirmar.click()
2963
- console.print("CONFIRMAR CLICADO COM SUCESSO... \n")
2964
- await worker_sleep(3)
2965
- except Exception as e:
2966
- retorno = f"Não foi possivel clicar em Confirma na tela de Pre Venda \nEtapas Executadas:\n{steps}"
2967
- return RpaRetornoProcessoDTO(
2968
- sucesso=False,
2969
- retorno=retorno,
2970
- status=RpaHistoricoStatusEnum.Falha,
2971
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
2972
- )
2790
+ await worker_sleep(1)
2791
+ pyautogui.write(str(item_cod))
2792
+ pyautogui.press('tab')
2793
+ await worker_sleep(3)
2973
2794
 
2974
2795
 
2975
- #CONFIRMANDO NA TELA DE PRE VENDA
2976
- try:
2977
- console.print("CONFIRMANDO POP UP DE Deseja realmente confirmar esta PRÉ VENDA ... \n")
2978
- app = Application().connect(class_name="TFrmPreVenda", timeout=10)
2979
- main_window = app["Confirm"]
2980
- main_window.set_focus()
2796
+ natureza_oper_select = panel_TGroup_Box.child_window(class_name="TDBIComboBox", found_index=0)
2797
+ nop_selected = natureza_oper_select.window_text()
2798
+ nop_selected_value = nop_selected[:4]
2981
2799
 
2982
- btn_yes = main_window.child_window(class_name="TButton", found_index=1)
2983
- btn_yes.click()
2984
- await worker_sleep(3)
2985
- except Exception as e:
2986
- retorno = f"Não foi possivel clicar para confirmar a janela 'Deseja realmente confirmar esta pre-venda' \nEtapas Executadas:\n{steps}"
2987
- return RpaRetornoProcessoDTO(
2988
- sucesso=False,
2989
- retorno=retorno,
2990
- status=RpaHistoricoStatusEnum.Falha,
2991
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
2992
- )
2800
+ itens_to_select = natureza_oper_select.texts()
2801
+ nop_to_be_select = ''
2993
2802
 
2803
+ for item in itens_to_select:
2804
+ 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())):
2805
+ nop_to_be_select = item
2806
+ break
2994
2807
 
2995
- warning_pop = await is_window_open_by_class("TFrmPreVenda", "Warning")
2996
- if warning_pop["IsOpened"] == True:
2997
- app = Application().connect(class_name="TFrmPreVenda", timeout=10)
2998
- main_window = app["Warning"]
2999
- main_window.set_focus()
3000
-
3001
- btn_ok = main_window.child_window(class_name="TButton", found_index=0)
3002
- btn_ok.click()
3003
- await worker_sleep(3)
3004
- else:
3005
- console.print("Nenhum pop-up de Warning Encontrado... \n")
3006
-
3007
-
3008
- #VERIFICANDO POP UP - DE ACORDO COM OS PARÂMETROS DO SISTEMA..
3009
- console.print("VERIFICANDO POP UP - DE ACORDO COM OS PARÂMETROS DO SISTEMA... \n")
3010
- information_pop_up = await is_window_open_by_class("TFrmPreVenda", "Confirm")
3011
- if information_pop_up["IsOpened"] == True:
3012
- msg_pop_up = await ocr_by_class(numero_nota_fiscal, "TFrmPreVenda", "Confirm")
3013
- console.print(f'retorno:{msg_pop_up.sucesso}')
3014
- console.print(f'retorno:{msg_pop_up}')
3015
- if msg_pop_up.sucesso == True:
3016
- msg_retorno = msg_pop_up.retorno
3017
- console.print(msg_retorno)
3018
- if 'finan' in msg_retorno.lower():
3019
- app = Application().connect(class_name="TFrmPreVenda", timeout=10)
3020
- main_window = app["Confirm"]
3021
- main_window.set_focus()
3022
-
3023
- btn_yes = main_window.child_window(class_name="TButton", found_index=1)
3024
- btn_yes.click()
3025
- else:
3026
- retorno = f"Pop up nao mapeado para seguimento do robo {msg_pop_up.retorno} \nEtapas Executadas:\n{steps}"
3027
- return RpaRetornoProcessoDTO(
3028
- sucesso=False,
3029
- retorno=retorno,
3030
- status=RpaHistoricoStatusEnum.Falha,
3031
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3032
- )
3033
- else:
3034
- retorno = f"Não foi possivel realizar a confirmação do msg do OCR \nEtapas Executadas:\n{steps}"
3035
- return RpaRetornoProcessoDTO(
3036
- sucesso=False,
3037
- retorno=retorno,
3038
- status=RpaHistoricoStatusEnum.Falha,
3039
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3040
- )
2808
+ natureza_oper_select.click()
2809
+ await worker_sleep(1)
2810
+ console.print(f"Descrição: {descricao}")
2811
+ console.print("Selecionando NOP do item: '5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC'")
2812
+ natureza_oper_select.select("5667 - VENDA DE COMB OU LUBRI - SEM ESTOQ E COM FINANC")
3041
2813
 
2814
+ await worker_sleep(1)
2815
+ console.print("Natureza da operação selecionado com sucesso, preenchendo os itens...\n")
3042
2816
 
3043
- #APROVAR CREDITO
3044
- try:
3045
- console.print("Aprovar Credito... \n")
3046
- app = Application().connect(class_name="TFrmPreVenda", timeout=10)
3047
- main_window = app["TFrmPreVenda"]
3048
- main_window.set_focus()
2817
+ #INSERINDO A QUANTIDADE
2818
+ main_window.set_focus()
2819
+ panel_TPage_Control= main_window.child_window(class_name="TcxPageControl", found_index=0)
2820
+ panel_tabSheet = panel_TPage_Control.child_window(class_name="TcxTabSheet", found_index=0)
3049
2821
 
3050
- panel_Tnotebook = main_window.child_window(class_name="TNotebook", found_index=0)
3051
- panel_Tnotebook = panel_Tnotebook.child_window(class_name="TPage", found_index=0)
3052
- btn_aprovar_credito = panel_Tnotebook.child_window(class_name="TBitBtn", found_index=8)
3053
- console.print("Clicando em aprovar Credito... \n")
3054
- btn_aprovar_credito.click()
3055
- await worker_sleep(2)
3056
- except Exception as e:
3057
- retorno = f"Não foi possivel clicar em aprovar credito na tela de Pre venda \nEtapas Executadas:\n{steps}"
2822
+ field_quantidade = panel_tabSheet.child_window(class_name="TDBIEditNumber", found_index=8)
2823
+ console.print("Inserindo a quantidade de Itens...\n")
2824
+ field_quantidade.click()
2825
+ await worker_sleep(1)
2826
+ pyautogui.press('del')
2827
+ await worker_sleep(1)
2828
+ pyautogui.press('backspace')
2829
+ await worker_sleep(1)
2830
+ pyautogui.write(quantidade)
2831
+ #field_quantidade.set_edit_text(quantidade)
2832
+ await worker_sleep(1)
2833
+ pyautogui.press('tab')
2834
+ await worker_sleep(2)
2835
+
2836
+ console.print("Verificando inclui itiem Pre Venda")
2837
+ app = Application().connect(class_name="TFrmIncluiItemPreVenda", timeout=60)
2838
+ main_window = app["TFrmIncluiItemPreVenda"]
2839
+ main_window.set_focus()
2840
+ send_keys("%i")
2841
+ await worker_sleep(2)
2842
+ #Divergencia de nop na capa e no item
2843
+ await find_nop_divergence()
2844
+ await worker_sleep(5)
2845
+ main_window.close()
2846
+
2847
+ # Inclui registro
2848
+ console.print(f"Incluindo registro...\n")
2849
+ try:
2850
+ ASSETS_PATH = "assets"
2851
+ inserir_registro = pyautogui.locateOnScreen(ASSETS_PATH + "\\entrada_notas\\IncluirRegistro.png", confidence=0.8)
2852
+ pyautogui.click(inserir_registro)
2853
+
2854
+ except Exception as e:
2855
+ console.print(
2856
+ f"Não foi possivel incluir o registro utilizando reconhecimento de imagem, Error: {e}...\n tentando inserir via posição...\n"
2857
+ )
2858
+ await incluir_registro()
2859
+ await worker_sleep(5)
2860
+
2861
+ await worker_sleep(8)
2862
+ #VERIFICANDO A EXISTENCIA DE WARNINGS
2863
+ console.print("Verificando a existência de Warning... \n")
2864
+ warning_pop_up = await is_window_open("Warning")
2865
+ if warning_pop_up["IsOpened"] == True:
2866
+ console.print("possui Pop-up de Warning, analisando... \n")
2867
+ ocr_pop_warning = await ocr_warnings(numero_cupom_fiscal)
2868
+ if ocr_pop_warning.sucesso == True:
2869
+ retorno = f"POP UP Warning não mapeado para seguimento do processo, mensagem: {ocr_pop_warning.retorno} \nEtapas Executadas:\n{steps}"
3058
2870
  return RpaRetornoProcessoDTO(
3059
2871
  sucesso=False,
3060
2872
  retorno=retorno,
3061
2873
  status=RpaHistoricoStatusEnum.Falha,
3062
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
2874
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
3063
2875
  )
3064
-
3065
-
3066
- console.print("O valor desta pré venda exige uma aprovação... \n")
3067
- try:
3068
- app = Application().connect(class_name="TFrmPreVenda", timeout=10)
3069
- main_window = app["Confirm"]
3070
- main_window.set_focus()
3071
-
3072
- btn_yes = main_window.child_window(class_name="TButton", found_index=1)
3073
- btn_yes.click()
3074
- await worker_sleep(3)
3075
- except:
3076
- retorno = f"Não foi possivel clicar no pop-up 'O valor desta pré venda exige uma aprovação financeira' na tela de Pre venda \nEtapas Executadas:\n{steps}"
2876
+ else:
2877
+ retorno = f"POP UP Warning não mapeado para seguimento do processo \nEtapas Executadas:\n{steps}"
3077
2878
  return RpaRetornoProcessoDTO(
3078
2879
  sucesso=False,
3079
2880
  retorno=retorno,
3080
2881
  status=RpaHistoricoStatusEnum.Falha,
3081
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
2882
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
3082
2883
  )
3083
-
3084
-
3085
- #VERIFICANDO SE A PRÉ VENDA FOI INCLUIDA COM SUCESSO
3086
- console.print("VERIFICANDO SE A APROVAÇÃO FINANCEIRA FOI REALIZADA COM SUCESSO... \n")
3087
- information_pop_up = await is_window_open("Information")
3088
- if information_pop_up["IsOpened"] == True:
3089
- msg_pop_up = await ocr_title(numero_nota_fiscal, "Information")
3090
- console.print(f'retorno:{msg_pop_up.sucesso}')
3091
- console.print(f'retorno:{msg_pop_up}')
3092
- if msg_pop_up.sucesso == True:
3093
- msg_retorno = msg_pop_up.retorno
3094
- console.print(msg_retorno)
3095
- if 'sucesso' in msg_retorno.lower():
3096
- try:
3097
- information_operacao_concluida = main_window.child_window(title="Information")
3098
- btn_ok = information_operacao_concluida.child_window(class_name="TButton")
3099
- btn_ok.click()
3100
- await worker_sleep(4)
3101
- except:
3102
- pyautogui.press('enter')
3103
- await worker_sleep(4)
3104
- else:
3105
- retorno = f"Pop up nao mapeado para seguimento do robo {msg_pop_up.retorno} \nEtapas Executadas:\n{steps}"
3106
- return RpaRetornoProcessoDTO(
3107
- sucesso=False,
3108
- retorno=retorno,
3109
- status=RpaHistoricoStatusEnum.Falha,
3110
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3111
- )
2884
+ await worker_sleep(5)
2885
+ #VERIFICANDO SE A PRÉ VENDA FOI INCLUIDA COM SUCESSO
2886
+ console.print("VERIFICANDO SE A PRÉ VENDA FOI INCLUIDA COM SUCESSO... \n")
2887
+ information_pop_up = await is_window_open("Informação")
2888
+ if information_pop_up["IsOpened"] == True:
2889
+ msg_pop_up = await ocr_title(numero_nota_fiscal, "Informação")
2890
+ console.print(f'retorno:{msg_pop_up.sucesso}')
2891
+ console.print(f'retorno:{msg_pop_up}')
2892
+ if msg_pop_up.sucesso == True:
2893
+ msg_retorno = msg_pop_up.retorno
2894
+ console.print(msg_retorno)
2895
+ if 'venda' in msg_retorno.lower():
2896
+ try:
2897
+ information_operacao_concluida = main_window.child_window(title="Informação")
2898
+ btn_ok = information_operacao_concluida.child_window(class_name="TButton")
2899
+ btn_ok.click()
2900
+ await worker_sleep(4)
2901
+ except:
2902
+ pyautogui.press('enter')
2903
+ await worker_sleep(4)
3112
2904
  else:
3113
- retorno = f"Não foi possivel realizar a confirmação do msg do OCR \nEtapas Executadas:\n{steps}"
2905
+ retorno = f"Pop up nao mapeado para seguimento do robo {msg_pop_up.retorno} \nEtapas Executadas:\n{steps}"
3114
2906
  return RpaRetornoProcessoDTO(
3115
2907
  sucesso=False,
3116
2908
  retorno=retorno,
3117
2909
  status=RpaHistoricoStatusEnum.Falha,
3118
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
2910
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Negocio)]
3119
2911
  )
3120
2912
  else:
3121
- retorno = f"Janela de confirmação de Aprovação financeira realizada com sucesso \nEtapas Executadas:\n{steps}"
3122
- return RpaRetornoProcessoDTO(
3123
- sucesso=False,
3124
- retorno=retorno,
3125
- status=RpaHistoricoStatusEnum.Falha,
3126
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3127
- )
3128
- await worker_sleep(3)
3129
-
3130
-
3131
- #FATURAR
3132
- try:
3133
- console.print("FATURAR... \n")
3134
- app = Application().connect(class_name="TFrmPreVenda", timeout=10)
3135
- main_window = app["TFrmPreVenda"]
3136
- main_window.set_focus()
3137
-
3138
- panel_Tnotebook = main_window.child_window(class_name="TNotebook", found_index=0)
3139
- panel_Tnotebook = panel_Tnotebook.child_window(class_name="TPage", found_index=0)
3140
- btn_faturar = panel_Tnotebook.child_window(class_name="TBitBtn", found_index=7)
3141
- btn_faturar.click()
3142
- console.print("BOTAO FATURAR CLICADO COM SUCESSO... \n")
3143
- await worker_sleep(5)
3144
- except Exception as e:
3145
- retorno = f"Não foi possivel clicar em Faturar na tela de pre venda, erro: {e} \nEtapas Executadas:\n{steps}"
2913
+ retorno = f"Não foi possivel realizar a confirmação do msg do OCR \nEtapas Executadas:\n{steps}"
3146
2914
  return RpaRetornoProcessoDTO(
3147
2915
  sucesso=False,
3148
2916
  retorno=retorno,
3149
2917
  status=RpaHistoricoStatusEnum.Falha,
3150
2918
  tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3151
2919
  )
3152
-
3153
-
3154
- console.print("Recalcular Parcelas da Pre venda... \n")
3155
- try:
3156
- app = Application().connect(class_name="TFrmPreVenda", timeout=40)
3157
- main_window = app["Confirm"]
3158
- main_window.set_focus()
3159
-
3160
- btn_no = main_window.child_window(class_name="TButton", found_index=0)
3161
- btn_no.click()
3162
- try:
3163
- btn_no.click()
3164
- except:
3165
- pass
3166
- await worker_sleep(3)
3167
- except:
3168
- retorno = f"Não foi possivel clicar no pop-up 'Recalcular Parcelas da Pre venda' na tela de Pre venda \nEtapas Executadas:\n{steps}"
3169
- return RpaRetornoProcessoDTO(
2920
+ else:
2921
+ retorno = f"Janela de confirmação de pre venda incluida nao encontrada \nEtapas Executadas:\n{steps}"
2922
+ return RpaRetornoProcessoDTO(
3170
2923
  sucesso=False,
3171
2924
  retorno=retorno,
3172
2925
  status=RpaHistoricoStatusEnum.Falha,
3173
2926
  tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3174
2927
  )
2928
+
2929
+ await worker_sleep(5)
2930
+ steps += ' ETAPA 04 - PRE VENDA INCLUIDA COM SUCESSO'
2931
+ #CONFIRMANDO POP UP DE PRÉ VENDA - PESQUISAR PRE VENDA
2932
+ try:
2933
+ console.print("CONFIRMANDO POP UP DE PRÉ VENDA - PESQUISAR PRE VENDA... \n")
2934
+ app = Application().connect(class_name="TFrmPreVenda", timeout=10)
2935
+ main_window = app["Confirm"]
2936
+ main_window.set_focus()
3175
2937
 
2938
+ btn_yes = main_window.child_window(class_name="TButton", found_index=1)
2939
+ btn_yes.click()
2940
+ await worker_sleep(3)
2941
+ except Exception as e:
2942
+ retorno = f"Pop Up de Confirm (Deseja pesquisar a Pré Venda ?) não encontrado \nEtapas Executadas:\n{steps}"
2943
+ return RpaRetornoProcessoDTO(
2944
+ sucesso=False,
2945
+ retorno=retorno,
2946
+ status=RpaHistoricoStatusEnum.Falha,
2947
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
2948
+ )
3176
2949
 
3177
- parcelas_nf_saida_pop_up = await is_window_open("Parcelas - Nota Fiscal Saída")
3178
- if parcelas_nf_saida_pop_up["IsOpened"] == True:
3179
- app = Application().connect(title="Parcelas - Nota Fiscal Saída", timeout=60)
3180
- main_window = app.window(title="Parcelas - Nota Fiscal Saída")
3181
- main_window.set_focus()
3182
- send_keys("%n")
3183
- await worker_sleep(3)
3184
- else:
3185
- retorno = f"Não foi encontrada a Janela de Parcelas - Nota Fiscal Saída \nEtapas Executadas:\n{steps}"
3186
- return RpaRetornoProcessoDTO(
3187
- sucesso=False,
3188
- retorno=retorno,
3189
- status=RpaHistoricoStatusEnum.Falha,
3190
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3191
- )
3192
2950
 
2951
+ #CONFIRMANDO NA TELA DE PRE VENDA
2952
+ try:
2953
+ console.print("CLICANDO EM CONFIRMAR... \n")
2954
+ app = Application().connect(class_name="TFrmPreVenda", timeout=60)
2955
+ main_window = app["TFrmPreVenda"]
2956
+ main_window.set_focus()
3193
2957
 
3194
- information_pop_up = await is_window_open("Information")
3195
- if information_pop_up["IsOpened"] == True:
3196
- app = Application().connect(title="Information", timeout=30)
3197
- main_window = app["Information"]
3198
- main_window.set_focus()
3199
- btn_ok = main_window.child_window(class_name="TButton", found_index=0)
3200
- btn_ok.click()
2958
+ panel_Tnotebook = main_window.child_window(class_name="TNotebook", found_index=0)
2959
+ panel_Tnotebook = panel_Tnotebook.child_window(class_name="TPage", found_index=0)
2960
+ btn_confirmar = panel_Tnotebook.child_window(class_name="TBitBtn", found_index=11)
2961
+ btn_confirmar.click()
2962
+ console.print("CONFIRMAR CLICADO COM SUCESSO... \n")
2963
+ await worker_sleep(3)
2964
+ except Exception as e:
2965
+ retorno = f"Não foi possivel clicar em Confirma na tela de Pre Venda \nEtapas Executadas:\n{steps}"
2966
+ return RpaRetornoProcessoDTO(
2967
+ sucesso=False,
2968
+ retorno=retorno,
2969
+ status=RpaHistoricoStatusEnum.Falha,
2970
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
2971
+ )
3201
2972
 
3202
2973
 
3203
- await worker_sleep(15)
2974
+ #CONFIRMANDO NA TELA DE PRE VENDA
2975
+ try:
2976
+ console.print("CONFIRMANDO POP UP DE Deseja realmente confirmar esta PRÉ VENDA ... \n")
2977
+ app = Application().connect(class_name="TFrmPreVenda", timeout=10)
2978
+ main_window = app["Confirm"]
2979
+ main_window.set_focus()
3204
2980
 
2981
+ btn_yes = main_window.child_window(class_name="TButton", found_index=1)
2982
+ btn_yes.click()
2983
+ await worker_sleep(3)
2984
+ except Exception as e:
2985
+ retorno = f"Não foi possivel clicar para confirmar a janela 'Deseja realmente confirmar esta pre-venda' \nEtapas Executadas:\n{steps}"
2986
+ return RpaRetornoProcessoDTO(
2987
+ sucesso=False,
2988
+ retorno=retorno,
2989
+ status=RpaHistoricoStatusEnum.Falha,
2990
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
2991
+ )
3205
2992
 
3206
- #FATURAMENTO PRÉ-VENDA
3207
- try:
3208
- console.print("FATURAMENTO PRÉ-VENDA... \n")
3209
- app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
3210
- main_window = app["TFrmDadosFaturamentoPreVenda"]
3211
- main_window.set_focus()
3212
- except Exception as e:
3213
- retorno = f"Não foi encontrada a Janela Faturamento de Pré Venda \nEtapas Executadas:\n{steps}"
2993
+
2994
+ warning_pop = await is_window_open_by_class("TFrmPreVenda", "Warning")
2995
+ if warning_pop["IsOpened"] == True:
2996
+ app = Application().connect(class_name="TFrmPreVenda", timeout=10)
2997
+ main_window = app["Warning"]
2998
+ main_window.set_focus()
2999
+
3000
+ btn_ok = main_window.child_window(class_name="TButton", found_index=0)
3001
+ btn_ok.click()
3002
+ await worker_sleep(3)
3003
+ else:
3004
+ console.print("Nenhum pop-up de Warning Encontrado... \n")
3005
+
3006
+
3007
+ #VERIFICANDO POP UP - DE ACORDO COM OS PARÂMETROS DO SISTEMA..
3008
+ console.print("VERIFICANDO POP UP - DE ACORDO COM OS PARÂMETROS DO SISTEMA... \n")
3009
+ information_pop_up = await is_window_open_by_class("TFrmPreVenda", "Confirm")
3010
+ if information_pop_up["IsOpened"] == True:
3011
+ msg_pop_up = await ocr_by_class(numero_nota_fiscal, "TFrmPreVenda", "Confirm")
3012
+ console.print(f'retorno:{msg_pop_up.sucesso}')
3013
+ console.print(f'retorno:{msg_pop_up}')
3014
+ if msg_pop_up.sucesso == True:
3015
+ msg_retorno = msg_pop_up.retorno
3016
+ console.print(msg_retorno)
3017
+ if 'finan' in msg_retorno.lower():
3018
+ app = Application().connect(class_name="TFrmPreVenda", timeout=10)
3019
+ main_window = app["Confirm"]
3020
+ main_window.set_focus()
3021
+
3022
+ btn_yes = main_window.child_window(class_name="TButton", found_index=1)
3023
+ btn_yes.click()
3024
+ else:
3025
+ retorno = f"Pop up nao mapeado para seguimento do robo {msg_pop_up.retorno} \nEtapas Executadas:\n{steps}"
3026
+ return RpaRetornoProcessoDTO(
3027
+ sucesso=False,
3028
+ retorno=retorno,
3029
+ status=RpaHistoricoStatusEnum.Falha,
3030
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3031
+ )
3032
+ else:
3033
+ retorno = f"Não foi possivel realizar a confirmação do msg do OCR \nEtapas Executadas:\n{steps}"
3214
3034
  return RpaRetornoProcessoDTO(
3215
3035
  sucesso=False,
3216
- retorno=result,
3036
+ retorno=retorno,
3217
3037
  status=RpaHistoricoStatusEnum.Falha,
3218
3038
  tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3219
3039
  )
3220
- await worker_sleep(2)
3221
- await find_warning_nop_divergence()
3222
- await worker_sleep(2)
3223
- #VERIFICANDO SE POSSUI POP UP WARNING
3224
- console.print("Verificando a presença de Warning... \n")
3225
- warning_boo = False
3226
- await worker_sleep(5)
3227
- try:
3228
- try:
3229
- app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=10)
3230
- main_window = app["Warning"]
3231
- main_window.set_focus()
3232
-
3233
- except:
3234
- console.print('Except Verificando warnings... \n')
3235
- app = Application().connect(class_name="Warning", timeout=10)
3236
- main_window = app["Warning"]
3237
- main_window.set_focus()
3238
- console.print("Possui Warning... \n")
3239
- await worker_sleep(2)
3240
- await find_warning_nop_divergence()
3241
- btn_ok = main_window.child_window(class_name="TButton", found_index=0)
3242
- btn_ok.click()
3243
- await worker_sleep(3)
3244
- warning_boo = True
3245
- except:
3246
- console.print("Não Possui Warning... \n")
3247
3040
 
3248
- #ALTERANDO TRIBUTO DOS ITENS
3249
- if warning_boo:
3250
- try:
3251
- console.print('Acessando a tela de Itens')
3252
- app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
3253
- main_window = app["TFrmDadosFaturamentoPreVenda"]
3254
- main_window.set_focus()
3255
- send_keys("%i")
3256
- await worker_sleep(2)
3257
- send_keys("%g")
3258
- await worker_sleep(2)
3259
3041
 
3260
- console.print("Conectando para realizar a alteração da tributação do produto... \n")
3261
- app = Application().connect(class_name="TFrmDadosTributacaoProdutoPreVenda", timeout=60)
3262
- main_window = app["TFrmDadosTributacaoProdutoPreVenda"]
3042
+ #APROVAR CREDITO
3043
+ try:
3044
+ console.print("Aprovar Credito... \n")
3045
+ app = Application().connect(class_name="TFrmPreVenda", timeout=10)
3046
+ main_window = app["TFrmPreVenda"]
3047
+ main_window.set_focus()
3263
3048
 
3264
- tpanel_dados_tributacao = main_window.child_window(class_name="TPanel", found_index=1)
3265
- tributacao_icms_select = tpanel_dados_tributacao.child_window(class_name="TDBIComboBox", found_index=4)
3049
+ panel_Tnotebook = main_window.child_window(class_name="TNotebook", found_index=0)
3050
+ panel_Tnotebook = panel_Tnotebook.child_window(class_name="TPage", found_index=0)
3051
+ btn_aprovar_credito = panel_Tnotebook.child_window(class_name="TBitBtn", found_index=8)
3052
+ console.print("Clicando em aprovar Credito... \n")
3053
+ btn_aprovar_credito.click()
3054
+ await worker_sleep(2)
3055
+ except Exception as e:
3056
+ retorno = f"Não foi possivel clicar em aprovar credito na tela de Pre venda \nEtapas Executadas:\n{steps}"
3057
+ return RpaRetornoProcessoDTO(
3058
+ sucesso=False,
3059
+ retorno=retorno,
3060
+ status=RpaHistoricoStatusEnum.Falha,
3061
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3062
+ )
3266
3063
 
3267
3064
 
3268
- if not item_arla:
3269
- console.print("Não é item Arla ajustando tributacao... \n")
3270
- tributacao_icms_select.click()
3271
- await worker_sleep(1)
3272
- set_combobox("||List", "061 - 061- MONOFASICO")
3273
- else:
3274
- console.print("Item Arla buscando pela aliquota do estado... \n")
3275
- aliquota = None
3276
- for item in conconfig_aliquota_icms:
3277
- if cidade_cliente in item["estado"]:
3278
- aliquota = item["aliquota"]
3279
- break
3065
+ console.print("O valor desta pré venda exige uma aprovação... \n")
3066
+ try:
3067
+ app = Application().connect(class_name="TFrmPreVenda", timeout=10)
3068
+ main_window = app["Confirm"]
3069
+ main_window.set_focus()
3280
3070
 
3281
- if aliquota:
3282
- console.print(f"A alíquota para o estado {cidade_cliente} é: {aliquota}")
3283
- tributacao_icms_select.click()
3284
- await worker_sleep(1)
3285
- tributacao = f"000 - 000- ICMS - {aliquota}%"
3286
- set_combobox("||List", tributacao)
3287
- else:
3288
- retorno = f"Estado {cidade_cliente} não encontrado \nEtapas Executadas:\n{steps}"
3289
- return RpaRetornoProcessoDTO(
3290
- sucesso=False,
3291
- retorno=retorno,
3292
- status=RpaHistoricoStatusEnum.Falha,
3293
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3294
- )
3295
- main_window.set_focus()
3296
- send_keys("%o")
3297
- except Exception as e:
3298
- retorno = f"Não foi possivel corrigir a tributação do itens na Janela Faturamento de Pré Venda, erro {e} \nEtapas Executadas:\n{steps}"
3071
+ btn_yes = main_window.child_window(class_name="TButton", found_index=1)
3072
+ btn_yes.click()
3073
+ await worker_sleep(3)
3074
+ except:
3075
+ retorno = f"Não foi possivel clicar no pop-up 'O valor desta pré venda exige uma aprovação financeira' na tela de Pre venda \nEtapas Executadas:\n{steps}"
3076
+ return RpaRetornoProcessoDTO(
3077
+ sucesso=False,
3078
+ retorno=retorno,
3079
+ status=RpaHistoricoStatusEnum.Falha,
3080
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3081
+ )
3082
+
3083
+
3084
+ #VERIFICANDO SE A PRÉ VENDA FOI INCLUIDA COM SUCESSO
3085
+ console.print("VERIFICANDO SE A APROVAÇÃO FINANCEIRA FOI REALIZADA COM SUCESSO... \n")
3086
+ information_pop_up = await is_window_open("Information")
3087
+ if information_pop_up["IsOpened"] == True:
3088
+ msg_pop_up = await ocr_title(numero_nota_fiscal, "Information")
3089
+ console.print(f'retorno:{msg_pop_up.sucesso}')
3090
+ console.print(f'retorno:{msg_pop_up}')
3091
+ if msg_pop_up.sucesso == True:
3092
+ msg_retorno = msg_pop_up.retorno
3093
+ console.print(msg_retorno)
3094
+ if 'sucesso' in msg_retorno.lower():
3095
+ try:
3096
+ information_operacao_concluida = main_window.child_window(title="Information")
3097
+ btn_ok = information_operacao_concluida.child_window(class_name="TButton")
3098
+ btn_ok.click()
3099
+ await worker_sleep(4)
3100
+ except:
3101
+ pyautogui.press('enter')
3102
+ await worker_sleep(4)
3103
+ else:
3104
+ retorno = f"Pop up nao mapeado para seguimento do robo {msg_pop_up.retorno} \nEtapas Executadas:\n{steps}"
3299
3105
  return RpaRetornoProcessoDTO(
3300
3106
  sucesso=False,
3301
- retorno=result,
3107
+ retorno=retorno,
3302
3108
  status=RpaHistoricoStatusEnum.Falha,
3303
3109
  tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3304
3110
  )
3305
-
3111
+ else:
3112
+ retorno = f"Não foi possivel realizar a confirmação do msg do OCR \nEtapas Executadas:\n{steps}"
3113
+ return RpaRetornoProcessoDTO(
3114
+ sucesso=False,
3115
+ retorno=retorno,
3116
+ status=RpaHistoricoStatusEnum.Falha,
3117
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3118
+ )
3119
+ else:
3120
+ retorno = f"Janela de confirmação de Aprovação financeira realizada com sucesso \nEtapas Executadas:\n{steps}"
3121
+ return RpaRetornoProcessoDTO(
3122
+ sucesso=False,
3123
+ retorno=retorno,
3124
+ status=RpaHistoricoStatusEnum.Falha,
3125
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3126
+ )
3127
+ await worker_sleep(3)
3306
3128
 
3307
- console.print("Processo de ajustar aliquota realizado com sucesso, adicionando a mensagem... \n")
3129
+
3130
+ #FATURAR
3131
+ try:
3132
+ console.print("FATURAR... \n")
3133
+ app = Application().connect(class_name="TFrmPreVenda", timeout=10)
3134
+ main_window = app["TFrmPreVenda"]
3135
+ main_window.set_focus()
3136
+
3137
+ panel_Tnotebook = main_window.child_window(class_name="TNotebook", found_index=0)
3138
+ panel_Tnotebook = panel_Tnotebook.child_window(class_name="TPage", found_index=0)
3139
+ btn_faturar = panel_Tnotebook.child_window(class_name="TBitBtn", found_index=7)
3140
+ btn_faturar.click()
3141
+ console.print("BOTAO FATURAR CLICADO COM SUCESSO... \n")
3142
+ await worker_sleep(5)
3143
+ except Exception as e:
3144
+ retorno = f"Não foi possivel clicar em Faturar na tela de pre venda, erro: {e} \nEtapas Executadas:\n{steps}"
3145
+ return RpaRetornoProcessoDTO(
3146
+ sucesso=False,
3147
+ retorno=retorno,
3148
+ status=RpaHistoricoStatusEnum.Falha,
3149
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3150
+ )
3151
+
3152
+
3153
+ console.print("Recalcular Parcelas da Pre venda... \n")
3154
+ try:
3155
+ app = Application().connect(class_name="TFrmPreVenda", timeout=40)
3156
+ main_window = app["Confirm"]
3157
+ main_window.set_focus()
3158
+
3159
+ btn_no = main_window.child_window(class_name="TButton", found_index=0)
3160
+ btn_no.click()
3308
3161
  try:
3309
- console.print("Conectando a janela de pre venda... \n")
3162
+ btn_no.click()
3163
+ except:
3164
+ pass
3165
+ await worker_sleep(3)
3166
+ except:
3167
+ retorno = f"Não foi possivel clicar no pop-up 'Recalcular Parcelas da Pre venda' na tela de Pre venda \nEtapas Executadas:\n{steps}"
3168
+ return RpaRetornoProcessoDTO(
3169
+ sucesso=False,
3170
+ retorno=retorno,
3171
+ status=RpaHistoricoStatusEnum.Falha,
3172
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3173
+ )
3174
+
3175
+
3176
+ parcelas_nf_saida_pop_up = await is_window_open("Parcelas - Nota Fiscal Saída")
3177
+ if parcelas_nf_saida_pop_up["IsOpened"] == True:
3178
+ app = Application().connect(title="Parcelas - Nota Fiscal Saída", timeout=60)
3179
+ main_window = app.window(title="Parcelas - Nota Fiscal Saída")
3180
+ main_window.set_focus()
3181
+ send_keys("%n")
3182
+ await worker_sleep(3)
3183
+ else:
3184
+ retorno = f"Não foi encontrada a Janela de Parcelas - Nota Fiscal Saída \nEtapas Executadas:\n{steps}"
3185
+ return RpaRetornoProcessoDTO(
3186
+ sucesso=False,
3187
+ retorno=retorno,
3188
+ status=RpaHistoricoStatusEnum.Falha,
3189
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3190
+ )
3191
+
3192
+
3193
+ information_pop_up = await is_window_open("Information")
3194
+ if information_pop_up["IsOpened"] == True:
3195
+ app = Application().connect(title="Information", timeout=30)
3196
+ main_window = app["Information"]
3197
+ main_window.set_focus()
3198
+ btn_ok = main_window.child_window(class_name="TButton", found_index=0)
3199
+ btn_ok.click()
3200
+
3201
+
3202
+ await worker_sleep(15)
3203
+
3204
+
3205
+ #FATURAMENTO PRÉ-VENDA
3206
+ try:
3207
+ console.print("FATURAMENTO PRÉ-VENDA... \n")
3208
+ app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
3209
+ main_window = app["TFrmDadosFaturamentoPreVenda"]
3210
+ main_window.set_focus()
3211
+ except Exception as e:
3212
+ retorno = f"Não foi encontrada a Janela Faturamento de Pré Venda \nEtapas Executadas:\n{steps}"
3213
+ return RpaRetornoProcessoDTO(
3214
+ sucesso=False,
3215
+ retorno=result,
3216
+ status=RpaHistoricoStatusEnum.Falha,
3217
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3218
+ )
3219
+ await worker_sleep(2)
3220
+ await find_warning_nop_divergence()
3221
+ await worker_sleep(2)
3222
+ #VERIFICANDO SE POSSUI POP UP WARNING
3223
+ console.print("Verificando a presença de Warning... \n")
3224
+ warning_boo = False
3225
+ await worker_sleep(5)
3226
+ try:
3227
+ try:
3228
+ app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=10)
3229
+ main_window = app["Warning"]
3230
+ main_window.set_focus()
3231
+
3232
+ except:
3233
+ console.print('Except Verificando warnings... \n')
3234
+ app = Application().connect(class_name="Warning", timeout=10)
3235
+ main_window = app["Warning"]
3236
+ main_window.set_focus()
3237
+ console.print("Possui Warning... \n")
3238
+ await worker_sleep(2)
3239
+ await find_warning_nop_divergence()
3240
+ btn_ok = main_window.child_window(class_name="TButton", found_index=0)
3241
+ btn_ok.click()
3242
+ await worker_sleep(3)
3243
+ warning_boo = True
3244
+ except:
3245
+ console.print("Não Possui Warning... \n")
3246
+
3247
+ #ALTERANDO TRIBUTO DOS ITENS
3248
+ if warning_boo:
3249
+ try:
3250
+ console.print('Acessando a tela de Itens')
3310
3251
  app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
3311
3252
  main_window = app["TFrmDadosFaturamentoPreVenda"]
3312
3253
  main_window.set_focus()
3313
- send_keys("%m")
3254
+ send_keys("%i")
3255
+ await worker_sleep(2)
3256
+ send_keys("%g")
3314
3257
  await worker_sleep(2)
3315
3258
 
3316
- mensagem_tab = pyautogui.locateOnScreen(ASSETS_PATH + "\\notas_saida\\icon_mensagem.png", confidence=0.7)
3317
- if mensagem_tab:
3318
- pyautogui.click(mensagem_tab)
3319
- await worker_sleep(4)
3320
- else:
3321
- retorno = f"Não foi possivel localizar o campo 'Mensagem' \nEtapas Executadas:\n{steps}"
3322
- return RpaRetornoProcessoDTO(
3323
- sucesso=False,
3324
- retorno=retorno,
3325
- status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3326
- )
3259
+ console.print("Conectando para realizar a alteração da tributação do produto... \n")
3260
+ app = Application().connect(class_name="TFrmDadosTributacaoProdutoPreVenda", timeout=60)
3261
+ main_window = app["TFrmDadosTributacaoProdutoPreVenda"]
3327
3262
 
3263
+ tpanel_dados_tributacao = main_window.child_window(class_name="TPanel", found_index=1)
3264
+ tributacao_icms_select = tpanel_dados_tributacao.child_window(class_name="TDBIComboBox", found_index=4)
3328
3265
 
3329
- panel_tab_sheet = main_window.child_window(class_name="TcxTabSheet", found_index=0)
3330
- field_observacao = panel_tab_sheet.child_window(class_name="TDBIMemo", found_index=0)
3331
- console.print(f"Mensagem a ser adicionada\n")
3332
- text_campo_observacao = f"Nome do Motorista: {nota.get("nomeMotorista")} - Placa: {nota.get("placaClienteCorreto")} - Quilometragem do Veículo: {nota.get("quilometragemVeiculo")}"
3333
- console.print(f"{text_campo_observacao}\n")
3334
- field_observacao.click()
3335
- await worker_sleep(2)
3336
- pyautogui.write(text_campo_observacao)
3337
- await worker_sleep(2)
3338
-
3339
- try:
3340
- app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
3341
- main_window = app["TFrmDadosFaturamentoPreVenda"]
3342
- main_window.set_focus()
3343
- btn_ok = main_window.child_window(class_name="TBitBtn", found_index=1)
3344
- btn_ok.click()
3345
- except:
3346
- btn_ok = main_window.child_window(title="&Ok")
3347
- btn_ok.click()
3348
- await worker_sleep(5)
3349
3266
 
3350
- await worker_sleep(10)
3351
- await find_warning_nop_divergence()
3352
- await worker_sleep(2)
3353
- warning_pop_up = await is_window_open("Warning")
3354
- if warning_pop_up["IsOpened"] == True:
3355
- console.print("possui Pop-up de Warning, analisando... \n")
3356
- app = Application().connect(title="Warning")
3357
- main_window = app["Warning"]
3358
- await worker_sleep(2)
3359
- main_window.set_focus()
3360
- console.print("Clicando em OK, para andamento do processo...\n")
3361
- btn_ok = main_window.child_window(title="OK", class_name="TButton")
3362
- if btn_ok.exists() and btn_ok.is_enabled():
3363
- btn_ok.click()
3364
- #Este click pode ser desnecessário, é apanas uma garantia
3365
- pyautogui.click(961, 562)
3366
- await worker_sleep(2)
3367
- else:
3368
- log_msg = "Warning - Erro ao clicar em Ok, na tela de warning...\n"
3369
- console.print(log_msg, style="bold red")
3370
- return RpaRetornoProcessoDTO(
3371
- sucesso=False, retorno=log_msg, status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3372
- )
3373
- await worker_sleep(1)
3374
- #SELECIONANDO O TIPO DE DOCUMENTO
3375
- try:
3376
- console.print("Conectando a janela de pre venda para colocar modelo \n")
3377
- app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=10)
3378
- main_window = app["TFrmDadosFaturamentoPreVenda"]
3379
- main_window.set_focus()
3380
- send_keys("%p")
3381
- await worker_sleep(2)
3267
+ if not item_arla:
3268
+ console.print("Não é item Arla ajustando tributacao... \n")
3269
+ tributacao_icms_select.click()
3270
+ await worker_sleep(1)
3271
+ set_combobox("||List", "061 - 061- MONOFASICO")
3272
+ else:
3273
+ console.print("Item Arla buscando pela aliquota do estado... \n")
3274
+ aliquota = None
3275
+ for item in conconfig_aliquota_icms:
3276
+ if cidade_cliente in item["estado"]:
3277
+ aliquota = item["aliquota"]
3278
+ break
3382
3279
 
3383
- panel_TPage= main_window.child_window(class_name="TPageControl", found_index=0)
3384
- panel_Ttabsheet= panel_TPage.child_window(class_name="TTabSheet", found_index=0)
3385
- modelo_select = panel_Ttabsheet.child_window(class_name="TDBIComboBox", found_index=1)
3386
- modelo_select.click()
3280
+ if aliquota:
3281
+ console.print(f"A alíquota para o estado {cidade_cliente} é: {aliquota}")
3282
+ tributacao_icms_select.click()
3387
3283
  await worker_sleep(1)
3388
- set_combobox("||List", "NFe - NOTA FISCAL ELETRONICA PROPRIA - DANFE SERIE 077")
3389
- await worker_sleep(3)
3390
- console.print("Verificando se o tipo de nota foi selecionado corretamente \n")
3391
- modelo_select = panel_Ttabsheet.child_window(class_name="TDBIComboBox", found_index=1)
3392
- tipo_selecionado = modelo_select.window_text()
3393
- if "077" in tipo_selecionado.lower():
3394
- console.print(f"Tipo de cobrança corretamente selecionado {tipo_selecionado}... \n")
3395
- else:
3396
- retorno = f"Não foi possivel selecionar o modelo do documento, tipo selecionado {tipo_selecionado}' \nEtapas Executadas:\n{steps}"
3397
- return RpaRetornoProcessoDTO(
3398
- sucesso=False,
3399
- retorno=retorno,
3400
- status=RpaHistoricoStatusEnum.Falha,
3401
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3402
- )
3403
-
3404
- main_window.set_focus()
3405
- try:
3406
- #Clcica no OK para seguir a transmissão da pré-venda
3407
- app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
3408
- main_window = app["TFrmDadosFaturamentoPreVenda"]
3409
- main_window.set_focus()
3410
- btn_ok = main_window.child_window(class_name="TBitBtn", found_index=1)
3411
- btn_ok.click()
3412
- except:
3413
- btn_ok = main_window.child_window(title="&Ok")
3414
- btn_ok.click()
3415
- await worker_sleep(5)
3416
-
3417
- except Exception as e:
3418
- retorno = f"Não foi possivel selecionar o modelo do documento {e}' \nEtapas Executadas:\n{steps}"
3284
+ tributacao = f"000 - 000- ICMS - {aliquota}%"
3285
+ set_combobox("||List", tributacao)
3286
+ else:
3287
+ retorno = f"Estado {cidade_cliente} não encontrado \nEtapas Executadas:\n{steps}"
3419
3288
  return RpaRetornoProcessoDTO(
3420
3289
  sucesso=False,
3421
3290
  retorno=retorno,
3422
3291
  status=RpaHistoricoStatusEnum.Falha,
3423
3292
  tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3424
- )
3425
- else:
3426
- console.print("Não possui pop de Warning...\n")
3427
-
3428
-
3429
- await worker_sleep(2)
3430
- await find_warning_nop_divergence()
3431
- await worker_sleep(2)
3432
- #VERIFICANDO SE POSSUI POP UP WARNING
3433
- console.print("Verificando a presença de Warning... \n")
3434
- warning_boo = False
3435
- try:
3436
- try:
3437
- app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=30)
3438
- main_window = app["Warning"]
3439
- main_window.set_focus()
3440
- except:
3441
- console.print('Except')
3442
- app = Application().connect(class_name="Warning", timeout=10)
3443
- main_window = app["Warning"]
3444
- main_window.set_focus()
3445
- console.print("Possui Warning... \n")
3446
- await find_warning_nop_divergence()
3447
- btn_ok = main_window.child_window(class_name="TButton", found_index=0)
3448
- btn_ok.click()
3449
- await worker_sleep(3)
3450
- warning_boo = True
3451
- except:
3452
- console.print("Não Possui Warning... \n")
3453
-
3293
+ )
3294
+ main_window.set_focus()
3295
+ send_keys("%o")
3296
+ except Exception as e:
3297
+ retorno = f"Não foi possivel corrigir a tributação do itens na Janela Faturamento de Pré Venda, erro {e} \nEtapas Executadas:\n{steps}"
3298
+ return RpaRetornoProcessoDTO(
3299
+ sucesso=False,
3300
+ retorno=result,
3301
+ status=RpaHistoricoStatusEnum.Falha,
3302
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3303
+ )
3454
3304
 
3455
- #ALTERANDO TRIBUTO DOS ITENS
3456
- if warning_boo:
3457
- try:
3458
- console.print('Acessando a tela de Itens')
3459
- app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
3460
- main_window = app["TFrmDadosFaturamentoPreVenda"]
3461
- main_window.set_focus()
3462
- send_keys("%i")
3463
- await worker_sleep(2)
3464
- send_keys("%g")
3465
- await worker_sleep(2)
3466
3305
 
3467
- await find_warning_nop_divergence()
3468
- await worker_sleep(2)
3469
- console.print("Conectando para realizar a alteração da tributação do produto... \n")
3470
- app = Application().connect(class_name="TFrmDadosTributacaoProdutoPreVenda", timeout=60)
3471
- main_window = app["TFrmDadosTributacaoProdutoPreVenda"]
3306
+ console.print("Processo de ajustar aliquota realizado com sucesso, adicionando a mensagem... \n")
3307
+ try:
3308
+ console.print("Conectando a janela de pre venda... \n")
3309
+ app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
3310
+ main_window = app["TFrmDadosFaturamentoPreVenda"]
3311
+ main_window.set_focus()
3312
+ send_keys("%m")
3313
+ await worker_sleep(2)
3472
3314
 
3473
- tpanel_dados_tributacao = main_window.child_window(class_name="TPanel", found_index=1)
3474
- tributacao_icms_select = tpanel_dados_tributacao.child_window(class_name="TDBIComboBox", found_index=4)
3315
+ mensagem_tab = pyautogui.locateOnScreen(ASSETS_PATH + "\\notas_saida\\icon_mensagem.png", confidence=0.7)
3316
+ if mensagem_tab:
3317
+ pyautogui.click(mensagem_tab)
3318
+ await worker_sleep(4)
3319
+ else:
3320
+ retorno = f"Não foi possivel localizar o campo 'Mensagem' \nEtapas Executadas:\n{steps}"
3321
+ return RpaRetornoProcessoDTO(
3322
+ sucesso=False,
3323
+ retorno=retorno,
3324
+ status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3325
+ )
3475
3326
 
3476
3327
 
3477
- if not item_arla:
3478
- console.print("Não é item Arla ajustando tributacao... \n")
3479
- tributacao_icms_select.click()
3480
- await worker_sleep(1)
3481
- set_combobox("||List", "061 - 061- MONOFASICO")
3482
- else:
3483
- console.print("Item Arla buscando pela aliquota do estado... \n")
3484
- aliquota = None
3485
- for item in conconfig_aliquota_icms:
3486
- if cidade_cliente in item["estado"]:
3487
- aliquota = item["aliquota"]
3488
- break
3328
+ panel_tab_sheet = main_window.child_window(class_name="TcxTabSheet", found_index=0)
3329
+ field_observacao = panel_tab_sheet.child_window(class_name="TDBIMemo", found_index=0)
3330
+ console.print(f"Mensagem a ser adicionada\n")
3331
+ text_campo_observacao = f"Nome do Motorista: {nota.get("nomeMotorista")} - Placa: {nota.get("placaClienteCorreto")} - Quilometragem do Veículo: {nota.get("quilometragemVeiculo")}"
3332
+ console.print(f"{text_campo_observacao}\n")
3333
+ field_observacao.click()
3334
+ await worker_sleep(2)
3335
+ pyautogui.write(text_campo_observacao)
3336
+ await worker_sleep(2)
3337
+
3338
+ try:
3339
+ app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
3340
+ main_window = app["TFrmDadosFaturamentoPreVenda"]
3341
+ main_window.set_focus()
3342
+ btn_ok = main_window.child_window(class_name="TBitBtn", found_index=1)
3343
+ btn_ok.click()
3344
+ except:
3345
+ btn_ok = main_window.child_window(title="&Ok")
3346
+ btn_ok.click()
3347
+ await worker_sleep(5)
3489
3348
 
3490
- if aliquota:
3491
- console.print(f"A alíquota para o estado {cidade_cliente} é: {aliquota}")
3492
- tributacao_icms_select.click()
3493
- await worker_sleep(1)
3494
- tributacao = f"000 - 000- ICMS - {aliquota}%"
3495
- set_combobox("||List", tributacao)
3496
- else:
3497
- retorno = f"Estado {cidade_cliente} não encontrado \nEtapas Executadas:\n{steps}"
3498
- return RpaRetornoProcessoDTO(
3499
- sucesso=False,
3500
- retorno=retorno,
3501
- status=RpaHistoricoStatusEnum.Falha,
3502
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3503
- )
3504
- main_window.set_focus()
3505
- send_keys("%o")
3506
- await worker_sleep(1)
3507
- try:
3508
- #find Message corrigir tributação
3509
- app = Application().connect(title="Corrige tributação", timeout=60)
3510
- corrige_tribute = app["Corrige tributação"]
3511
- corrige_tribute.child_window(title="&Não").click()
3512
- pyautogui.click(1109, 602)
3513
- except:
3514
- pyautogui.click(1109, 602)
3515
- console.print("Não encontrou a mensagem de corrigir tributacao\n")
3349
+ await worker_sleep(10)
3350
+ await find_warning_nop_divergence()
3351
+ await worker_sleep(2)
3352
+ warning_pop_up = await is_window_open("Warning")
3353
+ if warning_pop_up["IsOpened"] == True:
3354
+ console.print("possui Pop-up de Warning, analisando... \n")
3355
+ app = Application().connect(title="Warning")
3356
+ main_window = app["Warning"]
3357
+ await worker_sleep(2)
3358
+ main_window.set_focus()
3359
+ console.print("Clicando em OK, para andamento do processo...\n")
3360
+ btn_ok = main_window.child_window(title="OK", class_name="TButton")
3361
+ if btn_ok.exists() and btn_ok.is_enabled():
3362
+ btn_ok.click()
3363
+ #Este click pode ser desnecessário, é apanas uma garantia
3364
+ pyautogui.click(961, 562)
3365
+ await worker_sleep(2)
3366
+ else:
3367
+ log_msg = "Warning - Erro ao clicar em Ok, na tela de warning...\n"
3368
+ console.print(log_msg, style="bold red")
3369
+ return RpaRetornoProcessoDTO(
3370
+ sucesso=False, retorno=log_msg, status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3371
+ )
3372
+ await worker_sleep(1)
3373
+ #SELECIONANDO O TIPO DE DOCUMENTO
3374
+ try:
3375
+ console.print("Conectando a janela de pre venda para colocar modelo \n")
3376
+ app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=10)
3377
+ main_window = app["TFrmDadosFaturamentoPreVenda"]
3378
+ main_window.set_focus()
3379
+ send_keys("%p")
3380
+ await worker_sleep(2)
3516
3381
 
3517
- except Exception as e:
3518
- retorno = f"Não foi possivel corrigir a tributação do itens na Janela Faturamento de Pré Venda, erro {e} \nEtapas Executadas:\n{steps}"
3382
+ panel_TPage= main_window.child_window(class_name="TPageControl", found_index=0)
3383
+ panel_Ttabsheet= panel_TPage.child_window(class_name="TTabSheet", found_index=0)
3384
+ modelo_select = panel_Ttabsheet.child_window(class_name="TDBIComboBox", found_index=1)
3385
+ modelo_select.click()
3386
+ await worker_sleep(1)
3387
+ set_combobox("||List", "NFe - NOTA FISCAL ELETRONICA PROPRIA - DANFE SERIE 077")
3388
+ await worker_sleep(3)
3389
+ console.print("Verificando se o tipo de nota foi selecionado corretamente \n")
3390
+ modelo_select = panel_Ttabsheet.child_window(class_name="TDBIComboBox", found_index=1)
3391
+ tipo_selecionado = modelo_select.window_text()
3392
+ if "077" in tipo_selecionado.lower():
3393
+ console.print(f"Tipo de cobrança corretamente selecionado {tipo_selecionado}... \n")
3394
+ else:
3395
+ retorno = f"Não foi possivel selecionar o modelo do documento, tipo selecionado {tipo_selecionado}' \nEtapas Executadas:\n{steps}"
3519
3396
  return RpaRetornoProcessoDTO(
3520
3397
  sucesso=False,
3521
- retorno=result,
3398
+ retorno=retorno,
3522
3399
  status=RpaHistoricoStatusEnum.Falha,
3523
3400
  tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3524
3401
  )
3525
- else:
3526
- console.print("Não possui warning para alterar tributação... \n")
3527
-
3528
-
3529
- #ADICIONANDO MENSAGEM
3530
- await worker_sleep(5)
3531
- try:
3532
- console.print("Identificando - TFrmDadosFaturamentoPreVenda 3")
3533
- app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=10)
3534
- main_window = app["Confirm"]
3402
+
3535
3403
  main_window.set_focus()
3536
- except:
3537
- console.print("Identificando - TMessageForm 8")
3538
3404
  try:
3539
- await worker_sleep(3)
3540
- app = Application().connect(class_name="TMessageForm", timeout=10, title='Confirm')
3541
- main_window = app["TMessageForm"]
3405
+ #Clcica no OK para seguir a transmissão da pré-venda
3406
+ app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
3407
+ main_window = app["TFrmDadosFaturamentoPreVenda"]
3542
3408
  main_window.set_focus()
3409
+ btn_ok = main_window.child_window(class_name="TBitBtn", found_index=1)
3410
+ btn_ok.click()
3543
3411
  except:
3544
- console.print("TMessageForm não encontrado")
3545
-
3412
+ btn_ok = main_window.child_window(title="&Ok")
3413
+ btn_ok.click()
3414
+ await worker_sleep(5)
3415
+
3416
+ except Exception as e:
3417
+ retorno = f"Não foi possivel selecionar o modelo do documento {e}' \nEtapas Executadas:\n{steps}"
3418
+ return RpaRetornoProcessoDTO(
3419
+ sucesso=False,
3420
+ retorno=retorno,
3421
+ status=RpaHistoricoStatusEnum.Falha,
3422
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3423
+ )
3424
+ else:
3425
+ console.print("Não possui pop de Warning...\n")
3426
+
3427
+
3428
+ await worker_sleep(2)
3429
+ await find_warning_nop_divergence()
3430
+ await worker_sleep(2)
3431
+ #VERIFICANDO SE POSSUI POP UP WARNING
3432
+ console.print("Verificando a presença de Warning... \n")
3433
+ warning_boo = False
3434
+ try:
3546
3435
  try:
3547
- btn_yes = main_window.child_window(class_name="TButton", title="&Yes")
3548
- btn_yes.click()
3549
- console.print("Clicou Yes")
3436
+ app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=30)
3437
+ main_window = app["Warning"]
3438
+ main_window.set_focus()
3550
3439
  except:
3551
- await worker_sleep(3)
3552
- console.print("Clicando em 'OK' na tela de faturamente pré-venda")
3553
- app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=10)
3554
- main_window = app["TFrmDadosFaturamentoPreVenda"]
3440
+ console.print('Except')
3441
+ app = Application().connect(class_name="Warning", timeout=10)
3442
+ main_window = app["Warning"]
3555
3443
  main_window.set_focus()
3556
- main_window.child_window(title="&OK", class_name="TBitBtn").click()
3557
- await find_warning_nop_divergence()
3444
+ console.print("Possui Warning... \n")
3445
+ await find_warning_nop_divergence()
3446
+ btn_ok = main_window.child_window(class_name="TButton", found_index=0)
3447
+ btn_ok.click()
3448
+ await worker_sleep(3)
3449
+ warning_boo = True
3450
+ except:
3451
+ console.print("Não Possui Warning... \n")
3558
3452
 
3559
- #CONFIRMANDO NA TELA DE PRE VENDA
3453
+
3454
+ #ALTERANDO TRIBUTO DOS ITENS
3455
+ if warning_boo:
3560
3456
  try:
3561
- console.print("CONFIRMANDO POP UP DE Deseja realmente confirmar esta PRÉ VENDA ... \n")
3562
- app = Application().connect(class_name="TFrmPreVenda", timeout=10)
3563
- main_window = app["Confirm"]
3457
+ console.print('Acessando a tela de Itens')
3458
+ app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
3459
+ main_window = app["TFrmDadosFaturamentoPreVenda"]
3564
3460
  main_window.set_focus()
3461
+ send_keys("%i")
3462
+ await worker_sleep(2)
3463
+ send_keys("%g")
3464
+ await worker_sleep(2)
3565
3465
 
3566
- btn_yes = main_window.child_window(class_name="TButton", found_index=1)
3567
- btn_yes.click()
3568
- await worker_sleep(3)
3569
- except Exception as e:
3570
- await worker_sleep(6)
3571
- app = Application().connect(title="Transmição NF-e!",class_name="TMessageForm", timeout=10)
3572
- transmission_window = app["Transmição NF-e!"]
3573
- transmission_window.set_focus()
3574
- if transmission_window.exists():
3575
- console.print("Encontrou a tela de Transmissão da NF-e")
3466
+ await find_warning_nop_divergence()
3467
+ await worker_sleep(2)
3468
+ console.print("Conectando para realizar a alteração da tributação do produto... \n")
3469
+ app = Application().connect(class_name="TFrmDadosTributacaoProdutoPreVenda", timeout=60)
3470
+ main_window = app["TFrmDadosTributacaoProdutoPreVenda"]
3471
+
3472
+ tpanel_dados_tributacao = main_window.child_window(class_name="TPanel", found_index=1)
3473
+ tributacao_icms_select = tpanel_dados_tributacao.child_window(class_name="TDBIComboBox", found_index=4)
3474
+
3475
+
3476
+ if not item_arla:
3477
+ console.print("Não é item Arla ajustando tributacao... \n")
3478
+ tributacao_icms_select.click()
3479
+ await worker_sleep(1)
3480
+ set_combobox("||List", "061 - 061- MONOFASICO")
3576
3481
  else:
3577
- retorno = f"Não foi possivel clicar para confirmar a janela 'Deseja realmente confirmar esta pre-venda' \nEtapas Executadas:\n{steps}"
3578
- return RpaRetornoProcessoDTO(
3579
- sucesso=False,
3580
- retorno=retorno,
3581
- status=RpaHistoricoStatusEnum.Falha,
3582
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3583
- )
3482
+ console.print("Item Arla buscando pela aliquota do estado... \n")
3483
+ aliquota = None
3484
+ for item in conconfig_aliquota_icms:
3485
+ if cidade_cliente in item["estado"]:
3486
+ aliquota = item["aliquota"]
3487
+ break
3488
+
3489
+ if aliquota:
3490
+ console.print(f"A alíquota para o estado {cidade_cliente} é: {aliquota}")
3491
+ tributacao_icms_select.click()
3492
+ await worker_sleep(1)
3493
+ tributacao = f"000 - 000- ICMS - {aliquota}%"
3494
+ set_combobox("||List", tributacao)
3495
+ else:
3496
+ retorno = f"Estado {cidade_cliente} não encontrado \nEtapas Executadas:\n{steps}"
3497
+ return RpaRetornoProcessoDTO(
3498
+ sucesso=False,
3499
+ retorno=retorno,
3500
+ status=RpaHistoricoStatusEnum.Falha,
3501
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3502
+ )
3503
+ main_window.set_focus()
3504
+ send_keys("%o")
3505
+ await worker_sleep(1)
3506
+ try:
3507
+ #find Message corrigir tributação
3508
+ app = Application().connect(title="Corrige tributação", timeout=60)
3509
+ corrige_tribute = app["Corrige tributação"]
3510
+ corrige_tribute.child_window(title="&Não").click()
3511
+ pyautogui.click(1109, 602)
3512
+ except:
3513
+ pyautogui.click(1109, 602)
3514
+ console.print("Não encontrou a mensagem de corrigir tributacao\n")
3584
3515
 
3585
- #Transmitir e imprimir
3586
- try:
3587
- app = Application().connect(title="Transmição NF-e!",class_name="TMessageForm", timeout=10)
3588
- transmission_window = app["Transmição NF-e!"]
3589
- transmission_window.set_focus()
3590
- transmission_window.child_window(title='Transmitir e &Imprimir', class_name="TButton").click()
3591
3516
  except Exception as e:
3592
- retorno = f"Não encontrou a tela de Transmissão da NF-e, erro {e} \nEtapas Executadas:\n{steps}"
3517
+ retorno = f"Não foi possivel corrigir a tributação do itens na Janela Faturamento de Pré Venda, erro {e} \nEtapas Executadas:\n{steps}"
3593
3518
  return RpaRetornoProcessoDTO(
3594
3519
  sucesso=False,
3595
- retorno=retorno,
3596
- status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3520
+ retorno=result,
3521
+ status=RpaHistoricoStatusEnum.Falha,
3522
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3597
3523
  )
3524
+ else:
3525
+ console.print("Não possui warning para alterar tributação... \n")
3526
+
3598
3527
 
3599
- await worker_sleep(25)
3528
+ #ADICIONANDO MENSAGEM
3529
+ await worker_sleep(5)
3530
+ try:
3531
+ console.print("Identificando - TFrmDadosFaturamentoPreVenda 3")
3532
+ app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=10)
3533
+ main_window = app["Confirm"]
3534
+ main_window.set_focus()
3535
+ except:
3536
+ console.print("Identificando - TMessageForm 8")
3537
+ try:
3538
+ await worker_sleep(3)
3539
+ app = Application().connect(class_name="TMessageForm", timeout=10, title='Confirm')
3540
+ main_window = app["TMessageForm"]
3541
+ main_window.set_focus()
3542
+ except:
3543
+ console.print("TMessageForm não encontrado")
3544
+
3545
+ try:
3546
+ btn_yes = main_window.child_window(class_name="TButton", title="&Yes")
3547
+ btn_yes.click()
3548
+ console.print("Clicou Yes")
3549
+ except:
3550
+ await worker_sleep(3)
3551
+ console.print("Clicando em 'OK' na tela de faturamente pré-venda")
3552
+ app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=10)
3553
+ main_window = app["TFrmDadosFaturamentoPreVenda"]
3554
+ main_window.set_focus()
3555
+ main_window.child_window(title="&OK", class_name="TBitBtn").click()
3556
+ await find_warning_nop_divergence()
3557
+
3558
+ #CONFIRMANDO NA TELA DE PRE VENDA
3559
+ try:
3560
+ console.print("CONFIRMANDO POP UP DE Deseja realmente confirmar esta PRÉ VENDA ... \n")
3561
+ app = Application().connect(class_name="TFrmPreVenda", timeout=10)
3562
+ main_window = app["Confirm"]
3563
+ main_window.set_focus()
3564
+
3565
+ btn_yes = main_window.child_window(class_name="TButton", found_index=1)
3566
+ btn_yes.click()
3567
+ await worker_sleep(3)
3568
+ except Exception as e:
3569
+ await worker_sleep(6)
3570
+ app = Application().connect(title="Transmição NF-e!",class_name="TMessageForm", timeout=10)
3571
+ transmission_window = app["Transmição NF-e!"]
3572
+ transmission_window.set_focus()
3573
+ if transmission_window.exists():
3574
+ console.print("Encontrou a tela de Transmissão da NF-e")
3575
+ else:
3576
+ retorno = f"Não foi possivel clicar para confirmar a janela 'Deseja realmente confirmar esta pre-venda' \nEtapas Executadas:\n{steps}"
3577
+ return RpaRetornoProcessoDTO(
3578
+ sucesso=False,
3579
+ retorno=retorno,
3580
+ status=RpaHistoricoStatusEnum.Falha,
3581
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3582
+ )
3600
3583
 
3584
+ #Transmitir e imprimir
3585
+ try:
3586
+ app = Application().connect(title="Transmição NF-e!",class_name="TMessageForm", timeout=10)
3587
+ transmission_window = app["Transmição NF-e!"]
3588
+ transmission_window.set_focus()
3589
+ transmission_window.child_window(title='Transmitir e &Imprimir', class_name="TButton").click()
3601
3590
  except Exception as e:
3602
- retorno = f"Não foi possivel adicionar a 'Mensagem' na tela de Faturamento de pre venda, erro {e} \nEtapas Executadas:\n{steps}"
3591
+ retorno = f"Não encontrou a tela de Transmissão da NF-e, erro {e} \nEtapas Executadas:\n{steps}"
3603
3592
  return RpaRetornoProcessoDTO(
3604
3593
  sucesso=False,
3605
3594
  retorno=retorno,
3606
3595
  status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3607
3596
  )
3608
3597
 
3609
- await worker_sleep(20)
3598
+ await worker_sleep(25)
3610
3599
 
3611
- try_print=10
3612
- current_try_print=0
3613
- while current_try_print <= try_print:
3614
- try:
3615
- app = Application().connect(class_name="TFrmAguarde", timeout=60)
3616
- main_window = app["TppPrintDialog"]
3617
- tpanel_btn_ok = main_window.child_window(class_name="TPanel", found_index=1)
3618
- btn_ok_print_screen = tpanel_btn_ok.child_window(class_name="TButton", found_index=1)
3619
- btn_ok_print_screen.click()
3620
- await worker_sleep(3)
3621
- break
3622
- except Exception as e:
3623
- console.print(f"Tela 'Print' nao encontrada. Tentativa: {current_try_print+1} de {try_print} \n")
3624
- current_try_print+=1
3625
- await worker_sleep(25)
3626
-
3600
+ except Exception as e:
3601
+ retorno = f"Não foi possivel adicionar a 'Mensagem' na tela de Faturamento de pre venda, erro {e} \nEtapas Executadas:\n{steps}"
3602
+ return RpaRetornoProcessoDTO(
3603
+ sucesso=False,
3604
+ retorno=retorno,
3605
+ status=RpaHistoricoStatusEnum.Falha, tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3606
+ )
3607
+
3608
+ await worker_sleep(20)
3627
3609
 
3628
- if current_try_print >= try_print:
3629
- retorno = f"Não foi encontrada a tela para a impressão da nova venda \nEtapas Executadas:\n{steps}"
3630
- return RpaRetornoProcessoDTO(
3631
- sucesso=False,
3632
- retorno=retorno,
3633
- status=RpaHistoricoStatusEnum.Falha,
3634
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3635
- )
3636
-
3637
- console.print(f"NAVEGANDO NA TELA DE SALVAR RELATORIO\n")
3638
- #INSERINDO O DIRETORIO E SALVANDO O ARQUIVO
3610
+ try_print=10
3611
+ current_try_print=0
3612
+ while current_try_print <= try_print:
3639
3613
  try:
3640
- app = Application().connect(title="Salvar Saída de Impressão como")
3641
- main_window = app["Dialog"]
3642
- console.print("Tela 'Salvar' encontrada!")
3614
+ app = Application().connect(class_name="TFrmAguarde", timeout=60)
3615
+ main_window = app["TppPrintDialog"]
3616
+ tpanel_btn_ok = main_window.child_window(class_name="TPanel", found_index=1)
3617
+ btn_ok_print_screen = tpanel_btn_ok.child_window(class_name="TButton", found_index=1)
3618
+ btn_ok_print_screen.click()
3619
+ await worker_sleep(3)
3620
+ break
3621
+ except Exception as e:
3622
+ console.print(f"Tela 'Print' nao encontrada. Tentativa: {current_try_print+1} de {try_print} \n")
3623
+ current_try_print+=1
3624
+ await worker_sleep(25)
3625
+
3643
3626
 
3644
- console.print("Interagindo com a tela 'Salvar'...\n")
3645
- username = getpass.getuser()
3646
- path_to_txt = f"C:\\Users\\{username}\\Downloads\\NOVA VENDA {numero_cupom_fiscal}"
3627
+ if current_try_print >= try_print:
3628
+ retorno = f"Não foi encontrada a tela para a impressão da nova venda \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
+ console.print(f"NAVEGANDO NA TELA DE SALVAR RELATORIO\n")
3637
+ #INSERINDO O DIRETORIO E SALVANDO O ARQUIVO
3638
+ try:
3639
+ app = Application().connect(title="Salvar Saída de Impressão como")
3640
+ main_window = app["Dialog"]
3641
+ console.print("Tela 'Salvar' encontrada!")
3647
3642
 
3648
- main_window.type_keys("%n")
3649
- pyautogui.write(path_to_txt)
3650
- await worker_sleep(1)
3651
- main_window.type_keys("%l")
3652
- console.print("Arquivo salvo com sucesso...\n")
3653
- await worker_sleep(8)
3654
- except Exception as e:
3655
- retorno = f"Não foi salvar o arquivo com a nova venda, erro {e} \nEtapas Executadas:\n{steps}"
3656
- return RpaRetornoProcessoDTO(
3657
- sucesso=False,
3658
- retorno=result,
3659
- status=RpaHistoricoStatusEnum.Falha,
3660
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3661
- )
3643
+ console.print("Interagindo com a tela 'Salvar'...\n")
3644
+ username = getpass.getuser()
3645
+ path_to_txt = f"C:\\Users\\{username}\\Downloads\\NOVA VENDA {numero_cupom_fiscal}"
3662
3646
 
3663
- with open(f"{path_to_txt}.pdf", 'rb') as file:
3664
- file_bytes = io.BytesIO(file.read())
3647
+ main_window.type_keys("%n")
3648
+ pyautogui.write(path_to_txt)
3649
+ await worker_sleep(1)
3650
+ main_window.type_keys("%l")
3651
+ console.print("Arquivo salvo com sucesso...\n")
3652
+ await worker_sleep(8)
3653
+ except Exception as e:
3654
+ retorno = f"Não foi salvar o arquivo com a nova venda, erro {e} \nEtapas Executadas:\n{steps}"
3655
+ return RpaRetornoProcessoDTO(
3656
+ sucesso=False,
3657
+ retorno=result,
3658
+ status=RpaHistoricoStatusEnum.Falha,
3659
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3660
+ )
3665
3661
 
3666
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
3667
- desArquivo = f"NOVA VENDA {numero_cupom_fiscal}.pdf"
3668
- try:
3669
- await send_file(historico_id, desArquivo, "pdf", file_bytes, file_extension="pdf")
3670
- os.remove(f"{path_to_txt}.pdf")
3671
- except Exception as e:
3672
- 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} !"
3673
- console.print(result, style="bold red")
3674
- return RpaRetornoProcessoDTO(
3675
- sucesso=False,
3676
- retorno=result,
3677
- status=RpaHistoricoStatusEnum.Falha,
3678
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3679
- )
3662
+ with open(f"{path_to_txt}.pdf", 'rb') as file:
3663
+ file_bytes = io.BytesIO(file.read())
3664
+
3665
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
3666
+ desArquivo = f"NOVA VENDA {numero_cupom_fiscal}.pdf"
3667
+ try:
3668
+ await send_file(historico_id, desArquivo, "pdf", file_bytes, file_extension="pdf")
3669
+ os.remove(f"{path_to_txt}.pdf")
3670
+ except Exception as e:
3671
+ 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} !"
3672
+ console.print(result, style="bold red")
3673
+ return RpaRetornoProcessoDTO(
3674
+ sucesso=False,
3675
+ retorno=result,
3676
+ status=RpaHistoricoStatusEnum.Falha,
3677
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3678
+ )
3680
3679
 
3681
- information_pop_up = await is_window_open("Information")
3682
- if information_pop_up["IsOpened"] == True:
3683
- app = Application().connect(title="Information", timeout=30)
3684
- main_window = app["Information"]
3685
- main_window.set_focus()
3686
- btn_ok = main_window.child_window(class_name="TButton", found_index=0)
3687
- btn_ok.click()
3680
+ information_pop_up = await is_window_open("Information")
3681
+ if information_pop_up["IsOpened"] == True:
3682
+ app = Application().connect(title="Information", timeout=30)
3683
+ main_window = app["Information"]
3684
+ main_window.set_focus()
3685
+ btn_ok = main_window.child_window(class_name="TButton", found_index=0)
3686
+ btn_ok.click()
3688
3687
 
3689
3688
 
3690
- try:
3691
- app = Application().connect(class_name="TFrmProcessamentoFEe2", timeout=10)
3692
- main_window = app["TFrmProcessamentoFEe2"]
3693
- main_window.close()
3694
- except Exception as e:
3695
- console.print("Janela TFrmDadosFaturamentoPreVenda ja fechada")
3689
+ try:
3690
+ app = Application().connect(class_name="TFrmProcessamentoFEe2", timeout=10)
3691
+ main_window = app["TFrmProcessamentoFEe2"]
3692
+ main_window.close()
3693
+ except Exception as e:
3694
+ console.print("Janela TFrmDadosFaturamentoPreVenda ja fechada")
3696
3695
 
3697
3696
 
3698
- await worker_sleep(5)
3699
- is_confirm_pop_up = False
3700
- try:
3701
- app = Application().connect(class_name="TFrmGerenciadorNFe2", timeout=10)
3702
- main_window = app["Confirm"]
3703
- is_confirm_pop_up = True
3704
- except:
3705
- pass
3697
+ await worker_sleep(5)
3698
+ is_confirm_pop_up = False
3699
+ try:
3700
+ app = Application().connect(class_name="TFrmGerenciadorNFe2", timeout=10)
3701
+ main_window = app["Confirm"]
3702
+ is_confirm_pop_up = True
3703
+ except:
3704
+ pass
3706
3705
 
3707
3706
 
3708
- if is_confirm_pop_up == True:
3709
- msg_text = await ocr_by_class(numero_cupom_fiscal,"TFrmGerenciadorNFe2", "Confirm")
3710
- if 'imprimir' in msg_text.retorno.lower():
3711
- app = Application().connect(class_name="TFrmGerenciadorNFe2", timeout=10)
3712
- main_window = app["Confirm"]
3713
- main_window.set_focus()
3714
- send_keys("%n")
3715
-
3707
+ if is_confirm_pop_up == True:
3708
+ msg_text = await ocr_by_class(numero_cupom_fiscal,"TFrmGerenciadorNFe2", "Confirm")
3709
+ if 'imprimir' in msg_text.retorno.lower():
3710
+ app = Application().connect(class_name="TFrmGerenciadorNFe2", timeout=10)
3711
+ main_window = app["Confirm"]
3712
+ main_window.set_focus()
3713
+ send_keys("%n")
3714
+
3716
3715
 
3717
- #Fechar telas Antes de fazer nova pesquisa
3718
- await worker_sleep(10)
3716
+ #Fechar telas Antes de fazer nova pesquisa
3717
+ await worker_sleep(10)
3718
+ try:
3719
+ app = Application().connect(class_name="TFrmProcessamentoNFe2", timeout=10)
3720
+ window_lancando_nota = app["TFrmProcessamentoNFe2"]
3721
+ window_lancando_nota.set_focus()
3722
+ fechar_tela_processamento = "assets\\emsys\\button_fechar.PNG"
3719
3723
  try:
3720
- app = Application().connect(class_name="TFrmProcessamentoNFe2", timeout=10)
3721
- window_lancando_nota = app["TFrmProcessamentoNFe2"]
3722
- window_lancando_nota.set_focus()
3723
- fechar_tela_processamento = "assets\\emsys\\button_fechar.PNG"
3724
+ button_location = pyautogui.locateCenterOnScreen(
3725
+ fechar_tela_processamento, confidence=0.6
3726
+ )
3727
+ if button_location:
3728
+ pyautogui.click(button_location)
3729
+ console.print("Botão 'Fechar' clicado com sucesso!")
3730
+ except pyautogui.ImageNotFoundException:
3731
+ window_rect = main_window.rectangle()
3732
+ console.print(f"Area que sera utulizada para o recorte {window_rect}...\n")
3724
3733
  try:
3725
3734
  button_location = pyautogui.locateCenterOnScreen(
3726
- fechar_tela_processamento, confidence=0.6
3735
+ fechar_tela_processamento,
3736
+ region=(
3737
+ window_rect.left,
3738
+ window_rect.top,
3739
+ window_rect.width(),
3740
+ window_rect.height(),
3741
+ ),
3727
3742
  )
3728
3743
  if button_location:
3729
- pyautogui.click(button_location)
3730
- console.print("Botão 'Fechar' clicado com sucesso!")
3731
- except pyautogui.ImageNotFoundException:
3732
- window_rect = main_window.rectangle()
3733
- console.print(f"Area que sera utulizada para o recorte {window_rect}...\n")
3734
- try:
3735
- button_location = pyautogui.locateCenterOnScreen(
3736
- fechar_tela_processamento,
3737
- region=(
3738
- window_rect.left,
3739
- window_rect.top,
3740
- window_rect.width(),
3741
- window_rect.height(),
3742
- ),
3744
+ button_location = (
3745
+ button_location.x + window_rect.left,
3746
+ button_location.y + window_rect.top,
3743
3747
  )
3744
- if button_location:
3745
- button_location = (
3746
- button_location.x + window_rect.left,
3747
- button_location.y + window_rect.top,
3748
- )
3749
- console.print(
3750
- f"Botão encontrado nas coordenadas: {button_location}"
3751
- )
3752
- pyautogui.click(button_location)
3753
- await worker_sleep(10)
3754
- except pyautogui.ImageNotFoundException:
3755
- retorno = f"Não foi possivel fechar a tela de processamento, Error: {e} \nEtapas Executadas:\n{steps}"
3756
- console.print(f"Não foi possivel fechar a tela de processamento, Error: {e}...\n tentando inserir via posição...\n")
3757
- return RpaRetornoProcessoDTO(
3758
- sucesso=False,
3759
- retorno=retorno,
3760
- status=RpaHistoricoStatusEnum.Falha,
3761
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3748
+ console.print(
3749
+ f"Botão encontrado nas coordenadas: {button_location}"
3762
3750
  )
3763
- except Exception as e:
3764
- retorno = f"Não foi possivel fechar a tela de processamento, Error:{e} \nEtapas Executadas:\n{steps}"
3765
- console.print(f"Não foi possivel fechar a tela de processamento, Error:{e}...\n tentando inserir via posição...\n")
3751
+ pyautogui.click(button_location)
3752
+ await worker_sleep(10)
3753
+ except pyautogui.ImageNotFoundException:
3754
+ retorno = f"Não foi possivel fechar a tela de processamento, Error: {e} \nEtapas Executadas:\n{steps}"
3755
+ console.print(f"Não foi possivel fechar a tela de processamento, Error: {e}...\n tentando inserir via posição...\n")
3766
3756
  return RpaRetornoProcessoDTO(
3767
3757
  sucesso=False,
3768
3758
  retorno=retorno,
3769
3759
  status=RpaHistoricoStatusEnum.Falha,
3770
3760
  tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3771
3761
  )
3762
+ except Exception as e:
3763
+ retorno = f"Não foi possivel fechar a tela de processamento, Error:{e} \nEtapas Executadas:\n{steps}"
3764
+ console.print(f"Não foi possivel fechar a tela de processamento, Error:{e}...\n tentando inserir via posição...\n")
3765
+ return RpaRetornoProcessoDTO(
3766
+ sucesso=False,
3767
+ retorno=retorno,
3768
+ status=RpaHistoricoStatusEnum.Falha,
3769
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3770
+ )
3771
+ except:
3772
+ console.print("Janela TFrmProcessamentoNFe2 ja fechada")
3773
+
3774
+
3775
+ console.print("Verificando se possui pop-up imprimir boleta")
3776
+ boleta_screen = await is_window_open("Confirm")
3777
+ if boleta_screen["IsOpened"] == True:
3778
+ console.print("Janela aberta, fechando")
3779
+ try:
3780
+ console.print("Confirm")
3781
+ app = Application().connect(title="Confirm", timeout=10)
3782
+ main_window = app["Confirm"]
3783
+ main_window.set_focus()
3772
3784
  except:
3773
- console.print("Janela TFrmProcessamentoNFe2 ja fechada")
3785
+ console.print("Identificando - TMessageForm 7")
3786
+ app = Application().connect(class_name="TMessageForm", timeout=10, title='Confirm')
3787
+ main_window = app["TMessageForm"]
3788
+ main_window.set_focus()
3774
3789
 
3775
-
3776
- console.print("Verificando se possui pop-up imprimir boleta")
3777
- boleta_screen = await is_window_open("Confirm")
3778
- if boleta_screen["IsOpened"] == True:
3779
- console.print("Janela aberta, fechando")
3780
- try:
3781
- console.print("Confirm")
3782
- app = Application().connect(title="Confirm", timeout=10)
3783
- main_window = app["Confirm"]
3784
- main_window.set_focus()
3785
- except:
3786
- console.print("Identificando - TMessageForm 7")
3787
- app = Application().connect(class_name="TMessageForm", timeout=10, title='Confirm')
3788
- main_window = app["TMessageForm"]
3789
- main_window.set_focus()
3790
+ btn_no = main_window.child_window(class_name="TButton", title="&No")
3791
+ btn_no.click()
3790
3792
 
3791
- btn_no = main_window.child_window(class_name="TButton", title="&No")
3792
- btn_no.click()
3793
3793
 
3794
+ await worker_sleep(7)
3795
+ erro_screen = await is_window_open_by_class("TFrmDadosFaturamentoPreVenda","Confirm")
3796
+ if erro_screen["IsOpened"] == True:
3797
+ console.print("Janela aberta, fechando")
3798
+ try:
3799
+ console.print("Identificando - TFrmDadosFaturamentoPreVenda 4")
3800
+ app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=10)
3801
+ main_window = app["Confirm"]
3802
+ main_window.set_focus()
3803
+ except:
3804
+ console.print("Identificando - TMessageForm 9")
3805
+ app = Application().connect(class_name="TMessageForm", timeout=10, title='Confirm')
3806
+ main_window = app["TMessageForm"]
3807
+ main_window.set_focus()
3794
3808
 
3795
- await worker_sleep(7)
3796
- erro_screen = await is_window_open_by_class("TFrmDadosFaturamentoPreVenda","Confirm")
3797
- if erro_screen["IsOpened"] == True:
3798
- console.print("Janela aberta, fechando")
3799
- try:
3800
- console.print("Identificando - TFrmDadosFaturamentoPreVenda 4")
3801
- app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=10)
3802
- main_window = app["Confirm"]
3803
- main_window.set_focus()
3804
- except:
3805
- console.print("Identificando - TMessageForm 9")
3806
- app = Application().connect(class_name="TMessageForm", timeout=10, title='Confirm')
3807
- main_window = app["TMessageForm"]
3808
- main_window.set_focus()
3809
+ btn_no = main_window.child_window(class_name="TButton", title="&No")
3810
+ btn_no.click()
3811
+
3809
3812
 
3810
- btn_no = main_window.child_window(class_name="TButton", title="&No")
3811
- btn_no.click()
3812
-
3813
+ await worker_sleep(10)
3814
+ console.print("Verificando se a tela de Mensagem esta aberta")
3815
+ erro_screen = await is_window_open_by_class("TMemo","TMemo")
3816
+ if erro_screen["IsOpened"] == True:
3817
+ console.print("Janela aberta, fechando")
3818
+ app = Application().connect(class_name="TMemo", timeout=10)
3819
+ main_window = app["TMemo"]
3820
+ main_window.set_focus()
3821
+ await worker_sleep(5)
3822
+ main_window.close()
3823
+
3813
3824
 
3814
- await worker_sleep(10)
3815
- console.print("Verificando se a tela de Mensagem esta aberta")
3816
- erro_screen = await is_window_open_by_class("TMemo","TMemo")
3817
- if erro_screen["IsOpened"] == True:
3818
- console.print("Janela aberta, fechando")
3819
- app = Application().connect(class_name="TMemo", timeout=10)
3820
- main_window = app["TMemo"]
3825
+ console.print("Verificando se a tela de Faturamento Pre venda esta aberta")
3826
+ close_dados_faturamento = await is_window_open_by_class("TFrmDadosFaturamentoPreVenda","TFrmDadosFaturamentoPreVenda")
3827
+ if close_dados_faturamento["IsOpened"] == True:
3828
+ console.print("Janela aberta, fechando")
3829
+ try:
3830
+ app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
3831
+ main_window = app["TFrmDadosFaturamentoPreVenda"]
3821
3832
  main_window.set_focus()
3822
- await worker_sleep(5)
3823
- main_window.close()
3824
-
3825
-
3826
- console.print("Verificando se a tela de Faturamento Pre venda esta aberta")
3827
- close_dados_faturamento = await is_window_open_by_class("TFrmDadosFaturamentoPreVenda","TFrmDadosFaturamentoPreVenda")
3828
- if close_dados_faturamento["IsOpened"] == True:
3829
- console.print("Janela aberta, fechando")
3830
- try:
3831
- app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=60)
3832
- main_window = app["TFrmDadosFaturamentoPreVenda"]
3833
- main_window.set_focus()
3834
- btn_cancelar = main_window.child_window(class_name="TBitBtn", found_index=0)
3835
- btn_cancelar.click()
3836
- except:
3837
- btn_cancelar = main_window.child_window(title="&Cancela")
3838
- btn_cancelar.click()
3839
-
3833
+ btn_cancelar = main_window.child_window(class_name="TBitBtn", found_index=0)
3834
+ btn_cancelar.click()
3835
+ except:
3836
+ btn_cancelar = main_window.child_window(title="&Cancela")
3837
+ btn_cancelar.click()
3838
+
3840
3839
 
3841
- await worker_sleep(10)
3842
- console.print("Verificando se a tela de Faturamento Pre venda esta aberta")
3843
- close_dados_faturamento = await is_window_open_by_class("TFrmDadosFaturamentoPreVenda","TFrmDadosFaturamentoPreVenda")
3844
- if close_dados_faturamento["IsOpened"] == True:
3845
- console.print("Janela aberta, fechando")
3846
- try:
3847
- app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=180)
3848
- main_window = app["TFrmDadosFaturamentoPreVenda"]
3849
- main_window.set_focus()
3850
- await worker_sleep(2)
3851
- main_window.close()
3852
- except Exception as e:
3853
- console.print(f"Erro ao fechar a janela de dados faturamento pre venda {e}")
3840
+ await worker_sleep(10)
3841
+ console.print("Verificando se a tela de Faturamento Pre venda esta aberta")
3842
+ close_dados_faturamento = await is_window_open_by_class("TFrmDadosFaturamentoPreVenda","TFrmDadosFaturamentoPreVenda")
3843
+ if close_dados_faturamento["IsOpened"] == True:
3844
+ console.print("Janela aberta, fechando")
3845
+ try:
3846
+ app = Application().connect(class_name="TFrmDadosFaturamentoPreVenda", timeout=180)
3847
+ main_window = app["TFrmDadosFaturamentoPreVenda"]
3848
+ main_window.set_focus()
3849
+ await worker_sleep(2)
3850
+ main_window.close()
3851
+ except Exception as e:
3852
+ console.print(f"Erro ao fechar a janela de dados faturamento pre venda {e}")
3854
3853
 
3855
3854
 
3856
- await worker_sleep(5)
3857
- console.print("Verificando se a tela de Gerenciador esta aberta")
3858
- window_gerenciador_screen = await is_window_open_by_class("TFrmGerenciadorNFe2","TFrmGerenciadorNFe2")
3859
- if window_gerenciador_screen["IsOpened"] == True:
3860
- app = Application().connect(class_name="TFrmGerenciadorNFe2", timeout=10)
3861
- window_gerenciador = app["TFrmGerenciadorNFe2"]
3862
- window_gerenciador.set_focus()
3863
- await worker_sleep(2)
3864
- window_gerenciador.close()
3865
- else:
3866
- console.print("Janela TFrmGerenciadorNFe2 ja fechada")
3855
+ await worker_sleep(5)
3856
+ console.print("Verificando se a tela de Gerenciador esta aberta")
3857
+ window_gerenciador_screen = await is_window_open_by_class("TFrmGerenciadorNFe2","TFrmGerenciadorNFe2")
3858
+ if window_gerenciador_screen["IsOpened"] == True:
3859
+ app = Application().connect(class_name="TFrmGerenciadorNFe2", timeout=10)
3860
+ window_gerenciador = app["TFrmGerenciadorNFe2"]
3861
+ window_gerenciador.set_focus()
3862
+ await worker_sleep(2)
3863
+ window_gerenciador.close()
3864
+ else:
3865
+ console.print("Janela TFrmGerenciadorNFe2 ja fechada")
3867
3866
 
3868
3867
 
3869
- await worker_sleep(10)
3870
- console.print("Verificando se a tela de Pre venda esta aberta")
3871
- window_gerenciador_screen = await is_window_open_by_class("TFrmPreVenda","TFrmPreVenda")
3872
- if window_gerenciador_screen["IsOpened"] == True:
3873
- app = Application().connect(class_name="TFrmPreVenda", timeout=10)
3874
- window_gerenciador = app["TFrmPreVenda"]
3875
- window_gerenciador.set_focus()
3876
- await worker_sleep(2)
3877
- window_gerenciador.close()
3878
- else:
3879
- console.print("Janela TFrmPreVenda ja fechada")
3868
+ await worker_sleep(10)
3869
+ console.print("Verificando se a tela de Pre venda esta aberta")
3870
+ window_gerenciador_screen = await is_window_open_by_class("TFrmPreVenda","TFrmPreVenda")
3871
+ if window_gerenciador_screen["IsOpened"] == True:
3872
+ app = Application().connect(class_name="TFrmPreVenda", timeout=10)
3873
+ window_gerenciador = app["TFrmPreVenda"]
3874
+ window_gerenciador.set_focus()
3875
+ await worker_sleep(2)
3876
+ window_gerenciador.close()
3877
+ else:
3878
+ console.print("Janela TFrmPreVenda ja fechada")
3879
+
3880
3880
 
3881
-
3882
- except Exception as e:
3883
- retorno = f"Não foi possivel concluir o processo de pré venda {e} \nEtapas Executadas:\n{steps}"
3884
- return RpaRetornoProcessoDTO(
3885
- sucesso=False,
3886
- retorno=retorno,
3887
- status=RpaHistoricoStatusEnum.Falha,
3888
- tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3889
- )
3890
- else:
3891
- retorno = f"{preenchimento_header_pre_venda.retorno} \nEtapas Executadas:\n{steps}"
3881
+ except Exception as e:
3882
+ retorno = f"Não foi possivel concluir o processo de pré venda {e} \nEtapas Executadas:\n{steps}"
3892
3883
  return RpaRetornoProcessoDTO(
3893
3884
  sucesso=False,
3894
3885
  retorno=retorno,
3895
3886
  status=RpaHistoricoStatusEnum.Falha,
3896
3887
  tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3897
- )
3888
+ )
3889
+ else:
3890
+ retorno = f"{preenchimento_header_pre_venda.retorno} \nEtapas Executadas:\n{steps}"
3891
+ return RpaRetornoProcessoDTO(
3892
+ sucesso=False,
3893
+ retorno=retorno,
3894
+ status=RpaHistoricoStatusEnum.Falha,
3895
+ tags=[RpaTagDTO(descricao=RpaTagEnum.Tecnico)]
3896
+ )
3898
3897
  else:
3899
3898
  console.print(f"\nPesquisa: 'Não possui item para nota conjunta",style="bold green")
3900
3899