lib/xero_gateway/invoice.rb in xero_gateway-2.0.19 vs lib/xero_gateway/invoice.rb in xero_gateway-2.1.0
- old
+ new
@@ -28,17 +28,18 @@
# Xero::Gateway associated with this invoice.
attr_accessor :gateway
# Any errors that occurred when the #valid? method called.
- attr_reader :errors
+ # Or errors that were within the XML payload from Xero
+ attr_accessor :errors
# 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, :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
def initialize(params = {})
@errors ||= []
@payments ||= []
@@ -64,10 +65,14 @@
#
# Additionally sets address.errors array to an array of field/error.
def valid?
@errors = []
+ if !INVOICE_TYPE[invoice_type]
+ @errors << ['invoice_type', "must be one of #{INVOICE_TYPE.keys.join('/')}"]
+ end
+
if !invoice_id.nil? && invoice_id !~ GUID_REGEX
@errors << ['invoice_id', 'must be blank or a valid Xero GUID']
end
if invoice_status && !INVOICE_STATUS[invoice_status]
@@ -185,10 +190,11 @@
contact.to_xml(b)
b.Date Invoice.format_date(self.date || Date.today)
b.DueDate Invoice.format_date(self.due_date) if self.due_date
b.Status self.invoice_status if self.invoice_status
b.Reference self.reference if self.reference
+ b.BrandingThemeID self.branding_theme_id if self.branding_theme_id
b.LineAmountTypes self.line_amount_types
b.LineItems {
self.line_items.each do |line_item|
line_item.to_xml(b)
end
@@ -209,24 +215,26 @@
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 "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) }
when "SubTotal" then invoice.sub_total = BigDecimal.new(element.text)
when "TotalTax" then invoice.total_tax = BigDecimal.new(element.text)
when "Total" then invoice.total = BigDecimal.new(element.text)
when "InvoiceID" then invoice.invoice_id = element.text
- when "InvoiceNumber" then invoice.invoice_number = element.text
+ when "InvoiceNumber" then invoice.invoice_number = element.text
when "Payments" then element.children.each { | payment | invoice.payments << Payment.from_xml(payment) }
when "AmountDue" then invoice.amount_due = BigDecimal.new(element.text)
when "AmountPaid" then invoice.amount_paid = BigDecimal.new(element.text)
when "AmountCredited" then invoice.amount_credited = BigDecimal.new(element.text)
when "SentToContact" then invoice.sent_to_contact = (element.text.strip.downcase == "true")
when "Url" then invoice.url = element.text
+ when "ValidationErrors" then invoice.errors = element.children.map { |error| Error.parse(error) }
end
- end
+ end
invoice
- end
+ end
end
end