Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help on using fieldNames & fieldInfo #248

Open
turist79 opened this issue Nov 1, 2024 · 4 comments
Open

help on using fieldNames & fieldInfo #248

turist79 opened this issue Nov 1, 2024 · 4 comments

Comments

@turist79
Copy link

turist79 commented Nov 1, 2024

Hi

just making myself familiar with the API.
i am able to connect to my Inventree server (running in docker on other machine) using dedicated user with only "view" rights to all except Admin.
i can list all stock items with names and locations.
But somehow this simple thing from the documentation does not work in any way:

from inventree.api import InvenTreeAPI
from inventree.part import Part
from inventree.stock import StockItem

SERVER_ADDRESS = 'https://inventree.xxx'
MY_USERNAME = 'python_view'
MY_PASSWORD = 'yyy'

api = InvenTreeAPI(SERVER_ADDRESS, username=MY_USERNAME, password=MY_PASSWORD)

fields = Part.fieldNames(api)
for field in fields:
    print(field, '->', Part.fieldInfo(field, api))

it does not crash - just does not yield any result. i dont get why would be that, i have checked the source code - there is defenetely corresponding method for that in base inventree object.

PS: this is the right and only way to see the full ist of fields & properties of the obects or is there some documentation on that topic as well?

Thanks

@SchrodingersGat
Copy link
Member

@turist79 your code should be working just fine:

from inventree.api import InvenTreeAPI
from inventree.part import Part

api = InvenTreeAPI(
    'http://localhost:8000',
    username='admin',
    password='inventree'
)

fields = Part.fieldNames(api)

for f in fields:
    print("-", f, ':', Part.fieldInfo(f, api))

yields

- active : {'type': 'boolean', 'required': False, 'read_only': False, 'label': 'Active', 'help_text': 'Is this part active?', 'default': True}
- assembly : {'type': 'boolean', 'required': False, 'read_only': False, 'label': 'Assembly', 'help_text': 'Can this part be built from other parts?', 'default': False}
- barcode_hash : {'type': 'string', 'required': False, 'read_only': True, 'label': 'Barcode Hash', 'help_text': 'Unique hash of barcode data', 'max_length': 128}
- category : {'type': 'related field', 'required': False, 'read_only': False, 'label': 'Category', 'model': 'partcategory', 'api_url': '/api/part/category/', 'pk_field': 'pk', 'filters': {}, 'help_text': 'Part category'}
- category_name : {'type': 'string', 'required': False, 'read_only': True, 'label': 'Category Name'}
...
...
...
- tags : {'type': 'list', 'required': False, 'read_only': False, 'label': 'Tags', 'child': {'type': 'string', 'required': True, 'read_only': False}}

Can you perform other operations with the API?

@turist79
Copy link
Author

turist79 commented Nov 1, 2024

from inventree.api import InvenTreeAPI
from inventree.part import Part
from inventree.stock import StockItem


SERVER_ADDRESS = 'https://inventree.xxx'
MY_USERNAME = 'python_view'
MY_PASSWORD = 'xxx'

api = InvenTreeAPI(SERVER_ADDRESS, username=MY_USERNAME, password=MY_PASSWORD)


fields = Part.fieldNames(api)
for field in fields:
    print(field, '->', Part.fieldInfo(field, api))

items = StockItem.list(api)
for i_item in items:
   i_part=i_item.getPart()

   print(i_part.name,'@', 'None' if i_item.getLocation() is None else i_item.getLocation().name)

yields

ThinkSystem 2.5" 600GB 15K SAS 12Gb Hot Swap 512n HDD @ INFR
ThinkSystem 2.5" 600GB 15K SAS 12Gb Hot Swap 512n HDD @ None
ThinkSystem 2.5" 600GB 15K SAS 12Gb Hot Swap 512n HDD @ None
ThinkSystem 2.5" 600GB 15K SAS 12Gb Hot Swap 512n HDD @ INFR
ThinkSystem 2.5" 900GB 15K SAS 12Gb Hot Swap 512e HDD @ INFR
ThinkSystem 2.5" 900GB 15K SAS 12Gb Hot Swap 512e HDD @ INFR
ThinkSystem 2.5" 900GB 15K SAS 12Gb Hot Swap 512e HDD @ INFR
ThinkSystem SR630 V3 @ I/O

which is correct from 2 items with no location one is installed inside other stock item, the other is quarantined.
no other info is returned.

PS: those two moments are a big issue for me by the way - need to find workaround how ot see such items as in stock but not available.

@turist79
Copy link
Author

turist79 commented Nov 6, 2024

@SchrodingersGat is there any ideas why no field info is printed out as the result of the code above?

@SchrodingersGat
Copy link
Member

@turist79 sorry, I'm stumped on this one. Perhaps you could do some debugging, there may be an edge case that we have not considered

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants