Skip to content

Commit

Permalink
Merge pull request #4713 from lit-poks/seed/inactive-location-and-items
Browse files Browse the repository at this point in the history
Discarded Storage Location and Inactive Item
  • Loading branch information
cielf authored Oct 14, 2024
2 parents 2d9f1a0 + 5187d1e commit 140bbfe
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def random_record_for_org(org, klass)
end
Organization.seed_items(sf_org)

# At least one of the items is marked as inactive
Organization.all.each do |org|
org.items.order(created_at: :desc).last.update(active: false)
end

# Assign a value to some organization items to verify totals are working
Organization.all.each do |org|
org.items.where(value_in_cents: 0).limit(10).each do |item|
Expand Down Expand Up @@ -435,11 +440,20 @@ def random_record_for_org(org, klass)
inventory.square_footage = 20_000
end

inactive_storage = StorageLocation.find_or_create_by!(name: "Inactive Storage Location") do |inventory|
inventory.address = "Unknown"
inventory.organization = pdx_org
inventory.warehouse_type = StorageLocation::WAREHOUSE_TYPES[2]
inventory.square_footage = 5_000
end

inactive_storage.discard

#
# Define all the InventoryItem for each of the StorageLocation
#
StorageLocation.all.each do |sl|
sl.organization.items.each do |item|
StorageLocation.active_locations.each do |sl|
sl.organization.items.active.each do |item|
InventoryItem.create!(
storage_location: sl,
item: item,
Expand Down Expand Up @@ -582,7 +596,7 @@ def seed_quantity(item_name, organization, storage_location, quantity)
source = Donation::SOURCES.values.sample
# Depending on which source it uses, additional data may need to be provided.
donation = Donation.new(source: source,
storage_location: random_record_for_org(pdx_org, StorageLocation),
storage_location: StorageLocation.active_locations.sample,
organization: pdx_org,
issued_at: dates_generator.next)
case source
Expand Down Expand Up @@ -611,7 +625,7 @@ def seed_quantity(item_name, organization, storage_location, quantity)
20.times.each do
issued_at = dates_generator.next

storage_location = random_record_for_org(pdx_org, StorageLocation)
storage_location = StorageLocation.active_locations.sample
stored_inventory_items_sample = inventory.storage_locations[storage_location.id].items.values.sample(20)
delivery_method = Distribution.delivery_methods.keys.sample
shipping_cost = delivery_method == "shipped" ? (rand(20.0..100.0)).round(2).to_s : nil
Expand Down Expand Up @@ -705,7 +719,7 @@ def seed_quantity(item_name, organization, storage_location, quantity)

25.times do
purchase_date = dates_generator.next
storage_location = random_record_for_org(pdx_org, StorageLocation)
storage_location = StorageLocation.active_locations.sample
vendor = random_record_for_org(pdx_org, Vendor)
purchase = Purchase.new(
purchased_from: suppliers.sample,
Expand Down

0 comments on commit 140bbfe

Please sign in to comment.