Skip to content

Commit

Permalink
Number imports
Browse files Browse the repository at this point in the history
  • Loading branch information
mtnstar committed Jul 29, 2024
1 parent 3e8d165 commit 474bc13
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 29 deletions.
2 changes: 1 addition & 1 deletion app/domain/sac_imports/membership_years_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MembershipYearsReport
def initialize(output: $stdout)
@output = output
@source_file = CsvSourceFile.new(:NAV2)
@csv_report = CsvReport.new(:membership_years_report, REPORT_HEADERS)
@csv_report = CsvReport.new(:'6_membership_years_report', REPORT_HEADERS)
end

def create
Expand Down
24 changes: 12 additions & 12 deletions doc/import.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,58 +30,58 @@ Jeder Import erstellt einen CSV Report in RAILS_CORE_ROOT/log/sac_imports/. In d

Siehe [SacImports::CsvReport](../app/domain/sac_imports/csv_report.rb)

## Hitobito SAC Import 1: sac_imports:1_people
## 1: sac_imports:1_people

Diesen Import immer als erstes laufen lassen damit alle Personen in der DB vorhanden sind und entsprechend in andere Gruppen via Rollen assigned werden können.

Importiert alle Navision Kontakte und legt diese Unter `Top-Layer > Navision Import` ab.

`rake import:people FILE=tmp/xlsx/personen.xlsx REIMPORT_ALL=true`
`rake sac_imports:1_people FILE=tmp/xlsx/personen.xlsx REIMPORT_ALL=true`

Import Source File: **NAV1**

## Hitobito SAC Import 2: sac_imports:sektionen
## 2: sac_imports:2_sektionen

Mit diesem Import werden alle Sektionen und Ortsgruppen importiert.
Auf jeder Sektion/Ortsgruppe werden auch Attribute wie z.B. Kanton, Gründungsjahr usw. gesetzt

`rake import:sektionen`
`rake sac_imports:2_sektionen`

file: $CORE_ROOT/tmp/xlsx/sektionen.xlsx

- Importiert Sektionen/Ortsgruppen und erstellt deren Unterordnerstruktur

Import Source File: **NAV6**

## Hitobito SAC Import 3: sac_imports:huts
## 3: sac_imports:3_huts

Importiert alle Hütten und hängt diese unter den Sektionen entsprechend ein. Ausserdem werden die Hüttenfunktionärs-Rollen gleich mitangelegt.

`rake import:huts`
`rake sac_imports:huts`

file: $CORE_ROOT/tmp/xlsx/huetten_beziehungen.xlsx

Import Source File: **NAV5**

## Hitobito SAC Import 4: sac_imports:memberships
## 4: sac_imports:4_memberships

Importiert alle aktiven und inaktiven Stammsektions-Mitglied-Rollen.

`rails import:memberships FILE=tmp/xlsx/mitglieder_aktive.xlsx REIMPORT_ALL=true)`
`rake sac_imports:memberships FILE=tmp/xlsx/mitglieder_aktive.xlsx REIMPORT_ALL=true)`

Import Source File: **NAV2**

## Hitobito SAC Import 5: sac_imports:additional_memberships
## 5: sac_imports:5_additional_memberships

Sicherstellen das Import Mitglieder Stammsektion bereits ausgeführt wurde. Eine Mitgliedschaft Zusatzsektion ist nur möglich falls bereits eine Mitglied Stammsektion Rolle vorhanden ist.

`rails import:additional_memberships FILE=tmp/xlsx/zusatzmitgliedschaften.xlsx REIMPORT_ALL=true)`
`rake sac_imports:5_additional_memberships FILE=tmp/xlsx/zusatzmitgliedschaften.xlsx REIMPORT_ALL=true)`

Import Source File: **NAV3**

## Hitobito SAC Import 6: sac_imports:additional_memberships
## 6: sac_imports:additional_memberships

`rails sac_imports:membership_years_report`
`rake sac_imports:membership_years_report`

- Import Source File: **NAV2**
- CSV Report Output: `RAILS_CORE_ROOT/log/sac_imports/6_membership_years_report_2024-06-01-12:00.csv`
Expand Down
29 changes: 15 additions & 14 deletions lib/tasks/sac_imports.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,33 @@
# https://github.com/hitobito/hitobito_sac_cas.

namespace :sac_imports do

desc "Import all people from a navision export xlsx" \
" (options: FILE=tmp/xlsx/personen.xlsx REIMPORT_ALL=true)"
task 1_people: [:environment] do
SacImports::PeopleImporter.new(
Pathname(ENV["FILE"].to_s),
skip_existing: !["1", "true"].include?(ENV["REIMPORT_ALL"].to_s.downcase)
).import!
end

desc "Import sections from a navision export (tmp/xlsx/sektionen.xlsx)"
task sektionen: [:environment] do
task 2_sektionen: [:environment] do
import_file_path = "tmp/xlsx/sektionen.xlsx"
sektionen_excel = Rails.root.join(import_file_path)
SacImports::SektionenImporter.new(sektionen_excel).import!
end

desc "Import huts from a navision export"
task huts: [:environment] do
task 3_huts: [:environment] do
import_file_path = "tmp/xlsx/huetten_beziehungen.xlsx"
hut_relations_excel = Rails.root.join(import_file_path)
SacImports::HutsImporter.new(hut_relations_excel).import!
end

desc "Import all people from a navision export xlsx" \
" (options: FILE=tmp/xlsx/personen.xlsx REIMPORT_ALL=true)"
task people: [:environment] do
SacImports::PeopleImporter.new(
Pathname(ENV["FILE"].to_s),
skip_existing: !["1", "true"].include?(ENV["REIMPORT_ALL"].to_s.downcase)
).import!
end

desc "Import memberships from a navision export xlsx" \
" (options: FILE=tmp/xlsx/mitglieder_aktive.xlsx REIMPORT_ALL=true)"
task memberships: [:environment] do
task 4_memberships: [:environment] do
SacImports::Sektion::MembershipsImporter.new(
Pathname(ENV["FILE"].to_s),
skip_existing: !["1", "true"].include?(ENV["REIMPORT_ALL"].to_s.downcase)
Expand All @@ -40,15 +41,15 @@ namespace :sac_imports do

desc "Import additional memberships from a navision export xlsx" \
" (options: FILE=tmp/xlsx/zusatzmitgliedschaften.xlsx REIMPORT_ALL=true)"
task additonal_memberships: [:environment] do
task 5_additonal_memberships: [:environment] do
SacImports::Sektion::AdditionalMembershipsImporter.new(
Pathname(ENV["FILE"].to_s),
skip_existing: !["1", "true"].include?(ENV["REIMPORT_ALL"].to_s.downcase)
).import!
end

desc "Analyse imported and calculated membership years and create report"
task membership_years_report: [:environment] do
task 6_membership_years_report: [:environment] do
SacImports::MembershipYearsReport.new.create
end
end
2 changes: 1 addition & 1 deletion spec/domain/sac_imports/csv_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
describe SacImports::CsvReport do
let(:headers) { %i[membership_number sac_family_number name stammsektion] }
let(:csv_report) { described_class.new(:sektion_membership, headers) }
let(:report_file) { Rails.root.join("log", "sac_imports", "sektion_membership_#{Time.zone.now.strftime("%Y-%m-%d-%H:%M")}.csv") }
let(:report_file) { Rails.root.join("log", "sac_imports", "4_import_memberships_#{Time.zone.now.strftime("%Y-%m-%d-%H:%M")}.csv") }
let(:csv_content) { CSV.read(report_file, col_sep: ";") }

it "creates csv log with headers and appends rows" do
Expand Down
2 changes: 1 addition & 1 deletion spec/domain/sac_imports/membership_years_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
describe SacImports::MembershipYearsReport do
let(:nav2_csv_fixture) { File.expand_path("../../../fixtures/files/sac_imports_src/NAV2_stammmitgliedschaften_2024-01-04.csv", __FILE__) }
let(:report) { described_class.new }
let(:report_file) { Rails.root.join("log", "sac_imports", "membership_years_report_2024-01-23-11:42.csv") }
let(:report_file) { Rails.root.join("log", "sac_imports", "6_membership_years_report_2024-01-23-11:42.csv") }
let(:report_headers) { %w[membership_number person_name navision_membership_years hitobito_membership_years diff errors] }
let(:csv_report) { CSV.read(report_file, col_sep: ";") }

Expand Down

0 comments on commit 474bc13

Please sign in to comment.