diff --git a/db/changes/10440-fallas/00-claimState.sql b/db/changes/10440-fallas/00-claimState.sql new file mode 100644 index 000000000..329a9b977 --- /dev/null +++ b/db/changes/10440-fallas/00-claimState.sql @@ -0,0 +1,2 @@ +ALTER TABLE `vn`.`claimState` ADD `hasToNotify` TINYINT DEFAULT 0 NULL; +UPDATE `vn`.`claimState` SET `hasToNotify` = 1 WHERE `code` IN ('canceled', 'incomplete'); \ No newline at end of file diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 59fd4c235..dd1b76622 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1700,15 +1700,15 @@ INSERT INTO `vn`.`clientSample`(`id`, `clientFk`, `typeFk`, `created`, `workerFk (4, 1102, 2, CURDATE(), 18, 18, 567), (5, 1102, 3, CURDATE(), 19, 19, 567); -INSERT INTO `vn`.`claimState`(`id`, `code`, `description`, `roleFk`, `priority`) +INSERT INTO `vn`.`claimState`(`id`, `code`, `description`, `roleFk`, `priority`, `hasToNotify`) VALUES - ( 1, 'pending', 'Pendiente', 1, 1), - ( 2, 'managed', 'Gestionado', 1, 5), - ( 3, 'resolved', 'Resuelto', 72, 7), - ( 4, 'canceled', 'Anulado', 72, 6), - ( 5, 'incomplete', 'Incompleta', 72, 3), - ( 6, 'mana', 'Mana', 1, 4), - ( 7, 'lack', 'Faltas', 1, 2); + ( 1, 'pending', 'Pendiente', 1, 1, 0), + ( 2, 'managed', 'Gestionado', 1, 5, 0), + ( 3, 'resolved', 'Resuelto', 72, 7, 0), + ( 4, 'canceled', 'Anulado', 72, 6, 1), + ( 5, 'incomplete', 'Incompleta', 72, 3, 1), + ( 6, 'mana', 'Mana', 1, 4, 0), + ( 7, 'lack', 'Faltas', 1, 2, 0); INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `observation`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`) VALUES diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 447288077..b7242befb 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -70,6 +70,7 @@ "Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} ({{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [{{ticketId}}]({{{ticketUrl}}})", "Claim will be picked": "The product from the claim [({{claimId}})]({{{claimUrl}}}) from the client *{{clientName}}* will be picked", "Claim state has changed to incomplete": "The state of the claim [({{claimId}})]({{{claimUrl}}}) from client *{{clientName}}* has changed to *incomplete*", + "Claim state has changed to canceled": "The state of the claim [({{claimId}})]({{{claimUrl}}}) from client *{{clientName}}* has changed to *canceled*", "This ticket is not an stowaway anymore": "The ticket id [{{ticketId}}]({{{ticketUrl}}}) is not an stowaway anymore", "Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member", "Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member", diff --git a/loopback/locale/es.json b/loopback/locale/es.json index b71d9ec74..21abc6e9e 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -137,6 +137,7 @@ "Sent units from ticket": "Envio *{{quantity}}* unidades de [{{concept}} ({{itemId}})]({{{itemUrl}}}) a *\"{{nickname}}\"* provenientes del ticket id [{{ticketId}}]({{{ticketUrl}}})", "Claim will be picked": "Se recogerá el género de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}*", "Claim state has changed to incomplete": "Se ha cambiado el estado de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}* a *incompleta*", + "Claim state has changed to canceled": "Se ha cambiado el estado de la reclamación [({{claimId}})]({{{claimUrl}}}) del cliente *{{clientName}}* a *anulado*", "This ticket is not an stowaway anymore": "El ticket id [{{ticketId}}]({{{ticketUrl}}}) ha dejado de ser un polizón", "Client checked as validated despite of duplication": "Cliente comprobado a pesar de que existe el cliente id {{clientId}}", "ORDER_ROW_UNAVAILABLE": "No hay disponibilidad de este producto", diff --git a/modules/claim/back/methods/claim/specs/updateClaim.spec.js b/modules/claim/back/methods/claim/specs/updateClaim.spec.js index de7209c18..8d888eb40 100644 --- a/modules/claim/back/methods/claim/specs/updateClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/updateClaim.spec.js @@ -47,7 +47,7 @@ describe('Update Claim', () => { expect(error.message).toEqual(`You don't have enough privileges to change that field`); }); - it(`should success to update the claim within privileges `, async() => { + it(`should success to update the claimState to 'canceled' and send a rocket message`, async() => { const tx = await app.models.Claim.beginTransaction({}); try { @@ -55,13 +55,15 @@ describe('Update Claim', () => { const newClaim = await app.models.Claim.create(originalData, options); + const chatModel = app.models.Chat; + spyOn(chatModel, 'sendCheckingPresence').and.callThrough(); + const canceledState = 4; const claimManagerId = 72; const ctx = { req: { - accessToken: { - userId: claimManagerId - } + accessToken: {userId: claimManagerId}, + headers: {origin: 'http://localhost'} }, args: { observation: 'valid observation', @@ -69,11 +71,56 @@ describe('Update Claim', () => { hasToPickUp: false } }; + ctx.req.__ = (value, params) => { + return params.nickname; + }; await app.models.Claim.updateClaim(ctx, newClaim.id, options); let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options); expect(updatedClaim.observation).toEqual(ctx.args.observation); + expect(chatModel.sendCheckingPresence).toHaveBeenCalled(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it(`should success to update the claimState to 'incomplete' and send a rocket message`, async() => { + const tx = await app.models.Claim.beginTransaction({}); + + try { + const options = {transaction: tx}; + + const newClaim = await app.models.Claim.create(originalData, options); + + const chatModel = app.models.Chat; + spyOn(chatModel, 'sendCheckingPresence').and.callThrough(); + + const incompleteState = 5; + const claimManagerId = 72; + const ctx = { + req: { + accessToken: {userId: claimManagerId}, + headers: {origin: 'http://localhost'} + }, + args: { + observation: 'valid observation', + claimStateFk: incompleteState, + hasToPickUp: false + } + }; + ctx.req.__ = (value, params) => { + return params.nickname; + }; + await app.models.Claim.updateClaim(ctx, newClaim.id, options); + + let updatedClaim = await app.models.Claim.findById(newClaim.id, null, options); + + expect(updatedClaim.observation).toEqual(ctx.args.observation); + expect(chatModel.sendCheckingPresence).toHaveBeenCalled(); await tx.rollback(); } catch (e) { diff --git a/modules/claim/back/methods/claim/updateClaim.js b/modules/claim/back/methods/claim/updateClaim.js index 50ad52a6e..cc9937c19 100644 --- a/modules/claim/back/methods/claim/updateClaim.js +++ b/modules/claim/back/methods/claim/updateClaim.js @@ -96,9 +96,12 @@ module.exports = Self => { // When claimState has been changed if (args.claimStateFk) { const newState = await models.ClaimState.findById(args.claimStateFk, null, options); - - if (newState.code == 'incomplete') - notifyStateChange(ctx, salesPerson.id, claim); + if (newState.hasToNotify) { + if (newState.code == 'incomplete') + notifyStateChange(ctx, salesPerson.id, claim, newState.code); + if (newState.code == 'canceled') + notifyStateChange(ctx, claim.workerFk, claim, newState.code); + } } if (tx) await tx.commit(); @@ -125,11 +128,12 @@ module.exports = Self => { return canUpdate; } - async function notifyStateChange(ctx, workerId, claim) { - const origin = ctx.req.headers.origin; + async function notifyStateChange(ctx, workerId, claim, state) { const models = Self.app.models; + const origin = ctx.req.headers.origin; const $t = ctx.req.__; // $translate - const message = $t('Claim state has changed to incomplete', { + + const message = $t(`Claim state has changed to ${state}`, { claimId: claim.id, clientName: claim.client().name, claimUrl: `${origin}/#!/claim/${claim.id}/summary` diff --git a/modules/claim/back/models/claim-state.json b/modules/claim/back/models/claim-state.json index e0a536e11..2fd6d4845 100644 --- a/modules/claim/back/models/claim-state.json +++ b/modules/claim/back/models/claim-state.json @@ -13,20 +13,24 @@ }, "properties": { "id": { - "type": "Number", + "type": "number", "id": true, "description": "Identifier" }, "code": { - "type": "String", + "type": "string", "required": true }, "description": { - "type": "String", + "type": "string", "required": true }, "priority": { - "type": "Number", + "type": "number", + "required": true + }, + "hasToNotify": { + "type": "boolean", "required": true } }, diff --git a/modules/ticket/front/descriptor-menu/index.html b/modules/ticket/front/descriptor-menu/index.html index faa8eedfe..88ed4b46b 100644 --- a/modules/ticket/front/descriptor-menu/index.html +++ b/modules/ticket/front/descriptor-menu/index.html @@ -32,6 +32,12 @@ translate> as PDF + + as PDF without prices + diff --git a/modules/ticket/front/descriptor-menu/locale/es.yml b/modules/ticket/front/descriptor-menu/locale/es.yml index 56fa1a973..761687e74 100644 --- a/modules/ticket/front/descriptor-menu/locale/es.yml +++ b/modules/ticket/front/descriptor-menu/locale/es.yml @@ -2,6 +2,7 @@ Show Delivery Note...: Ver albarán... Send Delivery Note...: Enviar albarán... as PDF: como PDF as CSV: como CSV +as PDF without prices: como PDF sin precios Send PDF: Enviar PDF Send CSV: Enviar CSV Send CSV Delivery Note: Enviar albarán en CSV diff --git a/print/templates/reports/delivery-note/delivery-note.html b/print/templates/reports/delivery-note/delivery-note.html index 644e0cf04..35f9a2960 100644 --- a/print/templates/reports/delivery-note/delivery-note.html +++ b/print/templates/reports/delivery-note/delivery-note.html @@ -77,10 +77,10 @@ {{$t('reference')}} {{$t('quantity')}} {{$t('concept')}} - {{$t('price')}} - {{$t('discount')}} - {{$t('vat')}} - {{$t('amount')}} + {{$t('price')}} + {{$t('discount')}} + {{$t('vat')}} + {{$t('amount')}} @@ -88,10 +88,10 @@ {{sale.itemFk | zerofill('000000')}} {{sale.quantity}} {{sale.concept}} - {{sale.price | currency('EUR', $i18n.locale)}} - {{(sale.discount / 100) | percentage}} - {{sale.vatType}} - {{sale.price * sale.quantity * (1 - sale.discount / 100) | currency('EUR', $i18n.locale)}} + {{sale.price | currency('EUR', $i18n.locale)}} + {{(sale.discount / 100) | percentage}} + {{sale.vatType}} + {{sale.price * sale.quantity * (1 - sale.discount / 100) | currency('EUR', $i18n.locale)}} @@ -107,7 +107,7 @@ - + {{$t('subtotal')}} @@ -181,7 +181,7 @@ -
+
diff --git a/print/templates/reports/delivery-note/delivery-note.js b/print/templates/reports/delivery-note/delivery-note.js index dbfedae8f..adda6e756 100755 --- a/print/templates/reports/delivery-note/delivery-note.js +++ b/print/templates/reports/delivery-note/delivery-note.js @@ -45,6 +45,9 @@ module.exports = { return total; }, + showPrices() { + return this.type != 'withoutPrices'; + }, footerType() { const translatedType = this.$t(this.type); return `${translatedType} ${this.ticketId}`; diff --git a/print/templates/reports/delivery-note/locale/en.yml b/print/templates/reports/delivery-note/locale/en.yml index 93c09d98c..c74b87520 100644 --- a/print/templates/reports/delivery-note/locale/en.yml +++ b/print/templates/reports/delivery-note/locale/en.yml @@ -1,6 +1,7 @@ reportName: delivery-note deliveryNote: Delivery note proforma: Proforma +withoutPrices: Delivery note clientId: Client deliveryAddress: Delivery address fiscalData: Fiscal data diff --git a/print/templates/reports/delivery-note/locale/es.yml b/print/templates/reports/delivery-note/locale/es.yml index b33b376fd..5c5a6af4d 100644 --- a/print/templates/reports/delivery-note/locale/es.yml +++ b/print/templates/reports/delivery-note/locale/es.yml @@ -1,6 +1,7 @@ reportName: albaran deliveryNote: Albarán proforma: Proforma +withoutPrices: Albarán clientId: Cliente deliveryAddress: Dirección de entrega fiscalData: Datos fiscales diff --git a/print/templates/reports/delivery-note/locale/fr.yml b/print/templates/reports/delivery-note/locale/fr.yml index 74d52471d..df7ca053b 100644 --- a/print/templates/reports/delivery-note/locale/fr.yml +++ b/print/templates/reports/delivery-note/locale/fr.yml @@ -1,6 +1,7 @@ reportName: bon-de-livraison deliveryNote: Bon de livraison proforma: Proforma +withoutPrices: Bon de livraison clientId: Client deliveryAddress: Adresse de livraison fiscalData: Coordonnées diff --git a/print/templates/reports/delivery-note/locale/pt.yml b/print/templates/reports/delivery-note/locale/pt.yml index 93554f74b..1f418b31f 100644 --- a/print/templates/reports/delivery-note/locale/pt.yml +++ b/print/templates/reports/delivery-note/locale/pt.yml @@ -1,6 +1,7 @@ reportName: nota-de-entrega deliveryNote: Nota de Entrega proforma: Proforma +withoutPrices: Nota de Entrega clientId: Cliente deliveryAddress: Morada de Entrega fiscalData: Dados Fiscais