inventree / InvenTree

Open Source Inventory Management System
https://docs.inventree.org
MIT License
4.27k stars 772 forks source link

[FR] Filter Build Orders by Assigned User/Group #4383

Closed simonkuehling closed 1 year ago

simonkuehling commented 1 year ago

Please verify that this feature request has NOT been suggested before.

Problem statement

I am using Groups to assign build orders to different manufacturing departments (like "CNC", "Composites", "3D Printing", "Electronics" etc). Currently I don't see a filter option to only show build orders that are assigned to a specific user or group other than yourself.

Suggested solution

It would be very useful to have an additional filter in the build orders list to filter by assigned to: where users and groups can be selected. Or maybe split into two filters: assigned to user: and assigned to group: - otherwise the options drop-down would be confusing and possibly crowded.

I think this would live here, right? https://github.com/inventree/InvenTree/blob/75ca325892a09b6836250b863399649234d95d66/InvenTree/templates/js/translated/table_filters.js#L339-L359

is there a global variable already to access a list of users and groups? In case not, where should that be created best? Right there in table_filters.js from an api call, or maybe somewhere more central?

Describe alternatives you've considered

none that I can think of really - other than sorting the table by Assigned to column. But that is not so helpful with huge projects and many active build orders.

Examples of other systems

No response

Do you want to develop this?

SchrodingersGat commented 1 year ago

Nice idea! A few things going on here

Users vs Group

We actually have a superclass of this - the "owner". In fact you will find that the assigned_to responsible field on the Build model is a reference to an "owner" - which can be either a user or a group.

Filter by Owner

You'll need to add a new filter to the BuildFilter class in build/api.py. There's a similar filter already there for a reference:

https://github.com/inventree/InvenTree/blob/a2b55314cb9f4e5b3ae7cd5d84c1d884fb5c4ef1/InvenTree/build/api.py#L54

Filter Selection

Currently, filters (as defined in table_filters.js) can only be "static" values. However, it would be great to extend this to being able to make an API call to select from available options! If you want to address this issue, I can help you work through this part (I imagine this will be the most challenging detail)

matmair commented 1 year ago

I think we should get away with building the owner list on load.

SchrodingersGat commented 1 year ago

I think we should get away with building the owner list on load.

That would certainly make it easier to implement.

SchrodingersGat commented 1 year ago

@simonkuehling happy with these suggestions?

simonkuehling commented 1 year ago

@simonkuehling happy with these suggestions?

Yeah, I held back for a moment to form an opinion which option is best here... I think I am not quite sure about @matmair's comment regarding gathering the list on load. The API filter is needed anyway, isn't it?

I see this as two tasks to implement:

  1. get a list of all users/groups to create the JS filter options
  2. add a new filter to the build-order-API

right?

matmair commented 1 year ago

You will need the API filter on the backend and add the filter to the frontend.

simonkuehling commented 1 year ago

I'm kind of stuck a little figuring out how the selection options for the responsible field are generated - and how they are referenced in the API for example in creating a build order through POST /api/build/.*. The reference to an owner looks to be a numerical value - but how is that deciphered to see which User or Group this is? Reading from the API through GET /api/build/{id} I get a user- or group-ID in theresponsible field and a responsible_details block that seems to be an Owner model instance, but with build > create there is only the numerical responsible field...

Could you give me a tip here?

SchrodingersGat commented 1 year ago

The responsible field is the primary-key (ID) value of the particular owner instance.

You can see a list of available owners via the API, e.g. https://demo.inventree.org/api/user/owner/

The responsible_details is an extra set of fields which get bundled with the build serializer, so you can see information about the owner without having to perform a separate API or DB lookup.

So you can generate such a list either via the API (which I think would be a cleaner solution) or in the template which generates the javascript code itsefl.

simonkuehling commented 1 year ago

Ok, thanks - that helped! The pull request is submitted at #4408 now :+1: