Class: Solidus::Returnly::RefundPresenter
- Inherits:
-
Object
- Object
- Solidus::Returnly::RefundPresenter
- Defined in:
- lib/solidus/returnly/refund_presenter.rb
Class Method Summary collapse
- .present_estimate(calculator) ⇒ Object
- .present_line_items(calculator) ⇒ Object
- .present_refund(refunder) ⇒ Object
Class Method Details
.present_estimate(calculator) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/solidus/returnly/refund_presenter.rb', line 5 def self.present_estimate(calculator) total = Money.new 0 sub_total = Money.new 0 calculator.line_items_return_items.values.flatten.each do |return_item| total += Money.from_amount return_item.total sub_total += Money.from_amount return_item.pre_tax_amount end { total_amount: total.to_f, subtotal_amount: sub_total.to_f, tax_amount: (total - sub_total).to_f, discount_amount: calculator.order.promo_total.to_f, shipping_amount: calculator.order.shipment_total.to_f, line_items: present_line_items(calculator) } end |
.present_line_items(calculator) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/solidus/returnly/refund_presenter.rb', line 25 def self.present_line_items(calculator) calculator.line_items_return_items.values.map do |return_items| line_item = return_items.first.inventory_unit.line_item total_amount = 0.0 sub_total = 0.0 return_items.each do |return_item| total_amount += return_item.total sub_total += return_item.pre_tax_amount end { order_line_item_id: line_item.id, quantity: return_items.size, total_amount: total_amount.to_f, tax_amount: (total_amount - sub_total).to_f } end end |
.present_refund(refunder) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/solidus/returnly/refund_presenter.rb', line 47 def self.present_refund(refunder) customer_return = refunder.customer_return { refund_id: customer_return.number, created_at: customer_return.created_at, updated_at: customer_return.updated_at, line_items: customer_return.return_items.group_by{ |ri| ri.inventory_unit.line_item.id }.map do |_, return_items| first_return_item = return_items.first { refund_line_item_id: first_return_item.id, order_line_item_id: first_return_item.inventory_unit.line_item.id, refunded_amount_per_item: first_return_item.amount.to_f, total_refunded_per_line_item: return_items.sum(&:amount).to_f, quantity: return_items.size } end, transactions: [ id: refunder.reimbursement.id, amount: refunder.reimbursement.total ], restock: refunder.restock } end |