Sha256: 579d29ba3efbd5c4ab7353d7079cea329e6c09c43dedc00ef669c8a0a5bce3d4

Contents?: true

Size: 791 Bytes

Versions: 4

Compression:

Stored size: 791 Bytes

Contents

module Skr

    class TimeEntry < Model

        belongs_to :customer_project, inverse_of: :time_entries, export: true

        belongs_to :lanes_user, class_name: 'Lanes::User', export: true

        validates :start_at, :end_at, :description, presence: true

        validates :customer_project, :lanes_user, set: true


        has_one :inv_line, inverse_of: :time_entry, listen: { create: :mark_as_invoiced }

        export_sort :hours do | q, dir |
            q.order("end_at-start_at #{dir}")
        end

        def hours
            (end_at - start_at) / 1.hour
        end

        scope :open, ->{
            where(is_invoiced: false)
        }

        private

        def mark_as_invoiced(inv_line)
            update_attributes(is_invoiced: true)
        end

    end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
stockor-0.5.0 lib/skr/models/time_entry.rb
stockor-0.4.0 lib/skr/models/time_entry.rb
stockor-0.3.0 lib/skr/models/time_entry.rb
stockor-0.2 lib/skr/models/time_entry.rb