ruckus / quickbooks-ruby

Quickbooks Online REST API V3 - Ruby
MIT License
374 stars 302 forks source link

Can't create non inventory Item - need minorversion=4 #270

Closed vanboom closed 9 years ago

vanboom commented 9 years ago

I am having trouble creating a non inventory item...

item = Quickbooks::Model::Item.new(:type=>Quickbooks::Model::Item::INVENTORY_TYPE, :name=>"TESTITEM", :description=>"TEST ITEM", :income_account_id=>income_account.id, :asset_account=>asset_account.id)
newitem.id = service.create(item)

The item is successfully created, but shows up in Quickbooks as a Service item. After manually changing the item type in Quickbooks, I can query the item back into Ruby...

fetched_item = service.query("select * from Item where Id = '%s'"%newitem.id)
puts fetched_item.first.type

The Type returned by the fetched item is "Service"

I enabled logging, and it appears that the type field in the XML returned by Quickbooks is "Service".

I tried changing the type of the item in Quickbooks to "Inventory" and then the fetched item type is correctly set to "Inventory".

Thanks for an awesome gem - I appreciate any help or guidance in how I can debug this further.

vanboom commented 9 years ago

I created a Non Inventory item manually in Quickbooks, and then fetched the item by the ID number...

<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2015-10-28T11:53:54.598-07:00">
  <QueryResponse startPosition="1" maxResults="1">
    <Item domain="QBO" sparse="false">
      <Id>33</Id>
      <SyncToken>0</SyncToken>
      <MetaData>
        <CreateTime>2015-10-28T11:53:48-07:00</CreateTime>
        <LastUpdatedTime>2015-10-28T11:53:48-07:00</LastUpdatedTime>
      </MetaData>
      <Name>NONINVENTORYTEST</Name>
      <Description>non inventory test part</Description>
      <Active>true</Active>
      <FullyQualifiedName>NONINVENTORYTEST</FullyQualifiedName>
      <Taxable>true</Taxable>
      <UnitPrice>0</UnitPrice>
      <Type>Service</Type>
      <IncomeAccountRef name="parts">105</IncomeAccountRef>
      <PurchaseCost>0</PurchaseCost>
      <TrackQtyOnHand>false</TrackQtyOnHand>
    </Item>
  </QueryResponse>
</IntuitResponse>

The attribute is getting set to "Service", even though the part shows up in Quickbooks as a Non Inventory part.

vanboom commented 9 years ago

UPDATE: I found the answer on the Quickbooks API Help https://developer.intuit.com/docs/api/accounting/Item

When querying Item objects with minor versions earlier than 4 specified, NonInventory types are returned as type Service.

good grief.

vanboom commented 9 years ago

4 September 24, 2015
Includes all minor version 1, minor version 2, and phases 1 and 2 of minor version 3 plus the addition of the following:

In support of enhanced inventory, the following are added to the Item resource:

Item.Sku attribute. NonInventory to the list of valid Item.Type selections. -XSD: V3 minor version 4

Do we have a way to specify the minor version?

ruckus commented 9 years ago

You can pass along a :query attribute to your create call in the secondary options hash.

Give this a try:

newitem.id = service.create(item, :query => {:minorversion => 4})
vanboom commented 9 years ago

Thanks - I think passing the query parameter will work, however the macro for NON_INVENTORY_ITEM in the Item model is also incorrect, which causes a validation exception. See my PR #271

Maybe we can support minor version 4 out of the box? It is really strange that without it, Quickbooks will show an item as "Non Inventory" but return it in the API as "Service"!

ruckus commented 9 years ago

Closing this since we'll be merging in your PR after the final questions. Thanks again.