Class: Quickbooks::Model::TaxService
- Inherits:
-
BaseModelJSON
- Object
- BaseModel
- BaseModelJSON
- Quickbooks::Model::TaxService
- Defined in:
- lib/quickbooks/model/tax_service.rb
Constant Summary collapse
- REST_RESOURCE =
"taxservice/taxcode"
Class Method Summary collapse
Instance Method Summary collapse
- #check_details_item ⇒ Object
-
#initialize(options = {}) ⇒ TaxService
constructor
A new instance of TaxService.
Methods inherited from BaseModelJSON
Methods inherited from BaseModel
#as_json, attribute_names, #attributes, attrs_with_types, #inspect, inspect, reference_attrs, reference_setters, resource_for_collection, resource_for_singular, to_xml_big_decimal, #to_xml_inject_ns, #to_xml_ns
Methods included from Validator
Methods included from Definition
included, #is_name_list_entity?, #is_transaction_entity?
Constructor Details
#initialize(options = {}) ⇒ TaxService
Returns a new instance of TaxService.
14 15 16 17 |
# File 'lib/quickbooks/model/tax_service.rb', line 14 def initialize( = {}) self.tax_rate_details = ['tax_rate_details'] || [] super end |
Class Method Details
.from_json(response) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/quickbooks/model/tax_service.rb', line 19 def self.from_json(response) result = JSON.parse(response) if result.present? ts = Quickbooks::Model::TaxService.new ts.tax_code = result['TaxCode'] ts.tax_code_id = result['TaxCodeId'] result['TaxRateDetails'].each do |item| attrs = item.keys.inject({}){|mem, k| mem[k.underscore] = item[k]; mem} ts.tax_rate_details << Quickbooks::Model::TaxRateDetailLine.new(attrs) end return ts else return nil end end |
Instance Method Details
#check_details_item ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/quickbooks/model/tax_service.rb', line 35 def check_details_item if tax_rate_details.blank? errors.add(:tax_rate_details, "must have at least one item") else tax_rate_details.each do |line| unless line.valid? errors.add(:base, line.errors..join(', ')) end end names = tax_rate_details.map(&:tax_rate_name).uniq if names.size < tax_rate_details.size errors.add(:tax_rate_name, "Duplicate Tax Rate Name") end end end |