|
| 1 | +"""This module contains functions to help with actions in the fmcacov transaction.""" |
| 2 | + |
| 3 | + |
| 4 | +def open_forretningspartner(session, fp: str) -> None: |
| 5 | + """Start the transaction FMCACOV and open the given forretningspartner. |
| 6 | + If the fp-number also matches a cvr-number the fp-number will be opened. |
| 7 | +
|
| 8 | + Args: |
| 9 | + session: The SAP session to perform the action. |
| 10 | + fp: The forretningspartner number. |
| 11 | +
|
| 12 | + Raises: |
| 13 | + ValueError: If the forretningspartner wasn't found. |
| 14 | + """ |
| 15 | + session.StartTransaction('fmcacov') |
| 16 | + |
| 17 | + # Find forretningspartner |
| 18 | + session.findById("wnd[0]/usr/ctxtGPART_DYN").text = fp |
| 19 | + session.findById("wnd[0]").sendVKey(0) |
| 20 | + |
| 21 | + # Detect window "Forretningspartner * Entries" |
| 22 | + if session.findById('wnd[1]/usr', False) is not None: |
| 23 | + # Pop-up detected |
| 24 | + for row_id in range(3, 5): |
| 25 | + fp_row = session.FindById(f'wnd[1]/usr/lbl[103,{row_id}]') |
| 26 | + if fp_row.text == fp: |
| 27 | + fp_row.SetFocus() |
| 28 | + # Press 'Accept' button. |
| 29 | + session.FindById('wnd[1]/tbar[0]/btn[0]').press() |
| 30 | + break |
| 31 | + else: |
| 32 | + # Range exhausted |
| 33 | + raise ValueError(f"Forretningspartner '{fp}' was not found in pop-up.") |
| 34 | + |
| 35 | + |
| 36 | +def dismiss_key_popup(session, fp: str = "25564617") -> None: |
| 37 | + """Once a day a popup appears asking to generate a new "afstemningsnøgle". |
| 38 | + This function forces it to appear and clicks "Ja" on it. |
| 39 | + This is done by pretending to do "Kontovedligehold" on the given forretningspartner. |
| 40 | + The function should start and end at the home screen. |
| 41 | +
|
| 42 | + Args: |
| 43 | + session: The SAP session object. |
| 44 | + fp: The forretningspartner to used. Defaults to "25564617" a fictional person in AAK. |
| 45 | +
|
| 46 | + Raises: |
| 47 | + RuntimeError: If a popup other than the expected ones appear. |
| 48 | + """ |
| 49 | + open_forretningspartner(session, fp) |
| 50 | + |
| 51 | + # Right click the first row in the postliste and click "Kontovedligehold med filter" |
| 52 | + postliste = session.findById("wnd[0]/usr/tabsDATA_DISP/tabpDATA_DISP_FC1/ssubDATA_DISP_SCA:RFMCA_COV:0202/cntlRFMCA_COV_0100_CONT5/shellcont/shell") |
| 53 | + postliste.setCurrentCell(0, "VTREF") |
| 54 | + postliste.contextMenu() |
| 55 | + postliste.selectContextMenuItem("ACC_MAINT_FILTER") |
| 56 | + |
| 57 | + # Check if the key popup appeared |
| 58 | + popup = session.findbyid("wnd[1]", False) |
| 59 | + if popup: |
| 60 | + if popup.text == "Kontrol af afstemningsnøgle": |
| 61 | + # Press "Ja" |
| 62 | + session.findbyid("wnd[1]/usr/btnSPOP-OPTION1").press() |
| 63 | + else: |
| 64 | + raise RuntimeError(f"Another popup is blocking: {popup.text}") |
| 65 | + |
| 66 | + # Check and dismiss confirmation dialog |
| 67 | + confirmation_text = session.findbyid("wnd[1]/usr/txtMESSTXT1").text |
| 68 | + if 'oprettet' in confirmation_text: |
| 69 | + session.findById("wnd[1]/tbar[0]/btn[0]").press() |
| 70 | + else: |
| 71 | + raise RuntimeError(f"Confirmation dialog wasn't as expected: {confirmation_text}.") |
| 72 | + |
| 73 | + # Go back to home screen (Afbryd x 3) |
| 74 | + session.findById("wnd[0]/tbar[0]/btn[12]").press() |
| 75 | + session.findById("wnd[0]/tbar[0]/btn[12]").press() |
| 76 | + session.findById("wnd[0]/tbar[0]/btn[12]").press() |
0 commit comments