Skip to content

Commit 2c1124d

Browse files
authored
Merge branch 'main' into improve-distributions-by-country-report-performance
2 parents 257cf8f + 5538cc5 commit 2c1124d

File tree

17 files changed

+350
-15
lines changed

17 files changed

+350
-15
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ GEM
401401
timeout
402402
net-smtp (0.5.0)
403403
net-protocol
404-
newrelic_rpm (9.13.0)
404+
newrelic_rpm (9.16.0)
405405
nio4r (2.7.3)
406406
nokogiri (1.16.7-arm64-darwin)
407407
racc (~> 1.4)

app/controllers/audits_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def index
1010
end
1111

1212
def show
13-
@items = View::Inventory.items_for_location(@audit.storage_location)
13+
@items = View::Inventory.items_for_location(@audit.storage_location, include_omitted: true)
1414
end
1515

1616
def edit
@@ -93,7 +93,7 @@ def set_storage_locations
9393
end
9494

9595
def set_items
96-
@items = current_organization.items.alphabetized
96+
@items = current_organization.items.where(active: true).alphabetized
9797
end
9898

9999
def save_audit_status_and_redirect(params)

app/controllers/distributions_controller.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def index
5050
@items = current_organization.items.alphabetized.select(:id, :name)
5151
@item_categories = current_organization.item_categories.select(:id, :name)
5252
@storage_locations = current_organization.storage_locations.active_locations.alphabetized.select(:id, :name)
53-
@partners = Partner.joins(:distributions).where(distributions: @distributions).distinct.order(:name).select(:id, :name)
53+
@partners = current_organization.partners.active.alphabetized.select(:id, :name)
5454
@selected_item = filter_params[:by_item_id].presence
5555
@distribution_totals = DistributionTotalsService.new(current_organization.distributions, scope_filters)
5656
@total_value_all_distributions = @distribution_totals.total_value
@@ -117,7 +117,7 @@ def create
117117
elsif request_id
118118
@distribution.initialize_request_items
119119
end
120-
@items = current_organization.items.alphabetized
120+
@items = current_organization.items.active.alphabetized
121121
@partner_list = current_organization.partners.where.not(status: 'deactivated').alphabetized
122122

123123
inventory = View::Inventory.new(@distribution.organization_id)
@@ -147,7 +147,7 @@ def new
147147
@distribution.line_items.build
148148
@distribution.copy_from_donation(params[:donation_id], params[:storage_location_id])
149149
end
150-
@items = current_organization.items.alphabetized
150+
@items = current_organization.items.active.alphabetized
151151
@partner_list = current_organization.partners.where.not(status: 'deactivated').alphabetized
152152

153153
inventory = View::Inventory.new(current_organization.id)
@@ -173,7 +173,7 @@ def edit
173173
if (!@distribution.complete? && @distribution.future?) ||
174174
current_user.has_role?(Role::ORG_ADMIN, current_organization)
175175
@distribution.line_items.build if @distribution.line_items.size.zero?
176-
@items = current_organization.items.alphabetized
176+
@items = current_organization.items.active.alphabetized
177177
@partner_list = current_organization.partners.alphabetized
178178
@audit_warning = current_organization.audits
179179
.where(storage_location_id: @distribution.storage_location_id)
@@ -204,7 +204,7 @@ def update
204204
flash[:error] = insufficient_error_message(result.error.message)
205205
@distribution.line_items.build if @distribution.line_items.size.zero?
206206
@distribution.initialize_request_items
207-
@items = current_organization.items.alphabetized
207+
@items = current_organization.items.active.alphabetized
208208
@storage_locations = current_organization.storage_locations.active_locations.alphabetized
209209
render :edit
210210
end

app/models/distribution.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ 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)) }
51+
scope :with_period_supplies, -> { joins(line_items: :item).merge(Item.period_supplies) }
5052
# add item_id scope to allow filtering distributions by item
5153
scope :by_item_id, ->(item_id) { includes(:items).where(items: { id: item_id }) }
5254
# partner scope to allow filtering by partner
@@ -71,6 +73,10 @@ class Distribution < ApplicationRecord
7173
where("issued_at > :start_date AND issued_at <= :end_date",
7274
start_date: Time.zone.today.beginning_of_week.beginning_of_day, end_date: Time.zone.today.end_of_week.end_of_day)
7375
end
76+
scope :in_last_12_months, -> do
77+
where("issued_at > :start_date AND issued_at <= :end_date",
78+
start_date: 12.months.ago.beginning_of_day, end_date: Time.zone.today.end_of_day)
79+
end
7480

7581
delegate :name, to: :partner, prefix: true
7682

app/models/item.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def is_in_kit?(kits = nil)
143143
end
144144

145145
def can_delete?(inventory = nil, kits = nil)
146-
can_deactivate_or_delete?(inventory, kits) && line_items.none? && !barcode_count&.positive? && !in_request?
146+
can_deactivate_or_delete?(inventory, kits) && line_items.none? && !barcode_count&.positive? && !in_request? && kit.blank?
147147
end
148148

149149
# @return [Boolean]

app/models/partner.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,10 @@ def self.csv_export_headers
185185
"Contact Name",
186186
"Contact Phone",
187187
"Contact Email",
188-
"Notes"
188+
"Notes",
189+
"Counties Served",
190+
"Providing Diapers",
191+
"Providing Period Supplies"
189192
]
190193
end
191194

@@ -202,10 +205,21 @@ def csv_export_attributes
202205
contact_person[:name],
203206
contact_person[:phone],
204207
contact_person[:email],
205-
notes
208+
notes,
209+
profile.county_list_by_region,
210+
providing_diapers,
211+
providing_period_supplies
206212
]
207213
end
208214

215+
def providing_diapers
216+
distributions.in_last_12_months.with_diapers.any? ? "Y" : "N"
217+
end
218+
219+
def providing_period_supplies
220+
distributions.in_last_12_months.with_period_supplies.any? ? "Y" : "N"
221+
end
222+
209223
def contact_person
210224
return @contact_person if @contact_person
211225

app/models/partners/profile.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class Profile < Base
9191

9292
has_many :served_areas, foreign_key: "partner_profile_id", class_name: "Partners::ServedArea", dependent: :destroy, inverse_of: :partner_profile
9393

94+
has_many :counties, through: :served_areas
9495
accepts_nested_attributes_for :served_areas, allow_destroy: true
9596

9697
has_many_attached :documents
@@ -125,6 +126,11 @@ def split_pick_up_emails
125126
pick_up_email.split(/,|\s+/).compact_blank
126127
end
127128

129+
def county_list_by_region
130+
# provides a county list in case insensitive alpha order, by region, then county name
131+
counties.order(%w(lower(region) lower(name))).pluck(:name).join("; ")
132+
end
133+
128134
private
129135

130136
def check_social_media

app/views/audits/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</div>
1515
<div class="box-body">
1616
<%= simple_form_for @audit, data: { controller: "form-input" }, html: {class: "storage-location-required"} do |f| %>
17-
<%= render partial: "storage_locations/source", object: f, locals: { label: "Storage location", error: "What storage location are you auditing?" } %>
17+
<%= render partial: "storage_locations/source", object: f, locals: { label: "Storage location", error: "What storage location are you auditing?", include_omitted_items: true } %>
1818
<fieldset style="margin-bottom: 2rem;">
1919
<legend>Items in this audit</legend>
2020
<div id="audit_line_items" class="line-item-fields" data-capture-barcode="true">

db/seeds.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,8 @@ def seed_quantity(item_name, organization, storage_location, quantity)
739739
Flipper::Adapters::ActiveRecord::Feature.find_or_create_by(key: "new_logo")
740740
Flipper::Adapters::ActiveRecord::Feature.find_or_create_by(key: "read_events")
741741
Flipper.enable(:read_events)
742-
742+
Flipper::Adapters::ActiveRecord::Feature.find_or_create_by(key: "partner_step_form")
743+
Flipper.enable(:partner_step_form)
743744
# ----------------------------------------------------------------------------
744745
# Account Requests
745746
# ----------------------------------------------------------------------------

spec/factories/partners.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
status { :awaiting_review }
4141
end
4242

43+
trait :deactivated do
44+
status { :deactivated }
45+
end
46+
4347
after(:create) do |partner, evaluator|
4448
next if evaluator.try(:without_profile)
4549

0 commit comments

Comments
 (0)