Commit 872f361d authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻
Browse files

Merge branch 'import_only_active_volunteers_-_ijbIEv2j' into 'develop'

Nur aktive Freiwillige importieren (Mit Begleitung und Gruppeneinsatz)

See merge request !612
parents c63401ae 0f2e29a8
Pipeline #18764 passed with stage
in 38 minutes and 42 seconds
......@@ -24,3 +24,5 @@ public/system
*.vbs
db/bare_db_dump.sql
lib/access_import_test/*.xlsx
.stylelintrc
doc
class ChangeEventKindDefault < ActiveRecord::Migration[5.1]
def change
change_column_default(:events, :kind, nil)
change_column_default(:events, :kind, from: false, to: nil)
change_column_null(:events, :kind, true)
end
end
......@@ -735,6 +735,7 @@ ActiveRecord::Schema.define(version: 20180403135553) do
add_foreign_key "certificates", "volunteers"
add_foreign_key "client_notifications", "users"
add_foreign_key "clients", "users"
add_foreign_key "events", "departments"
add_foreign_key "feedbacks", "users", column: "author_id"
add_foreign_key "group_offers", "departments"
add_foreign_key "group_offers", "group_offer_categories"
......
......@@ -48,7 +48,7 @@ module AccUtils
end
def email(h_email)
return "unknown_email_#{Time.now.to_i}@example.com" if h_email.nil?
return "unknown_email_#{Time.zone.now.to_f}@example.com" if h_email.nil?
h_email.sub(/^\#mailto:/, '').sub(/\#$/, '')
end
......
......@@ -53,37 +53,32 @@ class AccessImport
def make_journal
start_message(:journal)
journal_transform.import_all
Import.client.or(Import.volunteer).find_each do |import|
journal_transform.import_all(
@journale.where_haupt_person(import.store['haupt_person']['pk_Hauptperson'])
)
end
display_stats(Journal)
end
def make_hours
start_message(:hour)
hour_transform.import_all
Import.volunteer.find_each do |import|
hour_transform.import_all(
@stundenerfassung.where_personen_rolle(import.access_id)
)
end
display_stats(Hour)
end
def make_billing_expenses
start_message(:billing_expense)
billing_expense_transform.import_all
display_stats(BillingExpense, Hour)
end
# Terminate Client and Volunteer at the very end, so their termination won't block
# other related records import
#
def run_acceptance_termination_on_clients_and_volunteers
Client.joins(:import).field_not_nil(:resigned_at).or(
Client.joins(:import).where(
'imports.store @> ?',
{ personen_rolle: { pk_PersonenRolle: 1666 } }.to_json
Import.volunteer.find_each do |import|
billing_expense_transform.import_all(
@freiwilligen_entschaedigung.where_personen_rolle(import.access_id)
)
).update_all(acceptance: :resigned)
Volunteer.joins(:import).field_not_nil(:resigned_at).or(
Volunteer.joins(:import)
.where('imports.store @> ?', { haupt_person: { email: nil } }.to_json)
).update_all(acceptance: :resigned)
end
display_stats(BillingExpense, Hour)
end
# Clean up after imports finished
......
......@@ -39,6 +39,7 @@ class AssignmentTransform < Transformer
volunteer ||= @ac_import.volunteer_transform.get_or_create_by_import(
fw_einsatz[:fk_PersonenRolle], freiwilliger
)
return if volunteer.blank?
begleitet = @begleitete.find(fw_einsatz[:fk_Begleitete])
client = @ac_import.client_transform.get_or_create_by_import(begleitet[:fk_PersonenRolle])
return if client.blank?
......
......@@ -23,6 +23,7 @@ class ClientTransform < Transformer
client = get_import_entity(:client, personen_rollen_id)
return client if client.present?
personen_rolle ||= @personen_rolle.find(personen_rollen_id)
return if personen_rolle[:d_Rollenende].present? && personen_rolle[:d_Rollenende] < Time.zone.now
haupt_person = @haupt_person.find(personen_rolle[:fk_Hauptperson]) || {}
client = Client.create!(prepare_attributes(personen_rolle, haupt_person))
if haupt_person == {} # handle access db inconsistencies
......
......@@ -29,6 +29,7 @@ class GroupAssignmentTransform < Transformer
return group_assignment if group_assignment.present?
einsatz ||= @freiwilligen_einsaetze.find(einsatz_id)
volunteer ||= @ac_import.volunteer_transform.get_or_create_by_import(einsatz[:fk_PersonenRolle])
return if volunteer.blank?
group_assignment = GroupAssignment.new(prepare_attributes(einsatz, volunteer))
return group_assignment if group_offer.blank?
group_assignment.group_offer = group_offer
......
......@@ -75,7 +75,7 @@ class GroupOfferTransform < Transformer
end
def grouped_group_assignments(group_assignments)
group_assignments.group_by do |group_assignment|
group_assignments.compact.group_by do |group_assignment|
group_assignment.import.store['freiwilligen_einsatz']['t_Kurzbezeichnung']
end
end
......
......@@ -13,11 +13,12 @@ class HourTransform < Transformer
hour = get_import_entity(:hour, erfassung_id)
return hour if hour.present?
erfassung ||= @stundenerfassung.find(erfassung_id)
return if erfassung[:z_Stundenzahl] <= 0
hourable = get_hourable(erfassung)
return if hourable.blank? || hourable.deleted?
volunteer = get_volunteer(erfassung)
return if volunteer.blank? || volunteer.deleted?
hour = Hour.create(prepare_attributes(erfassung, hourable, volunteer))
hour = Hour.create!(prepare_attributes(erfassung, hourable, volunteer))
update_timestamps(hour, hour.meeting_date)
end
......
......@@ -32,6 +32,7 @@ class VolunteerTransform < Transformer
volunteer = get_import_entity(:volunteer, personen_rollen_id)
return volunteer if volunteer.present?
personen_rolle ||= @personen_rolle.find(personen_rollen_id)
return if personen_rolle[:d_Rollenende].present? && personen_rolle[:d_Rollenende] < Time.zone.now
volunteer = Volunteer.new(prepare_attributes(personen_rolle))
volunteer.save!(validate: false)
update_timestamps(volunteer, personen_rolle[:d_Rollenbeginn], personen_rolle[:d_MutDatum])
......
......@@ -9,13 +9,7 @@ class AccessImportsTest < ActiveSupport::TestCase
assert_basic_values(result[:row], result[:found])
end
puts "Verified #{found_active_volunteers.size} volunteer records."
active_volunteer_ids = found_active_volunteers.map { |hash| hash[:found].id }
Volunteer.where.not(id: active_volunteer_ids).each do |volunteer|
assert volunteer.resigned?, "Volunteer(id: #{volunteer.id}, full_name: "\
"#{volunteer.contact.full_name}) not resigned, but it should have been"
end
puts "\nVerified #{found_active_volunteers.size} volunteer records.\n"
end
test 'active_clients' do
......@@ -25,13 +19,7 @@ class AccessImportsTest < ActiveSupport::TestCase
assert_basic_values(result[:row], result[:found])
end
puts "Verified #{found_active_clients.size} client records."
active_client_ids = found_active_clients.map { |hash| hash[:found].id }
Client.where.not(id: active_client_ids).each do |client|
assert client.resigned?, "Client(id: #{client.id}, full_name: "\
"#{client.contact.full_name}) not resigned, but it should have been"
end
puts "\nVerified #{found_active_clients.size} client records.\n"
end
def assert_basic_values(row, found)
......
......@@ -11,13 +11,29 @@ namespace :access do
@acimport.make_billing_expenses
@acimport.make_journal
@acimport.make_hours
@acimport.run_acceptance_termination_on_clients_and_volunteers
@acimport.overall_stats
else
warn 'No access file set. run "rails access:import file=path/to/access_file.accdb"'
end
end
desc 'Test imports'
task test: :environment do
if Rails.env.production?
abort 'This task should never be executed on a Production instance'
end
if Import.blank?
if ENV['file'].present?
Rake::Task['access:import'].invoke
else
warn 'No access file set!'
abort 'run "rails access:test file=path/to/access_file.accdb"'
end
end
Rails::TestUnit::Runner.rake_run(['lib/access_import_test'])
end
desc 'Set all Volunteers that where imported and created before May 2018 to intro_course = true'
task cleanup_afterwards: :environment do
# Make sure terminated assignments have log entry
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment