Skip to content

Commit

Permalink
Make sure that load_date gets set for UniUpdates, and filter duplicat…
Browse files Browse the repository at this point in the history
…es uses load_date for select
  • Loading branch information
jgreben committed Dec 14, 2016
1 parent 77b2869 commit b062467
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/models/change_current_location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ChangeCurrentLocation
attr_accessor :item_ids
attr_accessor :email
attr_accessor :comments
attr_accessor :batch_date
attr_accessor :load_date
attr_accessor :user_name
attr_accessor :action
attr_accessor :priority
Expand Down
2 changes: 1 addition & 1 deletion app/models/change_home_location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ChangeHomeLocation
attr_accessor :item_ids
attr_accessor :email
attr_accessor :comments
attr_accessor :batch_date
attr_accessor :load_date
attr_accessor :user_name
attr_accessor :action
attr_accessor :priority
Expand Down
2 changes: 1 addition & 1 deletion app/models/change_item_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ChangeItemType
attr_accessor :item_ids
attr_accessor :email
attr_accessor :comments
attr_accessor :batch_date
attr_accessor :load_date
attr_accessor :user_name
attr_accessor :action
attr_accessor :priority
Expand Down
2 changes: 1 addition & 1 deletion app/models/transfer_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class TransferItem
include FileParser
include ActiveModel::Model
attr_accessor :current_library, :new_library, :new_homeloc, :new_curloc, :new_item_type,
:item_ids, :email, :comments, :batch_date, :user_name, :action,
:item_ids, :email, :comments, :load_date, :user_name, :action,
:priority, :export_yn, :check_bc_first
validates :current_library, :new_library, :new_homeloc, :item_ids,
presence: true
Expand Down
4 changes: 3 additions & 1 deletion app/models/uni_updates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def self.create_for_batch(array_of_item_ids, uni_updates_batch)
array_of_item_ids.each do |item_id|
hashes_for_updates << {
batch_id: uni_updates_batch.batch_id,
load_date: uni_updates_batch.batch_date,
export_yn: uni_updates_batch.export_yn,
priority: uni_updates_batch.priority,
action: uni_updates_batch.action,
Expand All @@ -32,8 +33,9 @@ def self.create_for_batch(array_of_item_ids, uni_updates_batch)
def self.filter_duplicates(item_ids)
uniques = []
duplicates = []
today = Date.parse(Time.now.strftime('%d-%b-%y').upcase)
item_ids.each do |item_id|
if UniUpdates.where(item_id: item_id).empty?
if UniUpdates.where(item_id: item_id, load_date: today).empty?
uniques << item_id
else
duplicates << item_id
Expand Down
10 changes: 5 additions & 5 deletions app/models/uni_updates_batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class UniUpdatesBatch < ActiveRecord::Base

# rubocop:disable Metrics/AbcSize
def self.create_item_type_batch(params, total_bcs)
create(batch_date: params[:change_item_type][:batch_date],
create(batch_date: params[:change_item_type][:load_date],
user_name: params[:change_item_type][:user_name],
user_email: params[:change_item_type][:email],
orig_lib: params[:change_item_type][:current_library],
Expand All @@ -23,7 +23,7 @@ def self.create_item_type_batch(params, total_bcs)
end

def self.create_withdraw_item_batch(params, total_bcs)
create(batch_date: params[:withdraw_item][:batch_date],
create(batch_date: params[:withdraw_item][:load_date],
user_name: params[:withdraw_item][:user_name],
user_email: params[:withdraw_item][:email],
orig_lib: params[:withdraw_item][:current_library],
Expand All @@ -38,7 +38,7 @@ def self.create_withdraw_item_batch(params, total_bcs)
end

def self.create_transfer_item_batch(params, total_bcs)
create(batch_date: params[:transfer_item][:batch_date],
create(batch_date: params[:transfer_item][:load_date],
user_name: params[:transfer_item][:user_name],
user_email: params[:transfer_item][:email],
orig_lib: params[:transfer_item][:current_library],
Expand All @@ -56,7 +56,7 @@ def self.create_transfer_item_batch(params, total_bcs)
end

def self.create_current_location_batch(params, total_bcs)
create(batch_date: params[:change_current_location][:batch_date],
create(batch_date: params[:change_current_location][:load_date],
user_name: params[:change_current_location][:user_name],
user_email: params[:change_current_location][:email],
orig_lib: params[:change_current_location][:current_library],
Expand All @@ -71,7 +71,7 @@ def self.create_current_location_batch(params, total_bcs)
end

def self.create_home_location_batch(params, total_bcs)
create(batch_date: params[:change_home_location][:batch_date],
create(batch_date: params[:change_home_location][:load_date],
user_name: params[:change_home_location][:user_name],
user_email: params[:change_home_location][:user_name],
orig_lib: params[:change_home_location][:current_library],
Expand Down
2 changes: 1 addition & 1 deletion app/models/withdraw_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class WithdrawItem
include FileParser
include ActiveModel::Model
attr_accessor :current_library, :item_ids, :email, :comments, :batch_date,
attr_accessor :current_library, :item_ids, :email, :comments, :load_date,
:user_name, :action, :priority, :export_yn, :check_bc_first
validates :current_library, :item_ids, presence: true
end
2 changes: 1 addition & 1 deletion app/views/change_current_locations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<%= f.text_area 'comments', class: 'form-control' %>
</div>
</div>
<%= f.hidden_field :batch_date, value: Time.now.strftime("%d-%b-%y").upcase %>
<%= f.hidden_field :load_date, value: Time.now.strftime("%d-%b-%y").upcase %>
<%= f.hidden_field :user_name, value: current_user.user_id %>
<%= f.hidden_field :action, value: 'UPDCURLOC' %>
<%= f.hidden_field :priority, value: 3 %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/change_home_locations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<%= f.text_area 'comments', class: 'form-control' %>
</div>
</div>
<%= f.hidden_field :batch_date, value: Time.now.strftime("%d-%b-%y").upcase %>
<%= f.hidden_field :load_date, value: Time.now.strftime("%d-%b-%y").upcase %>
<%= f.hidden_field :user_name, value: current_user.user_id %>
<%= f.hidden_field :action, value: 'UPDHOMELOC' %>
<%= f.hidden_field :priority, value: 3 %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/change_item_types/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<%= f.text_area 'comments', class: 'form-control' %>
</div>
</div>
<%= f.hidden_field :batch_date, value: Time.now.strftime("%d-%b-%y").upcase %>
<%= f.hidden_field :load_date, value: Time.now.strftime("%d-%b-%y").upcase %>
<%= f.hidden_field :user_name, value: current_user.user_id %>
<%= f.hidden_field :action, value: 'UPDITEMTYPE' %>
<%= f.hidden_field :priority, value: 3 %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/transfer_items/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<%= f.text_area 'comments', class: 'form-control' %>
</div>
</div>
<%= f.hidden_field :batch_date, value: Time.now.strftime("%d-%b-%y").upcase %>
<%= f.hidden_field :load_date, value: Time.now.strftime("%d-%b-%y").upcase %>
<%= f.hidden_field :user_name, value: current_user.user_id %>
<%= f.hidden_field :action, value: 'TRANSFER' %>
<%= f.hidden_field :priority, value: 3 %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/withdraw_items/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<%= f.text_area 'comments', class: 'form-control' %>
</div>
</div>
<%= f.hidden_field :batch_date, value: Time.now.strftime("%d-%b-%y").upcase %>
<%= f.hidden_field :load_date, value: Time.now.strftime("%d-%b-%y").upcase %>
<%= f.hidden_field :user_name, value: current_user.user_id %>
<%= f.hidden_field :action, value: 'WITHDRAW' %>
<%= f.hidden_field :priority, value: 3 %>
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/files/test_file.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
123
456
789
011
8 changes: 8 additions & 0 deletions spec/init_libsys_webforms.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
require 'csv'

UnicornPolicy.destroy_all
keys = %w(type policy_num name description shadowed destination)
csv_text = File.read('/Users/jgreben/Projects/libsys-webforms/spec/fixtures/files/unicorn_policies.csv')
csv = CSV.parse(csv_text, headers: false)
csv.map { |a| Hash[keys.zip(a)] }
hash = csv.map { |a| Hash[keys.zip(a)] }
UnicornPolicy.create(hash)

ExpendituresFunds.destroy_all
keys = %w(fund_id fund_name_key old_fund_id min_pay_date max_pay_date is_endow inv_lib)
csv_text = File.read('/Users/jgreben/Projects/libsys-webforms/spec/fixtures/files/expenditures_funds.csv')
Expand Down

0 comments on commit b062467

Please sign in to comment.