Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
Implemented Windows#Invoice.update
Browse files Browse the repository at this point in the history
  • Loading branch information
ruckus committed Aug 12, 2013
1 parent 602ec96 commit 32fc074
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 2 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.19 (2013-08-12)

* Implemented Windows#Invoice.update

## 0.1.18 (2013-08-08)

* Fixed issue with incorrect time format for parsing UTC date/times. Thanks Sean Xie- https://github.com/seanxiesx
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ Company Meta Data | no | no | no | no | no | `load`
Customer | yes | yes | yes | no | yes |
Employee | no | no | yes | no | no |
Entitlement | n/a | n/a | n/a | n/a | n/a |
Invoice | yes | no | yes | no | yes |
Invoice | yes | yes | yes | no | yes |
Item | yes | no | yes | no | yes |
Journal Entry | no | no | no | no | no |
Payment | yes | no | yes | no | yes |
Expand Down
2 changes: 1 addition & 1 deletion lib/quickeebooks/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Quickeebooks

VERSION = "0.1.18"
VERSION = "0.1.19"

end
25 changes: 25 additions & 0 deletions lib/quickeebooks/windows/service/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@ def create(invoice)
end
perform_write(Quickeebooks::Windows::Model::Invoice, xml)
end

def update(invoice)
# XML is a wrapped 'object' where the type is specified as an attribute
# <Object xsi:type="Invoice">

# Intuit requires that some fields are unset / do not exist.
invoice.meta_data = nil
invoice.external_key = nil

# unset Id fields in addresses
if invoice.header.billing_address
invoice.header.billing_address.id = nil
end

if invoice.header.shipping_address
invoice.header.shipping_address.id = nil
end

xml_node = invoice.to_xml(:name => 'Object')
xml_node.set_attribute('xsi:type', 'Invoice')
xml = Quickeebooks::Shared::Service::OperationNode.new.mod do |content|
content << "<ExternalRealmId>#{self.realm_id}</ExternalRealmId>#{xml_node}"
end
perform_write(Quickeebooks::Windows::Model::Invoice, xml)
end

end
end
Expand Down
20 changes: 20 additions & 0 deletions spec/quickeebooks/windows/services/invoice_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,25 @@
invoice = service.fetch_by_id('40154')
invoice.header.doc_number.should == "1515"
end

it "can update an invoice" do
invoice_xml = windowsFixture("invoice_2.xml")
update_response_xml = windowsFixture("invoice_update_success.xml")
service = Quickeebooks::Windows::Service::Invoice.new
model = Quickeebooks::Windows::Model::Invoice
invoice = model.from_xml(invoice_xml)
invoice.header.customer_name.should == "Cafe Smith"

service.access_token = @oauth
service.realm_id = @realm_id
FakeWeb.register_uri(:post, service.url_for_resource(model::REST_RESOURCE), :status => ["200", "OK"], :body => update_response_xml)

# alter the note
invoice.header.note = "an updated note"
update_response = service.update(invoice)
update_response.success?.should == true
update_response.success.object_ref.id.value.should == "98"
update_response.success.request_name.should == "InvoiceMod"
end

end
80 changes: 80 additions & 0 deletions spec/xml/windows/invoice_2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<Invoice>
<Id idDomain="QB">40154</Id>
<SyncToken>1</SyncToken>
<MetaData>
<CreateTime>2013-01-29T17:53:55.874Z</CreateTime>
<LastUpdatedTime>2013-02-21T23:21:00.357Z</LastUpdatedTime>
</MetaData>
<ExternalKey idDomain="QB">40154</ExternalKey>
<Synchronized>true</Synchronized>
<Header>
<DocNumber>1515</DocNumber>
<TxnDate>2013-01-23T00:00:00Z</TxnDate>
<Status>Paid</Status>
<CustomerId idDomain="QB">694</CustomerId>
<CustomerName>Cafe Smith</CustomerName>
<RemitToId idDomain="QB">694</RemitToId>
<RemitToName>Cafe Smith</RemitToName>
<SalesRepId idDomain="QB">15</SalesRepId>
<SalesRepName>OT</SalesRepName>
<SalesTaxCodeId idDomain="QB">2</SalesTaxCodeId>
<SalesTaxCodeName>Non</SalesTaxCodeName>
<ShipDate>2013-01-23T00:00:00Z</ShipDate>
<SubTotalAmt>1520</SubTotalAmt>
<TaxId idDomain="QB">80</TaxId>
<TaxName>San Francisco County</TaxName>
<TaxRate>8.5</TaxRate>
<TaxAmt>0</TaxAmt>
<TotalAmt>1520</TotalAmt>
<ToBePrinted>false</ToBePrinted>
<ToBeEmailed>false</ToBeEmailed>
<ARAccountId idDomain="QB">48</ARAccountId>
<ARAccountName>Accounts Receivable</ARAccountName>
<SalesTermId idDomain="QB">6</SalesTermId>
<SalesTermName>Net 30</SalesTermName>
<DueDate>2013-02-22T00:00:00Z</DueDate>
<BillAddr>
<Id idDomain="QB">00000000000017bL</Id>
<Line1>1313</Line1>
<Line2>1313 Main Street</Line2>
<City>Napa</City>
<CountrySubDivisionCode>CA</CountrySubDivisionCode>
<PostalCode>94559</PostalCode>
<Default>true</Default>
<Tag>Billing</Tag>
</BillAddr>
<ShipAddr>
<Id idDomain="QB">00000000000018TF</Id>
<Line1>Cafe Smith</Line1>
<Line2>1313 Main Street</Line2>
<City>Napa</City>
<CountrySubDivisionCode>CA</CountrySubDivisionCode>
<PostalCode>94559</PostalCode>
<Default>false</Default>
<Tag>Shipping</Tag>
</ShipAddr>
<ShipMethodId idDomain="QB">5</ShipMethodId>
<Balance>0</Balance>
</Header>
<Line>
<Id idDomain="QB">40156</Id>
<Desc>2010 Charles Shaw</Desc>
<Amount>1520</Amount>
<Taxable>false</Taxable>
<ItemId idDomain="QB">330</ItemId>
<ItemName>SHAW2010</ItemName>
<ItemType>Inventory</ItemType>
<UnitPrice>760</UnitPrice>
<Qty>2</Qty>
<UOMId idDomain="QB">2</UOMId>
<UOMAbbrv>12-750ML</UOMAbbrv>
<SalesTaxCodeId idDomain="QB">2</SalesTaxCodeId>
<SalesTaxCodeName>Non</SalesTaxCodeName>
</Line>
<TaxLine>
<Id idDomain="QB">40157</Id>
<Amount>0</Amount>
<TaxId idDomain="QB">80</TaxId>
<TaxName>San Francisco County</TaxName>
</TaxLine>
</Invoice>
11 changes: 11 additions & 0 deletions spec/xml/windows/invoice_update_success.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<RestResponse xmlns="http://www.intuit.com/sb/cdm/v2">
<Success RequestId="f8e9785dd55d38b0d2c0d8cfca2a0d66">
<ObjectRef>
<Id idDomain="QB">98</Id>
<SyncToken>1</SyncToken>
<LastUpdatedTime>2013-08-12T17:48:50Z</LastUpdatedTime>
</ObjectRef>
<RequestName>InvoiceMod</RequestName>
<ProcessedTime>2013-08-12T17:48:50Z</ProcessedTime>
</Success>
</RestResponse>

1 comment on commit 32fc074

@theinventor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You rock :)

Please sign in to comment.