Esempio n. 1
0
    def pesquisar_transportador(sap_session, criterio):
        try:
            SAPTransaction.call(sap_session, 'xk03')
            if len(criterio) != 7:
                criterio = XK03.__pesquisar_codigo_transportador_por_cnpj_ou_cpf(
                    sap_session, criterio)
            XK03.__abrir_transacao(sap_session, criterio)
            nome = SAPGuiElements.get_text(sap_session, ELEMENTO_NOME)

            SAPGuiElements.press_button(sap_session, ELEMENTO_PROXIMA_PAGINA)
            identificador = SAPGuiElements.get_text(sap_session, ELEMENTO_CNPJ)
            if not identificador:
                identificador = SAPGuiElements.get_text(
                    sap_session, ELEMENTO_CPF)

            codigo_municipio = SAPGuiElements.get_text(
                sap_session, ELEMENTO_CODIGO_MUNICIPIO)
            codigo_municipio = "".join(re.findall("\\d*", codigo_municipio))
            municipio = MunicipioService.pesquisar_municipio_pelo_codigo(
                codigo_municipio)
            if municipio is None:
                raise RuntimeError(
                    'Não possivel definir o municipio do transportador!')

            transportador = Transportador()
            transportador.nome = nome
            transportador.codigo_sap = criterio
            transportador.cnpj_cpf = identificador
            transportador.municipio = municipio
            transportador.save()
            return transportador
        except Exception as e:
            traceback.print_exc(file=sys.stdout)
            raise e
Esempio n. 2
0
    def pesquisar_transportador(sap_session, numero_documento):

        VT01.__abrir_transacao(sap_session)

        if re.findall("^\\d{7}$", numero_documento):
            return VT01.pesquisar_transportador_por_codigo(
                sap_session, numero_documento)

        sap_session.findById("wnd[0]").sendVKey(4)
        SAPGuiElements.press_button(sap_session, FILTER_BUTTOn_ELEMENT)

        # campo para o selecionar o primeiro elemento da tabela caso encontre um transportador
        primeiro_elemento = "wnd[1]/usr/lbl[1,5]"
        # verificando se é um cnpj
        if re.findall("^\\d{14}$", numero_documento):
            SAPGuiElements.set_text(sap_session, ELEMENTO_CNPJ,
                                    numero_documento)

        elif re.findall("^\\d{11}$", numero_documento):
            SAPGuiElements.set_text(sap_session, ELEMENTO_CPF,
                                    numero_documento)
            primeiro_elemento = "wnd[1]/usr/lbl[1,3]"

        else:
            return "CNPJ ou CPF Inválido!"

        SAPGuiElements.press_keyboard_keys(sap_session, "Enter")

        error_message = SAPGuiElements.get_text(sap_session, "wnd[0]/sbar")

        if error_message:
            SAPTransaction.exit_transaction(sap_session)
            return False, error_message

        else:
            # selecionando o primeiro elemento da tabela
            SAPGuiElements.press_keyboard_keys(sap_session, "Enter")
            SAPGuiElements.press_keyboard_keys(sap_session, "Enter")
            codigo_transportador = SAPGuiElements.get_text(
                sap_session, "wnd[0]/usr/tabsHEADER_TABSTRIP1/tabpTABS_OV_"
                "PR/ssubG_HEADER_SUBSCREEN1:SAPMV56A:1021"
                "/ctxtVTTK-TDLNR")

            endereco_transportador = SAPGuiElements.get_text(
                sap_session, "wnd[0]/usr/tabsHEADER_TABSTRIP1/tabpTABS_OV"
                "_PR/ssubG_HEADER_SUBSCREEN1:SAPMV56A:1021/"
                "txtVTTKD-TXTSP")

            print('codigo :' + codigo_transportador)
            SAPTransaction.exit_transaction(sap_session)
            return True, codigo_transportador, endereco_transportador
Esempio n. 3
0
    def __inserir_remessas(sap_session, remessas):
        try:
            SAPGuiElements.press_button(sap_session,
                                        ELEMENTO_BOTAO_ADICIONAR_REMESSAS)

            remover_a = remessas[0].itens[0].produto.remover_a == 1
            if remover_a:
                VT01.__remover_a(sap_session)

            SAPGuiElements.press_button(
                sap_session, ELEMENTO_BOTAO_ADICIONAR_MAIS_REMESSAS)
            cont = 0
            for remessa in remessas:
                field = ELEMENT_SHIPPING_FIELDS.format(cont)
                sap_session.findById(field).text = remessa.numero_remessa
                cont = cont + 1

            SAPGuiElements.press_button(sap_session, ELEMENT_EXECUTE_BUTTON_1)
            SAPGuiElements.press_button(sap_session, ELEMENT_EXECUTE_BUTTON_2)

            mensagem = SAPGuiElements.verificar_mensagem_barra_inferior(
                sap_session)
            total_remessas_adicionadas = "".join(re.findall("\\d*", mensagem))
            total_remessas_adicionadas = int(total_remessas_adicionadas)
            total_remessas = len(remessas)

            if total_remessas_adicionadas != total_remessas:
                raise RuntimeError('Erro ao adicionar remessas!')

        except Exception as e:
            raise e
Esempio n. 4
0
    def inserir_inspecao_veicular(sap_session, numero_transporte,
                                  numero_inspecao_veicular):
        SAPTransaction.call(sap_session, 'vt02n')
        SAPGuiElements.set_text(sap_session, ELEMENTO_NUMERO_TRANSPORTE,
                                numero_transporte)
        SAPGuiElements.press_keyboard_keys(sap_session, "Enter")

        SAPGuiElements.select_element(sap_session, ELEMENTO_ABA_IDENTIFICACAO)
        SAPGuiElements.set_text(sap_session, ELEMENTO_NUMERO_INSPECAO_VEICULAR,
                                numero_inspecao_veicular)
        SAPGuiElements.press_button(sap_session, SAVE_BUTTON)

        tipo_mensagem = SAPGuiElements.get_sbar_message_type(sap_session)
        if tipo_mensagem and tipo_mensagem == 'S':
            return True, ""
        return False, "Erro ao inserir inspecao {} no transporte {}".format(
            numero_inspecao_veicular, numero_transporte)
Esempio n. 5
0
    def create(sap_session, carregamento):
        try:

            VT01.__abrir_transacao(sap_session)
            VT01.__inserir_codigo_transportador(
                sap_session, carregamento.transportador.codigo_sap)
            VT01.__inserir_dados_veiculo(sap_session, carregamento.veiculo)

            if carregamento.remessas[0].itens[0].produto.inspecao_produto == 1:
                VT01.__inserir_lote_controle_produto(
                    sap_session, carregamento.lotes_qualidade[-1])
            SAPGuiElements.enter(sap_session)

            SAPGuiElements.verificar_mensagem_barra_inferior(sap_session)

            VT01.__inserir_dados_motorista(sap_session, carregamento.motorista)

            # verificando se é necessário lacres para esse produto
            tipo_lacres = carregamento.remessas[0].itens[0].produto.tipo_lacres
            if tipo_lacres != 0:
                VT01.__inserir_lacres(sap_session, tipo_lacres,
                                      carregamento.lacres)

            # verificando se há número de pedido
            if carregamento.numero_pedido:
                VT01.__inserir_pedido(sap_session, carregamento.numero_pedido)

            SAPGuiElements.enter(sap_session)

            VT01.__inserir_remessas(sap_session, carregamento.remessas)
            SAPGuiElements.press_button(sap_session, ELEMENTO_SINTESE)
            sap_session.findById(ELEMENTO_ABA_DADOS).select()
            SAPGuiElements.press_button(sap_session,
                                        ELEMENTO_ORGANIZAR_TRANSPORTE)

            SAPGuiElements.salvar(sap_session)

            message = SAPGuiElements.verificar_mensagem_barra_inferior(
                sap_session)
            transport_number = VT01.extrair_numero_transport(message)
            return transport_number

        except Exception as e:
            traceback.print_exc(file=sys.stdout)
            raise e
Esempio n. 6
0
    def __abrir_transacao(sap_session, numero_inspecao_veicular):
        SAPTransaction.call(sap_session, 'qe01')
        SAPGuiElements.set_text(sap_session, ELEMENTO_LOTE_CONTROLE,
                                numero_inspecao_veicular)
        SAPGuiElements.set_text(sap_session, ELEMENTO_OPERACAO, "0010")
        SAPGuiElements.set_text(sap_session, ELEMENTO_CENTRO, "1014")
        sap_session.findById(ELEMENTO_FILTRO_CARACTERISTICAS).key = 1
        SAPGuiElements.press_keyboard_keys(sap_session, "Enter")

        existe_proxima_operacao = True
        while existe_proxima_operacao:
            '''
            row = 0
            while row < sap_session.findById(ELEMENTO_TABELA_RESULTADOS).RowCount:
                # print(row)
                # print(SAPGuiElements.get_text(sap_session, ELEMENTO_COLUNA_S.format(row)))
                # session.findById(ELEMENTO_TABELA_RESULTADOS).selectedRows = row
                row += 1
            '''
            QE01.__inserir_s(sap_session)
            SAPGuiElements.press_button(sap_session,
                                        ELEMENTO_BOTAO_SELECIONAR_TODOS)
            SAPGuiElements.press_button(sap_session, ELEMENTO_BOTAO_AVALIAR)
            # TODO verificar essa lógica
            SAPGuiElements.press_button(sap_session,
                                        ELEMENTO_BOTAO_PROXIMA_OPERACAO)
            existe_proxima_operacao = SAPGuiElements.is_enable(
                sap_session, ELEMENTO_BOTAO_PROXIMA_OPERACAO)

            try:
                SAPGuiElements.press_button(sap_session,
                                            ELEMENTO_BOTAO_GRAVAR_PRIMEIRO)
            except AttributeError:
                pass
        SAPGuiElements.press_button(sap_session, SAVE_BUTTON)
        tipo_mensagem = SAPGuiElements.get_sbar_message_type(sap_session)
        message = SAPGuiElements.get_text(sap_session, MESSAGE_ELEMENT)
        if tipo_mensagem and tipo_mensagem == 'S':
            return True, message
        else:
            return False, message
Esempio n. 7
0
    def create(sap_session, lote_inspecao):
        try:
            SAPTransaction.call(sap_session, 'qa01')
            SAPGuiElements.set_text(sap_session, ELEMENTO_CODIGO_PRODUTO, lote_inspecao.material)
            SAPGuiElements.set_text(sap_session, ELEMENTO_CENTRO, CENTRO)
            SAPGuiElements.set_text(sap_session, ELEMENTO_LOTE_ORIGEM, lote_inspecao.origem)
            SAPGuiElements.press_keyboard_keys(sap_session, "Enter")

            # verificando se o lote é de inspecao de produto(89) ou de veiculo(07)
            inspecionando_produto = lote_inspecao.origem == "89"
            if inspecionando_produto:
                sap_session.findById("wnd[1]/usr/lbl[1,3]").setFocus()
                SAPGuiElements.press_keyboard_keys(sap_session, "Enter")
                SAPGuiElements.set_text(sap_session, ELEMENTO_QUANTIDADE_LOTE, QUANTIDADE_LOTES)
                SAPGuiElements.set_text(sap_session, ELEMENTO_TXT_BREVE_INSP_PRODUTO, lote_inspecao.texto_breve)
            else:
                SAPGuiElements.set_text(sap_session, ELEMENTO_TXT_BREVE_INSP_VEICULO, lote_inspecao.texto_breve)

            # o lote e o deposito sao setados agora pq caso o lote seja de inspecao de produto, o sap mostra uma
            # mensagem antes de abrir a tela do lote
            SAPGuiElements.set_text(sap_session, ELEMENTO_LOTE, lote_inspecao.lote)
            SAPGuiElements.set_text(sap_session, ELEMENTO_DEPOSITO,
                                    lote_inspecao.deposito if lote_inspecao.deposito is not None else '')

            SAPGuiElements.salvar(sap_session)

            try:
                SAPGuiElements.press_button(sap_session, OPTIONAL_CREATE)
                error_message = SAPGuiElements.get_text(sap_session, ERROR_MESSAGE_ELEMENT)
                if error_message:
                    raise RuntimeError(QA01.get_formated_error_message(error_message, lote_inspecao.texto_breve))

            except AttributeError:
                pass

            mensagem = SAPGuiElements.verificar_mensagem_barra_inferior(sap_session)
            return QA01.get_batch_controller_number(mensagem)

        except Exception as e:
            traceback.print_exc(file=sys.stdout)
            raise e
Esempio n. 8
0
 def __abrir_detalhes_cabecalho(sap_session):
     SAPGuiElements.press_button(sap_session,
                                 ELEMENTO_BOTAO_DETALHE_CABECALHJO)
     SAPGuiElements.ignorar_alerta(sap_session)
Esempio n. 9
0
    def consultar_saldo_cliente(sap_session, cnpj, data_inicial, data_final, produto):
        SAPTransaction.call(sap_session, 'zsd020')
        SAPGuiElements.set_text(sap_session, ELEMENTO_LOCAL_NEGOCIOS, '1014')
        SAPGuiElements.set_text(sap_session, ELEMENTO_ORGANIZACAO_VENDAS, '1000')
        SAPGuiElements.set_text(sap_session, ELEMENTO_CANAL_DISTRIBUICAO, produto.canal_distribuicao.codigo)
        SAPGuiElements.set_text(sap_session, ELEMENTO_SETOR_VENDAS, produto.setor_atividade.codigo)
        SAPGuiElements.set_text(sap_session, ELEMENTO_DATA_INICIAL, data_inicial)
        SAPGuiElements.set_text(sap_session, ELEMENTO_DATA_FINAL, data_final)
        SAPGuiElements.set_text(sap_session, ELEMENTO_CODIGO_MATERIAL, produto.codigo_sap)
        SAPGuiElements.select_element(sap_session, ELEMENTO_APENAS_ORDENS_VENDA)
        SAPGuiElements.set_checkbox(sap_session, ELEMENTO_INCLUIR_BLOQUEADAS)
        SAPGuiElements.set_focus(sap_session, ELEMENTO_EMISSOR_ORDEM)
        SAPGuiElements.send_key(sap_session, 4)

        SAPGuiElements.set_text(sap_session, ELEMENTO_CAMPO_CNPJ, cnpj)
        SAPGuiElements.enter(sap_session)
        SAPGuiElements.enter(sap_session)
        SAPGuiElements.send_key(sap_session, 8)
        if SAPGuiElements.verificar_mensagem_barra_inferior(sap_session):
            return []

        SAPGuiElements.press_button(sap_session, ELEMENTO_BOTAO_SELECIONAR_LAYOUT)
        row = 0
        while row < sap_session.findById(ELEMENTO_TABELA_LAYOUTS).RowCount:
            nome_layout = sap_session.findById(ELEMENTO_TABELA_LAYOUTS).GetCellValue(row, "TEXT")

            if nome_layout == 'KSLIMA':
                sap_session.findById(ELEMENTO_TABELA_LAYOUTS).selectedRows = row
                sap_session.findById(ELEMENTO_TABELA_LAYOUTS).setCurrentCell(row, "TEXT")
                sap_session.findById(ELEMENTO_TABELA_LAYOUTS).firstVisibleRow = row
                sap_session.findById(ELEMENTO_TABELA_LAYOUTS).clickCurrentCell()
                break
            row += 1

        row = 0
        ordens = []
        while row < sap_session.findById(ELEMENTO_TABELA_ORDENS).RowCount:
            # converterndo o número da ordem para inteiro e assim eliminar os zeros a esquerda
            numero_ordem = str(int(sap_session.findById(ELEMENTO_TABELA_ORDENS).GetCellValue(row, ELEMENTO_COLUNA_ORDEM)))
            data = sap_session.findById(ELEMENTO_TABELA_ORDENS).GetCellValue(row, ELEMENTO_COLUNA_DATA)
            cidade = sap_session.findById(ELEMENTO_TABELA_ORDENS).GetCellValue(row, ELEMENTO_COLUNA_CIDADE)
            uf = sap_session.findById(ELEMENTO_TABELA_ORDENS).GetCellValue(row, ELEMENTO_COLUNA_UF)
            cliente = sap_session.findById(ELEMENTO_TABELA_ORDENS).GetCellValue(row, ELEMENTO_COLUNA_CLIENTE)
            qtd = sap_session.findById(ELEMENTO_TABELA_ORDENS).GetCellValue(row, ELEMENTO_COLUNA_QTD_ORDEM)
            qtd_saida = sap_session.findById(ELEMENTO_TABELA_ORDENS).GetCellValue(row, ELEMENTO_COLUNA_QTD_SAIDA)
            qtd_disponivel = sap_session.findById(ELEMENTO_TABELA_ORDENS).GetCellValue(row, ELEMENTO_COLUNA_QTD_DISPONIVEL)
            material = sap_session.findById(ELEMENTO_TABELA_ORDENS).GetCellValue(row, ELEMENTO_COLUNA_MATERIAL)

            codigo_material = sap_session.findById(ELEMENTO_TABELA_ORDENS).GetCellValue(row, ELEMENTO_COLUNA_COD_MATERIAL)
            codigo_material = str(int(codigo_material))

            pedido = sap_session.findById(ELEMENTO_TABELA_ORDENS).GetCellValue(row, ELEMENTO_COLUNA_PEDIDO)
            tipo_ordem = sap_session.findById(ELEMENTO_TABELA_ORDENS).GetCellValue(row, ELEMENTO_COLUNA_TIPO_ORDEM)
            status = sap_session.findById(ELEMENTO_TABELA_ORDENS).GetCellValue(row, ELEMENTO_COLUNA_STATUS)
            cnpj = sap_session.findById(ELEMENTO_TABELA_ORDENS).GetCellValue(row, ELEMENTO_COLUNA_CNPJ)

            ordem = Ordem()
            ordem.data = data
            ordem.numero = numero_ordem
            ordem.material = material
            ordem.codigo_material = codigo_material
            ordem.cliente = cliente
            ordem.cidade = cidade
            ordem.uf = uf
            ordem.qtd = qtd
            ordem.qtd_saida = qtd_saida
            ordem.qtd_disponivel = qtd_disponivel
            ordem.pedido = pedido
            ordem.tipo = tipo_ordem
            ordem.cnpj = cnpj
            ordem.status = status

            ordens.append(ordem)

            row += 1
        return ordens