Sha256: 3c2a4e6ad7df3738f2ebe8da6f5c0a30c1992b214b0b7473c19a603e89fc6f23

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

# create_table :charge_lines do |t|
#   t.string      :sti_type
#   t.references  :money
#   t.string      :description     #could be expanded to include type information, etc.
#   t.string      :external_identifier
#   t.string      :external_id_source
#
#   #polymorphic
#   t.references :charged_item, :polymorphic => true
#
#   t.timestamps
# end
#
# add_index :charge_lines, [:charged_item_id, :charged_item_type], :name => 'charged_item_idx'

class ChargeLine < ActiveRecord::Base
  attr_protected :created_at, :updated_at

  tracks_created_by_updated_by

  belongs_to :charged_item, :polymorphic => true
  belongs_to :money, :dependent => :destroy
  belongs_to :charge_type

  has_many :sales_tax_lines, as: :taxed_record, dependent: :destroy

  def taxed?
    self.charge_type.try(:taxable)
  end

  # calculates tax and save to sales_tax
  def calculate_tax(ctx={})
    taxation = ErpOrders::Taxation.new

    self.sales_tax = taxation.calculate_tax(self,
                                            ctx.merge({
                                                          amount: money.amount
                                                      }))
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
erp_orders-4.2.0 app/models/charge_line.rb