diff --git a/lib/machine-loader.js b/lib/machine-loader.js index e5a933ac..009d262f 100644 --- a/lib/machine-loader.js +++ b/lib/machine-loader.js @@ -213,6 +213,11 @@ function emptyMachineUnits ({ deviceId, newUnits, fiatCode }) { _.keys(_.omit(['cashbox'], movedBills)) ) + // This occurs when an empty unit is called when the units are already empty, hence, no bills moved around + if (_.isEmpty(billArr) && _.isEmpty(operationsToCreate)) { + return Promise.resolve() + } + return db.tx(t => { const q1Cols = ['id', 'device_id', 'operation_type'] const q1= t.none(pgp.helpers.insert(operationsToCreate, q1Cols, 'cash_unit_operation')) @@ -260,6 +265,11 @@ function refillMachineUnits ({ deviceId, newUnits }) { operation_type: it }))(operationNames) + // This occurs when a refill unit is called when the loading boxes are empty, hence, no bills moved around + if (_.isEmpty(operationsToCreate)) { + return Promise.resolve() + } + return db.tx(t => { const q1Cols = ['id', 'device_id', 'operation_type'] const q1= t.none(pgp.helpers.insert(operationsToCreate, q1Cols, 'cash_unit_operation'))