Class: Spree::ReturnItem

Inherits:
Base
  • Object
show all
Extended by:
DisplayMoney
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, page, spree_base_scopes

Methods included from Preferences::Preferable

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

Class Method Details

.from_inventory_unit(inventory_unit) ⇒ Object


122
123
124
125
# File 'app/models/spree/return_item.rb', line 122

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


147
148
149
150
151
152
153
154
155
156
# File 'app/models/spree/return_item.rb', line 147

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

#eligible_exchange_variantsObject


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

def eligible_exchange_variants
  exchange_variant_engine.eligible_variants(variant)
end

#exchange_processed?Boolean


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

def exchange_processed?
  exchange_inventory_units.present?
end

#exchange_requested?Boolean


127
128
129
# File 'app/models/spree/return_item.rb', line 127

def exchange_requested?
  exchange_variant.present?
end

#exchange_required?Boolean


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

def exchange_required?
  exchange_requested? && !exchange_processed?
end

#exchange_shipmentsObject


158
159
160
# File 'app/models/spree/return_item.rb', line 158

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

#reception_completed?Boolean


92
93
94
# File 'app/models/spree/return_item.rb', line 92

def reception_completed?
  COMPLETED_RECEPTION_STATUSES.include?(reception_status)
end

#return_quantityObject


12
13
14
# File 'app/models/spree/return_item.rb', line 12

def return_quantity
  @_return_quantity.nil? ? inventory_unit.quantity : @_return_quantity
end

#return_quantity=(value) ⇒ Object


8
9
10
# File 'app/models/spree/return_item.rb', line 8

def return_quantity=(value)
  @_return_quantity = value.to_i
end

#set_default_pre_tax_amountObject


162
163
164
# File 'app/models/spree/return_item.rb', line 162

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

#totalObject


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

def total
  pre_tax_amount + included_tax_total + additional_tax_total
end