Added has_many assoziations for creator and cashier to jobs, fixed all views according to that changes. Implemented allocation of roles infos when status changes in job model.

This commit is contained in:
2024-10-01 17:45:52 +02:00
parent de3aa07259
commit 5b60eb64ad
13 changed files with 212 additions and 69 deletions

View File

@@ -1,17 +1,19 @@
class CreateJobs < ActiveRecord::Migration[7.1]
def change
create_table :jobs do |t|
t.references :operator, null: true
t.references :costumer, null: true
t.string :operator_firstname
t.string :operator_lastname
t.references :creator, null: true
t.references :cashier, null: true
t.references :operator, null: true
t.string :costumer_firstname
t.string :costumer_lastname
t.boolean :printed, default: false
t.boolean :paid, default: false
t.string :operator_firstname
t.string :operator_lastname
t.string :cashier_firstname
t.string :cashier_lastname
t.datetime :printed_at
t.datetime :status_changed_at
t.datetime :paid_at
t.datetime :status_changed_at
t.boolean :intern, default: false
t.string :cost_center
t.string :status, default: "open", index: true

View File

@@ -12,10 +12,14 @@ class CreateUsers < ActiveRecord::Migration[7.2]
t.integer :jobs_as_costumer_count, default: 0
t.integer :jobs_as_operator_count, default: 0
t.integer :created_jobs_count, default: 0
t.integer :cashed_jobs_count, default: 0
t.timestamps
end
add_foreign_key :jobs, :users, column: :operator_id
add_foreign_key :jobs, :users, column: :costumer_id
add_foreign_key :jobs, :users, column: :operator_id
add_foreign_key :jobs, :users, column: :creator_id
add_foreign_key :jobs, :users, column: :cashier_id
end
end

20
db/schema.rb generated
View File

@@ -40,17 +40,19 @@ ActiveRecord::Schema[7.2].define(version: 2024_08_26_144016) do
end
create_table "jobs", force: :cascade do |t|
t.integer "operator_id"
t.integer "costumer_id"
t.string "operator_firstname"
t.string "operator_lastname"
t.integer "creator_id"
t.integer "cashier_id"
t.integer "operator_id"
t.string "costumer_firstname"
t.string "costumer_lastname"
t.boolean "printed", default: false
t.boolean "paid", default: false
t.string "operator_firstname"
t.string "operator_lastname"
t.string "cashier_firstname"
t.string "cashier_lastname"
t.datetime "printed_at"
t.datetime "status_changed_at"
t.datetime "paid_at"
t.datetime "status_changed_at"
t.boolean "intern", default: false
t.string "cost_center"
t.string "status", default: "open"
@@ -65,7 +67,9 @@ ActiveRecord::Schema[7.2].define(version: 2024_08_26_144016) do
t.boolean "created_by_operator", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["cashier_id"], name: "index_jobs_on_cashier_id"
t.index ["costumer_id"], name: "index_jobs_on_costumer_id"
t.index ["creator_id"], name: "index_jobs_on_creator_id"
t.index ["operator_id"], name: "index_jobs_on_operator_id"
t.index ["status"], name: "index_jobs_on_status"
end
@@ -88,6 +92,8 @@ ActiveRecord::Schema[7.2].define(version: 2024_08_26_144016) do
t.boolean "verified", default: false, null: false
t.integer "jobs_as_costumer_count", default: 0
t.integer "jobs_as_operator_count", default: 0
t.integer "created_jobs_count", default: 0
t.integer "cashed_jobs_count", default: 0
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["email"], name: "index_users_on_email", unique: true
@@ -96,7 +102,9 @@ ActiveRecord::Schema[7.2].define(version: 2024_08_26_144016) do
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "jobs", "users", column: "cashier_id"
add_foreign_key "jobs", "users", column: "costumer_id"
add_foreign_key "jobs", "users", column: "creator_id"
add_foreign_key "jobs", "users", column: "operator_id"
add_foreign_key "sessions", "users"
end

View File

@@ -15,8 +15,9 @@ User.create!(email: "david.boehm@hs-rm.de", firstname: "David", lastname: "Böhm
User.create!(email: "maximilian.lasser@hs-rm.de", firstname: "Max", lastname: "Lasser", role: :admin, password_digest: BCrypt::Password.create("admin"), verified: true)
# Operators
User.create!(email: "tutor.operator@hs-rm.de", firstname: "Tutor", lastname: "Operator", role: :operator, password_digest: BCrypt::Password.create("operator"), verified: true)
User.create!(email: "tutor2.operator@hs-rm.de", firstname: "Tutor2", lastname: "Operator", role: :operator, password_digest: BCrypt::Password.create("operator"), verified: true)
operators = []
operators << User.create!(email: "tutor.operator@hs-rm.de", firstname: "Tutor", lastname: "Operator", role: :operator, password_digest: BCrypt::Password.create("operator"), verified: true)
operators << User.create!(email: "tutor2.operator@hs-rm.de", firstname: "Tutor2", lastname: "Operator", role: :operator, password_digest: BCrypt::Password.create("operator"), verified: true)
# Students
User.create!(email: "stud.student@student.hs-rm.de", firstname: "Student", lastname: "Student", password_digest: BCrypt::Password.create("stud"), verified: true)
@@ -54,7 +55,7 @@ end
# created_at = Faker::Time.between_dates(from: Date.today - 60, to: Date.today, period: :day)
email="#{firstname}.#{lastname}@student.hs-rm.de".downcase.gsub('ö', 'oe').gsub('ä', 'ae').gsub('ü', 'ue').gsub('ß', 'ss')
email.delete(" ")
user=User.new(email: email, firstname: firstname, lastname: lastname, password_digest: BCrypt::Password.create("password"), verified: false, created_at: created_at).save!
User.new(email: email, firstname: firstname, lastname: lastname, password_digest: BCrypt::Password.create("password"), verified: false, created_at: created_at).save!
end
# Jobs paid (and some canceled) in the far past
@@ -76,7 +77,12 @@ end
end
job = Job.new(status:, privacy_policy: true, created_at: created_at)
job.pdf = File.open(Rails.root.join('db/pdfs/', pdf))
job.costumer = students[rand(0...9)]
student = students[rand(0..9)]
job.costumer = student
job.creator = student
operator = operators[rand(0...1)]
job.operator = operator if status != :open
job.cashier = operator if status == :paid
job.save!
job.update_column :printed_at, printed_at # write with update_column to avoid before_save action
job.update_column :status_changed_at, status_changed_at # write with update_column to avoid before_save action
@@ -105,7 +111,12 @@ end
end
job = Job.new(status:, privacy_policy: true, created_at: created_at)
job.pdf = File.open(Rails.root.join('db/pdfs/', pdf))
job.costumer = students[rand(0...9)]
student = students[rand(0...9)]
job.costumer = student
job.creator = student
operator = operators[rand(0...1)]
job.operator = operator if status == :paid
job.cashier = operator if status == :paid
job.save!
job.update_column :printed_at, printed_at # write with update_column to avoid before_save action
job.update_column :status_changed_at, status_changed_at # write with update_column to avoid before_save action
@@ -125,7 +136,28 @@ end
status = :open if i > 0
job = Job.new(status:, privacy_policy: true)
job.pdf = File.open(Rails.root.join('db/pdfs/', pdf))
job.costumer = students[rand(0...4)]
student = students[rand(0...4)]
job.costumer = student
job.creator = student
operator = operators[rand(0...1)]
job.operator = operator if status != :open
job.cashier = operator if status == :paid
job.save!
end
end
# Jobs created from operator
[ 'GanzWichtig.pdf', 'IchBinIn5MinDran.pdf', 'DerPlanDerImmerProblemeMacht.pdf',
'DieFarbenGefallenMirNicht.pdf', 'MachHinIchHabsEilig.pdf', 'WarumDauertDasSoLange.pdf',
'DenPlanBezahleIchNicht.pdf', 'IchWarAlsErstesDran.pdf', 'WarumIstDerPlotterDefekt.pdf',
'DasNächsteMalGeheIchWoAndersHin.pdf' ].shuffle.each do |pdf|
job = Job.new(privacy_policy: true)
job.pdf = File.open(Rails.root.join('db/pdfs/', pdf))
job.costumer = students[rand(0...9)]
job.costumer_firstname = job.costumer.firstname
job.costumer_lastname = job.costumer.lastname
job.creator = operators[rand(0...1)]
job.created_by_operator = true
job.inspect
job.save!
end