Skip to content

help on using fieldNames & fieldInfo #248

Open

Description

@turist79

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

Activity

  1. SchrodingersGat commented on Nov 1, 2024

    @SchrodingersGat
    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?

  2. turist79 commented on Nov 1, 2024

    @turist79
    Author
    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.

  3. turist79 commented on Nov 6, 2024

    @turist79
    Author

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

  4. SchrodingersGat commented on Nov 6, 2024

    @SchrodingersGat
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions