Verified Commit 5f52dacd authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻
Browse files

some MR review change requests fullfilling

parent e2429787
Pipeline #22644 failed with stage
in 40 minutes and 52 seconds
......@@ -5,7 +5,7 @@ class BillingExpensesController < ApplicationController
def index
authorize BillingExpense
@billing_semester_filters = BillingExpense.generate_semester_filters
@billing_semester_filters = BillingExpense.generate_semester_filters(:billed)
set_default_filter(semester: default_billing_semester)
@q = policy_scope(BillingExpense).ransack(params[:q])
@q.sorts = ['created_at desc'] if @q.sorts.empty?
......
......@@ -11,9 +11,7 @@ module FormatHelper
def format_hours_semester(hours)
return '' if hours.blank?
dates = hours.map(&:meeting_date)
if dates.size > 1
return format_hours_multiple_dates_semester(dates)
end
return format_hours_multiple_dates_semester(dates) if dates.size > 1
'%s. Semester %s' % [
BillingExpense.semester_of_year(dates.first),
BillingExpense.semester_display_year(dates.first)
......
......@@ -67,12 +67,12 @@ class BillingExpense < ApplicationRecord
bank: volunteer.bank,
iban: volunteer.iban
)
volunteer.update(last_billing_expense: billing_expense_semester(billing_semester))
volunteer.update!(last_billing_expense_on: billing_expense_semester(billing_semester))
end
end
end
def self.generate_semester_filters(scope = :billed)
def self.generate_semester_filters(scope)
scoped_hours = Hour.public_send(scope)
first_semester = semester_from_hours(scoped_hours, date_position: :minimum)
last_semester = semester_from_hours(scoped_hours)
......@@ -88,7 +88,8 @@ class BillingExpense < ApplicationRecord
def self.semester_filter_hash(date)
{ q: :semester, value: date.strftime('%Y-%m-%d'),
text: "#{semester_of_year(date)}. Semester #{semester_display_year(date)}" }
text: I18n.t('semester.one_semester', number: semester_of_year(date),
year: semester_display_year(date)) }
end
def final_amount
......
......@@ -41,27 +41,25 @@ module BillingExpenseSemesterUtils
end
def self.billable_semester_date(date)
if date.blank?
nil
elsif date.is_a?(Time)
date.beginning_of_day
else
Time.zone.parse(date).beginning_of_day
return if date.blank?
unless date.respond_to?(:beginning_of_time)
date = Time.zone.parse(date)
end
date.beginning_of_day
end
def self.dates_semester_start(date)
year = date.year
if semester_of_year(date) == 2
Time.zone.parse("#{date.year}-06-01").beginning_of_day
elsif date.month == 12
Time.zone.parse("#{date.year}-12-01").beginning_of_day
Time.zone.local(year, 6, 1).beginning_of_day
else
Time.zone.parse("#{date.year - 1}-12-01").beginning_of_day
year -= 1 if date.month.eql?(12)
Time.zone.local(year, 12, 1).beginning_of_day
end
end
def self.current_semester_start
@current_semester_start ||= dates_semester_start(Time.zone.now)
dates_semester_start(Time.zone.now)
end
end
end
......@@ -207,19 +207,17 @@ class Volunteer < ApplicationRecord
end
scope :with_billable_hours_meeting_date_semester, lambda { |date|
if date
where('hours.meeting_date < :end_date AND hours.meeting_date >= :start_date',
start_date: date,
end_date: date.advance(months: BillingExpense::SEMESTER_LENGTH))
end
all unless date
where('hours.meeting_date < :end_date AND hours.meeting_date >= :start_date',
start_date: date,
end_date: date.advance(months: BillingExpense::SEMESTER_LENGTH))
}
scope :with_billable_hours_no_expense_in_semester, lambda { |date|
if date
where(last_billing_expense: nil).or(
where.not('volunteers.last_billing_expense = ?', date.to_date)
)
end
all unless date
where(last_billing_expense_on: nil).or(
where.not('volunteers.last_billing_expense_on = ?', date)
)
}
scope :with_billable_hours_select, lambda {
......
......@@ -936,6 +936,9 @@ de:
remember_me: Angemeldet bleiben
reserve: Begleitung erstellen
seeking_clients: Klient/in suchen
semester:
one_semester: '%{number}. Semester %{year}'
two_semesters_same_year: '1. 2. Semester %{year}'
show_my_profile: Mein Profil
simple_form:
error_notification:
......
class AddLastBillingExpenseSemesterToVolunteers < ActiveRecord::Migration[5.1]
def change
add_column :volunteers, :last_billing_expense, :date
add_column :volunteers, :last_billing_expense_on, :datetime
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180713084814) do
ActiveRecord::Schema.define(version: 20180716084125) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......
......@@ -73,7 +73,7 @@ class BillingExpenseTest < ActiveSupport::TestCase
end
test 'generate_semester_filters_without_hours' do
semesters = BillingExpense.generate_semester_filters
semesters = BillingExpense.generate_semester_filters(:billed)
now = Time.zone.now
if (6..11).cover? now.month
value = "#{now.year}-06-01"
......@@ -94,7 +94,7 @@ class BillingExpenseTest < ActiveSupport::TestCase
create :billing_expense, hours: [create(:hour, meeting_date: '2014-02-03'),
create(:hour, meeting_date: '2015-06-30')]
semesters = BillingExpense.generate_semester_filters
semesters = BillingExpense.generate_semester_filters(:billed)
assert_equal [
{ q: :semester, value: '2015-06-01', text: '2. Semester 2015' },
......
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