lib/xero_gateway/invoice.rb in xero_gateway-2.1.0 vs lib/xero_gateway/invoice.rb in xero_gateway-2.3.0

- old
+ new

@@ -35,13 +35,12 @@ # Represents whether the line_items have been downloaded when getting from GET /API.XRO/2.0/INVOICES attr_accessor :line_items_downloaded # All accessible fields - attr_accessor :invoice_id, :invoice_number, :invoice_type, :invoice_status, :date, :due_date, :reference, :branding_theme_id, :line_amount_types, :currency_code, :line_items, :contact, :payments, :fully_paid_on, :amount_due, :amount_paid, :amount_credited, :sent_to_contact, :url + attr_accessor :invoice_id, :invoice_number, :invoice_type, :invoice_status, :date, :due_date, :reference, :branding_theme_id, :line_amount_types, :currency_code, :line_items, :contact, :payments, :fully_paid_on, :amount_due, :amount_paid, :amount_credited, :sent_to_contact, :url, :updated_date_utc - def initialize(params = {}) @errors ||= [] @payments ||= [] # Check if the line items have been downloaded. @@ -121,11 +120,17 @@ # Whether or not the line_items have been downloaded (GET/invoices does not download line items). def line_items_downloaded? @line_items_downloaded end - + + %w(sub_total tax_total total).each do |line_item_total_type| + define_method("#{line_item_total_type}=") do |new_total| + instance_variable_set("@#{line_item_total_type}", new_total) unless line_items_downloaded? + end + end + # If line items are not downloaded, then attempt a download now (if this record was found to begin with). def line_items if line_items_downloaded? @line_items @@ -213,9 +218,10 @@ when "Type" then invoice.invoice_type = element.text when "CurrencyCode" then invoice.currency_code = element.text when "Contact" then invoice.contact = Contact.from_xml(element) when "Date" then invoice.date = parse_date(element.text) when "DueDate" then invoice.due_date = parse_date(element.text) + when "UpdatedDateUTC" then invoice.updated_date_utc = parse_date(element.text) when "Status" then invoice.invoice_status = element.text when "Reference" then invoice.reference = element.text when "BrandingThemeID" then invoice.branding_theme_id = element.text when "LineAmountTypes" then invoice.line_amount_types = element.text when "LineItems" then element.children.each {|line_item| invoice.line_items_downloaded = true; invoice.line_items << LineItem.from_xml(line_item) }