Class: ProductTaxCode
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ProductTaxCode
- Defined in:
- app/models/product_tax_code.rb
Overview
== Schema Information
Table name: product_tax_codes
Database name: primary
id :integer not null, primary key
description :string
name :string not null
product_tax_code :string not null
tax_class :string not null
Has many collapse
Class Method Summary collapse
- .default_for_service ⇒ Object
-
.import_from_taxjar ⇒ Object
This method pulls down the tax categories from taxjar and update our tables.
- .options_for_select ⇒ Object
Instance Method Summary collapse
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Class Method Details
.default_for_service ⇒ Object
16 17 18 |
# File 'app/models/product_tax_code.rb', line 16 def self.default_for_service find_by(product_tax_code: '19000') end |
.import_from_taxjar ⇒ Object
This method pulls down the tax categories from taxjar and update
our tables.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/product_tax_code.rb', line 22 def self.import_from_taxjar counter = 0 Api::Taxjar.client.categories.each do |tj_cat| counter +=1 tax_code = tj_cat.product_tax_code.presence.chomp ptc = where(product_tax_code: tax_code).first_or_initialize ptc.name = tj_cat.name.chomp ptc.description = tj_cat.description.chomp # Taking a guess at mapping to our oversimplified tax classification, these are books, tangibles, as far as i can tell if ptc.new_record? && tax_code.first(2).in?(['20','51','40','81','41']) ptc.tax_class = 'g' else ptc.tax_class = 'svc' end ptc.save! end counter end |
.options_for_select ⇒ Object
42 43 44 |
# File 'app/models/product_tax_code.rb', line 42 def self. all.order(:name).map{|ptc| ["#{ptc.name} (#{ptc.product_tax_code})",ptc.id]} end |
Instance Method Details
#items ⇒ ActiveRecord::Relation<Item>
14 |
# File 'app/models/product_tax_code.rb', line 14 has_many :items, inverse_of: :product_tax_code |
#to_s ⇒ Object
46 47 48 |
# File 'app/models/product_tax_code.rb', line 46 def to_s "#{name} (#{product_tax_code})" end |