Class: Spree::ReturnItem
- Extended by:
- DisplayMoney
- Defined in:
- app/models/spree/return_item.rb,
app/models/spree/return_item/eligibility_validator/default.rb,
app/models/spree/return_item/eligibility_validator/rma_required.rb,
app/models/spree/return_item/eligibility_validator/base_validator.rb,
app/models/spree/return_item/eligibility_validator/order_completed.rb,
app/models/spree/return_item/eligibility_validator/inventory_shipped.rb,
app/models/spree/return_item/eligibility_validator/no_reimbursements.rb,
app/models/spree/return_item/eligibility_validator/time_since_purchase.rb,
app/models/spree/return_item/exchange_variant_eligibility/same_product.rb,
app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
Defined Under Namespace
Modules: EligibilityValidator, ExchangeVariantEligibility
Constant Summary collapse
- INTERMEDIATE_RECEPTION_STATUSES =
%i(given_to_customer lost_in_transit shipped_wrong_item short_shipped in_transit)
- COMPLETED_RECEPTION_STATUSES =
INTERMEDIATE_RECEPTION_STATUSES + [:received]
Class Attribute Summary collapse
-
.exchange_variant_engine ⇒ Class
Configurable engine for determining which variants can be exchanged for a given variant.
-
.refund_amount_calculator ⇒ Class
Configurable calculator for determining the amount ro refund when refunding.
-
.return_eligibility_validator ⇒ Class
Configurable validator for determining whether given return item is eligible for return.
Class Method Summary collapse
-
.build_exchange_inventory_unit ⇒ Object
Builds the exchange inventory unit for this return item, only if an exchange is required, correctly associating the variant, line item and order.
-
.eligible_exchange_variants(stock_locations = nil) ⇒ ActiveRecord::Relation<Spree::Variant>
The variants eligible for exchange for this return item.
-
.exchange_processed? ⇒ Boolean
True when an exchange has been processed for this return item.
-
.exchange_requested? ⇒ Boolean
True when an exchange has been requested on this return item.
-
.exchange_required? ⇒ Boolean
True when an exchange has been requested but has yet to be processed.
-
.exchange_shipment ⇒ Spree::Shipment?
The exchange inventory unit’s shipment if it exists.
-
.from_inventory_unit(inventory_unit) ⇒ Spree::ReturnItem
A valid return item for the given inventory unit if one exists, or a new one if one does not.
- .part_of_exchange? ⇒ Boolean
- .potential_reception_transitions ⇒ Object
-
.reception_completed? ⇒ Boolean
True when this retur item is in a complete reception state.
-
.set_default_amount ⇒ Object
Calculates and sets the default amount to be refunded.
- .skip_customer_return_processing=(value) ⇒ Object
-
.total ⇒ BigDecimal
The cost of the item after tax.
-
.total_excluding_vat ⇒ BigDecimal
(also: pre_tax_amount)
The cost of the item before VAT tax.
Methods included from DisplayMoney
Methods inherited from Base
display_includes, page, preference, #preferences
Methods included from Core::Permalinks
#generate_permalink, #save_permalink
Class Attribute Details
.exchange_variant_engine ⇒ Class
Configurable engine for determining which variants can be exchanged for a given variant.
21 |
# File 'app/models/spree/return_item.rb', line 21 class_attribute :exchange_variant_engine |
.refund_amount_calculator ⇒ Class
Configurable calculator for determining the amount ro refund when refunding.
29 |
# File 'app/models/spree/return_item.rb', line 29 class_attribute :refund_amount_calculator |
.return_eligibility_validator ⇒ Class
Configurable validator for determining whether given return item is eligible for return.
13 |
# File 'app/models/spree/return_item.rb', line 13 class_attribute :return_eligibility_validator |
Class Method Details
.build_exchange_inventory_unit ⇒ Object
Builds the exchange inventory unit for this return item, only if an exchange is required, correctly associating the variant, line item and order.
151 152 153 154 155 156 157 158 |
# File 'app/models/spree/return_item.rb', line 151 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) if exchange_required? end |
.eligible_exchange_variants(stock_locations = nil) ⇒ ActiveRecord::Relation<Spree::Variant>
This uses the exchange_variant_engine configured on the class.
Returns the variants eligible for exchange for this return item.
144 145 146 |
# File 'app/models/spree/return_item.rb', line 144 def eligible_exchange_variants(stock_locations = nil) exchange_variant_engine.eligible_variants(variant, stock_locations: stock_locations) end |
.exchange_processed? ⇒ Boolean
True when an exchange has been processed for this return item
118 119 120 |
# File 'app/models/spree/return_item.rb', line 118 def exchange_processed? exchange_inventory_unit.present? end |
.exchange_requested? ⇒ Boolean
Returns true when an exchange has been requested on this return item.
112 113 114 |
# File 'app/models/spree/return_item.rb', line 112 def exchange_requested? exchange_variant.present? end |
.exchange_required? ⇒ Boolean
Returns true when an exchange has been requested but has yet to be processed.
124 125 126 |
# File 'app/models/spree/return_item.rb', line 124 def exchange_required? exchange_requested? && !exchange_processed? end |
.exchange_shipment ⇒ Spree::Shipment?
Returns the exchange inventory unit’s shipment if it exists.
161 162 163 |
# File 'app/models/spree/return_item.rb', line 161 def exchange_shipment exchange_inventory_unit.try(:shipment) end |
.from_inventory_unit(inventory_unit) ⇒ Spree::ReturnItem
Returns a valid return item for the given inventory unit if one exists, or a new one if one does not.
105 106 107 108 |
# File 'app/models/spree/return_item.rb', line 105 def self.from_inventory_unit(inventory_unit) valid.find_by(inventory_unit: inventory_unit) || new(inventory_unit: inventory_unit).tap(&:set_default_amount) end |
.part_of_exchange? ⇒ Boolean
186 187 188 189 190 |
# File 'app/models/spree/return_item.rb', line 186 def part_of_exchange? # test whether this ReturnItem was either a) one for which an exchange was sent or # b) the exchanged item itself being returned in lieu of the original item exchange_requested? || sibling_intended_for_exchange('unexchanged') end |
.potential_reception_transitions ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'app/models/spree/return_item.rb', line 173 def potential_reception_transitions status_paths = reception_status_paths.to_states event_paths = reception_status_paths.events status_paths.delete(:cancelled) status_paths.delete(:expired) status_paths.delete(:unexchanged) event_paths.delete(:cancel) event_paths.delete(:expired) event_paths.delete(:unexchange) status_paths.map{ |status| I18n.t("spree.reception_states.#{status}", default: status.to_s.humanize) }.zip(event_paths) end |
.reception_completed? ⇒ Boolean
Returns true when this retur item is in a complete reception state.
89 90 91 |
# File 'app/models/spree/return_item.rb', line 89 def reception_completed? COMPLETED_RECEPTION_STATUSES.map(&:to_s).include?(reception_status.to_s) end |
.set_default_amount ⇒ Object
This uses the configured refund_amount_calculator configured on the class.
Calculates and sets the default amount to be refunded.
169 170 171 |
# File 'app/models/spree/return_item.rb', line 169 def set_default_amount self.amount = refund_amount_calculator.new.compute(self) end |
.skip_customer_return_processing=(value) ⇒ Object
93 94 95 96 97 98 99 |
# File 'app/models/spree/return_item.rb', line 93 def skip_customer_return_processing=(value) @skip_customer_return_processing = value Deprecation.warn \ 'From Solidus v2.11 onwards, #skip_customer_return_processing does ' \ 'nothing, and #process_inventory_unit! will restore calling ' \ 'customer_return#process_return!', caller(1) end |
.total ⇒ BigDecimal
Returns the cost of the item after tax.
129 130 131 |
# File 'app/models/spree/return_item.rb', line 129 def total amount + additional_tax_total end |
.total_excluding_vat ⇒ BigDecimal Also known as: pre_tax_amount
Returns the cost of the item before VAT tax.
134 135 136 |
# File 'app/models/spree/return_item.rb', line 134 def total_excluding_vat amount - included_tax_total end |