Class: Spree::CustomerReturn

Inherits:
Object
  • Object
show all
Extended by:
DisplayMoney
Includes:
Metadata, NumberIdentifier, Webhooks::HasWebhooks
Defined in:
app/models/spree/customer_return.rb

Instance Method Summary collapse

Methods included from DisplayMoney

money_methods

Instance Method Details

#can_create_reimbursement?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'app/models/spree/customer_return.rb', line 57

def can_create_reimbursement?
  !fully_reimbursed? && completely_decided? && no_pending_reimbursements?
end

#completely_decided?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/models/spree/customer_return.rb', line 33

def completely_decided?
  !return_items.undecided.exists?
end

#currencyObject



41
42
43
# File 'app/models/spree/customer_return.rb', line 41

def currency
  order&.currency
end

#fully_reimbursed?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'app/models/spree/customer_return.rb', line 37

def fully_reimbursed?
  completely_decided? && return_items.accepted.includes(:reimbursement).all? { |return_item| return_item.reimbursement.try(:reimbursed?) }
end

#no_pending_reimbursements?Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
67
# File 'app/models/spree/customer_return.rb', line 61

def no_pending_reimbursements?
  if association(:reimbursements).loaded?
    reimbursements.select(&:pending?).empty?
  else
    reimbursements.where(reimbursement_status: :pending).none?
  end
end

#orderObject

Temporarily tie a customer_return to one order



46
47
48
49
50
51
# File 'app/models/spree/customer_return.rb', line 46

def order
  return nil if return_items.blank?
  return nil if return_items.first.inventory_unit.blank?

  return_items.first.inventory_unit.order
end

#pre_tax_totalObject



53
54
55
# File 'app/models/spree/customer_return.rb', line 53

def pre_tax_total
  return_items.sum(:pre_tax_amount)
end