Module: Invoicexpress::Client::PurchaseOrders
- Included in:
- Invoicexpress::Client
- Defined in:
- lib/invoicexpress/client/purchase_orders.rb
Instance Method Summary collapse
-
#create_purchase_order(purchase_order, options = {}) ⇒ Object
Creates a new purchase order.
-
#purchase_order(purchase_order, options = {}) ⇒ Object
Returns a specific purchase order.
-
#purchase_order_mail(purchase_order_id, message, options = {}) ⇒ Object
Sends the purchase order by email.
-
#purchase_orders(options = {}) ⇒ Array<Invoicexpress::Models::PurchaseOrder>
Returns all your purchase orders.
-
#update_purchase_order(purchase_order, options = {}) ⇒ Object
Updates a purchase order Updates a purchase order.
-
#update_purchase_order_state(purchase_order_id, purchase_order_state, options = {}) ⇒ Invoicexpress::Models::PurchaseOrder
Changes the state of a purchase order.
Instance Method Details
#create_purchase_order(purchase_order, options = {}) ⇒ Object
Creates a new purchase order. Creates a new purchase order. Also allows to create a new supplier and/or new items in the same request. If the supplier name does not exist a new one is created. If items do not exist with the given names, new ones will be created. If item name already exists, the item is updated with the new values. Regarding item taxes, if the tax name is not found, no tax is applyed to that item.
28 29 30 31 32 33 |
# File 'lib/invoicexpress/client/purchase_orders.rb', line 28 def create_purchase_order(purchase_order, ={}) raise(ArgumentError, "purchase order has the wrong type") unless purchase_order.is_a?(Invoicexpress::Models::PurchaseOrder) params = { :klass => Invoicexpress::Models::PurchaseOrder, :body => purchase_order } post("purchase_orders.xml", params.merge()) end |
#purchase_order(purchase_order, options = {}) ⇒ Object
Returns a specific purchase order.
41 42 43 44 45 |
# File 'lib/invoicexpress/client/purchase_orders.rb', line 41 def purchase_order(purchase_order, ={}) params = { :klass => Invoicexpress::Models::PurchaseOrder } get("purchase_orders/#{id_from_purchase_order(purchase_order)}.xml", params.merge()) end |
#purchase_order_mail(purchase_order_id, message, options = {}) ⇒ Object
Sends the purchase order by email
105 106 107 108 109 110 |
# File 'lib/invoicexpress/client/purchase_orders.rb', line 105 def purchase_order_mail(purchase_order_id, , ={}) raise(ArgumentError, "message has the wrong type") unless .is_a?(Invoicexpress::Models::Message) params = { :body => , :klass => Invoicexpress::Models::PurchaseOrder } put("purchase_orders/#{purchase_order_id}/email-document.xml", params.merge()) end |
#purchase_orders(options = {}) ⇒ Array<Invoicexpress::Models::PurchaseOrder>
Returns all your purchase orders.
11 12 13 14 15 |
# File 'lib/invoicexpress/client/purchase_orders.rb', line 11 def purchase_orders( = {}) params = { :page => 1, :klass => Invoicexpress::Models::PurchaseOrder } get("purchase_orders.xml", params.merge()) end |
#update_purchase_order(purchase_order, options = {}) ⇒ Object
Updates a purchase order Updates a purchase order. Also allows to create a new supplier and/or new items in the same request. If the supplier name does not exist a new one is created. If items do not exist with the given names, new ones will be created. If item name already exists, the item is updated with the new values. Regarding item taxes, if the tax name is not found, no tax is applyed to that item. Be careful when updating the invoice items, any missing items from the original invoice will be deleted.
59 60 61 62 63 64 65 66 67 |
# File 'lib/invoicexpress/client/purchase_orders.rb', line 59 def update_purchase_order(purchase_order, ={}) raise(ArgumentError, "purchase order has the wrong type") unless purchase_order.is_a?(Invoicexpress::Models::PurchaseOrder) if !purchase_order.id raise ArgumentError, "Purchase Order ID is required" end params = { :klass => Invoicexpress::Models::PurchaseOrder, :body => purchase_order.to_core_purchase_order } put("purchase_orders/#{purchase_order.id}.xml", params.merge()) end |
#update_purchase_order_state(purchase_order_id, purchase_order_state, options = {}) ⇒ Invoicexpress::Models::PurchaseOrder
Changes the state of a purchase order. Possible state transitions:
-
draft to final – finalized
-
draft to deleted – deleted
-
final to second_copy – second_copy
-
final to accepted – accepted
-
final to refused – refused
-
final to canceled – canceled
-
second_copy to canceled – canceled
-
accepted to refused – refused
-
accepted to completed – completed
-
refused to canceled – canceled
-
refused to accepted – accepted
Any other transitions will fail. When canceling an purchase order you must specify a reason.
91 92 93 94 95 96 |
# File 'lib/invoicexpress/client/purchase_orders.rb', line 91 def update_purchase_order_state(purchase_order_id, purchase_order_state, ={}) raise(ArgumentError, "purchase_order_state has the wrong type") unless purchase_order_state.is_a?(Invoicexpress::Models::InvoiceState) params = { :klass => Invoicexpress::Models::PurchaseOrder, :body => purchase_order_state } put("purchase_orders/#{purchase_order_id}/change-state.xml", params.merge()) end |