-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
96 lines (88 loc) · 3.11 KB
/
test.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from ahk import AHK
from ahk.directives import NoTrayIcon
import time
import os
from sap.open import get_sap
from utils.helpers import use_dotenv
from utils.data_frames import get_single_sap
from state.output import output
import utils.prompts as pr
ahk = AHK(directives=[NoTrayIcon])
ahk.set_detect_hidden_windows(True)
ahk.set_title_match_mode(("RegEx", "Slow"))
def sqvi(table="PRICE", transaction="LIST_PRICE", copy_result=False):
use_dotenv()
out_file = os.path.join(os.environ["DIR_IN"], f"{table}.XLSX")
try:
sap = get_sap()
time.sleep(3)
if sap:
output.add(f"{pr.info}Downloading {table} from SAP")
if os.path.exists(out_file):
os.remove(out_file)
sap.activate()
ahk.send_input("/osqvi {Enter}")
ahk.win_wait_active("QuickViewer: Initial Screen")
time.sleep(2)
ahk.send_input(f"{transaction}")
ahk.send_input("{F8}")
ahk.win_wait_active("AP_LIST_PRICE")
time.sleep(1)
# select variant
ahk.send("+{F5}")
ahk.win_wait_active("ABAP: Variant Directory of Program")
time.sleep(1)
ahk.send("{down}")
time.sleep(1)
ahk.send("{up}")
time.sleep(1)
ahk.send("{F2}")
time.sleep(1)
# paste parts
ahk.send("{Tab}")
ahk.send("{Tab}")
ahk.send("{Enter}")
ahk.win_wait_active(f"Multiple Selection for Material Number")
time.sleep(1)
ahk.send("+{F12}")
time.sleep(3)
ahk.send("{F8}")
time.sleep(3)
# execute
ahk.send("{F8}")
ahk.win_wait_active("AP_LIST_PRICE")
time.sleep(5)
# save
# ahk.send("+{F10}")
# time.sleep(1)
# ahk.send("{up}")
# time.sleep(1)
# ahk.send("{Enter}")
# time.sleep(1)
# ahk.send("{Enter}")
# ahk.win_wait_active("Save As")
# time.sleep(2)
# ahk.send("+{tab} {tab}")
# time.sleep(2)
# ahk.send(f"{out_file}")
# ahk.send("{Enter}")
# time.sleep(2)
# # close excel results
# excel = ahk.win_wait_active(f"{table}.XLSX - Excel")
# if ahk.win_exists(f"{table}.XLSX - Excel"):
# ahk.send("^w")
# excel.minimize()
# # close sap results
# sap_results = ahk.win_wait_active("AP_LIST_PRICE")
# if sap_results.exist:
# sap_results.close()
#
# if copy_result:
# df = get_single_sap(table)
# df.to_clipboard(index=False)
# output.add(f"{pr.file}{df.shape[0]} results copied to clipboard")
#
# output.add(f"{pr.ok}{table} data downloaded")
except TimeoutError:
output.add(f"{pr.cncl}failed to launch SAP!")
sqvi()