inventree_part_import
inventree_part_import copied to clipboard
Note: Don't do scheduled updates. Stress the APIs as little as possible.
wanting to possibly schedule updating parts automatically, I enabled using "/" to process recursively all categories. Not sure if this could be useful for others, but I will park this here:
inventree_helpers.py
def get_category(inventree_api: InvenTreeAPI, category_path):
name = category_path.split("/")[-1]
categories = PartCategory.list(inventree_api, search=name)
if category_path == "/":
return [c for c in categories if c.parent == None]
for category in categories:
if category.pathstring == category_path:
return [category]
return None
def get_category_parts(part_categories: list[PartCategory], cascade):
parts=[]
for part_category in part_categories:
if len(part_categories) > 0:
info(f'Getting parts from category {part_category.name}')
parts.extend(Part.list(
part_category._api,
category=part_category.pk,
cascade=cascade,
purchaseable=True,
))
return parts
cli.py (optional
if not (categories := get_category(inventree_api, category_path)):
error(f"no such category '{category_path}'")
return
parts = [part for part in get_category_parts(categories, bool(update_recursive))]