Class: Spree::ReturnItem

Inherits:
Base
  • 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

Methods included from DisplayMoney

money_methods

Methods inherited from Base

belongs_to_required_by_default, for_store, has_many_inversing, json_api_columns, json_api_permitted_attributes, json_api_type, page, spree_base_scopes, spree_base_uniqueness_scope

Methods included from Preferences::Preferable

#clear_preferences, #default_preferences, #defined_preferences, #deprecated_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_deprecated, #preference_type, #set_preference

Class Method Details

.from_inventory_unit(inventory_unit) ⇒ Object



130
131
132
133
# File 'app/models/spree/return_item.rb', line 130

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_unitObject



155
156
157
158
159
160
161
162
163
164
165
# File 'app/models/spree/return_item.rb', line 155

def build_default_exchange_inventory_unit
  # The inventory unit needs to have the new variant
  # but it also needs to know the original line item
  # for pricing information for if the inventory unit is
  # ever returned. This means that the inventory unit's line_item
  # will have a different variant than the inventory unit itself
  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

#currencyObject



175
176
177
# File 'app/models/spree/return_item.rb', line 175

def currency
  return_authorization.try(:currency) || Spree::Store.default.default_currency
end

#eligible_exchange_variantsObject



151
152
153
# File 'app/models/spree/return_item.rb', line 151

def eligible_exchange_variants
  exchange_variant_engine.eligible_variants(variant)
end

#exchange_processed?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'app/models/spree/return_item.rb', line 139

def exchange_processed?
  exchange_inventory_units.present?
end

#exchange_requested?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'app/models/spree/return_item.rb', line 135

def exchange_requested?
  exchange_variant.present?
end

#exchange_required?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'app/models/spree/return_item.rb', line 143

def exchange_required?
  exchange_requested? && !exchange_processed?
end

#exchange_shipmentsObject



167
168
169
# File 'app/models/spree/return_item.rb', line 167

def exchange_shipments
  exchange_inventory_units.map(&:shipment).uniq
end

#reception_completed?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'app/models/spree/return_item.rb', line 100

def reception_completed?
  COMPLETED_RECEPTION_STATUSES.include?(reception_status)
end

#return_quantityObject



16
17
18
# File 'app/models/spree/return_item.rb', line 16

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_amountObject



171
172
173
# File 'app/models/spree/return_item.rb', line 171

def set_default_pre_tax_amount
  self.pre_tax_amount = refund_amount_calculator.new.compute(self)
end

#totalObject



147
148
149
# File 'app/models/spree/return_item.rb', line 147

def total
  pre_tax_amount + included_tax_total + additional_tax_total
end