-
-
Notifications
You must be signed in to change notification settings - Fork 571
Bug-5152 Updates storage_location export to pull in all org items, no… #5210
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
Open
bsbonus
wants to merge
2
commits into
rubyforgood:main
Choose a base branch
from
bsbonus:5152-update-storage-location-export-with-inactive-items
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -163,18 +163,31 @@ def self.csv_export_headers | |
|
|
||
| # @param storage_locations [Array<StorageLocation>] | ||
| # @param inventory [View::Inventory] | ||
| # @param current_organization [Organization] | ||
| # @return [String] | ||
| def self.generate_csv_from_inventory(storage_locations, inventory) | ||
| all_items = inventory.all_items.uniq(&:item_id).sort_by(&:name) | ||
| additional_headers = all_items.map(&:name).uniq | ||
| def self.generate_csv_from_inventory(storage_locations, inventory, current_organization) | ||
| # Get all inventoried and organization items | ||
| all_inventoried_items = inventory.all_items | ||
|
|
||
| # Not all items are inventoried, so we need to add the organization items to the headers. | ||
| # Yes it's another full table scan, but it's a small dataset and product wants the exports to consistently include all items (active, inactive, etc). | ||
| # This means we have to look for inactive items or items without inventory. | ||
| # note the remapping of item.id to item_id is to enable the uniq call to happen once across the two arrays. | ||
| all_organization_items = current_organization.items.select("DISTINCT ON (LOWER(name)) items.name, items.id as item_id").order("LOWER(name) ASC") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a feature that should be built into the |
||
|
|
||
| all_items = (all_inventoried_items + all_organization_items).uniq(&:item_id).sort_by { |item| item&.name&.downcase } | ||
|
|
||
| # Build headers from unique inventoried and organization items, using name as the key. | ||
| item_headers = all_items.map(&:name) | ||
|
|
||
| CSV.generate(headers: true) do |csv| | ||
| csv_data = storage_locations.map do |sl| | ||
| total_quantity = inventory.quantity_for(storage_location: sl.id) | ||
| attributes = [sl.name, sl.address, sl.square_footage, sl.warehouse_type, total_quantity] + | ||
| all_items.map { |i| inventory.quantity_for(storage_location: sl.id, item_id: i.item_id) } | ||
| all_items.map { |item| inventory.quantity_for(storage_location: sl.id, item_id: item.item_id) } | ||
| attributes.map { |attr| normalize_csv_attribute(attr) } | ||
| end | ||
| ([csv_export_headers + additional_headers] + csv_data).each do |row| | ||
| ([csv_export_headers + item_headers] + csv_data).each do |row| | ||
| csv << row | ||
| end | ||
| end | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This could get moved to just being an options hash, which is my general preference vs array of args. Thoughts?
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 -- do you have an opinion on this?
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.
You can use keyword arguments instead of an option hash.