-
-
Notifications
You must be signed in to change notification settings - Fork 573
Add filters to distribution by county and take into account kitted items #5541
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
cielf
wants to merge
10
commits into
rubyforgood:main
Choose a base branch
from
cielf:add-filters-to-distribution-by-county
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 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4ab623e
Changed report to use kitted items, added reporting category and item…
cielf f5f5e01
Merge branch 'main' into add-filters-to-distribution-by-county
cielf 9175660
Cleanup/rubocop happiness
cielf 6baee7e
More rubocop happiness
cielf f4d47cc
fix inaccurate comment
cielf 08e6fc5
spacing
cielf 9b77051
readability
cielf d6e5bfd
View object in place.
cielf 1295d99
Documentation changes
cielf 8654fae
Cleaned out unnecessary include
cielf 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -858,4 +858,4 @@ DEPENDENCIES | |
| webmock (~> 3.26) | ||
|
|
||
| BUNDLED WITH | ||
| 2.7.1 | ||
| 4.0.10 | ||
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 |
|---|---|---|
|
|
@@ -7,10 +7,26 @@ def report | |
| start_date = helpers.selected_range.first.utc.iso8601 | ||
| end_date = helpers.selected_range.last.utc.iso8601 | ||
|
|
||
| @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 | ||
|
|
||
| @breakdown = DistributionSummaryByCountyQuery.call( | ||
| organization_id: current_organization.id, | ||
| start_date: start_date, | ||
| end_date: end_date | ||
| end_date: end_date, | ||
| reporting_category: @selected_reporting_category, | ||
| item_id: @selected_item | ||
| ) | ||
| end | ||
|
|
||
| helper_method \ | ||
|
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. Might be more readable if you just define the |
||
| def filter_params | ||
| return {} unless params.key?(:filters) | ||
|
|
||
| params | ||
| .require(:filters) | ||
| .permit(:by_item_id, :by_reporting_category, :date_range) | ||
| 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
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
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 |
|---|---|---|
|
|
@@ -5,7 +5,9 @@ | |
| let(:organization_id) { organization.id } | ||
| let(:start_date) { nil } | ||
| let(:end_date) { nil } | ||
| let(:params) { {organization_id:, start_date:, end_date:} } | ||
| let(:reporting_category) { nil } | ||
| let(:item_id) { nil } | ||
| let(:params) { {organization_id:, start_date:, end_date:, reporting_category:} } | ||
|
|
||
| include_examples "distribution_by_county" | ||
|
|
||
|
|
@@ -64,4 +66,121 @@ | |
| expect(num_with_0).to eq 0 | ||
| end | ||
| end | ||
|
|
||
| describe "handling reporting categories" do | ||
| context "with loose items only" do | ||
| let(:reporting_category) { :cloth_diapers } | ||
| let(:params) { {organization_id:, start_date:, end_date:, reporting_category:} } | ||
|
|
||
| it "divides the item numbers and values according to the partner profile" do | ||
| create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1) | ||
| create(:distribution, :with_items, item: item_2, organization: user.organization, partner: partner_1) | ||
|
|
||
| breakdown = DistributionSummaryByCountyQuery.call(**params) | ||
| expect(breakdown.size).to eq(5) | ||
| expect(breakdown[4].quantity).to eq(0) | ||
| expect(breakdown[4].value).to be_within(0.01).of(0) | ||
| 4.times do |i| | ||
| expect(breakdown[i].quantity).to eq(25) | ||
| expect(breakdown[i].value).to be_within(0.01).of(26250.0) | ||
| end | ||
| end | ||
| end | ||
| context "with kits only" do | ||
|
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. spacing :) |
||
| let(:reporting_category) { :pads } | ||
| let(:params) { {organization_id:, start_date:, end_date:, reporting_category:} } | ||
|
|
||
| it "divides the item numbers and values according to the partner profile" do | ||
| create(:distribution, :with_items, item: kit_a.item, organization: user.organization, partner: partner_1) | ||
| create(:distribution, :with_items, item: item_2, organization: user.organization, partner: partner_1) | ||
|
|
||
| breakdown = DistributionSummaryByCountyQuery.call(**params) | ||
| expect(breakdown.size).to eq(5) | ||
| expect(breakdown[-1].quantity).to eq(0) | ||
| expect(breakdown[-1].value).to be_within(0.01).of(0) | ||
| 4.times do |i| | ||
| expect(breakdown[i].quantity).to eq(500) | ||
| expect(breakdown[i].value).to be_within(0.01).of(37500.0) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context "with an item that is in a kit and loose, and another item that is in the reporting category" do | ||
| let(:reporting_category) { :pads } | ||
| let(:params) { {organization_id:, start_date:, end_date:, reporting_category:} } | ||
|
|
||
| it "divides the item numbers and values according to the partner profile" do | ||
| create(:distribution, :with_items, item: kit_a.item, organization: user.organization, partner: partner_1) | ||
| create(:distribution, :with_items, item: item_3, organization: user.organization, partner: partner_1) | ||
| create(:distribution, :with_items, item: item_4, organization: user.organization, partner: partner_1) | ||
| breakdown = DistributionSummaryByCountyQuery.call(**params) | ||
| expect(breakdown.size).to eq(5) | ||
| expect(breakdown[-1].quantity).to eq(0) | ||
| expect(breakdown[-1].value).to be_within(0.01).of(0) | ||
| 4.times do |i| | ||
| expect(breakdown[i].quantity).to eq(550) | ||
| expect(breakdown[i].value).to be_within(0.01).of(40625.0) | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe "handling filtering by item" do | ||
| context "with loose items only" do | ||
| let(:item_id) { item_1.id } | ||
| let(:params) { {organization_id:, start_date:, end_date:, reporting_category:, item_id:} } | ||
|
|
||
| it "divides the item numbers and values according to the partner profile" do | ||
| create(:distribution, :with_items, item: item_1, organization: user.organization, partner: partner_1) | ||
| create(:distribution, :with_items, item: item_2, organization: user.organization, partner: partner_1) | ||
|
|
||
| breakdown = DistributionSummaryByCountyQuery.call(**params) | ||
| expect(breakdown.size).to eq(5) | ||
| expect(breakdown[4].quantity).to eq(0) | ||
| expect(breakdown[4].value).to be_within(0.01).of(0) | ||
| 4.times do |i| | ||
| expect(breakdown[i].quantity).to eq(25) | ||
| expect(breakdown[i].value).to be_within(0.01).of(26250.0) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context "with kits only" do | ||
| let(:item_id) { item_3.id } | ||
| let(:params) { {organization_id:, start_date:, end_date:, reporting_category:, item_id:} } | ||
|
|
||
| it "divides the item numbers and values according to the partner profile" do | ||
| create(:distribution, :with_items, item: kit_a.item, organization: user.organization, partner: partner_1) | ||
| create(:distribution, :with_items, item: item_2, organization: user.organization, partner: partner_1) | ||
|
|
||
| breakdown = DistributionSummaryByCountyQuery.call(**params) | ||
| expect(breakdown.size).to eq(5) | ||
| expect(breakdown[-1].quantity).to eq(0) | ||
| expect(breakdown[-1].value).to be_within(0.01).of(0) | ||
| 4.times do |i| | ||
| expect(breakdown[i].quantity).to eq(500) | ||
| expect(breakdown[i].value).to be_within(0.01).of(37500.0) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context "with an item that is in a kit and loose, and another item that is in the reporting category" do | ||
| let(:item_id) { item_3.id } | ||
| let(:params) { {organization_id:, start_date:, end_date:, reporting_category:, item_id:} } | ||
|
|
||
| it "divides the item numbers and values according to the partner profile" do | ||
| create(:distribution, :with_items, item: kit_a.item, organization: user.organization, partner: partner_1) | ||
| create(:distribution, :with_items, item: item_3, organization: user.organization, partner: partner_1) | ||
| create(:distribution, :with_items, item: item_4, organization: user.organization, partner: partner_1) | ||
| breakdown = DistributionSummaryByCountyQuery.call(**params) | ||
| expect(breakdown.size).to eq(5) | ||
| expect(breakdown[-1].quantity).to eq(0) | ||
| expect(breakdown[-1].value).to be_within(0.01).of(0) | ||
| 4.times do |i| | ||
| expect(breakdown[i].quantity).to eq(525) | ||
| expect(breakdown[i].value).to be_within(0.01).of(39375.0) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
Oops, something went wrong.
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.
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.
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.
We use View::Donations.in donations#index.
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.
(nods) Ok - I see we have an example with Donations, so I'll see if I can apply that.