Sha256: 22e8626f3c49066b20e91ab307910bfeee31a35056fa8464fd71942f52142bd4

Contents?: true

Size: 844 Bytes

Versions: 4

Compression:

Stored size: 844 Bytes

Contents

module Skr
    module Concerns

        module HasSkuLocLines

            extend ActiveSupport::Concern

            module InstanceMethods

                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
            end

            module ClassMethods

                def has_sku_loc_lines
                    self.send :include, InstanceMethods
                    export_methods :total
                end
            end

        end
    end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
stockor-0.5.0 lib/skr/concerns/has_sku_loc_lines.rb
stockor-0.4.0 lib/skr/concerns/has_sku_loc_lines.rb
stockor-0.3.0 lib/skr/concerns/has_sku_loc_lines.rb
stockor-0.2 lib/skr/concerns/has_sku_loc_lines.rb