Description
I was trying to create a sales receipt and found that no matter how I coded it up it was always throwing a Quickbooks error:
"You can't set both an amount and a discount percentage if the amount is not the sum of the discount percentage and the subtotal."
I struggled with this for some time trying different things to try and get around the error.
- Tried removing the line amount and only putting in a discount percentage. This did not work, the same error persisted.
- Tried removing the discount line details.
- Tried adding a DiscountAccountRef.
I then went into Postman and ran a few tests. Posting a successful discount line and then duplicating what I thought was happening by posting a discount line with both an amount and a percentage of 0. And sure enough it came back with the same error.
What I think is happening is the DiscountLineDetail object has the DiscountPercent property set as a non-nullable type of decimal. When the JSON serializer, serializes this object it defaults the DiscountPercent value to 0. When the request is sent to Quickbooks it always throws an error since it is always sending both a line amount and a discount percentage.
Making either or, both the Amount property and the DiscountPercent property to be nullable type decimal datatypes should correct the problem.