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, 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



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

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

#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)


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

def exchange_processed?
  exchange_inventory_unit.present?
end

#exchange_requested?Boolean

Returns:

  • (Boolean)


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

def exchange_requested?
  exchange_variant.present?
end

#exchange_required?Boolean

Returns:

  • (Boolean)


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

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)


78
79
80
# File 'app/models/spree/return_item.rb', line 78

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



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

def total
  pre_tax_amount + included_tax_total + additional_tax_total
end