Skip to content

Commit

Permalink
Added func for getting ID needed for item filter
Browse files Browse the repository at this point in the history
  • Loading branch information
JMaynor committed Sep 9, 2024
1 parent 847a304 commit 7ae1025
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
44 changes: 44 additions & 0 deletions ezoff/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion ezoff/workorders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7ae1025

Please sign in to comment.