Class: Spree::Reimbursement
- Inherits:
-
Base
- Object
- ApplicationRecord
- Base
- Spree::Reimbursement
show all
- Defined in:
- app/models/spree/reimbursement.rb
Defined Under Namespace
Modules: ReimbursementTypeValidator
Classes: Credit, IncompleteReimbursementError, ReimbursementTypeEngine
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
page, spree_base_scopes
#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Class Method Details
.build_from_customer_return(customer_return) ⇒ Object
76
77
78
79
80
81
82
|
# File 'app/models/spree/reimbursement.rb', line 76
def build_from_customer_return(customer_return)
order = customer_return.order
order.reimbursements.build({
customer_return: customer_return,
return_items: customer_return.return_items.accepted.not_reimbursed,
})
end
|
Instance Method Details
#calculated_total ⇒ Object
89
90
91
92
93
|
# File 'app/models/spree/reimbursement.rb', line 89
def calculated_total
return_items.map { |ri| ri.total.to_d.round(2) }.sum
end
|
#display_total ⇒ Object
85
86
87
|
# File 'app/models/spree/reimbursement.rb', line 85
def display_total
Spree::Money.new(total, { currency: order.currency })
end
|
#paid_amount ⇒ Object
95
96
97
98
99
|
# File 'app/models/spree/reimbursement.rb', line 95
def paid_amount
reimbursement_models.sum do |model|
model.total_amount_reimbursed_for(self)
end
end
|
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'app/models/spree/reimbursement.rb', line 105
def perform!
reimbursement_tax_calculator.call(self)
reload
update!(total: calculated_total)
reimbursement_performer.perform(self)
if unpaid_amount_within_tolerance?
reimbursed!
reimbursement_success_hooks.each { |h| h.call self }
send_reimbursement_email
else
errored!
reimbursement_failure_hooks.each { |h| h.call self }
raise IncompleteReimbursementError, Spree.t("validation.unpaid_amount_not_zero", amount: unpaid_amount)
end
end
|
#return_items_requiring_exchange ⇒ Object
131
132
133
|
# File 'app/models/spree/reimbursement.rb', line 131
def return_items_requiring_exchange
return_items.select(&:exchange_required?)
end
|
#simulate ⇒ Object
123
124
125
126
127
128
129
|
# File 'app/models/spree/reimbursement.rb', line 123
def simulate
reimbursement_simulator_tax_calculator.call(self)
reload
update!(total: calculated_total)
reimbursement_performer.simulate(self)
end
|
#unpaid_amount ⇒ Object
101
102
103
|
# File 'app/models/spree/reimbursement.rb', line 101
def unpaid_amount
total - paid_amount
end
|