mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-09 01:14:23 -05:00
Simplified & Removed the unnecessary nested loops
This commit is contained in:
@@ -60,34 +60,37 @@ class QboInvoice < ActiveRecord::Base
|
|||||||
i = Issue.find_by_id(issue.to_i)
|
i = Issue.find_by_id(issue.to_i)
|
||||||
i.qbo_invoice = QboInvoice.find_by_id(invoice.id.to_i)
|
i.qbo_invoice = QboInvoice.find_by_id(invoice.id.to_i)
|
||||||
i.save!
|
i.save!
|
||||||
|
}
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
is_changed = false
|
is_changed = false
|
||||||
|
|
||||||
# Update QBO with Milage & VIN
|
# update the invoive custom fields with infomation from the work ticket if available
|
||||||
invoice.custom_fields.each { |cf|
|
invoice.custom_fields.each { |cf|
|
||||||
# VIN
|
# VIN
|
||||||
if cf.name.eql? "VIN"
|
if cf.name.eql? "VIN"
|
||||||
cf.string_value = Vehicle.find(i.vehicles_id).vin if i.vehicles_id
|
vin = Vehicle.find(i.vehicles_id).vin
|
||||||
|
cf.string_value = vin if i.vehicles_id if not cf.string_value.to_s.eql? vin
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
# Update Matching Fields
|
# Custom Values
|
||||||
i.custom_field_values.each { |value|
|
begin
|
||||||
if cf.name.eql? CustomField.find_by_id(value.custom_field_id).name
|
value = i.custom_values.find_by(custom_field_id: CustomField.find_by_name(cf.name).id)
|
||||||
|
if value
|
||||||
if not cf.string_value.to_s.eql? value.value.to_s
|
if not cf.string_value.to_s.eql? value.value.to_s
|
||||||
cf.string_value = value.value.to_s
|
cf.string_value = value.value.to_s
|
||||||
is_changed = true
|
is_changed = true
|
||||||
end
|
end
|
||||||
break
|
|
||||||
end
|
end
|
||||||
}
|
rescue
|
||||||
}
|
# Nothing to do here, there is no match
|
||||||
}
|
end
|
||||||
|
|
||||||
# Push updates
|
# Push updates
|
||||||
Qbo.get_base(:invoice).service.update(invoice) if is_changed
|
Qbo.get_base(:invoice).service.update(invoice) if is_changed
|
||||||
end
|
end
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.update(id)
|
def self.update(id)
|
||||||
# Update the item table
|
# Update the item table
|
||||||
|
|||||||
Reference in New Issue
Block a user