|
4 | 4 |
|
5 | 5 | from selenium import webdriver |
6 | 6 | from selenium.webdriver.common.by import By |
| 7 | +from selenium.webdriver.common.keys import Keys |
7 | 8 |
|
8 | 9 |
|
9 | 10 | @dataclass |
@@ -126,3 +127,69 @@ def change_tab(browser: webdriver.Chrome, tab_index: int): |
126 | 127 |
|
127 | 128 | if current_index != tab_index: |
128 | 129 | browser.execute_script(f"__doPostBack('ctl00$ContentPlaceHolder2$ptFanePerson$ImgJournalMap','{tab_index}')") |
| 130 | + |
| 131 | + |
| 132 | +def approve_case(browser: webdriver.Chrome): |
| 133 | + """Approve a case, even if blocked by a note.""" |
| 134 | + change_tab(browser, 0) |
| 135 | + |
| 136 | + deadline_field = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtDeadline") |
| 137 | + deadline_field.clear() |
| 138 | + note_field = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtDeadlineNote") |
| 139 | + note_field.clear() |
| 140 | + |
| 141 | + browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab1_btnGodkend").click() |
| 142 | + browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab1_btnApproveYes").click() |
| 143 | + |
| 144 | + approve_persons_button = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab1_btnGodkendAlle") |
| 145 | + if not approve_persons_button.is_enabled(): |
| 146 | + |
| 147 | + person_table = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_GridViewMovingPersons") |
| 148 | + rows = person_table.find_elements(By.TAG_NAME, "tr") |
| 149 | + rows.pop(0) |
| 150 | + |
| 151 | + for row in rows: |
| 152 | + row.find_element(By.XPATH, "td[2]").click() |
| 153 | + browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab1_btnGodkend").click() |
| 154 | + approve_button = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab1_btnApproveYes") |
| 155 | + if approve_button.is_displayed(): |
| 156 | + approve_button.click() |
| 157 | + else: |
| 158 | + approve_persons_button.click() |
| 159 | + |
| 160 | + |
| 161 | +def check_all_approved(browser: webdriver.Chrome) -> bool: |
| 162 | + """Check all inhabiatants in table have a status 'Godkendt'. |
| 163 | + """ |
| 164 | + person_table = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_GridViewMovingPersons") |
| 165 | + rows = person_table.find_elements(By.TAG_NAME, "tr") |
| 166 | + rows.pop(0) |
| 167 | + |
| 168 | + for row in rows: |
| 169 | + row_status = row.find_element(By.XPATH, "td[6]").text |
| 170 | + if row_status != "Godkendt": |
| 171 | + return False |
| 172 | + return True |
| 173 | + |
| 174 | + |
| 175 | +def add_note(browser: webdriver.Chrome, message: str): |
| 176 | + """Add a note to a case.""" |
| 177 | + message = f"{date.today().strftime('%Y-%m-%d')} Besked fra Robot: {message}" |
| 178 | + browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_ButtonVisOpdater").click() |
| 179 | + |
| 180 | + existing_note = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtVisOpdaterNote").text |
| 181 | + if len(existing_note) > 0: |
| 182 | + message = "\n\n" + message |
| 183 | + browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtVisOpdaterNote").send_keys(Keys.CONTROL+Keys.END) |
| 184 | + |
| 185 | + browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtVisOpdaterNote").send_keys(message) |
| 186 | + browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_btnLongNoteUpdater").click() |
| 187 | + |
| 188 | + |
| 189 | +def get_note_text(browser: webdriver.Chrome) -> str: |
| 190 | + """Read note text and close the window, returning the value. |
| 191 | + """ |
| 192 | + browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_ButtonVisOpdater").click() |
| 193 | + text = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtVisOpdaterNote").text |
| 194 | + browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_btnLuk").click() |
| 195 | + return text |
0 commit comments