Skip to content

Add filters to distribution by county and take into account kitted items#5541

Open
cielf wants to merge 10 commits into
rubyforgood:mainfrom
cielf:add-filters-to-distribution-by-county
Open

Add filters to distribution by county and take into account kitted items#5541
cielf wants to merge 10 commits into
rubyforgood:mainfrom
cielf:add-filters-to-distribution-by-county

Conversation

@cielf

@cielf cielf commented Apr 21, 2026

Copy link
Copy Markdown
Collaborator

Description

We've had a request to make the distribution by county more useful. This

  • allows for filtration by 'loose' item or reporting category as well as date range
  • includes kitted items into the item totals

Still to be done

Documentation update

Type of change

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • automated tests
  • light manual testing

cielf added 4 commits April 20, 2026 19:07
… filters, restricting item filter to loose items only, added text re kitted items. Wondering about SQL portability from local to prod.
@cielf cielf requested review from dorner and janeewheatley April 21, 2026 00:57
@cielf

cielf commented Apr 21, 2026

Copy link
Copy Markdown
Collaborator Author

Couple of things right off the top:
1/ This does require a documentation update, but I'd like to have @janeewheatley have a quick look at it before I go down the road of screenshots, etc.
2/ Is the SQL I did portable?

@dorner dorner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I've never been able to follow the logic with these complex reports. If it works I'll accept that it works. 😁 What did you mean by whether the SQL was "portable"?

@reporting_categories = Item.reporting_categories_for_select
@items = current_organization.items.loose.alphabetized.select(:id, :name)
@selected_reporting_category = filter_params[:by_reporting_category].presence
@selected_item = filter_params[:by_item_id].presence

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we bundle these into a view object? I'd like us to use more of these rather than relying on a bunch of instance variables.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We use View::Donations.in donations#index.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

(nods) Ok - I see we have an example with Donations, so I'll see if I can apply that.

)
end

helper_method \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Might be more readable if you just define the filter_params method and call helper_method :filter_params at the top.

end
end
end
context "with kits only" do

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

spacing :)

@cielf

cielf commented Apr 25, 2026

Copy link
Copy Markdown
Collaborator Author

I've never been able to follow the logic with these complex reports. If it works I'll accept that it works. 😁 What did you mean by whether the SQL was "portable"?

One of the things that has not stayed in my head is whether we are using postgres in production , and I know there are some differences between the SQL used by different relational dbs -- the element that might be of concern is the CASE construct .

@dorner

dorner commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

We're using postgres in production :)

@cielf cielf marked this pull request as draft May 3, 2026 13:10
@cielf cielf marked this pull request as ready for review May 3, 2026 22:50
@cielf cielf requested a review from dorner May 3, 2026 22:51
.permit(:by_item_id, :by_reporting_category, :date_range)
end

def from_params(params:, organization:, helpers:)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do you need to pass helpers into this if you're including DateRangeHelpers?

All you need is a params method on the object. So you could do something like

def params = @params
def from_params(params:, organization:)
  @params = params
   filters = filter_params(params)
  start_data = selected_range.first.utc.iso8601
...

@cielf cielf May 14, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@dorner Hrm -- I wonder how this case is different from the donations view object where you are passing helpers and has included DateRangeHelper?

I tried your suggestion and it broke most of the DistributionByCounty tests -- looking at the rspec log it doesn't know about selected_range at that point.

However, removing the DateRangeHelper include is harmless (the relevant tests still pass), so I've done that.

@cielf cielf requested a review from dorner May 16, 2026 00:17
@dorner

dorner commented May 21, 2026

Copy link
Copy Markdown
Collaborator

Good on my end - over to manual QA @janeewheatley @ruestitch

@janeewheatley

Copy link
Copy Markdown
Collaborator

@cielf Would you mind writing out some testing steps for QA for this one? Thank you!

@cielf

cielf commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator Author

That kind of breaks the principle of having a different brain on the testing, but I understand that this is unfamiliar territory.

@cielf

cielf commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator Author

@janeewheatley ,

This is going to be a bit hand-wavey, rather than setting out specific values -- and you'll likely be swearing in my general direction in any case by the time you are done!

1/ A/ Set up some partners -- 1 with no areas served, and 2 that have overlapping areas served.
B/ Set up a couple of kits with contents that go across multiple reporting categories. Have some of those reporting categories to be the same in both kits. I suggest for sanity's sake that you use different levels for each item in each kit, and consider using wildly different levels between kits (like order of magnitude different) for ease of checking the arithmetic. Allocate a few hundred of each kit, so you have room to work with [You may need to enter some donations or adjustments to get enough items to do this.]

2/ Check that the reporting by categories filters works without kits by adding some distributions for those partners with various items across reporting categories, then seeing that the numbers make sense both without filters and with.

3/ Now, checking that it works for kits -- add first a single distribution with one kit to the no areas served partner , then making sure it works with multiple kits in the same distribution, and that if you are distributing to the partners with areas served, that the values look right in that case -- i.e. that if you, say are distributing 20 kits that each have 10 tampons and 15 diapers, that you have 200 tampons and 300 diapers accounted for -- and that they are distributed properly across the areas served. A. Check without the reporting category filter. B. Check with the reporting category filter.

4/ Similarly to #3, but to a partner that has areas served.

5/ Now, do a really complicated case that has distributions to each of the partners, and those distributions have both kits and non-kitted items. Some of the non-kitted items are in the same reporting category as the kitted items, some aren't. A. Check without the reporting category filter. B. Check with the reporting category filter.

6/ Now that you're reallly quite familiar with the thing, think about whether I've forgotten anything, and test that. [Do you know for sure that it's not counting across organizations? Do the other filters (IIRC there s a date filter) still work?

Is that what you're looking for?

@cielf

cielf commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

@janeewheatley 7/ Do the same tests for the items filter.

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.

3 participants