Create qbo_purchase.rb

Initial & untested commit for billable-purchases.

TODO:
Create database table
Add relationships
Attach to Issues
This commit is contained in:
2016-01-25 12:31:26 -05:00
parent 0b74f2cf52
commit e65d78bb25

View File

@@ -0,0 +1,47 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class QboPurchase < ActiveRecord::Base
unloadable
belongs_to :issues, :customer
attr_accessible :description
validates_presence_of :id, :line_id, :description, :customer_id
def self.get_base
Qbo.get_base(:purchase)
end
def self.get_purchase(id)
get_base.service.find_by_id(id)
end
def self.update_all
QboPurchases.get_base.service.all.each { |purchase|
purchase.line_items.all.each { |line_item|
detail = line_item.account_based_expense_line_detail if line_item.detail_type = :account_based_expense_line_detail
detail = line_item.item_based_expense_line_detail if line_item.detail_type = :item_based_expense_line_detail
if detail.billable_status = "Billable"
qbo_purchase = find_or_create_by(id: purchase.id)
qbo_purchase.line_id = line_item.id
qbo_purchase.description = line_item.description
qbo_purchase.customer_id = detail.customer_ref
#TODO attach to issues
#qbo_purchase.issue_id = Issue.find_by_invoice()
qbo_purchase.save!
end
}
}
end
end