diff --git a/ezoff/assets.py b/ezoff/assets.py index 8f2eb59..63546ef 100644 --- a/ezoff/assets.py +++ b/ezoff/assets.py @@ -688,3 +688,47 @@ def get_asset_history(asset_id: int) -> list[dict]: page += 1 return all_history + + +@Decorators.check_env_vars +def get_items_for_token_input(q: str) -> list[dict]: + """ + This isn't an official endpoint in the EZOfficeInventory API. It's used to populate + the token input dropdowns in the EZOfficeInventory UI. However, still works if called + and is needed if wanting to use the get_work_orders item filter. Which doesn't yet + support the asset ID as a filter. But does support the ID that comes from this endpoint. + Found this via the network tab in the browser. Not sure what the official name is + so I'm just going off of what the URL is. + + Note: If you use "#{Asset Sequence Num}" as the q search parameter, it should + only return one result. If you use a more general search term. like searching + for the name, you may get multiple. + """ + + url = os.environ["EZO_BASE_URL"] + "assets/items_for_token_input.json" + + try: + response = requests.get( + url, + headers={"Authorization": "Bearer " + os.environ["EZO_TOKEN"]}, + params={"include_id": "true", "q": q}, + timeout=10, + ) + except Exception as e: + print("Error, could not get items for token input from EZOfficeInventory: ", e) + raise Exception( + "Error, could not get items for token input from EZOfficeInventory: " + + str(e) + ) + + if response.status_code != 200: + print( + f"Error {response.status_code}, could not get items for token input from EZOfficeInventory: ", + response.content, + ) + raise Exception( + f"Error {response.status_code}, could not get items for token input from EZOfficeInventory: " + + str(response.content) + ) + + return response.json() diff --git a/ezoff/workorders.py b/ezoff/workorders.py index e00f1ee..ca0eefa 100644 --- a/ezoff/workorders.py +++ b/ezoff/workorders.py @@ -38,7 +38,7 @@ def get_work_orders(filter: Optional[dict]) -> dict: "filters[repetition_start_date]", "filters[repetition_start_date]", "filters[repetition_end_date]", - # "filters[preventive]", # Seems to cause 500 errors when used? + "filters[preventative]", "filters[on_repeat]", "filters[task_location]", # "filters[review_pending_on_me]", # Don't know if actually useful when API is calling and not user diff --git a/tests/test.py b/tests/test.py index 096cb31..5659c41 100644 --- a/tests/test.py +++ b/tests/test.py @@ -23,5 +23,9 @@ # res = ezoff.reactivate_asset(14753, {"fixed_asset[location_id]": 7}) -res = ezoff.get_work_orders({"filters[created_on]": "09/06/2024"}) +item_id = get_items_for_token_input("#14753")[0]["id"] + +pass + +res = ezoff.get_work_orders({"filters[item]": item_id}) pass