module Skr::Concerns::HasSkuLocLines::InstanceMethods

Public Instance Methods

other_charge_lines() click to toggle source
# File lib/skr/concerns/has_sku_loc_lines.rb, line 10
def other_charge_lines
    self.lines.select{|l| l.sku.is_other_charge? }
end
regular_lines() click to toggle source
# File lib/skr/concerns/has_sku_loc_lines.rb, line 14
def regular_lines
    self.lines.reject{|l| l.sku.is_other_charge? }
end
regular_lines_total() click to toggle source
# File lib/skr/concerns/has_sku_loc_lines.rb, line 18
def regular_lines_total
    self.regular_lines.sum{|l|l.extended_price}
end
subtotal() click to toggle source
# File lib/skr/concerns/has_sku_loc_lines.rb, line 22
def subtotal
    self.regular_lines.inject(0){|sum,line| sum + line.extended_price }
end
total() click to toggle source
# File lib/skr/concerns/has_sku_loc_lines.rb, line 26
def total
    if total = self.read_attribute('total')
        BigDecimal.new(total)
    elsif self.new_record? || self.association(:lines).loaded?
        self.lines.inject( BigDecimal.new('0') ){|sum,line| sum += line.extended_price }
    else
        BigDecimal.new( self.lines.sum('price*qty') )
    end
end