From 0bb91c25b75fef3da282e8bf62647f6926b76b9b Mon Sep 17 00:00:00 2001 From: matze Date: Thu, 14 Nov 2024 18:01:01 +0100 Subject: [PATCH] added get_inventory_logs_of_type() to Asset --- neofarm/lib.py | 2 +- neofarm/orm/asset.py | 13 +++++++++++++ test.py | 4 ++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/neofarm/lib.py b/neofarm/lib.py index 64a787b..5112d72 100644 --- a/neofarm/lib.py +++ b/neofarm/lib.py @@ -23,7 +23,7 @@ def init_api(): client_secret = client_secret ) break - except ConnectionError: + except: print("Fehler bei Verbindung mit Server (wahrscheinlich DuckDns) probiere erneut...") oauth = OAuth2(client_id=client_id, client=client, token=token) diff --git a/neofarm/orm/asset.py b/neofarm/orm/asset.py index d337fae..6f726bc 100644 --- a/neofarm/orm/asset.py +++ b/neofarm/orm/asset.py @@ -23,6 +23,19 @@ class Asset(jsonapi_requests.orm.ApiModel): break; return related + def get_inventory_logs_of_type(self, type): + if not issubclass(type, Log.Log): + raise ValueError("type specified is not a type of log use for example: get_logs_of_type(Log.Harvest)") + logs = type.get_list() + related = [] + for log in logs: + for quantity in log.quantities: + if quantity.inventory_asset: + if quantity.inventory_asset.id == self.id: + related.append(log) + break; + return related + class Land(Asset): class Meta(Asset.Meta): name = 'land' diff --git a/test.py b/test.py index acd5e82..7a1675e 100644 --- a/test.py +++ b/test.py @@ -1,5 +1,5 @@ import neofarm.lib as neo if __name__ == "__main__": - log = neo.Log.Seeding.get_list()[1] - print(log.notes) \ No newline at end of file + log = neo.Log.Input.from_id("d2e78314-730c-47ae-a0b4-aff42025475e") + print(log.quantities[0].inventory_asset.get_inventory_logs_of_type(neo.Log.Purchase)[0].name) \ No newline at end of file