Class: Spree::CustomerReturn
- Inherits:
-
Object
- Object
- Spree::CustomerReturn
- Extended by:
- DisplayMoney
- Includes:
- Metadata, NumberIdentifier, Webhooks::HasWebhooks
- Defined in:
- app/models/spree/customer_return.rb
Instance Method Summary collapse
- #can_create_reimbursement? ⇒ Boolean
- #completely_decided? ⇒ Boolean
- #currency ⇒ Object
- #fully_reimbursed? ⇒ Boolean
- #no_pending_reimbursements? ⇒ Boolean
-
#order ⇒ Object
Temporarily tie a customer_return to one order.
- #pre_tax_total ⇒ Object
Methods included from DisplayMoney
Instance Method Details
#can_create_reimbursement? ⇒ 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
33 34 35 |
# File 'app/models/spree/customer_return.rb', line 33 def completely_decided? !return_items.undecided.exists? end |
#currency ⇒ Object
41 42 43 |
# File 'app/models/spree/customer_return.rb', line 41 def currency order&.currency end |
#fully_reimbursed? ⇒ 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
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 |
#order ⇒ Object
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_total ⇒ Object
53 54 55 |
# File 'app/models/spree/customer_return.rb', line 53 def pre_tax_total return_items.sum(:pre_tax_amount) end |