Class: Spree::Reimbursement
- Inherits:
-
Base
- Object
- ActiveRecord::Base
- Base
- Spree::Reimbursement
show all
- Defined in:
- app/models/spree/reimbursement.rb,
app/models/spree/reimbursement/credit.rb
Defined Under Namespace
Modules: ReimbursementTypeValidator
Classes: Credit, IncompleteReimbursementError, ReimbursementTypeEngine
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
display_includes, page, preference, #preferences
#generate_permalink, #save_permalink
Class Method Details
.build_from_customer_return(customer_return) ⇒ Object
65
66
67
68
69
70
71
|
# File 'app/models/spree/reimbursement.rb', line 65
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
#all_exchanges? ⇒ Boolean
148
149
150
|
# File 'app/models/spree/reimbursement.rb', line 148
def all_exchanges?
return_items.all?(&:exchange_processed?)
end
|
#any_exchanges? ⇒ Boolean
144
145
146
|
# File 'app/models/spree/reimbursement.rb', line 144
def any_exchanges?
return_items.any?(&:exchange_processed?)
end
|
#calculated_total ⇒ Object
78
79
80
81
82
|
# File 'app/models/spree/reimbursement.rb', line 78
def calculated_total
return_items.to_a.sum(&:total).to_d.round(2, :down)
end
|
#display_total ⇒ Object
74
75
76
|
# File 'app/models/spree/reimbursement.rb', line 74
def display_total
Spree::Money.new(total, { currency: order.currency })
end
|
#paid_amount ⇒ Object
84
85
86
87
88
|
# File 'app/models/spree/reimbursement.rb', line 84
def paid_amount
reimbursement_models.sum do |model|
model.total_amount_reimbursed_for(self)
end
end
|
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'app/models/spree/reimbursement.rb', line 94
def perform!(created_by: nil)
unless created_by
Spree::Deprecation.warn("Calling #perform on #{self} without created_by is deprecated")
end
reimbursement_tax_calculator.call(self)
reload
update!(total: calculated_total)
reimbursement_performer.perform(self, created_by: created_by)
if unpaid_amount_within_tolerance?
reimbursed!
Spree::Event.fire 'reimbursement_reimbursed', reimbursement: self
if reimbursement_success_hooks.any?
Spree::Deprecation.warn \
"reimbursement_success_hooks are deprecated. Please remove them " \
"and subscribe to `reimbursement_reimbursed` event instead", caller(1)
end
reimbursement_success_hooks.each { |hook| hook.call self }
else
errored!
Spree::Event.fire 'reimbursement_errored', reimbursement: self
if reimbursement_failure_hooks.any?
Spree::Deprecation.warn \
"reimbursement_failure_hooks are deprecated. Please remove them " \
"and subscribe to `reimbursement_errored` event instead", caller(1)
end
reimbursement_failure_hooks.each { |hook| hook.call self }
end
if errored?
raise IncompleteReimbursementError, I18n.t("spree.validation.unpaid_amount_not_zero", amount: unpaid_amount)
end
end
|
#return_all(created_by: nil) ⇒ void
This method returns an undefined value.
Accepts all return items, saves the reimbursement, and performs the reimbursement
157
158
159
160
161
162
163
164
|
# File 'app/models/spree/reimbursement.rb', line 157
def return_all(created_by: nil)
unless created_by
Spree::Deprecation.warn("Calling #return_all on #{self} without created_by is deprecated")
end
return_items.each(&:accept!)
save!
perform!(created_by: created_by)
end
|
#return_items_requiring_exchange ⇒ Object
140
141
142
|
# File 'app/models/spree/reimbursement.rb', line 140
def return_items_requiring_exchange
return_items.select(&:exchange_required?)
end
|
#simulate(created_by: nil) ⇒ Object
129
130
131
132
133
134
135
136
137
138
|
# File 'app/models/spree/reimbursement.rb', line 129
def simulate(created_by: nil)
unless created_by
Spree::Deprecation.warn("Calling #simulate on #{self} without created_by is deprecated")
end
reimbursement_simulator_tax_calculator.call(self)
reload
update!(total: calculated_total)
reimbursement_performer.simulate(self, created_by: created_by)
end
|
The returned category is used as the category for Spree::Reimbursement::Credit.default_creditable_class.
#unpaid_amount ⇒ Object
90
91
92
|
# File 'app/models/spree/reimbursement.rb', line 90
def unpaid_amount
total - paid_amount
end
|