Skip to content

Commit 397c4dd

Browse files
authored
Clean up some model methods (#5042)
* Clean up some model methods * Remove kit allocations model * Remove has_many kit_allocations from storage location model
1 parent bc793b8 commit 397c4dd

15 files changed

+2
-177
lines changed

app/controllers/barcode_items_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# anomaly here is the :find action, which has some special logic built-in to it, see the comments below.
33
class BarcodeItemsController < ApplicationController
44
def index
5-
@items = Item.gather_items(current_organization, @global)
5+
@items = current_organization.items.joins(:barcode_items)
66
@base_items = BaseItem.alphabetized
77
@selected_barcodeable_id = filter_params[:barcodeable_id]
88
@selected_partner_key = filter_params[:by_item_partner_key]

app/controllers/items_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def show
6969
@inventory = View::Inventory.new(current_organization.id)
7070
storage_location_ids = @inventory.storage_locations_for_item(@item.id)
7171
@storage_locations_containing = StorageLocation.find(storage_location_ids)
72-
@barcodes_for = current_organization.items.barcodes_for(@item)
72+
@barcodes_for = BarcodeItem.where(barcodeable_id: @item.id)
7373
end
7474

7575
def update

app/models/donation.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,6 @@ def details
105105
end
106106
end
107107

108-
def remove(item)
109-
# doing this will handle either an id or an object
110-
item_id = item.to_i
111-
line_item = line_items.find_by(item_id: item_id)
112-
line_item&.destroy
113-
end
114-
115108
def money_raised_in_dollars
116109
money_raised.to_d / 100
117110
end

app/models/errors.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,6 @@ def message
4343
end
4444
end
4545

46-
class StorageLocationDoesNotMatch < StandardError
47-
def message
48-
"Storage location kit doesn't match"
49-
end
50-
end
51-
52-
class KitAllocationNotExists < StandardError
53-
def message
54-
"KitAllocation not found for given kit"
55-
end
56-
end
57-
5846
class InventoryAlreadyHasItems < StandardError
5947
def message
6048
"Could not complete action: inventory already has items stored"

app/models/item.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,6 @@ class Item < ApplicationRecord
106106

107107
before_destroy :validate_destroy, prepend: true
108108

109-
def self.barcoded_items
110-
joins(:barcode_items).order(:name).group(:id)
111-
end
112-
113-
def self.barcodes_for(item)
114-
BarcodeItem.where(barcodeable_id: item.id)
115-
end
116-
117109
def self.reactivate(item_ids)
118110
item_ids = Array.wrap(item_ids)
119111
Item.where(id: item_ids).find_each { |item| item.update(active: true) }
@@ -175,16 +167,8 @@ def other?
175167
partner_key == "other"
176168
end
177169

178-
def self.gather_items(current_organization, global = false)
179-
if global
180-
where(id: current_organization.barcode_items.all.pluck(:barcodeable_id))
181-
else
182-
where(id: current_organization.barcode_items.pluck(:barcodeable_id))
183-
end
184-
end
185170
# Convenience method so that other methods can be simplified to
186171
# expect an id or an Item object
187-
188172
def to_i
189173
id
190174
end

app/models/kit_allocation.rb

Lines changed: 0 additions & 17 deletions
This file was deleted.

app/models/manufacturer.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,4 @@ def self.by_donation_date(count = 10, date_range = nil)
3737
.order('donation_date DESC')
3838
.limit(count)
3939
end
40-
41-
private
42-
43-
def exists_in_org?
44-
organization.manufacturers.where(name: name).exists?
45-
end
4640
end

app/models/purchase.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,6 @@ def amount_spent_in_dollars
7979
amount_spent.dollars.to_f
8080
end
8181

82-
def remove(item)
83-
# doing this will handle either an id or an object
84-
item_id = item.to_i
85-
line_item = line_items.find_by(item_id: item_id)
86-
line_item&.destroy
87-
end
88-
8982
def self.organization_summary_by_dates(organization, date_range)
9083
purchases = where(organization: organization).during(date_range)
9184

app/models/storage_location.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class StorageLocation < ApplicationRecord
4242
inverse_of: :to,
4343
foreign_key: :to_id,
4444
dependent: :destroy
45-
has_many :kit_allocations, dependent: :destroy
4645

4746
validates :name, :address, presence: true
4847
validates :warehouse_type, inclusion: { in: WAREHOUSE_TYPES },

spec/factories/kit_allocations.rb

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)