Open StaverDmitry opened 5 years ago
Is this the expected behaviour?
The expected behavior according the the docs is that It will update the line item (when a line_item_id
) is supplied. This is still a bug as of writing this comment.
This gem was created before Lineitems had Id's. Lineitem Id's were introduced as part of "Linked Transactions", which is used for Billable Expenses.
Docs: https://developer.xero.com/documentation/api/accounting/linkedtransactions#overview Billable Expenses Demo: https://www.youtube.com/watch?v=9gwHEZudsNA
Prior to this Linked Transactions, lineitems were only relevant to the invoice they appears on (for calculating totals). After Linked Transactions a lineitem could be referenced by another document (AccRec for example).
In terms of the actual fix, you are correct.
A lineitem with LineItemId should be updated, not recreated.
So I'd classify this as a feature / improvement to the SDK. Tho, considering Billable Expenses was released in 2015 (6 years ago), I can see why it would also be classified as a bug at this stage.
If someone would like to fix this, please submit a PR, happy to merge & release
I just hit this problem with my app and after talking it through with Xero, it seems the problem is that Xero's XML is case-sensitive. The key should be LineItemID not LineItemId.
Looking through the code it looks like the problem is that LineItemId has been set as a string not as a guid - which has the fix for Id vs ID.
This is a
bug report
; Expected:invoice.save!
should update line items; What happens:invoice.save!
deletes and recreates line items with new ids.Hi! I'm not sure what's going on because following documentation and the way the gem is working it should work properly. Documentation says that
It is recommended that you include LineItemIDs on update requests. If LineItemIDs are not included with line items in an update request then the line items are deleted and recreated.
However it seems even though LineItemID is automatically included into ainvoice.save!
request, their ids are still changed. Here's the LIneItems part of the request I got frominvoice.to_xml
(some params including LineItemID are modified for security). As you can see the LineItemID is included here and I verified that it's correct.Here I just updated the
UnitAmount
of a single line item. Though seems like line items are always recreated even if nothing was changed.If I'm not mistaken, following the code
invoice.save!
should directly pass this xml to the http request to XERO. So theLineItemID
is included and it should just update those line items, but right afterinvoice.save!
method, line items in this sameinvoice
object get newline_item_id
's meaning they were recreated.