Sha256: 149e8488a816182a2b53c4c40b15fb4e478341f51d6de38abfc5e93813e846e2

Contents?: true

Size: 1.28 KB

Versions: 11

Compression:

Stored size: 1.28 KB

Contents

module Comee
  module Core
    class Invoice < ApplicationRecord
      before_save :update_invoice_total
      belongs_to :sales_order
      has_many :invoice_items

      has_noticed_notifications model_name: "Comee::Core::Notification"

      enum :status, {draft: 0, approved: 1}
      enum :payment_status, {not_settled: 0, settled: 1}

      validates :invoice_no, presence: true, uniqueness: true
      validates :date_issued, :payment_term, :status, :payment_status, presence: true
      validates :additional_charges, :total_price, numericality: {greater_than_or_equal_to: 0, allow_nil: true}

      delegate(:order_number, to: :sales_order)

      def update_invoice_total
        self.additional_charges ||= 0
        self.total_price ||= 0
        self.total_price -= additional_charges_was if additional_charges_was && additional_charges_changed?
        self.total_price += additional_charges
      end

      def self.ransackable_attributes(auth_object = nil)
        [
          "sales_order_id",
          "invoice_no",
          "date_issued",
          "ship_name",
          "delivery_date",
          "voyage_no",
          "status",
          "payment_status"
        ]
      end

      def self.ransackable_associations(auth_object = nil)
        ["sales_order"]
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
comee_core-0.1.23 app/models/comee/core/invoice.rb
comee_core-0.1.22 app/models/comee/core/invoice.rb
comee_core-0.1.21 app/models/comee/core/invoice.rb
comee_core-0.1.20 app/models/comee/core/invoice.rb
comee_core-0.1.19 app/models/comee/core/invoice.rb
comee_core-0.1.18 app/models/comee/core/invoice.rb
comee_core-0.1.17 app/models/comee/core/invoice.rb
comee_core-0.1.16 app/models/comee/core/invoice.rb
comee_core-0.1.15 app/models/comee/core/invoice.rb
comee_core-0.1.14 app/models/comee/core/invoice.rb
comee_core-0.1.13 app/models/comee/core/invoice.rb