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

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



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

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



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

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

#eligible_exchange_variantsObject



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

def eligible_exchange_variants
  exchange_variant_engine.eligible_variants(variant)
end

#exchange_processed?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'app/models/spree/return_item.rb', line 115

def exchange_processed?
  exchange_inventory_unit.present?
end

#exchange_requested?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'app/models/spree/return_item.rb', line 111

def exchange_requested?
  exchange_variant.present?
end

#exchange_required?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'app/models/spree/return_item.rb', line 119

def exchange_required?
  exchange_requested? && !exchange_processed?
end

#exchange_shipmentObject



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

def exchange_shipment
  exchange_inventory_unit.try(:shipment)
end

#reception_completed?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'app/models/spree/return_item.rb', line 76

def reception_completed?
  COMPLETED_RECEPTION_STATUSES.include?(reception_status)
end

#set_default_pre_tax_amountObject



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

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

#totalObject



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

def total
  pre_tax_amount + included_tax_total + additional_tax_total
end