fixed infinite recursion with type attribute of product asset NEXT: write Asset.logs and Asset.get_logs_of_type(type)

This commit is contained in:
2024-11-02 20:54:10 +01:00
parent a91a2750c9
commit ba5afc852b
4 changed files with 13 additions and 35 deletions

View File

@@ -4,10 +4,10 @@ from requests_oauthlib import OAuth2Session, OAuth2
import jsonapi_requests
import importlib
import neofarm.orm.my_meta
import neofarm.orm.log
import neofarm.orm.asset
import neofarm.orm.quantity
import neofarm.orm.taxonomy
import neofarm.orm.log as Log
import neofarm.orm.asset as Asset
import neofarm.orm.quantity as Quantity
import neofarm.orm.taxonomy as Taxonomy
importlib.reload(neofarm.orm.my_meta)
from . orm.my_meta import MyMeta
@@ -40,10 +40,6 @@ api = init_api()
MyMeta.set_api(api)
# these have to be defined after MyMeta.api is set for the correct value to be inherited
importlib.reload(neofarm.orm.log)
from . orm.log import *
importlib.reload(neofarm.orm.asset)
from . orm.asset import *
importlib.reload(neofarm.orm.quantity)
from . orm.quantity import *
importlib.reload(neofarm.orm.taxonomy)
from . orm.taxonomy import *
importlib.reload(neofarm.orm.taxonomy)

View File

@@ -41,5 +41,6 @@ class Product(Asset):
class Meta(Asset.Meta):
name = 'product'
type, path = Asset.Meta.get_type_and_path(name)
type = jsonapi_requests.orm.RelationField('product_type')
# do not rename to type as that will end in infinite recursion
product_type = jsonapi_requests.orm.RelationField('product_type')

View File

@@ -1,25 +0,0 @@
import lib as neo
if __name__ == "__main__":
seedings = neo.Seeding.get_list()
for seeding in seedings:
plant = seeding.getPlant()
equipment = seeding.equipment[0]
quantity = seeding.quantities[0]
print(f"name: {seeding.name}")
print(f"timestamp: {seeding.timestamp}")
print(f"plant name: {plant.name}")
print(f"plant crop: {plant.crop[0].name}")
print(f"plant loc: {plant.location.name}")
print(f"equipment: {equipment.name}")
print(f"isMovement: {seeding.isMovement}")
print(f"Q1 type: {quantity.type}")
print(f"Q1 measure: {quantity.measure}")
print(f"Q1 value: {quantity.value}")
print(f"Q1 units: {quantity.units.name}")
print(f"Q1 inv adj: {quantity.inventory_adjustment}")
print(f"Q1 inv ass: {quantity.inventory_asset.name}")
print(f"Q2 type: {quantity.type}")
print(f"Q2 measure: {quantity.measure}")
print(f"Q2 value: {quantity.value}")
print(f"Q2 units: {quantity.units.name}")

6
test.py Normal file
View File

@@ -0,0 +1,6 @@
import neofarm.lib as neo
if __name__ == "__main__":
asset = neo.Asset.Product.from_id("4abf4918-5d08-4694-8e14-35a6dedceb72")
name = asset.name
print(name)