Class: Spree::Claim
- Inherits:
-
Object
- Object
- Spree::Claim
- Includes:
- ActedBy, HasCustomFields, HasStatus, Metadata, NumberIdentifier, PostSale::Taxation, SingleStoreResource
- Defined in:
- app/models/spree/claim.rb
Overview
A customer reports a problem with a delivery and the merchant makes it right without necessarily asking for the goods back. What went wrong is recorded on ClaimReason, the merchant-owned vocabulary.
New in 6.0 — there was previously no way to model "send a replacement without asking for the original back". Transitions are workflows (docs/plans/6.0-returns-exchanges-claims.md).
Constant Summary collapse
- RESOLUTIONS =
Each resolution drives real behaviour in Spree::Claims::Resolve, so this stays closed — an unrecognised value would silently do nothing.
%w[refund replacement refund_and_replacement].freeze
Instance Method Summary collapse
- #display_refund_total ⇒ Object
- #refund_total ⇒ Object
-
#refunded_line_amounts ⇒ Hash{Integer => BigDecimal}
What a refund from this claim paid for, line by line — each line already carries the amount agreed for it.
-
#refunded_line_taxes ⇒ Hash{Integer => BigDecimal}
The tax inside #refunded_line_amounts, for the lines whose tax is recorded: each line's refund carries its tax in proportion to what the customer paid for it.
- #replacement_line_items ⇒ Object
- #taxed_lines ⇒ Object
Methods included from PostSale::Taxation
#calculate_tax!, #clear_tax!, #credited_tax_total, #settle_tax!
Methods included from Metadata
#private_metadata, #private_metadata=
Methods included from ActedBy
#acted_by_prefixed_id, #acted_by_type, assume_admin_actor_type, columns_for, models, registered_model_names
Instance Method Details
#display_refund_total ⇒ Object
79 80 81 |
# File 'app/models/spree/claim.rb', line 79 def display_refund_total Spree::Money.new(refund_total, currency: currency) end |
#refund_total ⇒ Object
50 51 52 |
# File 'app/models/spree/claim.rb', line 50 def refund_total claim_line_items.sum(&:refund_amount) end |
#refunded_line_amounts ⇒ Hash{Integer => BigDecimal}
What a refund from this claim paid for, line by line — each line already carries the amount agreed for it.
58 59 60 61 62 |
# File 'app/models/spree/claim.rb', line 58 def refunded_line_amounts claim_line_items.each_with_object(Hash.new(0)) do |line, amounts| amounts[line.line_item_id] += line.refund_amount.to_d end end |
#refunded_line_taxes ⇒ Hash{Integer => BigDecimal}
The tax inside #refunded_line_amounts, for the lines whose tax is recorded: each line's refund carries its tax in proportion to what the customer paid for it.
69 70 71 72 73 74 75 76 77 |
# File 'app/models/spree/claim.rb', line 69 def refunded_line_taxes claim_line_items.each_with_object(Hash.new(0)) do |line, taxes| next unless line.settles_tax? && line.paid_amount.positive? taxes[line.line_item_id] += Spree::Money::Rounding.to_currency( line.tax_total * line.refund_amount.to_d / line.paid_amount, currency ) end end |
#replacement_line_items ⇒ Object
83 84 85 |
# File 'app/models/spree/claim.rb', line 83 def replacement_line_items claim_line_items.select(&:send_replacement) end |
#taxed_lines ⇒ Object
87 88 89 |
# File 'app/models/spree/claim.rb', line 87 def taxed_lines claim_line_items end |