Sha256: 7db081cdcc817f7d8d8ccf021891dcfa13178bd643d8d42bb3013c39acb75ebb

Contents?: true

Size: 764 Bytes

Versions: 7

Compression:

Stored size: 764 Bytes

Contents

class Dorsale::BillingMachine::InvoiceLine < ActiveRecord::Base
  self.table_name = "dorsale_billing_machine_invoice_lines"

  belongs_to :invoice, inverse_of: :lines

  validates :invoice, presence: true

  default_scope -> {
    order(created_at: :asc)
  }

  def initialize(*)
    super
    assign_default_values
  end

  before_validation :assign_default_values
  before_validation :update_total

  def assign_default_values
      self.quantity   ||= 0
      self.unit_price ||= 0
      self.vat_rate ||= ::Dorsale::BillingMachine::DEFAULT_VAT_RATE
  end

  def update_total
    assign_default_values
    self.total = self.quantity * self.unit_price
  end

  after_save :update_invoice_total

  def update_invoice_total
    self.invoice.reload.save!
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dorsale-3.1.6 app/models/dorsale/billing_machine/invoice_line.rb
dorsale-3.1.5 app/models/dorsale/billing_machine/invoice_line.rb
dorsale-3.1.4 app/models/dorsale/billing_machine/invoice_line.rb
dorsale-3.1.3 app/models/dorsale/billing_machine/invoice_line.rb
dorsale-3.1.2 app/models/dorsale/billing_machine/invoice_line.rb
dorsale-3.1.1 app/models/dorsale/billing_machine/invoice_line.rb
dorsale-3.1.0 app/models/dorsale/billing_machine/invoice_line.rb