From e4eed9572492bed004d1519bdda108281d645c90 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 21 Mar 2022 10:02:56 +0100 Subject: [PATCH 1/5] notify rocket when claimState change to canceled --- db/changes/10430-ash/00-claimState.sql | 2 + db/dump/fixtures.sql | 16 +++--- loopback/locale/en.json | 1 + loopback/locale/es.json | 1 + .../methods/claim/specs/updateClaim.spec.js | 55 +++++++++++++++++-- .../claim/back/methods/claim/updateClaim.js | 16 ++++-- modules/claim/back/models/claim-state.json | 12 ++-- 7 files changed, 81 insertions(+), 22 deletions(-) create mode 100644 db/changes/10430-ash/00-claimState.sql diff --git a/db/changes/10430-ash/00-claimState.sql b/db/changes/10430-ash/00-claimState.sql new file mode 100644 index 000000000..329a9b977 --- /dev/null +++ b/db/changes/10430-ash/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 6f7cc87e5..63bf35681 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1695,15 +1695,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` ) VALUES diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 599febc48..07b94e381 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 7fcbc3f05..fe45c71dc 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 a646db355..47d512c98 100644 --- a/modules/claim/back/methods/claim/updateClaim.js +++ b/modules/claim/back/methods/claim/updateClaim.js @@ -92,9 +92,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(); @@ -121,11 +124,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 } }, From 35312911b0821fc4303b0107222800298174b311 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 21 Mar 2022 13:16:42 +0100 Subject: [PATCH 2/5] move db changes to correct folder --- db/changes/{10430-ash => 10440-fallas}/00-claimState.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/changes/{10430-ash => 10440-fallas}/00-claimState.sql (100%) diff --git a/db/changes/10430-ash/00-claimState.sql b/db/changes/10440-fallas/00-claimState.sql similarity index 100% rename from db/changes/10430-ash/00-claimState.sql rename to db/changes/10440-fallas/00-claimState.sql From 0dc1848870d84049cf8a256ebaf038fb5a91fcf0 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 22 Mar 2022 15:13:34 +0100 Subject: [PATCH 3/5] feat(print_deliveryNote): add withoutPrices type --- .../ticket/front/descriptor-menu/index.html | 9 +++++-- modules/ticket/front/descriptor-menu/index.js | 3 ++- .../front/descriptor-menu/locale/es.yml | 1 + .../reports/delivery-note/delivery-note.html | 24 +++++++++---------- .../reports/delivery-note/delivery-note.js | 4 ++++ 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/modules/ticket/front/descriptor-menu/index.html b/modules/ticket/front/descriptor-menu/index.html index d613fb5de..03a23c780 100644 --- a/modules/ticket/front/descriptor-menu/index.html +++ b/modules/ticket/front/descriptor-menu/index.html @@ -21,7 +21,7 @@ as PDF @@ -32,6 +32,12 @@ translate> as PDF + + as PDF without prices + @@ -44,7 +50,6 @@ vn-click-stop="sendDeliveryNoteMenu.show($event, 'left')" translate> Send Delivery Note... -
-

{{$t('title')}}

+

{{$t(type)}}

@@ -23,7 +23,7 @@ - + @@ -77,10 +77,10 @@ - - - - + + + + @@ -88,10 +88,10 @@ - - - - + + + + - +
{{client.id}}
{{$t('ticketId')}}{{$t(type)}} {{ticket.id}}
{{$t('reference')}} {{$t('quantity')}} {{$t('concept')}}{{$t('price')}}{{$t('discount')}}{{$t('vat')}}{{$t('amount')}}{{$t('price')}}{{$t('discount')}}{{$t('vat')}}{{$t('amount')}}
{{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 0ee7c8c91..7f9ca7d0f 100755 --- a/print/templates/reports/delivery-note/delivery-note.js +++ b/print/templates/reports/delivery-note/delivery-note.js @@ -119,6 +119,10 @@ module.exports = { ticketId: { type: [Number, String], required: true + }, + type: { + type: String, + required: true } } }; From 1051a9cafbe764b9201bd32e2df877219f1db21a Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 23 Mar 2022 09:42:00 +0100 Subject: [PATCH 4/5] traductions --- print/templates/reports/delivery-note/locale/en.yml | 1 + print/templates/reports/delivery-note/locale/es.yml | 1 + print/templates/reports/delivery-note/locale/fr.yml | 1 + print/templates/reports/delivery-note/locale/pt.yml | 1 + 4 files changed, 4 insertions(+) diff --git a/print/templates/reports/delivery-note/locale/en.yml b/print/templates/reports/delivery-note/locale/en.yml index 16d0954e2..05b6d73ed 100644 --- a/print/templates/reports/delivery-note/locale/en.yml +++ b/print/templates/reports/delivery-note/locale/en.yml @@ -1,5 +1,6 @@ reportName: delivery-note title: Delivery note +withoutPrices: Delivery note ticketId: Delivery note clientId: Client deliveryAddress: Delivery address diff --git a/print/templates/reports/delivery-note/locale/es.yml b/print/templates/reports/delivery-note/locale/es.yml index ca670ad59..1a6e156cc 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 title: Albarán ticketId: Albarán +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 6b3779a5b..1cc171669 100644 --- a/print/templates/reports/delivery-note/locale/fr.yml +++ b/print/templates/reports/delivery-note/locale/fr.yml @@ -1,5 +1,6 @@ reportName: bon-de-livraison title: Bon de livraison +withoutPrices: Bon de livraison ticketId: BL clientId: Client deliveryAddress: Adresse de livraison diff --git a/print/templates/reports/delivery-note/locale/pt.yml b/print/templates/reports/delivery-note/locale/pt.yml index 1a9c1fbd1..ca25041f2 100644 --- a/print/templates/reports/delivery-note/locale/pt.yml +++ b/print/templates/reports/delivery-note/locale/pt.yml @@ -1,5 +1,6 @@ reportName: nota-de-entrega title: Nota de Entrega +withoutPrices: Nota de Entrega ticketId: Nota de Entrega clientId: Cliente deliveryAddress: Morada de Entrega From ebfd0bdb29b4bfba2b3ff48422fbdee6831bc217 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 23 Mar 2022 09:46:44 +0100 Subject: [PATCH 5/5] use computed function --- .../reports/delivery-note/delivery-note.html | 20 +++++++++---------- .../reports/delivery-note/delivery-note.js | 3 +++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/print/templates/reports/delivery-note/delivery-note.html b/print/templates/reports/delivery-note/delivery-note.html index 09b799076..93e1c2255 100644 --- a/print/templates/reports/delivery-note/delivery-note.html +++ b/print/templates/reports/delivery-note/delivery-note.html @@ -77,10 +77,10 @@ - - - - + + + + @@ -88,10 +88,10 @@ - - - - + + + + - +
{{$t('reference')}} {{$t('quantity')}} {{$t('concept')}}{{$t('price')}}{{$t('discount')}}{{$t('vat')}}{{$t('amount')}}{{$t('price')}}{{$t('discount')}}{{$t('vat')}}{{$t('amount')}}
{{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 7f9ca7d0f..48aef8b64 100755 --- a/print/templates/reports/delivery-note/delivery-note.js +++ b/print/templates/reports/delivery-note/delivery-note.js @@ -44,6 +44,9 @@ module.exports = { }); return total; + }, + showPrices() { + return this.type != 'withoutPrices'; } }, methods: {