Class: Spree::ReturnLineItem
- Inherits:
-
Object
- Object
- Spree::ReturnLineItem
- Extended by:
- DisplayMoney
- Includes:
- PostSale::TaxedLine
- Defined in:
- app/models/spree/return_line_item.rb
Overview
One line on a Return — a quantity of a fulfilled item coming back.
Named for LineItem, which it mirrors: quantity is what the
customer said was coming, received_quantity what the warehouse counted.
Like a line item it carries its worth before tax in pre_tax_amount and
the tax on it beside that, both for the announced quantity.
Instance Method Summary collapse
-
#credited_quantity ⇒ Integer
The units this line gives back: none once the return is canceled, what arrived once the warehouse has counted, what was announced before.
-
#credited_worth ⇒ BigDecimal
What the credited units are worth, tax included.
-
#fold_tax_lines! ⇒ void
Copies the credit rows written at opening onto the line.
-
#refund_amount ⇒ BigDecimal
What this line refunds, tax included.
-
#refund_tax_amount ⇒ BigDecimal
The tax inside #refund_amount.
- #tax_total ⇒ Object
-
#total ⇒ BigDecimal
The announced units, tax included.
Methods included from DisplayMoney
Methods included from PostSale::TaxedLine
#credited_tax_total, #settles_tax?
Instance Method Details
#credited_quantity ⇒ Integer
The units this line gives back: none once the return is canceled, what arrived once the warehouse has counted, what was announced before.
65 66 67 68 69 |
# File 'app/models/spree/return_line_item.rb', line 65 def credited_quantity return 0 if self.return.canceled? self.return.counted? ? received_quantity.to_i : quantity.to_i end |
#credited_worth ⇒ BigDecimal
Returns what the credited units are worth, tax included.
72 73 74 |
# File 'app/models/spree/return_line_item.rb', line 72 def credited_worth refund_amount end |
#fold_tax_lines! ⇒ void
This method returns an undefined value.
Copies the credit rows written at opening onto the line. The before-tax figure is what was paid after discounts less the tax inside it, so the three columns add up to the cent.
81 82 83 84 85 86 87 88 89 |
# File 'app/models/spree/return_line_item.rb', line 81 def fold_tax_lines! included, additional = tax_totals_from(tax_lines.credits.reload) update_columns( pre_tax_amount: default_pre_tax_amount - included, included_tax_total: included, additional_tax_total: additional ) end |
#refund_amount ⇒ BigDecimal
What this line refunds, tax included. Once the warehouse has counted, only the units that arrived are paid for — a customer who announced three and sent two is owed two — and before the count there is nothing to go on but the announced quantity.
Rounded to the currency, because this is the ceiling a refund is checked against as well as the figure the dialog offers: a third of $29.99 taken three times is not $29.99 until it is.
A line opened before returns carried tax holds the price it was opened
with in pre_tax_amount and no tax, so it refunds exactly what it did.
43 44 45 |
# File 'app/models/spree/return_line_item.rb', line 43 def refund_amount counted_share(total) end |
#refund_tax_amount ⇒ BigDecimal
Returns the tax inside #refund_amount.
48 49 50 |
# File 'app/models/spree/return_line_item.rb', line 48 def refund_tax_amount counted_share(tax_total) end |
#tax_total ⇒ Object
57 58 59 |
# File 'app/models/spree/return_line_item.rb', line 57 def tax_total included_tax_total + additional_tax_total end |
#total ⇒ BigDecimal
Returns the announced units, tax included.
53 54 55 |
# File 'app/models/spree/return_line_item.rb', line 53 def total pre_tax_amount + tax_total end |