Commit 1229484f authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻 Committed by Kaspar
Browse files

directly create billing expense from volunteer view

parent a4000dab
class BillingExpense < ApplicationRecord
include FullBankDetails
before_validation :compute_amount
before_validation :auto_set_amount
belongs_to :volunteer
belongs_to :user, -> { with_deleted }
has_many :hours
......@@ -25,6 +26,10 @@ class BillingExpense < ApplicationRecord
super(compute_amount)
end
def auto_set_amount
self.amount = nil
end
def compute_amount
hour_count = id ? hours_sum : volunteer.billable_hours_sum
if hour_count > 50
......
......@@ -30,7 +30,9 @@ h1= t_title(:index, BillingExpense)
td= link_to t_action(:destroy), volunteer_billing_expense_path(@volunteer, record), confirm_deleting(record)
.row
.col-xs-12
= form_navigation_btn :new
= simple_form_for [@volunteer, BillingExpense.new] do |f|
= f.hidden_field :volunteer_id, value: @volunteer.id
= f.button :submits
.row
.col-xs-12
= button_link t('back'), @volunteer
......@@ -10,7 +10,11 @@ nav.navbar.section-navigation
- if @volunteer.seeking_clients?
li = button_link t_title(:new, Assignment), new_assignment_path(volunteer_id: @volunteer)
- if @volunteer.assignments.any?
li = button_link t_title(:new, BillingExpense), new_volunteer_billing_expense_path(@volunteer)
li
= simple_form_for [@volunteer, BillingExpense.new] do |f|
= f.hidden_field :volunteer_id, value: @volunteer.id
= f.button :submits
- if @volunteer.billing_expenses.any?
li = button_link t_title(:index, BillingExpense), volunteer_billing_expenses_path(@volunteer)
- if @volunteer.assignments?
li= button_link t('.new_certificate'), new_volunteer_certificate_path(@volunteer)
......
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