Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issued by filter #5515

Merged
merged 4 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion InvenTree/InvenTree/api_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@


# InvenTree API version
INVENTREE_API_VERSION = 131
INVENTREE_API_VERSION = 132

"""
Increment this API version number whenever there is a significant change to the API that any clients need to know about

v132 -> 2023-09-07 : https://github.com/inventree/InvenTree/pull/5515
- Add 'issued_by' filter to BuildOrder API list endpoint

v131 -> 2023-08-09 : https://github.com/inventree/InvenTree/pull/5415
- Annotate 'available_variant_stock' to the SalesOrderLine serializer

Expand Down
1 change: 1 addition & 0 deletions InvenTree/build/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Meta:
'parent',
'sales_order',
'part',
'issued_by',
]

status = rest_filters.NumberFilter(label='Status')
Expand Down
25 changes: 25 additions & 0 deletions InvenTree/templates/js/translated/table_filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@
*/


// Construct a dynamic API filter for the "issued by" field
function constructIssuedByFilter() {
return {
title: '{% trans "Issued By" %}',
options: function() {
let users = {};

inventreeGet('{% url "api-user-list" %}', {}, {
async: false,
success: function(response) {
for (let user of response) {
users[user.pk] = {
key: user.pk,
value: user.username
};
Comment on lines +31 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just if you want to learn something more modern, you could do it with reduce like:

response.reduce((users, user) => ({...users, [user.pk]: { key: user.pk, value: user.username }}), {})

Or using the map function and Object.fromEntries in combination.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @wolflu05 for the tip. This will all soon be replaced with React - and I am certainly focusing on writing more up-to-date code over there :)

}
}
});

return users;
}
}
}

// Construct a dynamic API filter for the "project" field
function constructProjectCodeFilter() {
return {
Expand Down Expand Up @@ -482,6 +506,7 @@ function getBuildTableFilters() {
return ownersList;
},
},
issued_by: constructIssuedByFilter(),
};

if (global_settings.PROJECT_CODES_ENABLED) {
Expand Down
Loading