lib/xeroizer/models/invoice.rb in xeroizer-0.4.3 vs lib/xeroizer/models/invoice.rb in xeroizer-0.4.4
- old
+ new
@@ -111,12 +111,12 @@
def sub_total=(value); raise SettingTotalDirectlyNotSupported.new(:sub_total); end
def total_tax=(value); raise SettingTotalDirectlyNotSupported.new(:total_tax); end
def total=(value); raise SettingTotalDirectlyNotSupported.new(:total); end
# Calculate sub_total from line_items.
- def sub_total
- if new_record? || (!new_record? && line_items && line_items.size > 0)
+ def sub_total(always_summary = false)
+ if !always_summary && (new_record? || (!new_record? && line_items && line_items.size > 0))
sum = (line_items || []).inject(BigDecimal.new('0')) { | sum, line_item | sum + line_item.line_amount }
# If the default amount types are inclusive of 'tax' then remove the tax amount from this sub-total.
sum -= total_tax if line_amount_types == 'Inclusive'
sum
@@ -124,20 +124,24 @@
attributes[:sub_total]
end
end
# Calculate total_tax from line_items.
- def total_tax
- if new_record? || (!new_record? && line_items && line_items.size > 0)
+ def total_tax(always_summary = false)
+ if !always_summary && (new_record? || (!new_record? && line_items && line_items.size > 0))
(line_items || []).inject(BigDecimal.new('0')) { | sum, line_item | sum + line_item.tax_amount }
else
attributes[:total_tax]
end
end
# Calculate the total from line_items.
- def total
- sub_total + total_tax
+ def total(always_summary = false)
+ unless always_summary
+ sub_total + total_tax
+ else
+ attributes[:total]
+ end
end
# Retrieve the PDF version of this invoice.
# @param [String] filename optional filename to store the PDF in instead of returning the data.
def pdf(filename = nil)