Skip to content

Commit f3250ca

Browse files
committed
Merge remote-tracking branch 'upstream/main' into 3067-add-indicator-fields-to-partner-export
- Kept both changes by fixing errors
2 parents 71a25a7 + b1e4750 commit f3250ca

File tree

15 files changed

+199
-12
lines changed

15 files changed

+199
-12
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/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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ def self.csv_export_headers
186186
"Contact Phone",
187187
"Contact Email",
188188
"Notes",
189+
"Counties Served",
189190
"Providing Diapers",
190191
"Providing Period Supplies"
191192
]
@@ -205,6 +206,7 @@ def csv_export_attributes
205206
contact_person[:phone],
206207
contact_person[:email],
207208
notes,
209+
profile.county_list_by_region,
208210
providing_diapers,
209211
providing_period_supplies
210212
]

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

spec/models/item_spec.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,4 +481,47 @@
481481
describe "versioning" do
482482
it { is_expected.to be_versioned }
483483
end
484+
485+
describe "kit items" do
486+
context "with kit and regular items" do
487+
let(:organization) { create(:organization) }
488+
let(:kit) { create(:kit, organization: organization) }
489+
let(:kit_item) { create(:item, kit: kit, organization: organization) }
490+
let(:regular_item) { create(:item, organization: organization) }
491+
492+
describe "#can_delete?" do
493+
it "returns false for kit items" do
494+
expect(kit_item.can_delete?).to be false
495+
end
496+
497+
it "returns true for regular items" do
498+
expect(regular_item.can_delete?).to be true
499+
end
500+
end
501+
502+
describe "#deactivate!" do
503+
it "deactivates both the kit item and its associated kit" do
504+
kit_item.deactivate!
505+
expect(kit_item.reload.active).to be false
506+
expect(kit.reload.active).to be false
507+
end
508+
509+
it "only deactivates regular items" do
510+
regular_item.deactivate!
511+
expect(regular_item.reload.active).to be false
512+
end
513+
end
514+
515+
describe "#validate_destroy" do
516+
it "prevents deletion of kit items" do
517+
expect { kit_item.destroy! }.to raise_error(ActiveRecord::RecordNotDestroyed)
518+
expect(kit_item.errors[:base]).to include("Cannot delete item - it has already been used!")
519+
end
520+
521+
it "allows deletion of regular items" do
522+
expect { regular_item.destroy! }.not_to raise_error
523+
end
524+
end
525+
end
526+
end
484527
end

0 commit comments

Comments
 (0)