From f5c8c092be42faff5dcb4091159549b24902a5f6 Mon Sep 17 00:00:00 2001 From: Mathias G Date: Thu, 21 Aug 2025 12:58:03 +0200 Subject: [PATCH 1/3] Changed opret_kundekontakter when 0 or 1 aftale is given --- .../sap/opret_kundekontakt.py | 76 ++++++++++++++----- 1 file changed, 57 insertions(+), 19 deletions(-) diff --git a/itk_dev_shared_components/sap/opret_kundekontakt.py b/itk_dev_shared_components/sap/opret_kundekontakt.py index 57c91b7..67ff8ce 100644 --- a/itk_dev_shared_components/sap/opret_kundekontakt.py +++ b/itk_dev_shared_components/sap/opret_kundekontakt.py @@ -26,7 +26,63 @@ def opret_kundekontakter(session, fp: str, aftaler: list[str] | None, """ fmcacov.open_forretningspartner(session, fp) - # Click 'Opret kundekontakt-flere + if not aftaler: + _select_no_aftaler(session) + elif len(aftaler) == 1: + _select_single_aftale(session, aftaler[0]) + else: + _select_multiple_aftaler(session, aftaler) + + # Set art + session.findById("wnd[0]/usr/tabsTSTRIP/tabpT_CA/ssubSUBSR_TSTRIP:SAPLBPT1:0510/cmbBCONTD-CTYPE").Value = art + + # Go to editor and paste (lock if multithreaded) + session.findById("wnd[0]/usr/subNOTICE:SAPLEENO:1002/btnEENO_TEXTE-EDITOR").press() + if lock: + lock.acquire() + _set_clipboard(notat) + session.findById("wnd[0]/tbar[1]/btn[9]").press() + if lock: + lock.release() + + # Back and save + session.findById("wnd[0]/tbar[0]/btn[3]").press() + session.findById("wnd[0]/tbar[0]/btn[11]").press() + + _confirm_kundekontakt(session, notat, art) + + +def _select_no_aftaler(session): + """Right click the fp and select 'Opret kundekontakt'. + + Args: + session: The sap session object. + """ + session.findById("wnd[0]/shellcont/shell").nodeContextMenu("GP0000000001") + session.findById("wnd[0]/shellcont/shell").selectContextMenuItem("POPUP") + + +def _select_single_aftale(session, aftale: str): + """Right click a single aftale and select 'Opret kundekontakt'. + + Args: + session: The sap session object. + aftale: The aftale number. + """ + tree = session.findById("wnd[0]/shellcont/shell") + node_key = tree_util.get_node_key_by_text(tree, aftale) + tree.nodeContextMenu(node_key) + tree.selectContextMenuItem("POPUP") + + +def _select_multiple_aftaler(session, aftaler: list[str]): + """Use 'Opret kundekontakt-flere' to select multiple aftaler. + + Args: + session: The sap session object. + aftaler: The list of aftaler. + """ + # Click 'Opret kundekontakt-flere session.findById("wnd[0]/shellcont/shell").nodeContextMenu("GP0000000001") session.findById("wnd[0]/shellcont/shell").selectContextMenuItem("FLERE") @@ -49,24 +105,6 @@ def opret_kundekontakter(session, fp: str, aftaler: list[str] | None, aftale_tree.ChangeCheckBox(key, name, True) session.findById("wnd[1]/usr/cntlCONTAINER_PSOBKEY/shellcont/shell/shellcont[1]/shell[0]").pressButton("OK") - # Set art - session.findById("wnd[0]/usr/tabsTSTRIP/tabpT_CA/ssubSUBSR_TSTRIP:SAPLBPT1:0510/cmbBCONTD-CTYPE").Value = art - - # Go to editor and paste (lock if multithreaded) - session.findById("wnd[0]/usr/subNOTICE:SAPLEENO:1002/btnEENO_TEXTE-EDITOR").press() - if lock: - lock.acquire() - _set_clipboard(notat) - session.findById("wnd[0]/tbar[1]/btn[9]").press() - if lock: - lock.release() - - # Back and save - session.findById("wnd[0]/tbar[0]/btn[3]").press() - session.findById("wnd[0]/tbar[0]/btn[11]").press() - - _confirm_kundekontakt(session, notat, art) - def _set_clipboard(text: str) -> None: """Private function to set text to the clipboard. From bfa3c7c362412e375c81aaca0b55dab51643cfaa Mon Sep 17 00:00:00 2001 From: Mathias G Date: Thu, 21 Aug 2025 14:19:11 +0200 Subject: [PATCH 2/3] Updated changelog --- changelog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/changelog.md b/changelog.md index 5a42e79..d2d221c 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- SAP: Changed how kundekontakter are created with 0 or 1 aftaler. + ## [2.13.0] - 2025-08-13 ### Added From be1fe284a8caacc48a30b3e86d650a2f3d650cfd Mon Sep 17 00:00:00 2001 From: Mathias G Date: Thu, 21 Aug 2025 14:24:07 +0200 Subject: [PATCH 3/3] Lint --- itk_dev_shared_components/sap/opret_kundekontakt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/itk_dev_shared_components/sap/opret_kundekontakt.py b/itk_dev_shared_components/sap/opret_kundekontakt.py index 67ff8ce..d08539b 100644 --- a/itk_dev_shared_components/sap/opret_kundekontakt.py +++ b/itk_dev_shared_components/sap/opret_kundekontakt.py @@ -82,7 +82,7 @@ def _select_multiple_aftaler(session, aftaler: list[str]): session: The sap session object. aftaler: The list of aftaler. """ - # Click 'Opret kundekontakt-flere + # Click 'Opret kundekontakt-flere session.findById("wnd[0]/shellcont/shell").nodeContextMenu("GP0000000001") session.findById("wnd[0]/shellcont/shell").selectContextMenuItem("FLERE")