Class: Spree::ReturnItem

Inherits:
Base
  • Object
show all
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 inherited from Base

page

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


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

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_exchange_inventory_unitObject


133
134
135
136
137
138
139
140
# File 'app/models/spree/return_item.rb', line 133

def build_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
  super(variant: exchange_variant, line_item: inventory_unit.line_item, order: inventory_unit.order) if exchange_required?
end

#display_pre_tax_amountObject


117
118
119
# File 'app/models/spree/return_item.rb', line 117

def display_pre_tax_amount
  Spree::Money.new(pre_tax_amount, { currency: currency })
end

#display_totalObject


125
126
127
# File 'app/models/spree/return_item.rb', line 125

def display_total
  Spree::Money.new(total, { currency: currency })
end

#eligible_exchange_variantsObject


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

def eligible_exchange_variants
  exchange_variant_engine.eligible_variants(variant)
end

#exchange_processed?Boolean

Returns:

  • (Boolean)

109
110
111
# File 'app/models/spree/return_item.rb', line 109

def exchange_processed?
  exchange_inventory_unit.present?
end

#exchange_requested?Boolean

Returns:

  • (Boolean)

105
106
107
# File 'app/models/spree/return_item.rb', line 105

def exchange_requested?
  exchange_variant.present?
end

#exchange_required?Boolean

Returns:

  • (Boolean)

113
114
115
# File 'app/models/spree/return_item.rb', line 113

def exchange_required?
  exchange_requested? && !exchange_processed?
end

#exchange_shipmentObject


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

def exchange_shipment
  exchange_inventory_unit.try(:shipment)
end

#reception_completed?Boolean

Returns:

  • (Boolean)

70
71
72
# File 'app/models/spree/return_item.rb', line 70

def reception_completed?
  COMPLETED_RECEPTION_STATUSES.include?(reception_status)
end

#set_default_pre_tax_amountObject


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

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

#totalObject


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

def total
  pre_tax_amount + additional_tax_total
end