diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 37cb8f7d9..9ffae7997 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -215,5 +215,6 @@ "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", "The worker has hours recorded that day": "El trabajador tiene horas fichadas ese día", "The worker has a marked absence that day": "El trabajador tiene marcada una ausencia ese día", - "You can not modify is pay method checked": "No se puede modificar el campo método de pago validado" -} \ No newline at end of file + "You can not modify is pay method checked": "No se puede modificar el campo método de pago validado", + "Can't transfer claimed sales": "No puedes transferir lineas reclamadas" + } \ No newline at end of file diff --git a/modules/monitor/front/routes.json b/modules/monitor/front/routes.json index 8fc995e4c..acad3ecbc 100644 --- a/modules/monitor/front/routes.json +++ b/modules/monitor/front/routes.json @@ -10,7 +10,12 @@ ], "card": [] }, - "keybindings": [], + "keybindings": [ + { + "key": "m", + "state": "monitor.index" + } + ], "routes": [ { "url": "/monitor", diff --git a/modules/order/front/routes.json b/modules/order/front/routes.json index c22ff24d1..2eeb60553 100644 --- a/modules/order/front/routes.json +++ b/modules/order/front/routes.json @@ -15,6 +15,12 @@ {"state": "order.card.line", "icon": "icon-lines"} ] }, + "keybindings": [ + { + "key": "o", + "state": "order.index" + } + ], "routes": [ { "url": "/order", diff --git a/modules/ticket/back/methods/ticket/specs/transferSales.spec.js b/modules/ticket/back/methods/ticket/specs/transferSales.spec.js index 58e598ea9..cd2ce8599 100644 --- a/modules/ticket/back/methods/ticket/specs/transferSales.spec.js +++ b/modules/ticket/back/methods/ticket/specs/transferSales.spec.js @@ -58,13 +58,63 @@ describe('sale transferSales()', () => { expect(error.message).toEqual(`The sales of the receiver ticket can't be modified`); }); - it('should transfer the sales from one ticket to a new one then send them back and delete the created ticket', async() => { + it('should throw an error if any of the sales has a claim', async() => { + const tx = await models.Ticket.beginTransaction({}); + + let error; + try { + const options = {transaction: tx}; + + const ticketId = 11; + const receiverTicketId = null; + const sales = await models.Ticket.getSales(ticketId, options); + + await models.Ticket.transferSales(ctx, ticketId, receiverTicketId, sales, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error.message).toEqual(`Can't transfer claimed sales`); + }); + + it('should be able to transfer claimed sales if the role is claimManager', async() => { + const tx = await models.Ticket.beginTransaction({}); + + let error; + try { + const options = {transaction: tx}; + + const claimManagerId = 72; + const myActiveCtx = { + accessToken: {userId: claimManagerId}, + }; + const myCtx = {req: myActiveCtx}; + + const ticketId = 11; + const receiverTicketId = null; + const sales = await models.Ticket.getSales(ticketId, options); + + await models.Ticket.transferSales(myCtx, ticketId, receiverTicketId, sales, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error).toBeUndefined(); + }); + + it('should transfer the sales from a ticket to a new one', async() => { const tx = await models.Ticket.beginTransaction({}); try { const options = {transaction: tx}; - const formerTicketId = 11; + const formerTicketId = 22; let createdTicketId = undefined; let formerTicketSales = await models.Ticket.getSales(formerTicketId, options); @@ -77,23 +127,11 @@ describe('sale transferSales()', () => { createdTicketId = createdTicket.id; formerTicketSales = await models.Ticket.getSales(formerTicketId, options); - createdTicketSales = await models.Ticket.getSales(createdTicketId, options); + let createdTicketSales = await models.Ticket.getSales(createdTicketId, options); expect(formerTicketSales.length).toEqual(0); expect(createdTicketSales.length).toEqual(2); - await models.Ticket.transferSales( - ctx, createdTicketId, formerTicketId, createdTicketSales, options); - - formerTicketSales = await models.Ticket.getSales(formerTicketId, options); - createdTicketSales = await models.Ticket.getSales(createdTicketId, options); - - createdTicket = await models.Ticket.findById(createdTicketId, null, options); - - expect(createdTicket.isDeleted).toBeTruthy(); - expect(formerTicketSales.length).toEqual(2); - expect(createdTicketSales.length).toEqual(0); - await tx.rollback(); } catch (e) { await tx.rollback(); @@ -109,10 +147,9 @@ describe('sale transferSales()', () => { try { const options = {transaction: tx}; - const currentTicket = await models.Ticket.findById(11, null, options); - const currentTicketSales = await models.Ticket.getSales(currentTicket.id, options); + const currentTicketId = 22; + const currentTicketSales = await models.Ticket.getSales(currentTicketId, options); - const currentTicketId = currentTicket.id; const receiverTicketId = undefined; currentTicketSales[0].quantity = 99; @@ -135,7 +172,7 @@ describe('sale transferSales()', () => { try { const options = {transaction: tx}; - const formerTicketId = 11; + const formerTicketId = 22; let createdTicketId = undefined; let formerTicketSales = await models.Ticket.getSales(formerTicketId, options); @@ -143,7 +180,7 @@ describe('sale transferSales()', () => { const completeSaleId = formerTicketSales[1].id; let partialSaleTotalQuantity = formerTicketSales[0].quantity; - expect(partialSaleTotalQuantity).toEqual(15); + expect(partialSaleTotalQuantity).toEqual(30); formerTicketSales[0].quantity = 1; diff --git a/modules/ticket/back/methods/ticket/transferSales.js b/modules/ticket/back/methods/ticket/transferSales.js index 6d55f764f..1b8476184 100644 --- a/modules/ticket/back/methods/ticket/transferSales.js +++ b/modules/ticket/back/methods/ticket/transferSales.js @@ -75,6 +75,13 @@ module.exports = Self => { for (const sale of originalSales) map.set(sale.id, sale); + const saleIds = sales.map(sale => sale.id); + + const isClaimManager = await models.Account.hasRole(userId, 'claimManager'); + const hasClaimedSales = await models.ClaimBeginning.findOne({where: {saleFk: {inq: saleIds}}}); + if (hasClaimedSales && !isClaimManager) + throw new UserError(`Can't transfer claimed sales`); + for (const sale of sales) { const originalSale = map.get(sale.id); const originalSaleData = { // <-- Loopback modifies original instance on save diff --git a/modules/worker/front/routes.json b/modules/worker/front/routes.json index 47334d841..ca33eaa76 100644 --- a/modules/worker/front/routes.json +++ b/modules/worker/front/routes.json @@ -24,6 +24,12 @@ {"state": "worker.card.workerLog", "icon": "history"} ] }, + "keybindings": [ + { + "key": "w", + "state": "worker.index" + } + ], "routes": [ { "url": "/worker",