From 26071e466eb00e309423b428c36c4f98aef2ed0c Mon Sep 17 00:00:00 2001 From: Flavio Perez Date: Thu, 1 Aug 2024 14:47:31 +0200 Subject: [PATCH] [person/department] new func to add department or get one by name --- gazu/person.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/gazu/person.py b/gazu/person.py index f782a9c2..6f0d09ef 100644 --- a/gazu/person.py +++ b/gazu/person.py @@ -77,6 +77,20 @@ def get_all_month_time_spents(id, date, client=default): client=client, ) +@cache +def get_department_by_name(name, client=default): + """ + Args: + name (str): department name. + + Returns: + dict: department corresponding to given name. + """ + return raw.fetch_first( + "departments", + {"name": name}, + client=client, + ) @cache def get_person(id, relations=False, client=default): @@ -182,6 +196,35 @@ def get_organisation(client=default): return raw.get("auth/authenticated", client=client)["organisation"] +def new_department( + name, + color="", + archived=False, + client=default + ): + """ + Create a new departement based on given parameters. + + Args: + name (str): the name of the departement. + color (str): the color of the departement. + archived (bool): Whether the departement is archived or not. + Returns: + dict: Created departement. + """ + department = get_department_by_name(name, client=client) + if department is None: + department = raw.post( + "data/departments", + { + "name": name, + "color": color, + "archived": archived + }, + client=client, + ) + return department + def new_person( first_name, last_name,