Class: Spree::ReturnItem
- Inherits:
-
Object
show all
- Extended by:
- DisplayMoney
- Includes:
- Webhooks::HasWebhooks
- Defined in:
- app/models/spree/return_item.rb
Defined Under Namespace
Modules: ExchangeVariantEligibility
Constant Summary
collapse
- COMPLETED_RECEPTION_STATUSES =
%w(received given_to_customer)
Class Method Summary
collapse
Instance Method Summary
collapse
money_methods
Class Method Details
.from_inventory_unit(inventory_unit) ⇒ Object
135
136
137
138
|
# File 'app/models/spree/return_item.rb', line 135
def self.from_inventory_unit(inventory_unit)
not_cancelled.find_by(inventory_unit: inventory_unit) ||
new(inventory_unit: inventory_unit).tap(&:set_default_pre_tax_amount)
end
|
Instance Method Details
#build_default_exchange_inventory_unit ⇒ Object
160
161
162
163
164
165
166
167
168
169
170
|
# File 'app/models/spree/return_item.rb', line 160
def build_default_exchange_inventory_unit
return unless exchange_required?
exchange_inventory_units.build(variant: exchange_variant, line_item: inventory_unit.line_item,
order: inventory_unit.order, quantity: return_quantity)
end
|
#currency ⇒ Object
180
181
182
|
# File 'app/models/spree/return_item.rb', line 180
def currency
return_authorization.try(:currency) || Spree::Store.default.default_currency
end
|
#eligible_exchange_variants ⇒ Object
156
157
158
|
# File 'app/models/spree/return_item.rb', line 156
def eligible_exchange_variants
exchange_variant_engine.eligible_variants(variant)
end
|
#exchange_processed? ⇒ Boolean
144
145
146
|
# File 'app/models/spree/return_item.rb', line 144
def exchange_processed?
exchange_inventory_units.present?
end
|
#exchange_requested? ⇒ Boolean
140
141
142
|
# File 'app/models/spree/return_item.rb', line 140
def exchange_requested?
exchange_variant.present?
end
|
#exchange_required? ⇒ Boolean
148
149
150
|
# File 'app/models/spree/return_item.rb', line 148
def exchange_required?
exchange_requested? && !exchange_processed?
end
|
#exchange_shipments ⇒ Object
172
173
174
|
# File 'app/models/spree/return_item.rb', line 172
def exchange_shipments
exchange_inventory_units.map(&:shipment).uniq
end
|
#pre_tax_amount=(amount) ⇒ Object
16
17
18
|
# File 'app/models/spree/return_item.rb', line 16
def pre_tax_amount=(amount)
self[:pre_tax_amount] = Spree::LocalizedNumber.parse(amount)
end
|
#reception_completed? ⇒ Boolean
105
106
107
|
# File 'app/models/spree/return_item.rb', line 105
def reception_completed?
COMPLETED_RECEPTION_STATUSES.include?(reception_status)
end
|
#return_quantity ⇒ Object
20
21
22
|
# File 'app/models/spree/return_item.rb', line 20
def return_quantity
@_return_quantity.nil? ? inventory_unit.quantity : @_return_quantity
end
|
#return_quantity=(value) ⇒ Object
12
13
14
|
# File 'app/models/spree/return_item.rb', line 12
def return_quantity=(value)
@_return_quantity = value.to_i
end
|
#set_default_pre_tax_amount ⇒ Object
176
177
178
|
# File 'app/models/spree/return_item.rb', line 176
def set_default_pre_tax_amount
self.pre_tax_amount = refund_amount_calculator.new.compute(self)
end
|
#total ⇒ Object
152
153
154
|
# File 'app/models/spree/return_item.rb', line 152
def total
pre_tax_amount + included_tax_total + additional_tax_total
end
|