Skip to content

Commit 222064d

Browse files
authored
Merge pull request #5237 from rubyforgood/kit-seed
Kit seed
2 parents 2874664 + 33badec commit 222064d

File tree

1 file changed

+144
-0
lines changed

1 file changed

+144
-0
lines changed

db/seeds.rb

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,110 @@ def seed_quantity(item_name, organization, storage_location, quantity)
759759
end
760760
end
761761

762+
# ----------------------------------------------------------------------------
763+
# Kits
764+
# ----------------------------------------------------------------------------
765+
766+
complete_orgs.each do |org|
767+
# Create comprehensive kits representing each NDBN category
768+
769+
# Diaper Care Kit - covering multiple diaper categories
770+
diaper_kit_params = {
771+
name: "Diaper Care Kit",
772+
line_items_attributes: [
773+
{item_id: org.items.find_by(name: "Kids (Size 1)").id, quantity: 50},
774+
{item_id: org.items.find_by(name: "Kids (Size 2)").id, quantity: 50},
775+
{item_id: org.items.find_by(name: "Kids (Size 3)").id, quantity: 50},
776+
{item_id: org.items.find_by(name: "Wipes (Baby)").id, quantity: 10},
777+
{item_id: org.items.find_by(name: "Diaper Rash Cream/Powder").id, quantity: 2}
778+
].compact_blank
779+
}
780+
781+
if diaper_kit_params[:line_items_attributes].any?
782+
diaper_kit_service = KitCreateService.new(organization_id: org.id, kit_params: diaper_kit_params)
783+
diaper_kit_service.call
784+
end
785+
786+
# Menstrual Care Kit
787+
menstrual_kit_params = {
788+
name: "Menstrual Care Kit",
789+
line_items_attributes: [
790+
{item_id: org.items.find_by(name: "Pads").id, quantity: 20},
791+
{item_id: org.items.find_by(name: "Tampons").id, quantity: 20},
792+
{item_id: org.items.find_by(name: "Liners (Menstrual)").id, quantity: 15}
793+
].compact_blank
794+
}
795+
796+
if menstrual_kit_params[:line_items_attributes].any?
797+
menstrual_kit_service = KitCreateService.new(organization_id: org.id, kit_params: menstrual_kit_params)
798+
menstrual_kit_service.call
799+
end
800+
801+
# Adult Incontinence Kit
802+
adult_kit_params = {
803+
name: "Adult Incontinence Kit",
804+
line_items_attributes: [
805+
{item_id: org.items.find_by(name: "Adult Briefs (Large/X-Large)").id, quantity: 30},
806+
{item_id: org.items.find_by(name: "Adult Incontinence Pads").id, quantity: 25},
807+
{item_id: org.items.find_by(name: "Wipes (Adult)").id, quantity: 5},
808+
{item_id: org.items.find_by(name: "Underpads (Pack)").id, quantity: 5}
809+
].compact_blank
810+
}
811+
812+
if adult_kit_params[:line_items_attributes].any?
813+
adult_kit_service = KitCreateService.new(organization_id: org.id, kit_params: adult_kit_params)
814+
adult_kit_service.call
815+
end
816+
817+
# Baby Care Essentials Kit - covering miscellaneous category
818+
baby_care_kit_params = {
819+
name: "Baby Care Essentials Kit",
820+
line_items_attributes: [
821+
{item_id: org.items.find_by(name: "Bibs (Adult & Child)").id, quantity: 5},
822+
{item_id: org.items.find_by(name: "Wipes (Baby)").id, quantity: 8},
823+
{item_id: org.items.find_by(name: "Diaper Rash Cream/Powder").id, quantity: 1},
824+
{item_id: org.items.find_by(name: "Cloth Diapers (Prefolds & Fitted)").id, quantity: 10}
825+
].compact_blank
826+
}
827+
828+
if baby_care_kit_params[:line_items_attributes].any?
829+
baby_care_service = KitCreateService.new(organization_id: org.id, kit_params: baby_care_kit_params)
830+
baby_care_service.call
831+
end
832+
833+
# Training Kit - covering training pants category
834+
training_kit_params = {
835+
name: "Potty Training Kit",
836+
line_items_attributes: [
837+
{item_id: org.items.find_by(name: "Cloth Potty Training Pants/Underwear").id, quantity: 8},
838+
{item_id: org.items.find_by(name: "Kids Pull-Ups (2T-3T)").id, quantity: 20},
839+
{item_id: org.items.find_by(name: "Kids Pull-Ups (3T-4T)").id, quantity: 20},
840+
{item_id: org.items.find_by(name: "Wipes (Baby)").id, quantity: 5}
841+
].compact_blank
842+
}
843+
844+
if training_kit_params[:line_items_attributes].any?
845+
training_kit_service = KitCreateService.new(organization_id: org.id, kit_params: training_kit_params)
846+
training_kit_service.call
847+
end
848+
end
849+
850+
# Create kit inventory for storage locations
851+
complete_orgs.each do |org|
852+
org.storage_locations.active.each do |storage_location|
853+
org.kits.active.each do |kit|
854+
next unless kit.item # Ensure kit has an associated item
855+
856+
# Create inventory for each kit
857+
InventoryItem.create!(
858+
storage_location: storage_location,
859+
item: kit.item,
860+
quantity: Faker::Number.within(range: 10..50)
861+
)
862+
end
863+
end
864+
end
865+
762866
dates_generator = DispersedPastDatesGenerator.new
763867
complete_orgs.each do |org|
764868
# ----------------------------------------------------------------------------
@@ -843,6 +947,46 @@ def seed_quantity(item_name, organization, storage_location, quantity)
843947

844948
DistributionCreateService.new(distribution).call
845949
end
950+
951+
# Create some distributions that use kits instead of individual items
952+
kit_items = org.items.joins(:kit).where(kits: {active: true})
953+
if kit_items.any?
954+
5.times do |index|
955+
issued_at = dates_generator.next
956+
storage_location = org.storage_locations.active.sample
957+
kit_item = kit_items.sample
958+
959+
# Check if there's inventory for this kit
960+
kit_inventory_qty = storage_location.item_total(kit_item.id)
961+
next if kit_inventory_qty.zero?
962+
963+
delivery_method = Distribution.delivery_methods.keys.sample
964+
shipping_cost = (delivery_method == "shipped") ? rand(20.0..100.0).round(2).to_s : nil
965+
966+
kit_distribution = Distribution.new(
967+
storage_location: storage_location,
968+
partner: random_record_for_org(org, Partner),
969+
organization: org,
970+
issued_at: issued_at,
971+
created_at: 3.days.ago(issued_at),
972+
delivery_method: delivery_method,
973+
shipping_cost: shipping_cost,
974+
comment: "Kit distribution"
975+
)
976+
977+
distribution_qty = [rand(1..3), kit_inventory_qty / 2].min
978+
if distribution_qty >= 1
979+
kit_distribution.line_items.push(
980+
LineItem.new(
981+
quantity: distribution_qty,
982+
item_id: kit_item.id
983+
)
984+
)
985+
986+
DistributionCreateService.new(kit_distribution).call
987+
end
988+
end
989+
end
846990
end
847991

848992
# ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)