Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
aoz-003
Commits
044c0b4e
Commit
044c0b4e
authored
Jun 12, 2018
by
Zsolt Benke
Browse files
Filter volunteers on new billing_expense by period
parent
38e06737
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/controllers/billing_expenses_controller.rb
View file @
044c0b4e
class
BillingExpensesController
<
ApplicationController
before_action
:set_billing_expense
,
only:
[
:show
,
:update_overwritten_amount
,
:destroy
]
before_action
:set_billing_periods
,
only:
[
:index
,
:new
,
:create
]
before_action
:set_selection
,
only:
[
:index
,
:download
]
def
index
authorize
BillingExpense
@billing_periods
=
BillingExpense
.
generate_periods
set_default_filter
(
period:
@billing_periods
.
first
[
:value
])
set_default_filter
(
period:
default_billing_period
)
@q
=
policy_scope
(
BillingExpense
).
ransack
(
params
[
:q
])
@q
.
sorts
=
[
'created_at desc'
]
if
@q
.
sorts
.
empty?
@billing_expenses
=
@q
.
result
...
...
@@ -55,7 +54,7 @@ class BillingExpensesController < ApplicationController
@billing_expense
=
BillingExpense
.
new
authorize
@billing_expense
@q
=
Volunteer
.
with_billable_hours
.
ransack
(
params
[
:q
])
@q
=
Volunteer
.
with_billable_hours
(
selected_billing_period
)
.
ransack
(
params
[
:q
])
@volunteers
=
@q
.
result
@selected_volunteers
=
params
[
:selected_volunteers
].
presence
||
[]
end
...
...
@@ -91,10 +90,26 @@ class BillingExpensesController < ApplicationController
authorize
@billing_expense
end
def
set_billing_periods
@billing_periods
=
BillingExpense
.
generate_periods
end
def
set_selection
@selected_billing_expenses
=
params
[
:selected_billing_expenses
].
presence
||
[]
end
def
default_billing_period
@billing_periods
.
first
[
:value
]
end
def
selected_billing_period
filter
=
params
[
:q
]
return
default_billing_period
unless
filter
.
present?
return
nil
if
filter
[
:all
].
present?
return
filter
[
:period
]
end
def
pdf_file_name
(
record
)
'Spesenauszahlung-'
+
[
...
...
app/views/billing_expenses/index.html.slim
View file @
044c0b4e
...
...
@@ -16,7 +16,7 @@ h1
-
if
@volunteer
=
>
button_link
navigation_glyph
(
:back
),
@volunteer
-
else
=
>
button_link
'Spesenformulare erstellen'
,
new_billing_expense_path
=
>
button_link
'Spesenformulare erstellen'
,
new_billing_expense_path
(
q:
params
[
:q
].
permit!
)
.table-responsive
table
.table
...
...
test/system/billing_expenses_test.rb
View file @
044c0b4e
...
...
@@ -3,34 +3,34 @@ require 'application_system_test_case'
class
BillingExpensesTest
<
ApplicationSystemTestCase
def
setup
superadmin
=
create
:user
date
=
'2018-01-01'
.
to_time
@
date
=
'2018-01-01'
.
to_time
@volunteer1
=
create
:volunteer
,
bank:
'UBS'
@assignment1
=
create
:assignment
,
volunteer:
@volunteer1
create
:hour
,
volunteer:
@volunteer1
,
hourable:
@assignment1
,
hours:
2.5
billed_hour1
=
create
:hour
,
volunteer:
@volunteer1
,
hourable:
@assignment1
,
hours:
3.5
,
meeting_date:
date
hours:
3.5
,
meeting_date:
@
date
@billing_expense1
=
create
:billing_expense
,
volunteer:
@volunteer1
,
hours:
[
billed_hour1
],
created_at:
2
.
hours
.
ago
group_assignment1
=
create
:group_assignment
,
volunteer:
@volunteer1
create
:hour
,
hourable:
group_assignment1
.
group_offer
,
volunteer:
@volunteer1
,
hours:
35
,
meeting_date:
date
hours:
35
,
meeting_date:
@
date
@volunteer2
=
create
:volunteer
assignment2
=
create
:assignment
,
volunteer:
@volunteer2
create
:hour
,
volunteer:
@volunteer2
,
hourable:
assignment2
,
hours:
4.5
,
meeting_date:
date
hours:
4.5
,
meeting_date:
@
date
@volunteer3
=
create
:volunteer
,
iban:
nil
assignment3
=
create
:assignment
,
volunteer:
@volunteer3
create
:hour
,
volunteer:
@volunteer3
,
hourable:
assignment3
,
hours:
2.5
,
meeting_date:
date
hours:
2.5
,
meeting_date:
@
date
@volunteer4
=
create
:volunteer
group_assignment4
=
create
:group_assignment
,
volunteer:
@volunteer4
billed_hour4
=
create
:hour
,
volunteer:
@volunteer4
,
hourable:
group_assignment4
.
group_offer
,
hours:
5.5
,
meeting_date:
date
-
1
.
month
hours:
5.5
,
meeting_date:
@
date
-
1
.
month
@billing_expense4
=
create
:billing_expense
,
volunteer:
@volunteer4
,
hours:
[
billed_hour4
],
created_at:
1
.
hour
.
ago
...
...
@@ -94,6 +94,46 @@ class BillingExpensesTest < ApplicationSystemTestCase
refute_text
@volunteer4
end
test
'new billing_expense respects the period filter'
do
volunteer1
=
create
:volunteer
create
:hour
,
volunteer:
volunteer1
,
hours:
1
,
meeting_date:
@date
-
2
.
month
create
:hour
,
volunteer:
volunteer1
,
hours:
2
,
meeting_date:
@date
-
3
.
month
volunteer2
=
create
:volunteer
create
:hour
,
volunteer:
volunteer2
,
hours:
1
,
meeting_date:
@date
+
1
.
month
create
:hour
,
volunteer:
volunteer2
,
hours:
2
,
meeting_date:
@date
-
2
.
month
volunteer3
=
create
:volunteer
create
:hour
,
volunteer:
volunteer3
,
hours:
1
,
meeting_date:
@date
+
1
.
month
create
:hour
,
volunteer:
volunteer3
,
hours:
2
,
meeting_date:
@date
+
3
.
month
visit
billing_expenses_path
click_link
'Spesenformulare erstellen'
assert_text
"
#{
volunteer2
}
"
assert_text
"
#{
volunteer3
}
"
refute_text
"
#{
volunteer1
}
"
visit
billing_expenses_path
click_link
'Periode: Januar 2018 - Juni 2018'
click_link
'Juli 2017 - Dezember 2017'
click_link
'Spesenformulare erstellen'
assert_text
"
#{
volunteer1
}
"
assert_text
"
#{
volunteer2
}
"
refute_text
"
#{
volunteer3
}
"
visit
billing_expenses_path
click_link
'Periode: Januar 2018 - Juni 2018'
click_link
'Alle'
click_link
'Spesenformulare erstellen'
assert_text
"
#{
volunteer1
}
"
assert_text
"
#{
volunteer2
}
"
assert_text
"
#{
volunteer3
}
"
end
test
'volunteer profile shows only billing expenses for this volunteer'
do
login_as
@volunteer1
.
user
visit
volunteer_path
(
@volunteer1
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment