Class: Spree::Reimbursement
- Inherits:
-
Object
- Object
- Spree::Reimbursement
show all
- Includes:
- NumberIdentifier
- Defined in:
- app/models/spree/reimbursement.rb
Defined Under Namespace
Modules: ReimbursementTypeValidator
Classes: Credit, IncompleteReimbursementError, ReimbursementTypeEngine
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.build_from_customer_return(customer_return) ⇒ Object
81
82
83
84
85
|
# File 'app/models/spree/reimbursement.rb', line 81
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
92
93
94
95
96
|
# File 'app/models/spree/reimbursement.rb', line 92
def calculated_total
return_items.map { |ri| ri.total.to_d.round(2) }.sum
end
|
#display_total ⇒ Object
88
89
90
|
# File 'app/models/spree/reimbursement.rb', line 88
def display_total
Spree::Money.new(total, currency: order.currency)
end
|
#paid_amount ⇒ Object
98
99
100
101
102
|
# File 'app/models/spree/reimbursement.rb', line 98
def paid_amount
reimbursement_models.sum do |model|
model.total_amount_reimbursed_for(self)
end
end
|
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'app/models/spree/reimbursement.rb', line 108
def perform!(performer = nil)
reimbursement_tax_calculator.call(self)
reload
update!(total: calculated_total, performed_by: performer)
reimbursement_performer.perform(self)
if unpaid_amount_within_tolerance?
reimbursed!
reimbursement_success_hooks.each { |h| h.call self }
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
133
134
135
|
# File 'app/models/spree/reimbursement.rb', line 133
def return_items_requiring_exchange
return_items.select(&:exchange_required?)
end
|
#simulate ⇒ Object
125
126
127
128
129
130
131
|
# File 'app/models/spree/reimbursement.rb', line 125
def simulate
reimbursement_simulator_tax_calculator.call(self)
reload
update!(total: calculated_total)
reimbursement_performer.simulate(self)
end
|
#unpaid_amount ⇒ Object
104
105
106
|
# File 'app/models/spree/reimbursement.rb', line 104
def unpaid_amount
total - paid_amount
end
|