From 8c5f0d3019a818c838a566ee7405aad852fa2f4e Mon Sep 17 00:00:00 2001 From: joan Date: Fri, 19 Nov 2021 09:24:31 +0100 Subject: [PATCH] feat(createClaim): disallow claim creation for a ticket delivered more than seven days ago Refs: 3278 --- loopback/locale/es.json | 3 ++- modules/claim/back/methods/claim/createFromSales.js | 6 ++++++ modules/ticket/front/sale/index.html | 3 ++- modules/ticket/front/sale/index.js | 10 ++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 4a5448d34..e42c13c72 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -212,5 +212,6 @@ "You don't have enough privileges to set this credit amount": "No tienes suficientes privilegios para establecer esta cantidad de crédito", "You can't change the credit set to zero from a manager": "No puedes cambiar el cŕedito establecido a cero por un gerente", "The PDF document does not exists": "El documento PDF no existe. Prueba a regenerarlo desde la opción 'Regenerar PDF factura'", - "The type of business must be filled in basic data": "El tipo de negocio debe estar rellenado en datos básicos" + "The type of business must be filled in basic data": "El tipo de negocio debe estar rellenado en datos básicos", + "You can't create a claim from a ticket delivered more than seven days ago": "No puedes crear una reclamación de un ticket entregado hace más de siete días" } \ No newline at end of file diff --git a/modules/claim/back/methods/claim/createFromSales.js b/modules/claim/back/methods/claim/createFromSales.js index f22aabbf3..cdbce865b 100644 --- a/modules/claim/back/methods/claim/createFromSales.js +++ b/modules/claim/back/methods/claim/createFromSales.js @@ -57,8 +57,14 @@ module.exports = Self => { } }, myOptions); + const landedPlusWeek = new Date(ticket.landed); + landedPlusWeek.setDate(landedPlusWeek.getDate() + 7); + const isClaimable = landedPlusWeek >= new Date(); + if (ticket.isDeleted) throw new UserError(`You can't create a claim for a removed ticket`); + if (!isClaimable) + throw new UserError(`You can't create a claim from a ticket delivered more than seven days ago`); const newClaim = await Self.create({ ticketFk: ticketId, diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index cbb95d901..0aa41226b 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -469,7 +469,8 @@ + ng-click="$ctrl.createClaim()" + ng-if="$ctrl.isClaimable"> Add claim = new Date(); + } + return false; + } + getSaleTotal(sale) { if (sale.quantity == null || sale.price == null) return null;