-
-
Notifications
You must be signed in to change notification settings - Fork 493
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
4219 Fixed Order of items in inventory adjustment #4380
base: main
Are you sure you want to change the base?
4219 Fixed Order of items in inventory adjustment #4380
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the appropriate place to make the change for the order of items for the inventory adjustments is the adjustments controller, not the storage location controller.
There is code there that appears to be alphabetizing the items -- but I believe it is not alphabetizing them by item name, so it ends up being in the order they were added.
Please also provide tests for your changes.
@cielf Thank you for the review. After checking from logs, I find out that when we changes storage location from drop down, there is an ajax call happens |
@@ -160,6 +160,7 @@ def inventory | |||
.active | |||
|
|||
@inventory_items += include_omitted_items(@inventory_items.collect(&:item_id)) if params[:include_omitted_items] == "true" | |||
@inventory_items.alphabetized |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you meant
@inventory_items = @inventory_items.alphabetized
...but even that won't work. alphabetized
does an order
on the database columns, but at this point @inventory_items
isn't an ActiveRecord query, it's an array. It's probably easiest just to do @inventory_items.sort_by! { |ii| ii.item.name }
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dorner Yes, I got it now.
But i think @inventory_items.sort_by { |inventory_item| inventory_item.item.name }
will work instead of @inventory_items.sort_by!(&:name)
as inventory_item record doesn't have name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but can you write or update a test verifying that the data is alphabetized? E.g. create inventory items in reverse alphabetical order and verify that they are displayed in proper order. You can use a request test for this.
@iamronakgupta I fear that you are "barking up the wrong tree" -- working to solve the problem in the wrong place. For clarity, here is the result when I manually tested it just now. You can see that the items dropdown in the Inventory Adjustments screen is not showing the items in alphabetical order. The changes you have made so far would affect a different screen -- the storage locations view. |
@cielf I think this is working because order and sort_by method puts words with lowercase at the bottom and uppercase at top |
Yup. Looks like that is what it is doing, And it's what it was doing. IMO, it should be a case insensitive sort because humans sort case insensitively - but that would currently make it inconsistent with the rest of the system. |
@cielf So, how should I implement it? with case sensitive or insensitive? |
With case sensitive. We'd want to make all the sorts case insensitive at the same time. |
@iamronakgupta this has been sitting for a while - are you planning on picking it back up? |
Resolves #4219