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
Constant Summary
Constants included from Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
Has many collapse
Class Method Summary collapse
- .default_for_service ⇒ ProductTaxCode?
-
.import_from_taxjar ⇒ Integer
This method pulls down the tax categories from taxjar and update our tables.
- .options_for_select ⇒ Array<Array(String, Integer)>
Instance Method Summary collapse
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Class Method Details
.default_for_service ⇒ ProductTaxCode?
18 19 20 |
# File 'app/models/product_tax_code.rb', line 18 def self.default_for_service find_by(product_tax_code: '19000') end |
.import_from_taxjar ⇒ Integer
This method pulls down the tax categories from taxjar and update
our tables.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/product_tax_code.rb', line 25 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 ptc.tax_class = if ptc.new_record? && tax_code.first(2).in?(%w[20 51 40 81 41]) 'g' else 'svc' end ptc.save! end counter end |
.options_for_select ⇒ Array<Array(String, Integer)>
46 47 48 |
# File 'app/models/product_tax_code.rb', line 46 def self. order(:name).map { |ptc| ["#{ptc.name} (#{ptc.product_tax_code})", ptc.id] } end |
Instance Method Details
#items ⇒ ActiveRecord::Relation<Item>
15 |
# File 'app/models/product_tax_code.rb', line 15 has_many :items, inverse_of: :product_tax_code |
#to_s ⇒ String
51 52 53 |
# File 'app/models/product_tax_code.rb', line 51 def to_s "#{name} (#{product_tax_code})" end |