Commit 06af8184 authored by Jakub Motycka's avatar Jakub Motycka
Browse files

Merge branch 'develop' into 'main'

Production deploy

See merge request !1225
parents bedeba28 b1d66518
Pipeline #140864 passed with stage
in 12 minutes and 28 seconds
......@@ -16,6 +16,9 @@ class BillingExpense < ApplicationRecord
belongs_to :spa_summary, optional: true
has_many :hours, dependent: :nullify
has_many :assignments, through: :hours, source: :hourable, source_type: 'Assignment'
has_many :group_offers, through: :hours, source: :hourable, source_type: 'GroupOffer'
default_scope { order(created_at: :desc) }
scope :semester, lambda { |date|
......@@ -79,6 +82,31 @@ class BillingExpense < ApplicationRecord
end
# end class methods
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/PerceivedComplexity
def detected_kst
if assignments.count > 0
if assignments.count > 1
assignment_id = hours.where(hourable_type: 'Assignment').group(:hourable_id).order('sum_hours desc').sum(:hours).first[0]
assignment = Assignment.find(assignment_id)
else
assignment = assignments.first
end
client = assignment.client
if ['city', 'canton_dz'].include?(client.cost_unit)
'3140001'
elsif ['canton', 'canton_mna', 'refugee_housing', 'canton_tandem'].include?(client.cost_unit)
'3140002'
else
''
end
elsif group_offers.count > 0
'3140001'
end
end
# rubocop:enable Metrics/PerceivedComplexity
# rubocop:enable Metrics/AbcSize
def add_semester_relations!(semester_date)
self.start_of_semester = semester_date
......
......@@ -119,6 +119,9 @@ class Volunteer < ApplicationRecord
validates :terms_of_use_accepted, acceptance: { accept: '1' }, presence: true, if: -> { validate_terms_of_use_acceptance }
# sql condition != does not include NULL sources
scope :without_shortterm, -> { where('entry_source IS NULL or entry_source != ?', Volunteer.entry_sources[:shortterm_application_form]) }
scope :with_staffomatic, -> { where.not(staffomatic_user_id: nil) }
scope :without_staffomatic, -> { where(staffomatic_user_id: nil) }
......@@ -199,6 +202,7 @@ class Volunteer < ApplicationRecord
def self.semester_process_eligible(semester)
joins(:contact).where.not(id: have_semester_process(semester).ids)
.without_shortterm
.active_semester_mission(semester)
end
......
......@@ -93,7 +93,7 @@
p
= t('billing_expense_pdf.kst')
br
'3120000
= @billing_expense.detected_kst
td
p
= t('billing_expense_pdf.amount')
......
......@@ -172,4 +172,53 @@ class BillingExpenseTest < ActiveSupport::TestCase
assert_equal sorted_by_desc[i], billing_expense
end
end
test 'detected_kst' do
volunteer = create :volunteer
volunteer2 = create :volunteer, bank: 'Bank 2'
creator = volunteer2.registrar
group_assignment1 = create :group_assignment, volunteer: volunteer2, creator: creator
group_offer = group_assignment1.group_offer
group_offer.title = 'Group offer'
group_offer.group_offer_category = create :group_offer_category
group_offer.department = create :department
group_offer.save
hour2g = create :hour, volunteer: volunteer2, hours: 75, meeting_date: 10.days.ago,
hourable: group_assignment1.group_offer
billing_expense = create :billing_expense, volunteer: volunteer, hours: [hour2g]
# only group offer
assert_equal '3140001', billing_expense.detected_kst
hour1 = create :hour, volunteer: volunteer, hours: 1
hour2 = create :hour, volunteer: volunteer, hours: 2
hour3 = create :hour, volunteer: volunteer, hours: 3
billing_expense = create :billing_expense, volunteer: volunteer,
hours: [hour2g, hour1, hour2, hour3]
assert_equal '', billing_expense.detected_kst
# group offer with assignment city
hour3.hourable.client.city!
assert_equal '3140001', billing_expense.detected_kst
# group offer with assignment canton_dz
hour3.hourable.client.canton_dz!
assert_equal '3140001', billing_expense.detected_kst
# group offer with assignment canton
hour3.hourable.client.canton!
assert_equal '3140002', billing_expense.detected_kst
# group offer with assignment canton_mna
hour3.hourable.client.canton_mna!
assert_equal '3140002', billing_expense.detected_kst
# group offer with assignment refugee_housing
hour3.hourable.client.refugee_housing!
assert_equal '3140002', billing_expense.detected_kst
# group offer with assignment canton_tandem
hour3.hourable.client.canton_tandem!
assert_equal '3140002', billing_expense.detected_kst
# group offer with assignment canton_tandem
hour3.hourable.client.ukraine!
assert_equal '', billing_expense.detected_kst
end
end
......@@ -282,4 +282,41 @@ class VolunteerTest < ActiveSupport::TestCase
@volunteer.accepted!
end
end
test 'sum of volunteers with and without shortterm is same' do
volunteer2 = create :volunteer
@volunteer.shortterm_application_form!
assert_equal(Volunteer.count, Volunteer.shortterm_application_form.count + Volunteer.without_shortterm.count)
end
test 'semester_process_eligible does not include shortterm' do
volunteer2 = create :volunteer
active_assignment = create(:assignment, :active, { volunteer: volunteer2 })
semester_process = create :semester_process
semester = semester_process.semester
semester = (active_assignment.period_start..active_assignment.period_start.advance(weeks: 5))
semester_process.semester = semester
semester_process.save
@volunteer.shortterm_application_form!
eligible_ids = Volunteer.semester_process_eligible(semester_process.semester).collect(&:id)
refute_includes(eligible_ids, @volunteer.id)
end
test 'semester_process_eligible includes not shortterm' do
volunteer2 = create :volunteer
active_assignment = create(:assignment, :active, { volunteer: volunteer2 })
semester_process = create :semester_process
semester = semester_process.semester
semester = (active_assignment.period_start..active_assignment.period_start.advance(weeks: 5))
semester_process.semester = semester
semester_process.save
volunteer2.application_form!
eligible_ids = Volunteer.semester_process_eligible(semester_process.semester).collect(&:id)
assert_includes(eligible_ids, volunteer2.id)
end
end
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