inventree / inventree-python

Python library for communication with inventree via API
https://docs.inventree.org/en/latest/api/python/python/
MIT License
26 stars 34 forks source link

isUsedIn() Method Appears Broken #223

Closed jacobfelknor closed 2 months ago

jacobfelknor commented 2 months ago

I am attempting to use the Part.isUsedIn() method to return a list of all BOM items for a given part.

However, it appears that this method is currently returning ALL bom items, not just those that represent the given part. I suspect that the keyword used to query for the BomItem via the API has changed, as I noticed the request in the web interface of InvenTree is using the uses param.

For now, I'm working around the issue by constructing the API request myself as follows:

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

INVENTREE_API = InvenTreeAPI(...)

part = Part(...)

used_in_bomitems = [
    BomItem(INVENTREE_API, data=bomitem_data)
    for bomitem_data in INVENTREE_API.get("bom/", params={"uses": part.pk})
]

I believe this can be resolved by changing these lines to use the uses kwarg instead of sub_part

SchrodingersGat commented 2 months ago

@jacobfelknor yep, you're right:

  1. This is a bug
  2. Changing to uses=<x> is the appropriate action here

Can you please submit a PR with this change?

jacobfelknor commented 2 months ago

Will do. I'll have time tomorrow