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

Add row for grand totals to storage locations index view #4768

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tatheerf02
Copy link
Contributor

@tatheerf02 tatheerf02 commented Nov 9, 2024

Resolves #4520

Description

Display another row at the bottom of the storage locations index that aggregates the total inventory quantity and dollar value across all locations, taking into account any filters applied.

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Added a new system test that ensures the row is displayed on the index with the correct total values.

Updates existing tests to account for the new row in the table

Screenshots

📸 Storage locations index (no filters) image
📸 Storage locations index (with filters) image

@tatheerf02 tatheerf02 force-pushed the 4520-storage-locations-totals branch 2 times, most recently from 751fa34 to a46bd92 Compare November 10, 2024 17:13
Comment on lines +94 to +100
def inventory_total_quantity(inventory = nil)
if inventory
inventory.quantity_for(storage_location: id)
else
size
end
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracted this conditional to a method in the model to prevent duplication between the ERB files - do we like this approach?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd rather just add a parameter to sizewhere you can pass the inventory in to avoid reloading it. I.e.

def size(inventory=nil)
  inventory ||= View::Inventory.new(organization_id)
  inventory.quantity_for(storage_location: id)
end

Comment on lines +106 to +109
within "tbody tr:last-child" do
expect(page).to have_content(100) # The expected total inventory
expect(page).to have_content("$100.00") # The expected total fair market value
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a better way to test the totals show up as expected without writing a system test?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes! You can look at some other request tests to see how it parses the rendered body and checks for elements.

@tatheerf02 tatheerf02 marked this pull request as ready for review November 10, 2024 17:21
@cielf cielf requested review from dorner and cielf November 12, 2024 15:57
Copy link
Collaborator

@cielf cielf left a comment

Choose a reason for hiding this comment

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

Hey @tatheerf02 -- I'm noticing that the totals are not aligned with the inventory and fair market value -- I expect that the values for each storage location are not right-aligned as they should be.

Can you take care of that? It fits here, but I can put it to a new issue if need be.

@tatheerf02
Copy link
Contributor Author

Hey @tatheerf02 -- I'm noticing that the totals are not aligned with the inventory and fair market value -- I expect that the values for each storage location are not right-aligned as they should be.

Can you take care of that? It fits here, but I can put it to a new issue if need be.

Hey @cielf! Sorry I'm a lil confused, I see that all column values are currently left-aligned, and the grand totals follow that pattern. Are you suggesting they should all be right-aligned instead? Thanks!

@cielf
Copy link
Collaborator

cielf commented Nov 13, 2024

Hey @cielf! Sorry I'm a lil confused, I see that all column values are currently left-aligned, and the grand totals follow that pattern. Are you suggesting they should all be right-aligned instead? Thanks!

@tatheerf02 Yup -- that's exactly what I'm suggesting. Thank you.

@tatheerf02
Copy link
Contributor Author

@cielf How do you feel about something like this? I right-aligned the titles for those columns as well so they wouldn't look mismatched
image

@cielf
Copy link
Collaborator

cielf commented Nov 20, 2024

Looks very good to me! @dorner -- Do you have any technical concerns?

Comment on lines +94 to +100
def inventory_total_quantity(inventory = nil)
if inventory
inventory.quantity_for(storage_location: id)
else
size
end
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd rather just add a parameter to sizewhere you can pass the inventory in to avoid reloading it. I.e.

def size(inventory=nil)
  inventory ||= View::Inventory.new(organization_id)
  inventory.quantity_for(storage_location: id)
end

@@ -92,6 +92,23 @@
end
end

it "displays the correct grand totals across all storage locations" do
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be a request spec, not a system spec since there's no interaction. Request specs are a lot faster and more lightweight.

Comment on lines +106 to +109
within "tbody tr:last-child" do
expect(page).to have_content(100) # The expected total inventory
expect(page).to have_content("$100.00") # The expected total fair market value
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes! You can look at some other request tests to see how it parses the rendered body and checks for elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add totals for inventory and FMV to storage locations index page.
3 participants