Created
January 4, 2011 19:02
-
-
Save SkyM/765212 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.import_data_from_quickbase | |
quickbase = QuickBase::Client.init("username" => QB_USERNAME, "password" => QB_PASSWORD, "apptoken" => QB_APP_TOKEN, "printRequestsAndResponses" => true) | |
#pull down the entire list of products like a boss | |
quickbase_products = quickbase.doQuery(QB_PRODUCTS_TABLE,nil, nil, nil, "1.2.3.4.6.7.13.17.55.63.82.92.114.115.128.131.11.132.54.133.134.8.127.135.136.137.138.139.140.141.143.144.145.146.147.148.149.150.151.152.153.154.155.156.157.12.158.159.160.161.162.163.164.165.166.167.10.168.169.170.16.171.172.9.184.185.186.187", nil, nil, nil ) | |
product_count = quickbase_products.count | |
(0...product_count).each do |i| | |
puts "Doing #{i} / #{product_count}" | |
quickbase_product = quickbase_products[i] | |
product = Product.find_or_initialize_by_quickbase_record_id(:quickbase_record_id => quickbase_product.record_id_) | |
if product.id | |
puts "Found existing product. Checking modified dates..." | |
else | |
puts "No record found, creating new record" | |
product.update_attributes(:from_quickbase => true) | |
end | |
if product.last_quickbase_sync.nil? || Time.at(quickbase_product.date_modified.to_i / 1000) > product.last_quickbase_sync | |
puts "Time check passed, this needs to be updated." | |
product.update_attributes({ | |
:quickbase_record_id => (quickbase_product.record_id_.value rescue quickbase_product.record_id_ ) , | |
#:color => (quickbase_product.class.value rescue quickbase_product.class) , | |
:vendor => (quickbase_product.vendor.value rescue quickbase_product.vendor) , | |
:qty_inventory => (quickbase_product.qty_invtry.value rescue quickbase_product.qty_invtry) , | |
:sku => (quickbase_product.sku.value rescue quickbase_product.sku) , | |
:photo_file => (quickbase_product.photo_folder_file.value rescue quickbase_product.photo_folder_file) , | |
:photo_swatch => (quickbase_product.related_look.value rescue quickbase_product.related_look) , | |
:photo_file_folder => (quickbase_product.photo__swatch_file_folder.value rescue quickbase_product.photo__swatch_file_folder) , | |
:active => (quickbase_product.active.value rescue quickbase_product.active) , | |
:super_category => (quickbase_product.super_class.value rescue quickbase_product.super_class) , | |
:quickbase_vendor_record_id => (quickbase_product.related_vendor__ref_.value rescue quickbase_product.related_vendor__ref_) , | |
:listid => (quickbase_product.qbpos_listid.value rescue quickbase_product.qbpos_listid) , | |
:alu => (quickbase_product.qbpos_alu.value rescue quickbase_product.qbpos_alu) , | |
#quantityoncustomerorder:attribute => (quickbase_product.attrib_3_name.value rescue quickbase_product.attrib_3_name) , | |
:cogsaccount => (quickbase_product.qbpos_cogsaccount.value rescue quickbase_product.qbpos_cogsaccount) , | |
:cost => (quickbase_product.cost_std.value rescue quickbase_product.cost_std) , | |
:departmentcode => (quickbase_product.qbpos_departmentcode.value rescue quickbase_product.qbpos_departmentcode) , | |
:departmentlistid => (quickbase_product.qbpos_departmentlistid.value rescue quickbase_product.qbpos_departmentlistid) , | |
:desc1 => (quickbase_product.description.value rescue quickbase_product.description) , | |
:desc2 => (quickbase_product.description__detailed_.value rescue quickbase_product.description__detailed_) , | |
:incomeaccount => (quickbase_product.qbpos_incomeaccount.value rescue quickbase_product.qbpos_incomeaccount) , | |
:isbelowreorder => (quickbase_product.qbpos_isbelowreorder.value rescue quickbase_product.qbpos_isbelowreorder) , | |
:iseligibleforcomission => (quickbase_product.qbpos_iseligibleforcommission.value rescue quickbase_product.qbpos_iseligibleforcommission), | |
:isprintingtags => (quickbase_product.qbpos_isprintingtags.value rescue quickbase_product.qbpos_isprintingtags) , | |
:isunorderable => (quickbase_product.qbpos_isunorderable.value rescue quickbase_product.qbpos_isunorderable) , | |
:itemnumber => (quickbase_product.qbpos_itemnumber.value rescue quickbase_product.qbpos_itemnumber) , | |
:itemtype => (quickbase_product.qbpos_itemtype.value rescue quickbase_product.qbpos_itemtype) , | |
:marginpercent => (quickbase_product.qbpos_marginpercent.value rescue quickbase_product.qbpos_marginpercent) , | |
:markuppercent => (quickbase_product.qbpos_markuppercent.value rescue quickbase_product.qbpos_markuppercent) , | |
:msrp => (quickbase_product.qbpos_msrp.value rescue quickbase_product.qbpos_msrp) , | |
:onhandstore01 => (quickbase_product.qbpos_onhandstore01.value rescue quickbase_product.qbpos_onhandstore01) , | |
:onhandstore02 => (quickbase_product.qbpos_onhandstore02.value rescue quickbase_product.qbpos_onhandstore02) , | |
:onhandstore03 => (quickbase_product.qbpos_onhandstore03.value rescue quickbase_product.qbpos_onhandstore03) , | |
:onhandstore04 => (quickbase_product.qbpos_onhandstore04.value rescue quickbase_product.qbpos_onhandstore04) , | |
:onhandstore05 => (quickbase_product.qbpos_onhandstore05.value rescue quickbase_product.qbpos_onhandstore05) , | |
:onhandstore06 => (quickbase_product.qbpos_onhandstore06.value rescue quickbase_product.qbpos_onhandstore06) , | |
:onhandstore07 => (quickbase_product.qbpos_onhandstore07.value rescue quickbase_product.qbpos_onhandstore07) , | |
:onhandstore08 => (quickbase_product.qbpos_onhandstore08.value rescue quickbase_product.qbpos_onhandstore08) , | |
:onhandstore09 => (quickbase_product.qbpos_onhandstore09.value rescue quickbase_product.qbpos_onhandstore09) , | |
:onhandstore10 => (quickbase_product.qbpos_onhandstore10.value rescue quickbase_product.qbpos_onhandstore10) , | |
:orderbyunit => (quickbase_product.qbpos_orderbyunit.value rescue quickbase_product.qbpos_orderbyunit) , | |
:ordercost => (quickbase_product.qbpos_ordercost.value rescue quickbase_product.qbpos_ordercost) , | |
:price1 => (quickbase_product.price.value rescue quickbase_product.price) , | |
:price2 => (quickbase_product.qbpos_price2.value rescue quickbase_product.qbpos_price2) , | |
:price3 => (quickbase_product.qbpos_price3.value rescue quickbase_product.qbpos_price3) , | |
:price4 => (quickbase_product.qbpos_price4.value rescue quickbase_product.qbpos_price4) , | |
:price5 => (quickbase_product.qbpos_price5.value rescue quickbase_product.qbpos_price5) , | |
:quantityoncustomerorder => (quickbase_product.qbpos_quantityoncustomerorder.value rescue quickbase_product.qbpos_quantityoncustomerorder), | |
:quantityonhand => (quickbase_product.qbpos_quantityonhand.value rescue quickbase_product.qbpos_quantityonhand) , | |
:quantityonorder => (quickbase_product.qbpos_quantityonorder.value rescue quickbase_product.qbpos_quantityonorder) , | |
:reorderpoint => (quickbase_product.qbpos_reorderpoint.value rescue quickbase_product.qbpos_reorderpoint) , | |
:sellbyunit => (quickbase_product.qbpos_sellbyunit.value rescue quickbase_product.qbpos_sellbyunit) , | |
:serialflag => (quickbase_product.qbpos_serialflag.value rescue quickbase_product.qbpos_serialflag) , | |
:size => (quickbase_product.attrib_4.value rescue quickbase_product.attrib_4) , | |
:storeexchangestatus => (quickbase_product.qbpos_storeexchangestatus.value rescue quickbase_product.qbpos_storeexchangestatus) , | |
:taxcode => (quickbase_product.qbpos_taxcode.value rescue quickbase_product.qbpos_taxcode) , | |
:unitofmeasure => (quickbase_product.qbpos_unitofmeasure.value rescue quickbase_product.qbpos_unitofmeasure) , | |
:upc => (quickbase_product.upc_display.value rescue quickbase_product.upc_display) , | |
:vendorcode => (quickbase_product.qbpos_vendorcode.value rescue quickbase_product.qbpos_vendorcode) , | |
:vendorlistid => (quickbase_product.qbpos_vendorlistid.value rescue quickbase_product.qbpos_vendorlistid) , | |
:customfield1 => (quickbase_product.attrib_2_name.value rescue quickbase_product.attrib_2_name) , | |
:customfield2 => (quickbase_product.vendor_color_code.value rescue quickbase_product.vendor_color_code) , | |
:customfield3 => (quickbase_product.vendor_style_code.value rescue quickbase_product.vendor_style_code) , | |
:customfield4 => (quickbase_product.season.value rescue quickbase_product.season) , | |
:customfield5 => (quickbase_product.qbpos_customfield5.value rescue quickbase_product.qbpos_customfield5) , | |
:last_quickbase_sync => Time.now | |
}) | |
else | |
puts "Date check failed, this record does not need to be updated" | |
end | |
puts "ok finished product import #{i} / #{product_count}" | |
end | |
puts "finished importing products" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment