Module: Skr::Concerns::HasSkuLocLines::InstanceMethods
- Defined in:
- lib/skr/concerns/has_sku_loc_lines.rb
Instance Method Summary collapse
- #other_charge_lines ⇒ Object
- #regular_lines ⇒ Object
- #regular_lines_total ⇒ Object
- #subtotal ⇒ Object
- #total ⇒ Object
Instance Method Details
#other_charge_lines ⇒ Object
10 11 12 |
# 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 ⇒ Object
14 15 16 |
# 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 ⇒ Object
18 19 20 |
# 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 ⇒ Object
22 23 24 |
# 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 ⇒ Object
26 27 28 29 30 31 32 33 34 |
# 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 |