Verified Commit 067ad272 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻
Browse files

get quittierte assignment archived to assignment_log

- in volunteers#show only the unterminated assignments are listed
   - the assignment is logged by quittieren, so the AssignmentLog copy
     gets displayed
parent cdb7861e
......@@ -113,6 +113,7 @@ class AssignmentsController < ApplicationController
def verify_termination
@assignment.update(termination_verified_at: Time.zone.now,
termination_verified_by: current_user)
@assignment.create_log_of_self
redirect_back(fallback_location: terminated_index_assignments_path)
flash[:notice] = 'Der Einsatz wurde erfolgreich quittiert.'
end
......
......@@ -46,13 +46,18 @@ class Assignment < ApplicationRecord
ended? && termination_submitted_by.present?
end
private
def create_log_of_self_and_delete_self
def create_log_of_self
return false if running? # prevent deleteing of running assignment
log = AssignmentLog.new(attributes.except('id', 'created_at', 'updated_at'))
log.assignment = self
log.save
log
end
private
def create_log_of_self_and_delete_self
create_log_of_self
delete
end
end
......@@ -19,6 +19,11 @@ module AssignmentCommon
scope :zurich, (-> { joins(:client).merge(Client.zurich) })
scope :not_zurich, (-> { joins(:client).merge(Client.not_zurich) })
scope :termination_submitted, (-> { where.not(termination_submitted_by_id: nil) })
scope :termination_not_submitted, (-> { where(termination_submitted_by_id: nil) })
scope :unterminated, (-> { where(termination_verified_by_id: nil) })
scope :terminated, (-> { where.not(termination_verified_by_id: nil) })
def creator
super || User.deleted.find_by(id: creator_id)
end
......
......@@ -173,7 +173,7 @@ h3= t('.availability')
- if @volunteer.assignments.any?
h3#assignments Begleitungen
= render 'assignments/client_volunteer_index', assignments: @volunteer.assignments
= render 'assignments/client_volunteer_index', assignments: @volunteer.assignments.unterminated
- if @volunteer.assignment_logs.any?
h3 Archivierte Begleitungen
......
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