获取项目失败后更新 XERO 项目
Update XERO Item after fetching item fails
我正在使用 xeroizer gem 并遇到一些问题。
这是我控制器中的内容:
items_found = Item.where(code: codes)
if items_found
xero.Item.batch_save do
binding.pry
items_found.each do |existing_item|
if existing_item.xero_id
item = xero.Item.find(existing_item.xero_id)
item.description = existing_item.description
item.unit_price = existing_item.rate
else
item = xero.Item.first(where: { code: existing_item.code })
item.description = existing_item.description
item.unit_price = existing_item.rate
end
end
end
end
items_found
数组包含已存储并存在于 xero 中的所有项目,我从 code
数组中获取这些项目。如果 xero_id
被存储,我尝试找到 Item
但它失败了。
然而,在 binding.pry
调用
之后,我的代码因此错误而失败
Xeroizer::ApiException - PostDataInvalidException: The element 'CogsAccountCode' was not recognised. Ensure the element name has the correct case and that there are no duplicate elements of the same name.
Generated by the following XML:
<ApiException xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ErrorNumber>14</ErrorNumber>
<Type>PostDataInvalidException</Type>
<Message>The element 'CogsAccountCode' was not recognised. Ensure the element name has the correct case and that there are no duplicate elements of the same name.</Message>
</ApiException>:
() home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/http.rb:197:in `handle_error!'
() home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/http.rb:116:in `http_request'
() home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/http.rb:41:in `http_post'
() home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/application_http_proxy.rb:24:in `http_post'
() home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/record/base_model.rb:167:in `block (2 levels) in save_records'
() home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/record/base_model.rb:165:in `block in save_records'
() home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/record/base_model.rb:164:in `save_records'
() home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/record/base_model.rb:191:in `batch_save'
app/controllers/xero_session_controller.rb:286:in `create_items'
我找到了类似的 error
复印机上没有提到CogsAccountCode
gem documentation/code。
如有任何帮助,我们将不胜感激。
我的 codes
数组中有一个拼写错误(奇怪地)没有被捕获并且仍在填充 items_found
。
我一修复它并 codes
正确插入,错误就消失了。
我正在使用 xeroizer gem 并遇到一些问题。
这是我控制器中的内容:
items_found = Item.where(code: codes)
if items_found
xero.Item.batch_save do
binding.pry
items_found.each do |existing_item|
if existing_item.xero_id
item = xero.Item.find(existing_item.xero_id)
item.description = existing_item.description
item.unit_price = existing_item.rate
else
item = xero.Item.first(where: { code: existing_item.code })
item.description = existing_item.description
item.unit_price = existing_item.rate
end
end
end
end
items_found
数组包含已存储并存在于 xero 中的所有项目,我从 code
数组中获取这些项目。如果 xero_id
被存储,我尝试找到 Item
但它失败了。
然而,在 binding.pry
调用
Xeroizer::ApiException - PostDataInvalidException: The element 'CogsAccountCode' was not recognised. Ensure the element name has the correct case and that there are no duplicate elements of the same name.
Generated by the following XML:
<ApiException xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ErrorNumber>14</ErrorNumber>
<Type>PostDataInvalidException</Type>
<Message>The element 'CogsAccountCode' was not recognised. Ensure the element name has the correct case and that there are no duplicate elements of the same name.</Message>
</ApiException>:
() home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/http.rb:197:in `handle_error!'
() home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/http.rb:116:in `http_request'
() home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/http.rb:41:in `http_post'
() home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/application_http_proxy.rb:24:in `http_post'
() home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/record/base_model.rb:167:in `block (2 levels) in save_records'
() home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/record/base_model.rb:165:in `block in save_records'
() home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/record/base_model.rb:164:in `save_records'
() home/alex/.rvm/gems/ruby-2.3.5/bundler/gems/xeroizer-2d305fbdfdb1/lib/xeroizer/record/base_model.rb:191:in `batch_save'
app/controllers/xero_session_controller.rb:286:in `create_items'
我找到了类似的 error
复印机上没有提到CogsAccountCode
gem documentation/code。
如有任何帮助,我们将不胜感激。
我的 codes
数组中有一个拼写错误(奇怪地)没有被捕获并且仍在填充 items_found
。
我一修复它并 codes
正确插入,错误就消失了。