
Invoice line item 100% discount amount gives validation error
I am attempting to submit an invoice with a zero total because the user has applied store credit. I am applying the discount as a discountAmount to each line item. Here's an example LineItem object
However, when applied to an invoice, I get the following validation error:
The discount rate '228.65' is invalid. Discount must not be greater than the line total.
Examining the invoice object, I can see that the line item has the discountRate set to the same value as the discountAmount:
discount_rate => 228.65
discount_amount => 228.65
even though discountRate was set to null when adding the line item.
How do I prevent this validation error?
This code is provided by the developer community - Xero does not warrant it in any way
However, when applied to an invoice, I get the following validation error:
The discount rate '228.65' is invalid. Discount must not be greater than the line total.
Examining the invoice object, I can see that the line item has the discountRate set to the same value as the discountAmount:
discount_rate => 228.65
discount_amount => 228.65
even though discountRate was set to null when adding the line item.
How do I prevent this validation error?
3
Replies

Hi Robin,
This looks like a bit of a bug at our end. I did some testing in the API Explorer and it looks like currently this will error if a discount amount equal to the lineamount is provided AS WELL as a LineAmount of 0. If the LineAmount is omitted or set to null then it will calculate correctly.
I'm not familiar with the language you're using so I'm not sure where it would be getting defaulted to 0 rather than null.
I'm going to raise a bug with the team
This looks like a bit of a bug at our end. I did some testing in the API Explorer and it looks like currently this will error if a discount amount equal to the lineamount is provided AS WELL as a LineAmount of 0. If the LineAmount is omitted or set to null then it will calculate correctly.
I'm not familiar with the language you're using so I'm not sure where it would be getting defaulted to 0 rather than null.
I'm going to raise a bug with the team

Thanks Steven. I am using the xero-php-oauth2 library.

Hi Steven,
I'm now getting this error - where are you at with this bug fix?
Thanks so much!
I'm now getting this error - where are you at with this bug fix?
Thanks so much!