fix: allow swaps with total < 0 (#143)

This commit is contained in:
Sebastian Rindom
2020-12-02 17:37:46 +01:00
committed by GitHub
parent 454504cdf4
commit 304431e7c3
5 changed files with 130 additions and 55 deletions
@@ -477,7 +477,7 @@ class BrightpearlService extends BaseService {
const soId =
fromSwap.metadata && fromSwap.metadata.brightpearl_sales_order_id
if (!soId) {
if (!soId || fromSwap.amount_paid <= 0) {
return
}
@@ -558,6 +558,10 @@ class BrightpearlService extends BaseService {
const order = await client.orders.retrieve(salesOrderId)
await client.warehouses.createReservation(order, this.options.warehouse)
const total = order.rows.reduce((acc, next) => {
return acc + parseFloat(next.net) + parseFloat(next.tax)
}, 0)
const paymentMethod = fromOrder.payment_method
const paymentType = "RECEIPT"
const payment = {
@@ -566,7 +570,7 @@ class BrightpearlService extends BaseService {
paymentMethodCode: this.options.payment_method_code || "1220",
orderId: salesOrderId,
currencyIsoCode: fromOrder.currency_code,
amountPaid: fromSwap.return.refund_amount,
amountPaid: total,
paymentDate: new Date(),
paymentType,
}