Skip to content

Commit

Permalink
Remove old/unused #for_csv_export methods (#4995)
Browse files Browse the repository at this point in the history
  • Loading branch information
coalest authored Feb 7, 2025
1 parent f43336f commit 53def81
Show file tree
Hide file tree
Showing 14 changed files with 0 additions and 82 deletions.
4 changes: 0 additions & 4 deletions app/models/adjustment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ class Adjustment < ApplicationRecord
include Filterable
scope :at_location, ->(location_id) { where(storage_location_id: location_id) }
scope :by_user, ->(user_id) { where(user_id: user_id) }
scope :for_csv_export, ->(organization, *) {
where(organization: organization)
.includes(:storage_location, :line_items)
}
scope :during, ->(range) { where(adjustments: { created_at: range }) }

validate :storage_locations_belong_to_organization
Expand Down
5 changes: 0 additions & 5 deletions app/models/barcode_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ class BarcodeItem < ApplicationRecord

scope :by_value, ->(value) { where(value: value) }

scope :for_csv_export, ->(organization, *) {
where(organization: organization)
.includes(:barcodeable)
}

scope :global, -> { where(barcodeable_type: "BaseItem") }

# aliases of barcodeable
Expand Down
4 changes: 0 additions & 4 deletions app/models/concerns/provideable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ module Provideable
included do
belongs_to :organization # Automatically validates presence as of Rails 5

scope :for_csv_export, ->(organization, *) {
where(organization: organization).order(:business_name)
}

def self.import_csv(csv, organization)
csv.each do |row|
loc = new(row.to_hash)
Expand Down
5 changes: 0 additions & 5 deletions app/models/distribution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ class Distribution < ApplicationRecord
scope :recent, ->(count = 3) { order(issued_at: :desc).limit(count) }
scope :future, -> { where(issued_at: Time.zone.tomorrow..) }
scope :during, ->(range) { where(distributions: { issued_at: range }) }
scope :for_csv_export, ->(organization, filters = {}, date_range = nil) {
where(organization: organization)
.includes(:partner, :storage_location, :line_items)
.apply_filters(filters, date_range)
}
scope :apply_filters, ->(filters, date_range) {
class_filter(filters.merge(during: date_range))
}
Expand Down
5 changes: 0 additions & 5 deletions app/models/donation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ class Donation < ApplicationRecord
scope :from_manufacturer, ->(manufacturer_id) {
where(manufacturer_id: manufacturer_id)
}
scope :for_csv_export, ->(organization, *) {
where(organization: organization)
.includes(:line_items, :storage_location, :donation_site)
.order(created_at: :desc)
}

before_create :combine_duplicates

Expand Down
5 changes: 0 additions & 5 deletions app/models/donation_site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ class DonationSite < ApplicationRecord
include Geocodable
include Exportable

scope :for_csv_export, ->(organization, *) {
where(organization: organization)
.order(:name)
}

scope :active, -> { where(active: true) }

scope :alphabetized, -> { order(:name) }
Expand Down
5 changes: 0 additions & 5 deletions app/models/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ class Item < ApplicationRecord
scope :by_partner_key, ->(partner_key) { where(partner_key: partner_key) }

scope :by_size, ->(size) { joins(:base_item).where(base_items: { size: size }) }
scope :for_csv_export, ->(organization, *) {
where(organization: organization)
.includes(:base_item)
.alphabetized
}

# Scopes - explanation of business rules for filtering scopes as of 20240527. This was a mess, but is much better now.
# 1/ Disposable. Disposables are only the disposable diapers for children. So we deliberately exclude adult and cloth
Expand Down
5 changes: 0 additions & 5 deletions app/models/partner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ class Partner < ApplicationRecord
before_save { email&.downcase! }
before_update :invite_new_partner, if: :should_invite_because_email_changed?

scope :for_csv_export, ->(organization, *) {
where(organization: organization)
.order(:name)
}

scope :alphabetized, -> { order(:name) }
scope :active, -> { where.not(status: :deactivated) }

Expand Down
5 changes: 0 additions & 5 deletions app/models/purchase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ class Purchase < ApplicationRecord
scope :purchased_from, ->(purchased_from) { where(purchased_from: purchased_from) }
scope :during, ->(range) { where(purchases: { issued_at: range }) }
scope :recent, ->(count = 3) { order(issued_at: :desc).limit(count) }
scope :for_csv_export, ->(organization, *) {
where(organization: organization)
.includes(:line_items, :storage_location)
.order(created_at: :desc)
}

scope :active, -> { joins(:line_items).joins(:items).where(items: { active: true }) }

Expand Down
5 changes: 0 additions & 5 deletions app/models/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ class Request < ApplicationRecord
scope :by_status, ->(status) { where(status: status) }
scope :by_request_type, ->(request_type) { where(request_type: request_type) }
scope :during, ->(range) { where(created_at: range) }
scope :for_csv_export, ->(organization, *) {
where(organization: organization)
.includes(:partner)
.order(created_at: :desc)
}

def total_items
request_items.sum { |item| item["quantity"] }
Expand Down
1 change: 0 additions & 1 deletion app/models/storage_location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class StorageLocation < ApplicationRecord
include Exportable

scope :alphabetized, -> { order(:name) }
scope :for_csv_export, ->(organization, *) { where(organization: organization) }
scope :active, -> { where(discarded_at: nil) }
scope :with_transfers_to, ->(organization) {
joins(:transfers_to).where(organization_id: organization.id).distinct.order(:name)
Expand Down
4 changes: 0 additions & 4 deletions app/models/transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ class Transfer < ApplicationRecord
belongs_to :storage_location, class_name: "StorageLocation", inverse_of: :transfers_from, foreign_key: :from_id
scope :from_location, ->(location_id) { where(from_id: location_id) }
scope :to_location, ->(location_id) { where(to_id: location_id) }
scope :for_csv_export, ->(organization, *) {
where(organization: organization)
.includes(:line_items, :from, :to)
}
scope :during, ->(range) { where(created_at: range) }

validate :storage_locations_belong_to_organization
Expand Down
8 changes: 0 additions & 8 deletions spec/models/barcode_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
describe "by_item_partner_key" # TODO: Write test
describe "by_base_item_partner_key" # TODO: Write test
describe "by_value" # TODO: Write test
describe "for_csv_export" # TODO: Write test
describe "global" do
it "includes all barcodes, for both base items and regular items" do
create(:global_barcode_item)
Expand Down Expand Up @@ -133,13 +132,6 @@
end

context "scopes >" do
it "->for_csv_export will accept an organization and provide all barcodes for that org" do
barcode_item
create(:barcode_item, organization: create(:organization))
results = BarcodeItem.for_csv_export(barcode_item.organization)
expect(results).to eq([barcode_item])
end

it "#by_item_partner_key returns barcodes that match the partner key" do
bases = create_list(:base_item, 2)
i1 = create(:item, name: "Item 1", base_item: bases.first)
Expand Down
21 changes: 0 additions & 21 deletions spec/models/distribution_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,27 +315,6 @@
end

context "CSV export >" do
let(:organization_2) { create(:organization) }
let(:item1) { create(:item, organization: organization) }
let(:item2) { create(:item, organization: organization) }
let!(:distribution_1) { create(:distribution, :with_items, item: item1, organization: organization, issued_at: 3.days.ago) }
let!(:distribution_2) { create(:distribution, :with_items, item: item2, organization: organization, issued_at: 1.day.ago) }
let!(:distribution_3) { create(:distribution, organization: organization_2, issued_at: Time.zone.today) }

describe "for_csv_export >" do
it "filters only to the given organization" do
expect(Distribution.for_csv_export(organization)).to match_array [distribution_1, distribution_2]
end

it "filters only to the given filter" do
expect(Distribution.for_csv_export(organization, { by_item_id: item1.id })).to match_array [distribution_1]
end

it "filters only to the given issue time range" do
expect(Distribution.for_csv_export(organization, {}, 4.days.ago..2.days.ago)).to match_array [distribution_1]
end
end

describe "csv_export_attributes" do
let(:item) { create(:item, organization: organization) }
let!(:distribution) { create(:distribution, :with_items, item: item, organization: organization, issued_at: 3.days.ago) }
Expand Down

0 comments on commit 53def81

Please sign in to comment.