From 59003614309f7a984a2982dd9f2b14a8866bf6dc Mon Sep 17 00:00:00 2001 From: sabrine33 Date: Fri, 15 Nov 2024 09:18:01 +0000 Subject: [PATCH] add few locations requested for traction to the location_creator task --- app/models/location_creator.rb | 15 ++++++--- lib/tasks/location_creator.rake | 55 ++++++++++++++++++++++++++++----- 2 files changed, 59 insertions(+), 11 deletions(-) diff --git a/app/models/location_creator.rb b/app/models/location_creator.rb index bbaf3f60..99e49245 100644 --- a/app/models/location_creator.rb +++ b/app/models/location_creator.rb @@ -27,17 +27,24 @@ def create_locations(type, location, parents) parents.each do |parent| if location[:number] (1..location[:number]).each do |i| - locations << create_location("#{location[:location]} #{i}", location_type, parent, location[:container]) + locations << create_location("#{location[:location]} #{i}", location_type, parent, location[:container], + location[:barcode]) end else - locations << create_location(location[:location], location_type, parent, location[:container]) + locations << create_location(location[:location], location_type, parent, location[:container], + location[:barcode]) end end end end - def create_location(location, location_type, parent, container) - UnorderedLocation.find_or_create_by!(name: location, container: container) do |l| + def create_location(location, location_type, parent, container, barcode) + puts "Creating location: #{location} #{barcode}" + + find_or_create_attributes = { name: location, container: container } + find_or_create_attributes[:barcode] = barcode if barcode.present? + + UnorderedLocation.find_or_create_by!(find_or_create_attributes) do |l| l.parent = parent l.location_type = location_type end diff --git a/lib/tasks/location_creator.rake b/lib/tasks/location_creator.rake index 075222d8..ee65681b 100644 --- a/lib/tasks/location_creator.rake +++ b/lib/tasks/location_creator.rake @@ -6,12 +6,53 @@ desc 'locations' namespace :locations do desc 'create some locations' task create: :environment do |_t| - location_creator = LocationCreator.new('Site' => { location: 'Sanger', container: false }, - 'Building' => { location: 'Ogilvie', container: false }, - 'Room' => { location: 'AA315', container: false }, - 'Freezer' => { location: 'Freezer1', container: true }, - 'Shelf' => { location: 'Shelf', number: 2, container: true }, - 'Tray' => { location: 'Tray', number: 208, container: true }) - location_creator.run! + locations = [ + LocationCreator.new('Site' => { location: 'Sanger', container: false }, + 'Building' => { location: 'Ogilvie', container: false }, + 'Room' => { location: 'AA214', container: false }, + 'Freezer' => { location: 'Long Read DTOL Freezer 2', container: true }, + 'Shelf' => { location: 'Shelf 3', container: true }, + 'Rack' => { location: 'Rack 3', container: true }, + 'Tray' => { location: 'Drawer 2', barcode: 'lw-drawer-2-30398', + container: true }), + + LocationCreator.new('Site' => { location: 'Sanger', container: false }, + 'Building' => { location: 'Ogilvie', container: false }, + 'Room' => { location: 'AA309', container: false }, + 'Freezer -20C' => { location: 'LRT020', container: false }, + 'Shelf' => { location: 'SHELF 1', container: false }, + 'Drawer' => { location: 'Drawer 1', barcode: 'lw-drawer-1-37292', + container: true }), + + LocationCreator.new('Site' => { location: 'Sanger', container: false }, + 'Building' => { location: 'Ogilvie', container: false }, + 'Room' => { location: 'AA309', container: false }, + 'Upright fridge +4c' => { location: 'LRT018', container: false }, + 'Shelf' => { location: 'Shelf 1', barcode: 'lw-shelf-1-30503', + container: true }), + + LocationCreator.new('Site' => { location: 'Sanger', container: false }, + 'Building' => { location: 'Ogilvie', container: false }, + 'Room' => { location: 'AA309', container: false }, + 'Freezer -20 upright' => { location: 'LRT006', container: true }, + 'Shelf' => { location: 'Shelf 1', barcode: 'lw-shelf-1-30472', + container: true }), + + LocationCreator.new('Site' => { location: 'Sanger', container: false }, + 'Building' => { location: 'Ogilvie', container: false }, + 'Room' => { location: 'AA309', container: false }, + 'Upright fridge +4c' => { location: 'LRT007', container: true }, + 'Shelf' => { location: 'Shelf 1', barcode: 'lw-shelf-1-30451', + container: true }), + + LocationCreator.new('Site' => { location: 'Sanger', container: false }, + 'Building' => { location: 'Ogilvie', container: false }, + 'Room' => { location: 'AA315', container: false }, + 'Freezer' => { location: 'Freezer1', container: true }, + 'Shelf' => { location: 'Shelf', number: 2, container: true }, + 'Tray' => { location: 'Tray', number: 208, container: true }) + ] + + locations.each(&:run!) end end