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

Resolves #4544. filter manufacturer donations summary report by date #4558

Merged
merged 7 commits into from
Sep 6, 2024

Conversation

guswhitten
Copy link
Contributor

Checklist:

  • I have performed a self-review of my own code,
  • I have commented my code, particularly in hard-to-understand areas,
  • I have made corresponding changes to the documentation,
  • I have added tests that prove my fix is effective or that my feature works,
  • New and existing unit tests pass locally with my changes ("bundle exec rake"),
  • Title include "WIP" if work is in progress.

Resolves #4544

Description

Manufacturer Donations Summary Report individual manufacturers donations count were not being filtered by the selected date range (past year).

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Tests added in spec/requests/reports/manufacturer_donations_summary_spec.rb

Screenshots

Before:
human-essentials-4544-before

After:
human-essentials-4544-after

cielf
cielf previously requested changes Jul 30, 2024
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 @guswhitten -- This is just a functional, not a technical review. It looks like the filtration works -- but the ranking isn't working properly as yet.

I added a third manufacturer with a 5000 item donation on December 31 2023, and did an "All Time" filtration and got the result below. The manufacturers should be listed in order of number of items from most to least.
Screenshot 2024-07-30 at 10 48 10 AM

@cielf cielf requested a review from dorner August 2, 2024 20:14
@cielf
Copy link
Collaborator

cielf commented Aug 2, 2024

@ dorner - bit late in the day, but if you have the cycles still, could you take a technical look at this? (I'll do the last functional confirm either later today or in the morning)

manufacturers = select do |m|
donation_volume = m.donations.joins(:line_items).where(issued_at: date_range).sum(:quantity)
if donation_volume.positive?
m.instance_variable_set(:@num_of_donations, donation_volume)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We really don't want to set instance variables from outside the class. The way I'd do this is to create a method on Manufacturer called donation_count which you can memoize if necessary by setting the result to an instance variable if it doesn't exist, e.g. @donation_count ||= ... .

Having said that, this is something you can solve in straight SQL (or ActiveRecord). It should be something along the lines of:

self.joins(donations: :line_items).where(donations: {issued_at: date_range}).
   select('sum(quantity) as quantity_count').
   group('manufacturers.id').
   having('sum(quantity) > 0').
   order('quantity_count desc').to_a

https://chatgpt.com/g/g-m5lMeGifF-sql-expert is a good resource to talk through this if necessary.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That looks like a significant enough adjustment that I'm going to hold off on the final functional check.

@guswhitten guswhitten requested a review from dorner August 16, 2024 22:33
Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

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

Hey @guswhitten - unfortunately removing the volume method is breaking a bunch of specs (and a bunch of pages). Can this be fixed?

@cielf
Copy link
Collaborator

cielf commented Sep 6, 2024

@dorner Bringing this one back to your attention.

@cielf
Copy link
Collaborator

cielf commented Sep 6, 2024

Functionality looks good.

Copy link
Collaborator

@dorner dorner left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@dorner dorner dismissed cielf’s stale review September 6, 2024 20:12

CL onfirmed functionality works now per above comment.

@dorner dorner merged commit 5217bce into rubyforgood:main Sep 6, 2024
19 checks passed
Copy link
Contributor

github-actions bot commented Sep 8, 2024

@guswhitten: Your PR Resolves #4544. filter manufacturer donations summary report by date is part of today's Human Essentials production release: 2024.09.08.
Thank you very much for your contribution!

norrismei pushed a commit to norrismei/human-essentials that referenced this pull request Sep 22, 2024
…rt by date (rubyforgood#4558)

* Resolves rubyforgood#4544. filter manufacturer donations summary report by selected range

* initiate workflow?

* add instance variable to each manufacturer to hold number of donations in current timeframe

* set donation count variable and sort using active record query

* add back def volume method in manufacturer model
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.

[BUG] Mismatch between overall manufacturer numbers and individual manufacturer donation numbers
3 participants