Skip to content
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

Line items are recreated instead of being updated #480

Open
StaverDmitry opened this issue Jun 18, 2019 · 5 comments
Open

Line items are recreated instead of being updated #480

StaverDmitry opened this issue Jun 18, 2019 · 5 comments
Labels

Comments

@StaverDmitry
Copy link

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 a invoice.save! request, their ids are still changed.
Here's the LIneItems part of the request I got from invoice.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.

  <LineItems>
    <LineItem>
      <ItemCode>my-item-code</ItemCode>
      <Description>description</Description>
      <UnitAmount>1</UnitAmount>
      <TaxType>TAX004</TaxType>
      <TaxAmount>0.0</TaxAmount>
      <LineAmount>1.0</LineAmount>
      <AccountCode>100</AccountCode>
      <Tracking>
        <TrackingCategory>
          <Name>TC_name</Name>
          <Option>TC_option</Option>
          <TrackingCategoryID>TC_ID</TrackingCategoryID>
        </TrackingCategory>
      </Tracking>
      <Quantity>1.0</Quantity>
      <LineItemId>myawesomeid-f8d1-590c-8036-212eeb63a8hc</LineItemId>
    </LineItem>
  </LineItems>

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 the LineItemID is included and it should just update those line items, but right after invoice.save! method, line items in this same invoice object get new line_item_id's meaning they were recreated.

@RORingBBK
Copy link

Is this the expected behaviour?

@toyhammered
Copy link
Contributor

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.

@rjaus rjaus added the feature label Oct 11, 2021
@rjaus
Copy link
Collaborator

rjaus commented Oct 11, 2021

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

@troubadournz
Copy link
Contributor

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.

@troubadournz
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants