lib/economic/current_invoice_line.rb in rconomic-0.1.0 vs lib/economic/current_invoice_line.rb in rconomic-0.2.0
- old
+ new
@@ -1,13 +1,37 @@
require 'economic/entity'
require 'economic/current_invoice'
module Economic
+ # Represents a current invoice line.
+ #
+ # API documentation: http://www.e-conomic.com/apidocs/Documentation/T_Economic_Api_ICurrentInvoiceLine.html
+ #
+ # See Economic::CurrentInvoice for usage example
class CurrentInvoiceLine < Entity
has_properties :invoice_handle, :description, :delivery_date, :unit_handle, :product_handle, :quantity, :unit_net_price, :discount_as_percent, :unit_cost_price, :total_net_amount, :total_margin, :margin_as_percent
+ def handle
+ Handle.new(:number => number)
+ end
+
+ def invoice
+ return nil if invoice_handle.blank?
+ @invoice ||= session.current_invoices.find(invoice_handle)
+ end
+
+ def invoice=(invoice)
+ self.invoice_handle = invoice.handle
+ @invoice = invoice
+ end
+
+ def invoice_handle=(handle)
+ @invoice = nil unless handle == @invoice_handle
+ @invoice_handle = handle
+ end
+
def initialize_defaults
self.invoice_handle = nil
self.description = nil
self.delivery_date = nil
self.unit_handle = nil
@@ -25,10 +49,10 @@
# to be sent via SOAP
def build_soap_data
data = ActiveSupport::OrderedHash.new
data['Number'] = 0 # Doesn't seem to be used
- data['InvoiceHandle'] = { 'Id' => invoice_handle[:id] } unless invoice_handle.blank?
+ data['InvoiceHandle'] = invoice.handle.to_hash unless invoice.blank?
data['Description'] = description unless description.blank?
data['DeliveryDate'] = delivery_date
data['UnitHandle'] = { 'Number' => unit_handle[:number] } unless unit_handle.blank?
data['ProductHandle'] = { 'Number' => product_handle[:number] } unless product_handle.blank?
data['Quantity'] = quantity unless quantity.blank?
\ No newline at end of file