Skip to content

Commit 7ae234f

Browse files
authored
Merge branch 'main' into summary-report-guide-correction
2 parents a995c3b + fd980e8 commit 7ae234f

42 files changed

Lines changed: 1152 additions & 488 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/controllers/partners_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def index
1515

1616
respond_to do |format|
1717
format.html
18-
format.csv { send_data Exports::ExportPartnersCSVService.new(@partners.unscope(:includes)).generate_csv, filename: "Partners-#{Time.zone.today}.csv" }
18+
format.csv { send_data Exports::ExportPartnersCSVService.new(@partners.unscope(:includes), current_organization).generate_csv, filename: "Partners-#{Time.zone.today}.csv" }
1919
end
2020
end
2121

app/helpers/donations_helper.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ def total_received_from_product_drives(range = selected_range)
1616
number_with_delimiter total_received_from_product_drives_unformatted(range)
1717
end
1818

19+
def total_number_of_drives(range = selected_range)
20+
formatted_range = format_date_range_to_iso(range)
21+
current_organization.product_drives.within_date_range(formatted_range).count
22+
end
23+
1924
private
2025

2126
def total_received_donations_unformatted(range = selected_range)
@@ -25,4 +30,8 @@ def total_received_donations_unformatted(range = selected_range)
2530
def total_received_from_product_drives_unformatted(range = selected_range)
2631
LineItem.active.where(itemizable: current_organization.donations.by_source(:product_drive).during(range)).sum(:quantity)
2732
end
33+
34+
def format_date_range_to_iso(range)
35+
"#{range.begin.to_date.iso8601} - #{range.end.to_date.iso8601}"
36+
end
2837
end

app/models/base_item.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class BaseItem < ApplicationRecord
3939
"Adult Briefs (XXXL)" => "adult_incontinence",
4040
"Adult Cloth Diapers (Large/XL/XXL)" => "adult_incontinence",
4141
"Adult Cloth Diapers (Small/Medium)" => "adult_incontinence",
42-
"adult_incontinence Pads" => "adult_incontinence",
42+
"Adult Incontinence Pads" => "adult_incontinence",
4343
"Bed Pads (Cloth)" => "other",
4444
"Bed Pads (Disposable)" => "other",
4545
"Bibs (Adult & Child)" => "other",
@@ -69,7 +69,7 @@ class BaseItem < ApplicationRecord
6969
"Kids S/M (38-65 lbs)" => "disposable_diapers",
7070
"Kit" => nil,
7171
"Liners (Incontinence)" => "adult_incontinence",
72-
"Liners (Menstrual)" => "menstrual",
72+
"Liners (Menstrual)" => "period_liners",
7373
"Other" => "other",
7474
"Pads" => "pads",
7575
"Swimmers" => "disposable_diapers",

app/models/distribution.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Distribution < ApplicationRecord
4747
enum :state, { scheduled: 5, complete: 10 }
4848
enum :delivery_method, { pick_up: 0, delivery: 1, shipped: 2 }
4949
scope :active, -> { joins(:line_items).joins(:items).where(items: { active: true }) }
50-
scope :with_diapers, -> { joins(line_items: :item).merge(Item.disposable.or(Item.cloth_diapers)) }
50+
scope :with_diapers, -> { joins(line_items: :item).merge(Item.disposable_diapers.or(Item.cloth_diapers)) }
5151
scope :with_period_supplies, -> { joins(line_items: :item).merge(Item.period_supplies) }
5252
# add item_id scope to allow filtering distributions by item
5353
scope :by_item_id, ->(item_id) { includes(:items).where(items: { id: item_id }) }

app/models/item.rb

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Item < ApplicationRecord
2929
include Exportable
3030
include Valuable
3131

32+
after_initialize :set_default_distribution_quantity, if: :new_record?
3233
after_update :update_associated_kit_name, if: -> { kit.present? }
3334
before_create :set_reporting_category
3435
before_destroy :validate_destroy, prepend: true
@@ -67,56 +68,22 @@ class Item < ApplicationRecord
6768

6869
scope :by_size, ->(size) { joins(:base_item).where(base_items: { size: size }) }
6970

70-
# Scopes - explanation of business rules for filtering scopes as of 20240527. This was a mess, but is much better now.
71-
# 1/ Disposable. Disposables are only the disposable diapers for children. So we deliberately exclude adult and cloth
72-
# 2/ Cloth. Cloth diapers for children. Exclude adult cloth. Cloth training pants also go here.
73-
# 3/ Adult incontinence. Items for adult incontinence -- diapers, ai pads, but not adult wipes.
74-
# 4/ Period supplies. All things with 'menstrual in the category'
75-
# 5/ Other -- Miscellaneous, and wipes
76-
# Known holes and ambiguities as of 20240527. Working on these with the business
77-
# 1/ Liners. We are adding a new item for AI liners, and renaming the current liners to be specifically for periods,
78-
# having confirmed with the business that the majority of liners are for menstrual use.
79-
# However, there is a product which can be used for either, so we are still sussing out what to do about that.
80-
81-
scope :disposable, -> {
82-
joins(:base_item)
83-
.where("lower(base_items.category) LIKE '%diaper%'")
84-
.where.not("lower(base_items.category) LIKE '%cloth%' OR lower(base_items.name) LIKE '%cloth%'")
85-
.where.not("lower(base_items.category) LIKE '%adult%'")
86-
}
87-
88-
scope :cloth_diapers, -> {
89-
joins(:base_item)
90-
.where("lower(base_items.category) LIKE '%cloth%'")
91-
.or(where("base_items.category = 'Training Pants'"))
92-
.where.not("lower(base_items.category) LIKE '%adult%'")
93-
}
94-
95-
scope :adult_incontinence, -> {
96-
joins(:base_item)
97-
.where("lower(base_items.category) LIKE '%adult%' AND lower(base_items.category) NOT LIKE '%wipes%'")
98-
}
99-
10071
scope :period_supplies, -> {
101-
joins(:base_item)
102-
.where("lower(base_items.category) LIKE '%menstrual%'")
103-
}
104-
105-
scope :other_categories, -> {
106-
joins(:base_item)
107-
.where("lower(base_items.category) LIKE '%wipes%'")
108-
.or(where("base_items.category = 'Miscellaneous'"))
72+
where(reporting_category: [:pads, :tampons, :period_liners, :period_underwear, :period_other])
10973
}
11074

11175
enum :reporting_category, {
11276
adult_incontinence: "adult_incontinence",
11377
cloth_diapers: "cloth_diapers",
11478
disposable_diapers: "disposable_diapers",
11579
menstrual: "menstrual",
116-
other: "other",
80+
other_categories: "other",
11781
pads: "pads",
82+
period_liners: "period_liners",
83+
period_other: "period_other",
84+
period_underwear: "period_underwear",
11885
tampons: "tampons"
119-
}, scopes: false, instance_methods: false
86+
}, instance_methods: false
12087

12188
def self.reactivate(item_ids)
12289
item_ids = Array.wrap(item_ids)
@@ -228,6 +195,10 @@ def set_reporting_category
228195
self.reporting_category = base_item.reporting_category if base_item.reporting_category
229196
end
230197

198+
def set_default_distribution_quantity
199+
self.distribution_quantity ||= kit_id.present? ? 1 : 50
200+
end
201+
231202
def update_associated_kit_name
232203
kit.update(name: name)
233204
end

app/models/organization.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ def address_changed?
168168
street_changed? || city_changed? || state_changed? || zipcode_changed?
169169
end
170170

171+
def partials_to_show
172+
partner_form_fields.presence || ALL_PARTIALS.map { |partial| partial[1] }
173+
end
174+
171175
def self.seed_items(organization = Organization.all)
172176
base_items = BaseItem.without_kit.map(&:to_h)
173177

app/models/partner.rb

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,7 @@ class Partner < ApplicationRecord
6666
where(status: status.to_sym)
6767
}
6868

69-
ALL_PARTIALS = %w[
70-
media_information
71-
agency_stability
72-
organizational_capacity
73-
sources_of_funding
74-
area_served
75-
population_served
76-
executive_director
77-
pick_up_person
78-
agency_distribution_information
79-
attached_documents
80-
].freeze
69+
ALL_PARTIALS = Organization::ALL_PARTIALS.map { |partial| partial[1] }.freeze
8170

8271
# @return [String]
8372
def display_status
@@ -126,33 +115,8 @@ def self.import_csv(csv, organization_id)
126115
errors
127116
end
128117

129-
def contact_person
130-
return @contact_person if @contact_person
131-
132-
@contact_person = {
133-
name: profile.primary_contact_name,
134-
email: profile.primary_contact_email,
135-
phone: profile.primary_contact_phone ||
136-
profile.primary_contact_mobile
137-
}
138-
end
139-
140-
def agency_info
141-
return @agency_info if @agency_info
142-
143-
symbolic_agency_type = profile.agency_type&.to_sym
144-
@agency_info = {
145-
address: [profile.address1, profile.address2].select(&:present?).join(', '),
146-
city: profile.city,
147-
state: profile.state,
148-
zip_code: profile.zip_code,
149-
website: profile.website,
150-
agency_type: (symbolic_agency_type == :other) ? "#{I18n.t symbolic_agency_type, scope: :partners_profile}: #{profile.other_agency_type}" : (I18n.t symbolic_agency_type, scope: :partners_profile)
151-
}
152-
end
153-
154118
def partials_to_show
155-
organization.partner_form_fields.presence || ALL_PARTIALS
119+
organization.partials_to_show
156120
end
157121

158122
def quantity_year_to_date

app/models/partners/profile.rb

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
# address2 :string
99
# agency_mission :text
1010
# agency_type :string
11-
# application_data :text
1211
# at_fpl_or_below :integer
1312
# case_management :boolean
1413
# city :string
1514
# client_capacity :string
1615
# currently_provide_diapers :boolean
1716
# describe_storage_space :text
1817
# distribution_times :string
19-
# distributor_type :string
2018
# enable_child_based_requests :boolean default(TRUE), not null
2119
# enable_individual_requests :boolean default(TRUE), not null
2220
# enable_quantity_based_requests :boolean default(TRUE), not null
@@ -144,7 +142,44 @@ class Profile < Base
144142
validate :has_at_least_one_request_setting
145143
validate :pick_up_email_addresses
146144

145+
# For the sake of documentation, here are the partials each field belongs to. In the order those
146+
# partials appear in the actual form.
147+
# agency_information -- this partial is always shown, contains the agency information AND the Program / Delivery Address sections of the form
148+
# agency_type, other_agency_type, agency_mission, address1, address2, city, state, zip_code,
149+
# program_address1, program_address2, program_city, program_state, program_zip_code
150+
# media_information
151+
# website, facebook, twitter, instagram, no_social_media_presence
152+
# agency_stability
153+
# founded, form_990, program_name, program_description, program_age, evidence_based, case_management,
154+
# essentials_use, receives_essentials_from_other, currently_provide_diapers
155+
# organizational_capacity
156+
# client_capacity, storage_space, describe_storage_space
157+
# sources_of_funding
158+
# sources_of_funding, sources_of_diapers, essentials_budget, essentials_funding_source
159+
# area_served
160+
# has no associated Partners::Profile fields
161+
# population_served
162+
# income_requirement_desc, income_verification, population_black, population_white,
163+
# population_hispanic, population_asian, population_american_indian, population_island,
164+
# population_multi_racial, population_other, zips_served, at_fpl_or_below, above_1_2_times_fpl
165+
# greater_2_times_fpl, poverty_unknown
166+
# executive_director
167+
# executive_director_name, executive_director_phone, executive_director_email, primary_contact_name,
168+
# primary_contact_phone, primary_contact_mobile, primary_contact_email
169+
# pick_up_person
170+
# pick_up_name, pick_up_phone, pick_up_email
171+
# agency_distribution_information
172+
# distribution_times, new_client_times, more_docs_required
173+
# attached_documents
174+
# has no associated Partners::Profile fields
175+
# partner_settings -- this partial is always shown
176+
# enable_quantity_based_requests, enable_child_based_requests, enable_individual_requests
177+
178+
# These are columns which currently do not appear in any partial of the profile form.
179+
# It is possible these will be removed in the future.
147180
self.ignored_columns += %w[
181+
application_data
182+
distributor_type
148183
evidence_based_description
149184
program_client_improvement
150185
incorporate_plan

0 commit comments

Comments
 (0)