-
Notifications
You must be signed in to change notification settings - Fork 89
Credit Note Allocations (plus minor tweaks) #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
85318d3
00ab8a4
acb8be4
4a84a93
fd6e9e7
663b11d
2d9937b
0a2c0ff
024925f
466cc1b
39fdab4
3cf2ed8
0fe6d6f
e20bf15
4aa6dd2
beee9c4
dd5e3e0
6c3da48
b290bfa
20aa4c3
1c1d325
559f859
f30db4e
5cf6434
83b4139
15da8a5
6a88f01
8c4b50d
10ea103
1170bfa
00c0f9c
0e7ecf5
f6dea68
0aefa57
429b1d4
df94dbb
0a416d3
e2205b2
4f12bbe
8dee24f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module XeroGateway | ||
class Allocation < BaseRecord | ||
attributes( | ||
'AppliedAmount' => :float, | ||
'Date' => :date, | ||
'CreditNoteID' => :string, | ||
'CreditNoteNumber' => :string, | ||
'Invoice' => { | ||
'InvoiceID' => :string, | ||
'InvoiceNumber' => :string | ||
} | ||
) | ||
|
||
alias invoice_id invoice_invoice_id | ||
alias invoice_number invoice_invoice_number | ||
alias invoice_id= invoice_invoice_id= | ||
alias invoice_number= invoice_invoice_number= | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ class Invoice | |
# 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, :currency_rate, :payments, :fully_paid_on, :amount_due, :amount_paid, :amount_credited, | ||
:sent_to_contact, :url, :updated_date_utc | ||
:sent_to_contact, :url, :updated_at, :credit_note_allocations | ||
attr_writer :contact, :line_items | ||
|
||
def initialize(params = {}) | ||
|
@@ -58,6 +58,7 @@ def initialize(params = {}) | |
end | ||
|
||
@line_items ||= [] | ||
@credit_note_allocations ||= [] | ||
end | ||
|
||
# Validate the Address record according to what will be valid by the gateway. | ||
|
@@ -213,8 +214,8 @@ def self.from_xml(invoice_element, gateway = nil, options = {}) | |
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_at = parse_date_time(element.text) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing this probably makes the PR a breaking change unfortunately. Do you think it would be worth maintaining the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well the reason for the change was simply that the attr_accessor is for |
||
when "FullyPaidOnDate" then invoice.fully_paid_on = 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 | ||
|
@@ -223,13 +224,18 @@ def self.from_xml(invoice_element, gateway = nil, options = {}) | |
when "SubTotal" then invoice.sub_total = BigDecimal(element.text) | ||
when "TotalTax" then invoice.total_tax = BigDecimal(element.text) | ||
when "Total" then invoice.total = BigDecimal(element.text) | ||
when "Payments" then element.children.each { | payment | invoice.payments << Payment.from_xml(payment) } | ||
when "Payments" then element.children.each do |payment| | ||
invoice.payments << Payment.from_xml(payment).tap { |p| p.currency_code = invoice.currency_code } | ||
end | ||
when "AmountDue" then invoice.amount_due = BigDecimal(element.text) | ||
when "AmountPaid" then invoice.amount_paid = BigDecimal(element.text) | ||
when "AmountCredited" then invoice.amount_credited = BigDecimal(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) } | ||
when "CreditNotes" then element.children.each do |credit_note| | ||
invoice.credit_note_allocations << Allocation.from_xml(credit_note) | ||
end | ||
end | ||
end | ||
invoice | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good solution for now, but we should really build up a list of the entities that are "flattenable" and those that just happen to be returning a single value :)