GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Correct way to obtain substitute part list and BOM depth "level" · Issue #176 · inventree/inventree-python Open DescriptionHello, I have been using the InvenTree API to generate BOMs in a custom XLSX format. It seems the InvenTree web does not allow me to export specific fields from the BOM to XLSX and it seems easier to use the API directly. Then I can also format the text (color etc.) These are the steps I have used so far:
api = InvenTreeAPI(SERVER_ADDRESS, username=MY_USERNAME, password=MY_PASSWORD) parts = Part.list(api) row = 0 for part in parts: try: bom_list = part.getBomItems() except: continue # Skip items with no BOM if len(bom_list) == 0: continue
# Sort BOM part types (i.e. individual parts, followed by sub-assemblies) # Note: Looking up parts from BomItems is kinda slow...But it works bom_list_main = [] bom_list_subs = [] bom_list_sorted = [] for bom_item in bom_list: try: sub_part = Part(api, pk=bom_item.sub_part) if sub_part.assembly: bom_list_subs.append(bom_item) else: bom_list_main.append(bom_item) except: continue bom_list_sorted.extend(bom_list_main) bom_list_sorted.extend(bom_list_subs)
for bom_item in bom_list_sorted: try: # Lookup selected BOM part part = Part(api, pk=bom_item.sub_part) # Calculate build quantity, assuming current stock (round to nearest) can_build = bom_item.available_stock / (bom_item.quantity * bom_multiplier) if bom_item.quantity else 0 if part.assembly: # Handle nested BOMs, i.e. when BOM part is an assembly: # Sort nested BOM items again # Handle nested BOM and print fields to XLSX ... else: # Handle individual BOM items: ...
The above steps handle all situations, except substitute parts, so I am now trying to handle that.
On an unrelated note. I was wondering if these scripts I have been working on can be useful in any way - perhaps as an "example" of how to use the API. This API has been most useful, so it would be nice to give back to the project somehow. :) Activity
MetadataMetadataAssigneesLabelsNo labels TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |