in src/main/scala/com/gu/invoicing/refund/Impl.scala [226:244]
def getInvoiceItemAdjustments(invoiceId: String): List[InvoiceItemAdjustment] =
post[InvoiceItemAdjustmentsQueryResult](
s"$zuoraApiHost/v1/action/query",
s"""{"queryString": "select Id, InvoiceId, InvoiceItemName, SourceId, SourceType, Status, Type, Amount FROM InvoiceItemAdjustment where InvoiceId = '$invoiceId'"}""",
).records
/** Zuora uses Half Up rounding to two decimal places with rounding increment of 0.1 Corresponds to rounding rules
* specified under Zuora | Billing Settings | Customize Currencies
*/
def roundHalfUp(x: BigDecimal): BigDecimal = x.setScale(2, BigDecimal.RoundingMode.HALF_UP)
// https://knowledgecenter.zuora.com/Billing/Billing_and_Payments/TB_Rounding_and_Precision
def roundAdjustments(
adjustments: List[InvoiceItemAdjustmentWrite],
): List[InvoiceItemAdjustmentWrite] = {
adjustments
.filter(a => roundHalfUp(a.Amount) != 0)
.map(a => a.copy(Amount = roundHalfUp(a.Amount)))
}