Bug #358 Credit create no da un error comprensible

This commit is contained in:
gerard 2018-06-18 13:41:49 +02:00
parent 532d20cd7f
commit 1ecb3f3d2b
3 changed files with 9 additions and 12 deletions

View File

@ -4,7 +4,7 @@
"Unable to mark the equivalence surcharge": "Unable to mark the equivalence surcharge",
"The default consignee can not be unchecked": "The default consignee can not be unchecked",
"Unable to default a disabled consignee": "Unable to default a disabled consignee",
"Can't be blank": "No puede estar en blanco",
"Can't be blank": "Can't be blank",
"Invalid TIN": "Invalid TIN",
"TIN must be unique": "TIN must be unique",
"A user with that name already exists": "A user with that name already exists",
@ -18,5 +18,5 @@
"That payment method requires an IBAN": "That payment method requires an IBAN",
"State cannot be blank": "State cannot be blank",
"Cannot change the payment method if no salesperson": "Cannot change the payment method if no salesperson",
"Observation type cannot be blank": "Observation type cannot be blank"
"Only manager can change the credit": "Only manager can change the credit"
}

View File

@ -4,7 +4,7 @@
"Unable to mark the equivalence surcharge": "No se puede marcar el recargo de equivalencia",
"The default consignee can not be unchecked": "No se puede desmarcar el consignatario predeterminado",
"Unable to default a disabled consignee": "No se puede poner predeterminado un consignatario desactivado",
"Can't be blank": "Can't be blank",
"Can't be blank": "No puede estar en blanco",
"Invalid TIN": "DNI Incorrecto",
"TIN must be unique": "El NIF/CIF debe ser único",
"A user with that name already exists": "Ya existe un usuario con ese nombre",
@ -23,5 +23,6 @@
"Observation type must be unique": "El tipo de observación no puede repetirse",
"The credit must be an integer greater than or equal to zero": "The credit must be an integer greater than or equal to zero",
"The grade must be similar to the last one": "El grade debe ser similar al último",
"NO_AGENCY_AVAILABLE": "NO_AGENCY_AVAILABLE"
"NO_AGENCY_AVAILABLE": "NO_AGENCY_AVAILABLE",
"Only manager can change the credit": "Solo el gerente puede cambiar el credito de este cliente"
}

View File

@ -111,11 +111,7 @@ module.exports = Self => {
}
if (changes.credit !== undefined) {
try {
await validateCreditChange(ctx, finalState);
} catch (e) {
throw new UserError('You are not allowed to change the credit');
}
await validateCreditChange(ctx, finalState);
let filter = {fields: ['id'], where: {userFk: ctx.options.accessToken.userId}};
let worker = await Self.app.models.Worker.findOne(filter);
@ -146,7 +142,7 @@ module.exports = Self => {
let limits = await models.ClientCreditLimit.find(filter);
if (limits.length == 0)
throw new Error('Credit limits not found');
throw new UserError('Credit limits not found');
// Si el usuario no tiene alguno de los roles no continua
@ -162,7 +158,7 @@ module.exports = Self => {
let count = await models.RoleMapping.count(where);
if (count <= 0)
throw new Error('The role cannot set this credit amount');
throw new UserError('The role cannot set this credit amount');
// Si se puso a 0 por gerencia, solo gerencia puede aumentarlo
@ -185,6 +181,6 @@ module.exports = Self => {
let instance = await Self.rawSql(query, [instances[0].workerFk]);
if (instance[0].hasRoleManager)
throw new Error('Only manager can change the credit');
throw new UserError('Only manager can change the credit');
}
};