-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (34 loc) · 1.41 KB
/
main.py
File metadata and controls
40 lines (34 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import win32com.client
import subprocess
import time
import config
def getSAPTransaction(self):
session = self.connection.Children(0)
#acessando a transação SE16N
session.findById("wnd[0]/tbar[0]/okcd").text = "/nse16n"
session.findById("wnd[0]").sendVKey(0)
#Tabelas VBAP
session.findById("wnd[0]/usr/ctxtGD-TAB").text = "VBAP"
session.findById("wnd[0]").sendVKey(8)
class SapGui(object):
def __init__(self):
try:
#verifica se o SAP GUI já está aberto
sapgui = win32com.client.GetObject('SAPGUI')
except:
#se não estiver aberto, abrirá via .exe
self.path = config.SAP_EXE
subprocess.Popen(self.path)
time.sleep(5)
finally:
SapGuiAuto = win32com.client.GetObject("SAPGUI")
application = SapGuiAuto.GetScriptingEngine
#faz conexão com a connection do SAP_CONNECT
self.connection = application.OpenConnection(config.SAP_CONNECT, True)
session = self.connection.Children(0)
session.findById("wnd[0]/usr/txtRSYST-BNAME").text = config.SAP_USER
session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = config.SAP_PASS
session.findById("wnd[0]").sendVKey(0)
getSAPTransaction(self)
if __name__ == '__main__':
Object = SapGui()