@@ -26,6 +26,62 @@ def opret_kundekontakter(session, fp: str, aftaler: list[str] | None,
2626 """
2727 fmcacov .open_forretningspartner (session , fp )
2828
29+ if not aftaler :
30+ _select_no_aftaler (session )
31+ elif len (aftaler ) == 1 :
32+ _select_single_aftale (session , aftaler [0 ])
33+ else :
34+ _select_multiple_aftaler (session , aftaler )
35+
36+ # Set art
37+ session .findById ("wnd[0]/usr/tabsTSTRIP/tabpT_CA/ssubSUBSR_TSTRIP:SAPLBPT1:0510/cmbBCONTD-CTYPE" ).Value = art
38+
39+ # Go to editor and paste (lock if multithreaded)
40+ session .findById ("wnd[0]/usr/subNOTICE:SAPLEENO:1002/btnEENO_TEXTE-EDITOR" ).press ()
41+ if lock :
42+ lock .acquire ()
43+ _set_clipboard (notat )
44+ session .findById ("wnd[0]/tbar[1]/btn[9]" ).press ()
45+ if lock :
46+ lock .release ()
47+
48+ # Back and save
49+ session .findById ("wnd[0]/tbar[0]/btn[3]" ).press ()
50+ session .findById ("wnd[0]/tbar[0]/btn[11]" ).press ()
51+
52+ _confirm_kundekontakt (session , notat , art )
53+
54+
55+ def _select_no_aftaler (session ):
56+ """Right click the fp and select 'Opret kundekontakt'.
57+
58+ Args:
59+ session: The sap session object.
60+ """
61+ session .findById ("wnd[0]/shellcont/shell" ).nodeContextMenu ("GP0000000001" )
62+ session .findById ("wnd[0]/shellcont/shell" ).selectContextMenuItem ("POPUP" )
63+
64+
65+ def _select_single_aftale (session , aftale : str ):
66+ """Right click a single aftale and select 'Opret kundekontakt'.
67+
68+ Args:
69+ session: The sap session object.
70+ aftale: The aftale number.
71+ """
72+ tree = session .findById ("wnd[0]/shellcont/shell" )
73+ node_key = tree_util .get_node_key_by_text (tree , aftale )
74+ tree .nodeContextMenu (node_key )
75+ tree .selectContextMenuItem ("POPUP" )
76+
77+
78+ def _select_multiple_aftaler (session , aftaler : list [str ]):
79+ """Use 'Opret kundekontakt-flere' to select multiple aftaler.
80+
81+ Args:
82+ session: The sap session object.
83+ aftaler: The list of aftaler.
84+ """
2985 # Click 'Opret kundekontakt-flere
3086 session .findById ("wnd[0]/shellcont/shell" ).nodeContextMenu ("GP0000000001" )
3187 session .findById ("wnd[0]/shellcont/shell" ).selectContextMenuItem ("FLERE" )
@@ -49,24 +105,6 @@ def opret_kundekontakter(session, fp: str, aftaler: list[str] | None,
49105 aftale_tree .ChangeCheckBox (key , name , True )
50106 session .findById ("wnd[1]/usr/cntlCONTAINER_PSOBKEY/shellcont/shell/shellcont[1]/shell[0]" ).pressButton ("OK" )
51107
52- # Set art
53- session .findById ("wnd[0]/usr/tabsTSTRIP/tabpT_CA/ssubSUBSR_TSTRIP:SAPLBPT1:0510/cmbBCONTD-CTYPE" ).Value = art
54-
55- # Go to editor and paste (lock if multithreaded)
56- session .findById ("wnd[0]/usr/subNOTICE:SAPLEENO:1002/btnEENO_TEXTE-EDITOR" ).press ()
57- if lock :
58- lock .acquire ()
59- _set_clipboard (notat )
60- session .findById ("wnd[0]/tbar[1]/btn[9]" ).press ()
61- if lock :
62- lock .release ()
63-
64- # Back and save
65- session .findById ("wnd[0]/tbar[0]/btn[3]" ).press ()
66- session .findById ("wnd[0]/tbar[0]/btn[11]" ).press ()
67-
68- _confirm_kundekontakt (session , notat , art )
69-
70108
71109def _set_clipboard (text : str ) -> None :
72110 """Private function to set text to the clipboard.
0 commit comments