Sha256: 7b08c9c8cda6134fd22d369376a898adeb283d2be9c59aea091d8b3e147a19bc

Contents?: true

Size: 1.14 KB

Versions: 10

Compression:

Stored size: 1.14 KB

Contents

require 'xeroizer/models/account'
require 'xeroizer/models/line_amount_type'

module Xeroizer
  module Record
    class LineItemModel < BaseModel
        
    end
    
    class LineItem < Base
      TAX_TYPE = Account::TAX_TYPE unless defined?(TAX_TYPE)
      
      string  :item_code
      string  :description
      decimal :quantity
      decimal :unit_amount
      string  :account_code
      string  :tax_type
      decimal :tax_amount
      decimal :line_amount, :calculated => true
      decimal :discount_rate
      
      has_many  :tracking, :model_name => 'TrackingCategoryChild'
      
      def line_amount=(line_amount)
        @line_amount_set = true
        attributes[:line_amount] = line_amount
      end
            
      # Calculate the line_total (if there is a quantity and unit_amount).
      # Description-only lines have been allowed since Xero V2.09.
      def line_amount(summary_only = false)
        return attributes[:line_amount] if summary_only || @line_amount_set
        
        BigDecimal((quantity * unit_amount * ((100.0 - discount_rate)/100.0)).to_s).round(2) if quantity && unit_amount
      end
      
    end
    
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
xeroizer-float-2.15.5.2 lib/xeroizer/models/line_item.rb
xeroizer-float-2.15.5.1 lib/xeroizer/models/line_item.rb
xeroizer-float-2.15.3.16 lib/xeroizer/models/line_item.rb
xeroizer-float-2.15.3.15 lib/xeroizer/models/line_item.rb
xeroizer-float-2.15.3.14 lib/xeroizer/models/line_item.rb
xeroizer-float-2.15.3.13 lib/xeroizer/models/line_item.rb
xeroizer-float-2.15.3.12 lib/xeroizer/models/line_item.rb
xeroizer-float-2.15.3.11 lib/xeroizer/models/line_item.rb
xeroizer-float-2.15.3.10 lib/xeroizer/models/line_item.rb
xeroizer-float-2.15.3.9 lib/xeroizer/models/line_item.rb