ITK-dev-shared-components 1.0.0__tar.gz → 1.1.0__tar.gz
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.
- itk_dev_shared_components-1.1.0/PKG-INFO +58 -0
- itk_dev_shared_components-1.1.0/README.md +39 -0
- {itk_dev_shared_components-1.0.0 → itk_dev_shared_components-1.1.0}/itk_dev_shared_components/graph/authentication.py +2 -1
- {itk_dev_shared_components-1.0.0 → itk_dev_shared_components-1.1.0}/itk_dev_shared_components/graph/mail.py +6 -6
- {itk_dev_shared_components-1.0.0 → itk_dev_shared_components-1.1.0}/itk_dev_shared_components/sap/gridview_util.py +7 -5
- {itk_dev_shared_components-1.0.0 → itk_dev_shared_components-1.1.0}/itk_dev_shared_components/sap/multi_session.py +44 -25
- itk_dev_shared_components-1.1.0/itk_dev_shared_components/sap/opret_kundekontakt.py +107 -0
- {itk_dev_shared_components-1.0.0 → itk_dev_shared_components-1.1.0}/itk_dev_shared_components/sap/sap_login.py +11 -12
- {itk_dev_shared_components-1.0.0 → itk_dev_shared_components-1.1.0}/itk_dev_shared_components/sap/sap_util.py +6 -4
- {itk_dev_shared_components-1.0.0 → itk_dev_shared_components-1.1.0}/itk_dev_shared_components/sap/tree_util.py +5 -4
- itk_dev_shared_components-1.1.0/itk_dev_shared_components.egg-info/PKG-INFO +58 -0
- {itk_dev_shared_components-1.0.0 → itk_dev_shared_components-1.1.0}/pyproject.toml +1 -1
- itk_dev_shared_components-1.0.0/PKG-INFO +0 -24
- itk_dev_shared_components-1.0.0/README.md +0 -5
- itk_dev_shared_components-1.0.0/itk_dev_shared_components/sap/opret_kundekontakt.py +0 -65
- itk_dev_shared_components-1.0.0/itk_dev_shared_components.egg-info/PKG-INFO +0 -24
- {itk_dev_shared_components-1.0.0 → itk_dev_shared_components-1.1.0}/LICENSE +0 -0
- {itk_dev_shared_components-1.0.0 → itk_dev_shared_components-1.1.0}/itk_dev_shared_components/__init__.py +0 -0
- {itk_dev_shared_components-1.0.0 → itk_dev_shared_components-1.1.0}/itk_dev_shared_components/graph/__init__.py +0 -0
- {itk_dev_shared_components-1.0.0 → itk_dev_shared_components-1.1.0}/itk_dev_shared_components/sap/__init__.py +0 -0
- {itk_dev_shared_components-1.0.0 → itk_dev_shared_components-1.1.0}/itk_dev_shared_components.egg-info/SOURCES.txt +0 -0
- {itk_dev_shared_components-1.0.0 → itk_dev_shared_components-1.1.0}/itk_dev_shared_components.egg-info/dependency_links.txt +0 -0
- {itk_dev_shared_components-1.0.0 → itk_dev_shared_components-1.1.0}/itk_dev_shared_components.egg-info/requires.txt +0 -0
- {itk_dev_shared_components-1.0.0 → itk_dev_shared_components-1.1.0}/itk_dev_shared_components.egg-info/top_level.txt +0 -0
- {itk_dev_shared_components-1.0.0 → itk_dev_shared_components-1.1.0}/setup.cfg +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: itk_dev_shared_components
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Shared components to use in RPA projects
|
|
5
|
+
Author-email: ITK Development <itk-rpa@mkb.aarhus.dk>
|
|
6
|
+
Project-URL: Homepage, https://github.com/itk-dev-rpa/itk-dev-shared-components
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/itk-dev-rpa/itk-dev-shared-components/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
11
|
+
Requires-Python: >=3.7
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: pywin32>=306
|
|
15
|
+
Requires-Dist: selenium>=4.10.0
|
|
16
|
+
Requires-Dist: msal>=1.24.1
|
|
17
|
+
Requires-Dist: requests>=2.31.0
|
|
18
|
+
Requires-Dist: beautifulsoup4>=4.12.2
|
|
19
|
+
|
|
20
|
+
# itk-dev-shared-components
|
|
21
|
+
|
|
22
|
+
## Links
|
|
23
|
+
|
|
24
|
+
[Documentation](https://itk-dev-rpa.github.io/itk-dev-shared-components-docs/)
|
|
25
|
+
|
|
26
|
+
[Pypi](https://pypi.org/project/ITK-dev-shared-components/)
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
pip install itk-dev-shared-components
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Intro
|
|
35
|
+
|
|
36
|
+
This python library contains helper modules for RPA development.
|
|
37
|
+
It's based on the need of [ITK Dev](https://itk.aarhus.dk/), but it has been
|
|
38
|
+
generalized to be useful for others as well.
|
|
39
|
+
|
|
40
|
+
## Integrations
|
|
41
|
+
|
|
42
|
+
### SAP Gui
|
|
43
|
+
|
|
44
|
+
Helper functions for using SAP Gui. A few examples include:
|
|
45
|
+
|
|
46
|
+
- Login to SAP.
|
|
47
|
+
- Handling multiple sessions in multiple threads.
|
|
48
|
+
- Convenience functions for gridviews and trees.
|
|
49
|
+
|
|
50
|
+
### Microsoft Graph
|
|
51
|
+
|
|
52
|
+
Helper functions for using Microsoft Graph to read emails from shared inboxes.
|
|
53
|
+
Some examples are:
|
|
54
|
+
|
|
55
|
+
- Authentication using username and password.
|
|
56
|
+
- List and get emails.
|
|
57
|
+
- Get attachment data.
|
|
58
|
+
- Move and delete emails.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# itk-dev-shared-components
|
|
2
|
+
|
|
3
|
+
## Links
|
|
4
|
+
|
|
5
|
+
[Documentation](https://itk-dev-rpa.github.io/itk-dev-shared-components-docs/)
|
|
6
|
+
|
|
7
|
+
[Pypi](https://pypi.org/project/ITK-dev-shared-components/)
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
pip install itk-dev-shared-components
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Intro
|
|
16
|
+
|
|
17
|
+
This python library contains helper modules for RPA development.
|
|
18
|
+
It's based on the need of [ITK Dev](https://itk.aarhus.dk/), but it has been
|
|
19
|
+
generalized to be useful for others as well.
|
|
20
|
+
|
|
21
|
+
## Integrations
|
|
22
|
+
|
|
23
|
+
### SAP Gui
|
|
24
|
+
|
|
25
|
+
Helper functions for using SAP Gui. A few examples include:
|
|
26
|
+
|
|
27
|
+
- Login to SAP.
|
|
28
|
+
- Handling multiple sessions in multiple threads.
|
|
29
|
+
- Convenience functions for gridviews and trees.
|
|
30
|
+
|
|
31
|
+
### Microsoft Graph
|
|
32
|
+
|
|
33
|
+
Helper functions for using Microsoft Graph to read emails from shared inboxes.
|
|
34
|
+
Some examples are:
|
|
35
|
+
|
|
36
|
+
- Authentication using username and password.
|
|
37
|
+
- List and get emails.
|
|
38
|
+
- Get attachment data.
|
|
39
|
+
- Move and delete emails.
|
|
@@ -3,6 +3,7 @@ connection."""
|
|
|
3
3
|
|
|
4
4
|
import msal
|
|
5
5
|
|
|
6
|
+
|
|
6
7
|
# pylint: disable-next=too-few-public-methods
|
|
7
8
|
class GraphAccess:
|
|
8
9
|
"""An object that handles access to the Graph api.
|
|
@@ -45,7 +46,7 @@ def authorize_by_username_password(username: str, password: str, *, client_id: s
|
|
|
45
46
|
password: The password of the user.
|
|
46
47
|
client_id: The Graph API client id in 8-4-4-12 format.
|
|
47
48
|
tenant_id: The Graph API tenant id in 8-4-4-12 format.
|
|
48
|
-
|
|
49
|
+
|
|
49
50
|
Returns:
|
|
50
51
|
GraphAccess: The GraphAccess object used to authorize Graph access.
|
|
51
52
|
"""
|
|
@@ -162,15 +162,15 @@ def get_attachment_data(attachment: Attachment, graph_access: GraphAccess) -> io
|
|
|
162
162
|
"""
|
|
163
163
|
email = attachment.email
|
|
164
164
|
endpoint = f"https://graph.microsoft.com/v1.0/users/{email.user}/messages/{email.id}/attachments/{attachment.id}/$value"
|
|
165
|
-
response =
|
|
165
|
+
response = _get_request(endpoint, graph_access)
|
|
166
166
|
data_bytes = response.content
|
|
167
167
|
return io.BytesIO(data_bytes)
|
|
168
168
|
|
|
169
169
|
|
|
170
|
-
def move_email(email: Email, folder_path: str, graph_access: GraphAccess, *, well_known_folder: bool=False) -> None:
|
|
170
|
+
def move_email(email: Email, folder_path: str, graph_access: GraphAccess, *, well_known_folder: bool = False) -> None:
|
|
171
171
|
"""Move an email to another folder under the same user.
|
|
172
172
|
If well_known_folder is true, the folder path is assumed to be a well defined folder.
|
|
173
|
-
See https://learn.microsoft.com/en-us/graph/api/resources/mailfolder?view=graph-rest-1.0
|
|
173
|
+
See https://learn.microsoft.com/en-us/graph/api/resources/mailfolder?view=graph-rest-1.0
|
|
174
174
|
for a list of well defined folder names.
|
|
175
175
|
|
|
176
176
|
Args:
|
|
@@ -208,7 +208,7 @@ def move_email(email: Email, folder_path: str, graph_access: GraphAccess, *, wel
|
|
|
208
208
|
email.id = new_id
|
|
209
209
|
|
|
210
210
|
|
|
211
|
-
def delete_email(email: Email, graph_access: GraphAccess, *, permanent: bool=False) -> None:
|
|
211
|
+
def delete_email(email: Email, graph_access: GraphAccess, *, permanent: bool = False) -> None:
|
|
212
212
|
"""Delete an email from the mailbox.
|
|
213
213
|
If permanent is true the email is completely removed from the user's mailbox.
|
|
214
214
|
If permanent is false the email is instead moved to the Deleted Items folder.
|
|
@@ -235,7 +235,7 @@ def delete_email(email: Email, graph_access: GraphAccess, *, permanent: bool=Fal
|
|
|
235
235
|
|
|
236
236
|
|
|
237
237
|
def _find_folder(response: dict, target_folder: str) -> str:
|
|
238
|
-
"""Find the target folder in
|
|
238
|
+
"""Find the target folder in
|
|
239
239
|
|
|
240
240
|
Args:
|
|
241
241
|
response: The json dict of the HTTP response.
|
|
@@ -300,7 +300,7 @@ def _get_request(endpoint: str, graph_access: GraphAccess) -> requests.models.Re
|
|
|
300
300
|
|
|
301
301
|
Returns:
|
|
302
302
|
Response: The response object of the GET request.
|
|
303
|
-
|
|
303
|
+
|
|
304
304
|
Raises:
|
|
305
305
|
HTTPError: Any errors raised while performing GET request.
|
|
306
306
|
"""
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""This module provides static functions to perform common tasks with SAP GuiGridView COM objects."""
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
def scroll_entire_table(grid_view, return_to_top=False) -> None:
|
|
4
5
|
"""This function scrolls through the entire table to load all cells.
|
|
5
6
|
|
|
@@ -23,7 +24,7 @@ def get_all_rows(grid_view, pre_load=True) -> tuple[tuple[str]]:
|
|
|
23
24
|
Args:
|
|
24
25
|
grid_view: A SAP GuiGridView object.
|
|
25
26
|
pre_load: Whether to first scroll through the table to load all values.
|
|
26
|
-
If a row hasn't been loaded before reading, the row data will be empty.
|
|
27
|
+
If a row hasn't been loaded before reading, the row data will be empty.
|
|
27
28
|
|
|
28
29
|
Returns:
|
|
29
30
|
tuple[tuple[str]]: A 2D tuple of all cell values in the gridview.
|
|
@@ -48,14 +49,14 @@ def get_all_rows(grid_view, pre_load=True) -> tuple[tuple[str]]:
|
|
|
48
49
|
return tuple(output)
|
|
49
50
|
|
|
50
51
|
|
|
51
|
-
def get_row(grid_view, row:int, scroll_to_row=False) -> tuple[str]:
|
|
52
|
+
def get_row(grid_view, row: int, scroll_to_row=False) -> tuple[str]:
|
|
52
53
|
"""Returns the data of a single row.
|
|
53
54
|
|
|
54
55
|
Args:
|
|
55
56
|
grid_view: A SAP GuiGridView object.
|
|
56
57
|
row: The zero-based index of the row.
|
|
57
58
|
scroll_to_row: Whether to scroll to the row before reading the data.
|
|
58
|
-
This ensures the data of the row has been loaded before reading.
|
|
59
|
+
This ensures the data of the row has been loaded before reading.
|
|
59
60
|
|
|
60
61
|
Returns:
|
|
61
62
|
tuple[str]: A tuple of the row's data.
|
|
@@ -108,7 +109,7 @@ def get_column_titles(grid_view) -> tuple[str]:
|
|
|
108
109
|
return tuple(grid_view.GetColumnTitles(c)[0] for c in grid_view.ColumnOrder)
|
|
109
110
|
|
|
110
111
|
|
|
111
|
-
def find_row_index_by_value(grid_view, column:str, value:str) -> int:
|
|
112
|
+
def find_row_index_by_value(grid_view, column: str, value: str) -> int:
|
|
112
113
|
"""Find the index of the first row where the given column's value
|
|
113
114
|
matches the given value. Returns -1 if no row is found.
|
|
114
115
|
|
|
@@ -137,7 +138,8 @@ def find_row_index_by_value(grid_view, column:str, value:str) -> int:
|
|
|
137
138
|
|
|
138
139
|
return -1
|
|
139
140
|
|
|
140
|
-
|
|
141
|
+
|
|
142
|
+
def find_all_row_indices_by_value(grid_view, column: str, value: str) -> list[int]:
|
|
141
143
|
"""Find all indices of the rows where the given column's value
|
|
142
144
|
match the given value. Returns an empty list if no row is found.
|
|
143
145
|
|
|
@@ -10,15 +10,16 @@ import math
|
|
|
10
10
|
import pythoncom
|
|
11
11
|
import win32com.client
|
|
12
12
|
import win32gui
|
|
13
|
+
import win32api
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
|
|
16
|
+
def run_with_session(session_index: int, func: Callable, args: tuple) -> None:
|
|
15
17
|
"""Run a function in a specific session based on the sessions index.
|
|
16
18
|
This function is meant to be run inside a separate thread.
|
|
17
19
|
The function must take a session object as its first argument.
|
|
18
20
|
Note that this function will not spawn the sessions before running,
|
|
19
21
|
use spawn_sessions to do that.
|
|
20
22
|
"""
|
|
21
|
-
|
|
22
23
|
pythoncom.CoInitialize()
|
|
23
24
|
|
|
24
25
|
sap = win32com.client.GetObject("SAPGUI")
|
|
@@ -31,17 +32,24 @@ def run_with_session(session_index:int, func:Callable, args:tuple) -> None:
|
|
|
31
32
|
pythoncom.CoUninitialize()
|
|
32
33
|
|
|
33
34
|
|
|
34
|
-
def run_batch(func:Callable, args:tuple[tuple]
|
|
35
|
+
def run_batch(func: Callable, args: tuple[tuple]) -> None:
|
|
35
36
|
"""Run a function in parallel sessions.
|
|
36
|
-
|
|
37
|
+
A number of threads equal to the length of args will be spawned.
|
|
37
38
|
The function must take a session object as its first argument.
|
|
38
39
|
Note that this function will not spawn the sessions before running,
|
|
39
40
|
use spawn_sessions to do that.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
func: A callable function to run in the threads.
|
|
44
|
+
args: A tuple of tuples containing arguments to be passed to func.
|
|
45
|
+
|
|
46
|
+
Raises:
|
|
47
|
+
Exception: Any exception raised in any of the threads.
|
|
40
48
|
"""
|
|
41
49
|
|
|
42
50
|
threads = []
|
|
43
|
-
for i in
|
|
44
|
-
t = ExThread(target=run_with_session, args=(i, func,
|
|
51
|
+
for i, arg in enumerate(args):
|
|
52
|
+
t = ExThread(target=run_with_session, args=(i, func, arg))
|
|
45
53
|
threads.append(t)
|
|
46
54
|
|
|
47
55
|
for t in threads:
|
|
@@ -53,7 +61,7 @@ def run_batch(func:Callable, args:tuple[tuple], num_sessions=6) -> None:
|
|
|
53
61
|
raise t.error
|
|
54
62
|
|
|
55
63
|
|
|
56
|
-
def run_batches(func:Callable, args:tuple[tuple], num_sessions=6):
|
|
64
|
+
def run_batches(func: Callable, args: tuple[tuple], num_sessions: int = 6) -> None:
|
|
57
65
|
"""Run a function in parallel batches.
|
|
58
66
|
This function runs the input function for each set of arguments in args.
|
|
59
67
|
The function will be run in parallel batches of size {num_sessions}.
|
|
@@ -64,7 +72,7 @@ def run_batches(func:Callable, args:tuple[tuple], num_sessions=6):
|
|
|
64
72
|
|
|
65
73
|
for b in range(0, len(args), num_sessions):
|
|
66
74
|
batch = args[b:b+num_sessions]
|
|
67
|
-
run_batch(func,
|
|
75
|
+
run_batch(func, batch)
|
|
68
76
|
|
|
69
77
|
|
|
70
78
|
def spawn_sessions(num_sessions=6) -> list:
|
|
@@ -100,14 +108,39 @@ def spawn_sessions(num_sessions=6) -> list:
|
|
|
100
108
|
while connection.Sessions.count < num_sessions:
|
|
101
109
|
time.sleep(0.1)
|
|
102
110
|
|
|
103
|
-
|
|
111
|
+
arrange_sessions()
|
|
112
|
+
|
|
113
|
+
return tuple(connection.Sessions)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def get_all_sap_sessions() -> tuple:
|
|
117
|
+
"""Returns a tuple of all open SAP sessions (on connection index 0).
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
tuple: A tuple of SAP GuiSession objects.
|
|
121
|
+
"""
|
|
122
|
+
sap = win32com.client.GetObject("SAPGUI")
|
|
123
|
+
app = sap.GetScriptingEngine
|
|
124
|
+
connection = app.Connections(0)
|
|
125
|
+
return tuple(connection.Sessions)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def arrange_sessions():
|
|
129
|
+
"""Take all toplevel windows of currently open SAP sessions
|
|
130
|
+
and arrange them equally on the screen.
|
|
131
|
+
"""
|
|
132
|
+
sessions = get_all_sap_sessions()
|
|
104
133
|
num_sessions = len(sessions)
|
|
105
134
|
|
|
106
135
|
# Calculate number of columns and rows
|
|
107
136
|
c = math.ceil(math.sqrt(num_sessions))
|
|
108
137
|
r = math.ceil(num_sessions / c)
|
|
109
138
|
|
|
110
|
-
|
|
139
|
+
screen_width = win32api.GetSystemMetrics(0)
|
|
140
|
+
screen_height = win32api.GetSystemMetrics(1)
|
|
141
|
+
|
|
142
|
+
w = screen_width // c
|
|
143
|
+
h = screen_height // r
|
|
111
144
|
|
|
112
145
|
for i, session in enumerate(sessions):
|
|
113
146
|
window = session.findById("wnd[0]")
|
|
@@ -117,20 +150,6 @@ def spawn_sessions(num_sessions=6) -> list:
|
|
|
117
150
|
y = i // c * h
|
|
118
151
|
win32gui.MoveWindow(hwnd, x, y, w, h, True)
|
|
119
152
|
|
|
120
|
-
return sessions
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
def get_all_sap_sessions() -> tuple:
|
|
124
|
-
"""Returns a tuple of all open SAP sessions (on connection index 0).
|
|
125
|
-
|
|
126
|
-
Returns:
|
|
127
|
-
tuple: A tuple of SAP GuiSession objects.
|
|
128
|
-
"""
|
|
129
|
-
sap = win32com.client.GetObject("SAPGUI")
|
|
130
|
-
app = sap.GetScriptingEngine
|
|
131
|
-
connection = app.Connections(0)
|
|
132
|
-
return tuple(connection.Sessions)
|
|
133
|
-
|
|
134
153
|
|
|
135
154
|
class ExThread(threading.Thread):
|
|
136
155
|
"""A thread with a handle to get an exception raised inside the thread: ExThread.error"""
|
|
@@ -141,5 +160,5 @@ class ExThread(threading.Thread):
|
|
|
141
160
|
def run(self):
|
|
142
161
|
try:
|
|
143
162
|
self._target(*self._args, **self._kwargs)
|
|
144
|
-
except Exception as e:
|
|
163
|
+
except Exception as e: # pylint: disable=broad-exception-caught
|
|
145
164
|
self.error = e
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""This module provides a single function to conveniently perform the action 'opret-kundekontaker' in SAP."""
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
from datetime import date
|
|
5
|
+
|
|
6
|
+
import win32clipboard
|
|
7
|
+
|
|
8
|
+
from itk_dev_shared_components.sap import tree_util
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def opret_kundekontakter(session, fp: str, aftaler: list[str] | None,
|
|
12
|
+
art: Literal[' ', 'Automatisk', 'Fakturagrundlag', 'Fuldmagt ifm. værge', 'Konverteret', 'Myndighedshenvend.', 'Orientering', 'Returpost', 'Ringeaktivitet', 'Skriftlig henvend.', 'Telefonisk henvend.'],
|
|
13
|
+
notat: str, lock=None) -> None:
|
|
14
|
+
"""Creates a kundekontakt on the given FP and aftaler.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
session: The SAP session to preform the action.
|
|
18
|
+
fp: The forretningspartner number.
|
|
19
|
+
aftaler: A list of aftaler to put the kundekontakt on. If empty or None the kundekontakt will be created on fp-level.
|
|
20
|
+
art: The art of the kundekontakt.
|
|
21
|
+
notat: The text of the kundekontakt.
|
|
22
|
+
lock: A threading.Lock object to allow this function to run properly when multithreaded. Defaults to None.
|
|
23
|
+
|
|
24
|
+
Raises:
|
|
25
|
+
RuntimeError: If the kundekontakt wasn't created.
|
|
26
|
+
"""
|
|
27
|
+
session.StartTransaction('fmcacov')
|
|
28
|
+
|
|
29
|
+
# Find forretningspartner
|
|
30
|
+
session.findById("wnd[0]/usr/ctxtGPART_DYN").text = fp
|
|
31
|
+
session.findById("wnd[0]").sendVKey(0)
|
|
32
|
+
|
|
33
|
+
# Click 'Opret kundekontakt-flere
|
|
34
|
+
session.findById("wnd[0]/shellcont/shell").nodeContextMenu("GP0000000001")
|
|
35
|
+
session.findById("wnd[0]/shellcont/shell").selectContextMenuItem("FLERE")
|
|
36
|
+
|
|
37
|
+
# When running multithreaded the toolbar buttons in the pop-up doesn't appear sometimes.
|
|
38
|
+
# Open and close the pop-up until they appear
|
|
39
|
+
for _ in range(10):
|
|
40
|
+
if session.findById("wnd[1]/usr/cntlCONTAINER_PSOBKEY/shellcont/shell/shellcont[1]/shell[0]").ButtonCount == 2:
|
|
41
|
+
break
|
|
42
|
+
session.findById("wnd[1]").close()
|
|
43
|
+
session.findById("wnd[0]/shellcont/shell").nodeContextMenu("GP0000000001")
|
|
44
|
+
session.findById("wnd[0]/shellcont/shell").selectContextMenuItem("FLERE")
|
|
45
|
+
else:
|
|
46
|
+
raise RuntimeError("The toolbar buttons in 'Opret kundekontakter-flere' didn't show up after 10 tries.")
|
|
47
|
+
|
|
48
|
+
# Vælg aftaler
|
|
49
|
+
if aftaler:
|
|
50
|
+
aftale_tree = session.findById("wnd[1]/usr/cntlCONTAINER_PSOBKEY/shellcont/shell/shellcont[1]/shell[1]")
|
|
51
|
+
for aftale in aftaler:
|
|
52
|
+
key, name = tree_util.get_item_by_text(aftale_tree, aftale, True)
|
|
53
|
+
aftale_tree.ChangeCheckBox(key, name, True)
|
|
54
|
+
session.findById("wnd[1]/usr/cntlCONTAINER_PSOBKEY/shellcont/shell/shellcont[1]/shell[0]").pressButton("OK")
|
|
55
|
+
|
|
56
|
+
# Set art
|
|
57
|
+
session.findById("wnd[0]/usr/tabsTSTRIP/tabpT_CA/ssubSUBSR_TSTRIP:SAPLBPT1:0510/cmbBCONTD-CTYPE").Value = art
|
|
58
|
+
|
|
59
|
+
# Go to editor and paste (lock if multithreaded)
|
|
60
|
+
session.findById("wnd[0]/usr/subNOTICE:SAPLEENO:1002/btnEENO_TEXTE-EDITOR").press()
|
|
61
|
+
if lock:
|
|
62
|
+
lock.acquire()
|
|
63
|
+
_set_clipboard(notat)
|
|
64
|
+
session.findById("wnd[0]/tbar[1]/btn[9]").press()
|
|
65
|
+
if lock:
|
|
66
|
+
lock.release()
|
|
67
|
+
|
|
68
|
+
# Back and save
|
|
69
|
+
session.findById("wnd[0]/tbar[0]/btn[3]").press()
|
|
70
|
+
session.findById("wnd[0]/tbar[0]/btn[11]").press()
|
|
71
|
+
|
|
72
|
+
_confirm_kundekontakt(session, notat, art)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _set_clipboard(text: str) -> None:
|
|
76
|
+
"""Private function to set text to the clipboard.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
text: Text to set to clipboard.
|
|
80
|
+
"""
|
|
81
|
+
win32clipboard.OpenClipboard()
|
|
82
|
+
win32clipboard.EmptyClipboard()
|
|
83
|
+
win32clipboard.SetClipboardText(text)
|
|
84
|
+
win32clipboard.CloseClipboard()
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _confirm_kundekontakt(session, notat: str, art: str):
|
|
88
|
+
"""Confirm the kundekontakt was created
|
|
89
|
+
Compare the top 10 kundekontakter in the table with the input of this function
|
|
90
|
+
Compare date, art and (up to) the first 10 letters of the notat
|
|
91
|
+
"""
|
|
92
|
+
session.findById("wnd[0]/usr/tabsDATA_DISP/tabpDATA_DISP_FC3").select()
|
|
93
|
+
table = session.findById("wnd[0]/usr/tabsDATA_DISP/tabpDATA_DISP_FC3/ssubDATA_DISP_SCA:RFMCA_COV:0204/cntlRFMCA_COV_0100_CONT3/shellcont/shell")
|
|
94
|
+
|
|
95
|
+
rows = min(10, table.RowCount)
|
|
96
|
+
|
|
97
|
+
for row in range(rows):
|
|
98
|
+
kundekontakt_date = table.GetCellValue(row, "DATE")
|
|
99
|
+
kontaktart = table.GetCellValue(row, "ZZ_KONTAKTART")
|
|
100
|
+
kontakttekst = table.GetCellValue(row, "ZZ_TEXT")
|
|
101
|
+
|
|
102
|
+
length_to_compare = min([10, len(notat), len(kontakttekst)])
|
|
103
|
+
|
|
104
|
+
if (date.today().strftime("%d.%m.%Y") == kundekontakt_date and art == kontaktart and notat[:length_to_compare] == kontakttekst[:length_to_compare]):
|
|
105
|
+
break
|
|
106
|
+
else:
|
|
107
|
+
raise RuntimeError("The kundekontakt wasn't found in the kontakt-table after creation.")
|
|
@@ -14,7 +14,7 @@ import win32com.client
|
|
|
14
14
|
from itk_dev_shared_components.sap import multi_session
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
def login_using_portal(username:str, password:str):
|
|
17
|
+
def login_using_portal(username: str, password: str):
|
|
18
18
|
"""Open KMD Portal in Edge, login and start SAP GUI.
|
|
19
19
|
Args:
|
|
20
20
|
user: KMD Portal username.
|
|
@@ -25,7 +25,7 @@ def login_using_portal(username:str, password:str):
|
|
|
25
25
|
driver.get('https://portal.kmd.dk/irj/portal')
|
|
26
26
|
driver.maximize_window()
|
|
27
27
|
|
|
28
|
-
#Login
|
|
28
|
+
# Login
|
|
29
29
|
user_field = driver.find_element(By.ID, 'logonuidfield')
|
|
30
30
|
pass_field = driver.find_element(By.ID, 'logonpassfield')
|
|
31
31
|
login_button = driver.find_element(By.ID, 'buttonLogon')
|
|
@@ -35,11 +35,11 @@ def login_using_portal(username:str, password:str):
|
|
|
35
35
|
pass_field.send_keys(password)
|
|
36
36
|
login_button.click()
|
|
37
37
|
|
|
38
|
-
#Opus
|
|
38
|
+
# Opus
|
|
39
39
|
mine_genveje = driver.find_element(By.CSS_SELECTOR, "div[title='Mine Genveje']")
|
|
40
40
|
mine_genveje.click()
|
|
41
41
|
|
|
42
|
-
#Wait for download and launch file
|
|
42
|
+
# Wait for download and launch file
|
|
43
43
|
_wait_for_download()
|
|
44
44
|
|
|
45
45
|
driver.quit()
|
|
@@ -63,7 +63,7 @@ def _wait_for_download():
|
|
|
63
63
|
raise TimeoutError(f".sap file not found in {downloads_folder}")
|
|
64
64
|
|
|
65
65
|
|
|
66
|
-
def login_using_cli(username: str, password: str, client:str='751', system:str='P02', timeout:int=10) -> None:
|
|
66
|
+
def login_using_cli(username: str, password: str, client: str = '751', system: str = 'P02', timeout: int = 10) -> None:
|
|
67
67
|
"""Open and login to SAP with commandline expressions.
|
|
68
68
|
Args:
|
|
69
69
|
username: AZ username
|
|
@@ -90,7 +90,7 @@ def login_using_cli(username: str, password: str, client:str='751', system:str='
|
|
|
90
90
|
raise ValueError("Unable to log in. Please check username and password.")
|
|
91
91
|
|
|
92
92
|
|
|
93
|
-
def _wait_for_sap_session(timeout:int) -> None:
|
|
93
|
+
def _wait_for_sap_session(timeout: int) -> None:
|
|
94
94
|
"""Check every second if the SAP Gui scripting engine is available until timeout is reached.
|
|
95
95
|
Args:
|
|
96
96
|
timeout: The time in seconds to wait for SAP Logon to start. Defaults to 10.
|
|
@@ -120,10 +120,10 @@ def _check_for_splash_screen() -> bool:
|
|
|
120
120
|
return image is not None
|
|
121
121
|
|
|
122
122
|
|
|
123
|
-
def change_password(username:str, old_password:str, new_password:str,
|
|
124
|
-
client:str='751',
|
|
125
|
-
system:str='...KMD OPUS Produktion [P02]',
|
|
126
|
-
timeout:int=10) -> None:
|
|
123
|
+
def change_password(username: str, old_password: str, new_password: str,
|
|
124
|
+
client: str = '751',
|
|
125
|
+
system: str = '...KMD OPUS Produktion [P02]',
|
|
126
|
+
timeout: int = 10) -> None:
|
|
127
127
|
"""Change the password of a user in SAP Gui. Closes SAP when done.
|
|
128
128
|
Args:
|
|
129
129
|
username: The username of the user.
|
|
@@ -136,10 +136,9 @@ def change_password(username:str, old_password:str, new_password:str,
|
|
|
136
136
|
TimeoutError: If the connection couldn't be established within the timeout limit.
|
|
137
137
|
ValueError: If the current credentials are not valid or if the password can't be changed.
|
|
138
138
|
ValueError: If the new password is not valid.
|
|
139
|
-
|
|
140
139
|
"""
|
|
141
140
|
|
|
142
|
-
subprocess.Popen(r"C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe")
|
|
141
|
+
subprocess.Popen(r"C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe") # pylint: disable=consider-using-with
|
|
143
142
|
|
|
144
143
|
# Wait for SAP Logon to open
|
|
145
144
|
for _ in range(timeout):
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
"""This module provides miscellaneous static functions to
|
|
1
|
+
"""This module provides miscellaneous static functions to perform common tasks in SAP."""
|
|
2
|
+
|
|
2
3
|
|
|
3
4
|
def print_all_descendants(container, max_depth=-1, indent=0):
|
|
4
5
|
"""Prints the object and all of its descendants recursively
|
|
@@ -7,7 +8,7 @@ def print_all_descendants(container, max_depth=-1, indent=0):
|
|
|
7
8
|
Args:
|
|
8
9
|
container: A SAP GuiContainer object.
|
|
9
10
|
max_depth: The maximum depth of the recursive search. Defaults to -1.
|
|
10
|
-
indent: The indentation level of the printed text.
|
|
11
|
+
indent: The indentation level of the printed text.
|
|
11
12
|
This increases for each level of the recursion. Defaults to 0.
|
|
12
13
|
"""
|
|
13
14
|
indent_text = ' |'*indent
|
|
@@ -18,8 +19,9 @@ def print_all_descendants(container, max_depth=-1, indent=0):
|
|
|
18
19
|
print(indent_text, child.Id)
|
|
19
20
|
|
|
20
21
|
if (hasattr(child, 'Children') and child.Children is not None
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
and len(child.Children) != 0
|
|
23
|
+
and (indent < max_depth or max_depth == -1)):
|
|
24
|
+
|
|
23
25
|
print_all_descendants(child, max_depth, indent+1)
|
|
24
26
|
else:
|
|
25
27
|
print(indent_text)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""This module provides static functions to perform common tasks with SAP GuiTree COM objects."""
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
def get_node_key_by_text(tree, text: str, fuzzy: bool = False) -> str:
|
|
4
5
|
"""Get the node key of a node based on its text.
|
|
5
6
|
|
|
6
7
|
Args:
|
|
@@ -23,17 +24,17 @@ def get_node_key_by_text(tree, text: str, fuzzy: bool=False) -> str:
|
|
|
23
24
|
raise ValueError(f"No node with the text '{text}' was found.")
|
|
24
25
|
|
|
25
26
|
|
|
26
|
-
def get_item_by_text(tree, text: str, fuzzy: bool=False) -> tuple[str,str]:
|
|
27
|
+
def get_item_by_text(tree, text: str, fuzzy: bool = False) -> tuple[str, str]:
|
|
27
28
|
"""Get the node key and item name of an item based on its text.
|
|
28
29
|
|
|
29
30
|
Args:
|
|
30
31
|
tree: A SAP GuiTree object.
|
|
31
32
|
text: The text to search for.
|
|
32
33
|
fuzzy: Whether to check if the item text just contains the search text.
|
|
33
|
-
|
|
34
|
+
|
|
34
35
|
Raises:
|
|
35
36
|
ValueError: If no tem is found with the given text.
|
|
36
|
-
|
|
37
|
+
|
|
37
38
|
Returns:
|
|
38
39
|
tuple[str,str]: The node key and item name of the found item.
|
|
39
40
|
"""
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: itk-dev-shared-components
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Shared components to use in RPA projects
|
|
5
|
+
Author-email: ITK Development <itk-rpa@mkb.aarhus.dk>
|
|
6
|
+
Project-URL: Homepage, https://github.com/itk-dev-rpa/itk-dev-shared-components
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/itk-dev-rpa/itk-dev-shared-components/issues
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
11
|
+
Requires-Python: >=3.7
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: pywin32>=306
|
|
15
|
+
Requires-Dist: selenium>=4.10.0
|
|
16
|
+
Requires-Dist: msal>=1.24.1
|
|
17
|
+
Requires-Dist: requests>=2.31.0
|
|
18
|
+
Requires-Dist: beautifulsoup4>=4.12.2
|
|
19
|
+
|
|
20
|
+
# itk-dev-shared-components
|
|
21
|
+
|
|
22
|
+
## Links
|
|
23
|
+
|
|
24
|
+
[Documentation](https://itk-dev-rpa.github.io/itk-dev-shared-components-docs/)
|
|
25
|
+
|
|
26
|
+
[Pypi](https://pypi.org/project/ITK-dev-shared-components/)
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
pip install itk-dev-shared-components
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Intro
|
|
35
|
+
|
|
36
|
+
This python library contains helper modules for RPA development.
|
|
37
|
+
It's based on the need of [ITK Dev](https://itk.aarhus.dk/), but it has been
|
|
38
|
+
generalized to be useful for others as well.
|
|
39
|
+
|
|
40
|
+
## Integrations
|
|
41
|
+
|
|
42
|
+
### SAP Gui
|
|
43
|
+
|
|
44
|
+
Helper functions for using SAP Gui. A few examples include:
|
|
45
|
+
|
|
46
|
+
- Login to SAP.
|
|
47
|
+
- Handling multiple sessions in multiple threads.
|
|
48
|
+
- Convenience functions for gridviews and trees.
|
|
49
|
+
|
|
50
|
+
### Microsoft Graph
|
|
51
|
+
|
|
52
|
+
Helper functions for using Microsoft Graph to read emails from shared inboxes.
|
|
53
|
+
Some examples are:
|
|
54
|
+
|
|
55
|
+
- Authentication using username and password.
|
|
56
|
+
- List and get emails.
|
|
57
|
+
- Get attachment data.
|
|
58
|
+
- Move and delete emails.
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: itk_dev_shared_components
|
|
3
|
-
Version: 1.0.0
|
|
4
|
-
Summary: Shared components to use in RPA projects
|
|
5
|
-
Author-email: ITK Development <itk-rpa@mkb.aarhus.dk>
|
|
6
|
-
Project-URL: Homepage, https://github.com/itk-dev-rpa/itk-dev-shared-components
|
|
7
|
-
Project-URL: Bug Tracker, https://github.com/itk-dev-rpa/itk-dev-shared-components/issues
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
-
Classifier: Operating System :: Microsoft :: Windows
|
|
11
|
-
Requires-Python: >=3.7
|
|
12
|
-
Description-Content-Type: text/markdown
|
|
13
|
-
License-File: LICENSE
|
|
14
|
-
Requires-Dist: pywin32>=306
|
|
15
|
-
Requires-Dist: selenium>=4.10.0
|
|
16
|
-
Requires-Dist: msal>=1.24.1
|
|
17
|
-
Requires-Dist: requests>=2.31.0
|
|
18
|
-
Requires-Dist: beautifulsoup4>=4.12.2
|
|
19
|
-
|
|
20
|
-
# itk-dev-shared-components
|
|
21
|
-
|
|
22
|
-
https://pypi.org/project/ITK-dev-shared-components/
|
|
23
|
-
|
|
24
|
-
pip install ITK-dev-shared-components
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"""This module provides a single function to conveniently perform the action 'opret-kundekontaker' in SAP."""
|
|
2
|
-
|
|
3
|
-
from typing import Literal
|
|
4
|
-
import win32clipboard
|
|
5
|
-
from itk_dev_shared_components.sap import tree_util
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def opret_kundekontakter(session, fp:str, aftaler:list[str] | None,
|
|
9
|
-
art:Literal[' ', 'Automatisk', 'Fakturagrundlag', 'Fuldmagt ifm. værge', 'Konverteret', 'Myndighedshenvend.', 'Orientering', 'Returpost', 'Ringeaktivitet', 'Skriftlig henvend.', 'Telefonisk henvend.'],
|
|
10
|
-
notat:str, lock=None) -> None:
|
|
11
|
-
"""Creates a kundekontakt on the given FP and aftaler.
|
|
12
|
-
|
|
13
|
-
Args:
|
|
14
|
-
session (COM Object): The SAP session to preform the action.
|
|
15
|
-
fp (str): The forretningspartner number.
|
|
16
|
-
aftaler (list[str] | None): A list of aftaler to put the kundekontakt on. If empty or None the kundekontakt will be created on fp-level.
|
|
17
|
-
art (str): The art of the kundekontakt.
|
|
18
|
-
notat (str): The text of the kundekontakt.
|
|
19
|
-
lock (threading.Lock, optional): A threading.Lock object to allow this function to run properly when multithreaded. Defaults to None.
|
|
20
|
-
"""
|
|
21
|
-
session.StartTransaction('fmcacov')
|
|
22
|
-
|
|
23
|
-
# Find forretningspartner
|
|
24
|
-
session.findById("wnd[0]/usr/ctxtGPART_DYN").text = fp
|
|
25
|
-
session.findById("wnd[0]").sendVKey(0)
|
|
26
|
-
|
|
27
|
-
# Click 'Opret kundekontakt-flere
|
|
28
|
-
session.findById("wnd[0]/shellcont/shell").nodeContextMenu("GP0000000001")
|
|
29
|
-
session.findById("wnd[0]/shellcont/shell").selectContextMenuItem("FLERE")
|
|
30
|
-
|
|
31
|
-
# Vælg aftaler
|
|
32
|
-
if aftaler:
|
|
33
|
-
aftale_tree = session.findById("wnd[1]/usr/cntlCONTAINER_PSOBKEY/shellcont/shell/shellcont[1]/shell[1]")
|
|
34
|
-
for aftale in aftaler:
|
|
35
|
-
key, name = tree_util.get_item_by_text(aftale_tree, aftale, True)
|
|
36
|
-
aftale_tree.ChangeCheckBox(key, name, True)
|
|
37
|
-
session.findById("wnd[1]/usr/cntlCONTAINER_PSOBKEY/shellcont/shell/shellcont[1]/shell[0]").pressButton("OK")
|
|
38
|
-
|
|
39
|
-
# Set art
|
|
40
|
-
session.findById("wnd[0]/usr/tabsTSTRIP/tabpT_CA/ssubSUBSR_TSTRIP:SAPLBPT1:0510/cmbBCONTD-CTYPE").Value = art
|
|
41
|
-
|
|
42
|
-
# Go to editor and paste (lock if multithreaded)
|
|
43
|
-
session.findById("wnd[0]/usr/subNOTICE:SAPLEENO:1002/btnEENO_TEXTE-EDITOR").press()
|
|
44
|
-
if lock:
|
|
45
|
-
lock.acquire()
|
|
46
|
-
_set_clipboard(notat)
|
|
47
|
-
session.findById("wnd[0]/tbar[1]/btn[9]").press()
|
|
48
|
-
if lock:
|
|
49
|
-
lock.release()
|
|
50
|
-
|
|
51
|
-
# Back and save
|
|
52
|
-
session.findById("wnd[0]/tbar[0]/btn[3]").press()
|
|
53
|
-
session.findById("wnd[0]/tbar[0]/btn[11]").press()
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
def _set_clipboard(text:str) -> None:
|
|
57
|
-
"""Private function to set text to the clipboard.
|
|
58
|
-
|
|
59
|
-
Args:
|
|
60
|
-
text: Text to set to clipboard.
|
|
61
|
-
"""
|
|
62
|
-
win32clipboard.OpenClipboard()
|
|
63
|
-
win32clipboard.EmptyClipboard()
|
|
64
|
-
win32clipboard.SetClipboardText(text)
|
|
65
|
-
win32clipboard.CloseClipboard()
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: itk-dev-shared-components
|
|
3
|
-
Version: 1.0.0
|
|
4
|
-
Summary: Shared components to use in RPA projects
|
|
5
|
-
Author-email: ITK Development <itk-rpa@mkb.aarhus.dk>
|
|
6
|
-
Project-URL: Homepage, https://github.com/itk-dev-rpa/itk-dev-shared-components
|
|
7
|
-
Project-URL: Bug Tracker, https://github.com/itk-dev-rpa/itk-dev-shared-components/issues
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
-
Classifier: Operating System :: Microsoft :: Windows
|
|
11
|
-
Requires-Python: >=3.7
|
|
12
|
-
Description-Content-Type: text/markdown
|
|
13
|
-
License-File: LICENSE
|
|
14
|
-
Requires-Dist: pywin32>=306
|
|
15
|
-
Requires-Dist: selenium>=4.10.0
|
|
16
|
-
Requires-Dist: msal>=1.24.1
|
|
17
|
-
Requires-Dist: requests>=2.31.0
|
|
18
|
-
Requires-Dist: beautifulsoup4>=4.12.2
|
|
19
|
-
|
|
20
|
-
# itk-dev-shared-components
|
|
21
|
-
|
|
22
|
-
https://pypi.org/project/ITK-dev-shared-components/
|
|
23
|
-
|
|
24
|
-
pip install ITK-dev-shared-components
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|