From 30933220aca2d32dfddd1ee4a2129aea66c58f64 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Mon, 24 Oct 2022 09:37:17 +0200 Subject: [PATCH 01/14] #4507 greuge.js/json now insert userFk @2h --- modules/client/back/models/greuge.js | 15 +++++++++++++++ modules/client/back/models/greuge.json | 4 ++++ modules/client/front/greuge/index/index.html | 2 ++ modules/client/front/greuge/index/locale/es.yml | 3 ++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/client/back/models/greuge.js b/modules/client/back/models/greuge.js index bd5f2865d..42820fd60 100644 --- a/modules/client/back/models/greuge.js +++ b/modules/client/back/models/greuge.js @@ -1,6 +1,21 @@ +const LoopBackContext = require('loopback-context'); + module.exports = function(Self) { require('../methods/greuge/sumAmount')(Self); + Self.observe('before save', function(ctx, next) { + const loopBackContext = LoopBackContext.getCurrentContext(); + + let userFk = loopBackContext.active.accessToken.userId; + + if (ctx.instance) + ctx.instance.userFk = userFk; + else + ctx.data.userFk = userFk; + + next(); + }); + Self.validatesLengthOf('description', { max: 45, message: 'Description should have maximum of 45 characters' diff --git a/modules/client/back/models/greuge.json b/modules/client/back/models/greuge.json index 918ff0ca5..e8790715a 100644 --- a/modules/client/back/models/greuge.json +++ b/modules/client/back/models/greuge.json @@ -34,6 +34,10 @@ "greugeTypeFk": { "type": "number", "required": true + }, + "userFk": { + "type": "number", + "required": true } }, diff --git a/modules/client/front/greuge/index/index.html b/modules/client/front/greuge/index/index.html index b48fe9466..cdc9c37d4 100644 --- a/modules/client/front/greuge/index/index.html +++ b/modules/client/front/greuge/index/index.html @@ -29,6 +29,7 @@ Date + Created by Comment Type Amount @@ -37,6 +38,7 @@ {{::greuge.shipped | date:'dd/MM/yyyy HH:mm' }} + {{::greuge.userFk}} {{::greuge.description}} diff --git a/modules/client/front/greuge/index/locale/es.yml b/modules/client/front/greuge/index/locale/es.yml index 513e6ff7b..d1f202862 100644 --- a/modules/client/front/greuge/index/locale/es.yml +++ b/modules/client/front/greuge/index/locale/es.yml @@ -1,4 +1,5 @@ Date: Fecha Comment: Comentario Amount: Importe -Type: Tipo \ No newline at end of file +Type: Tipo +Created by: Creado por \ No newline at end of file From 1327f0ae9ddb550c8b0536f4f34eb4375851feac Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Thu, 10 Nov 2022 08:18:05 +0100 Subject: [PATCH 02/14] Added requested changes, refs #4507 @1:20h --- .../10502-november/00-greuge.userFK_userFk.sql | 1 + modules/client/back/models/greuge.json | 16 ++++++++-------- modules/client/front/greuge/index/index.html | 2 +- modules/client/front/greuge/index/index.js | 6 ++++++ 4 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 db/changes/10502-november/00-greuge.userFK_userFk.sql diff --git a/db/changes/10502-november/00-greuge.userFK_userFk.sql b/db/changes/10502-november/00-greuge.userFK_userFk.sql new file mode 100644 index 000000000..2a5323fa3 --- /dev/null +++ b/db/changes/10502-november/00-greuge.userFK_userFk.sql @@ -0,0 +1 @@ +ALTER TABLE vn.greuge CHANGE userFK userFk int(10) unsigned DEFAULT NULL NULL; \ No newline at end of file diff --git a/modules/client/back/models/greuge.json b/modules/client/back/models/greuge.json index e8790715a..a694c7552 100644 --- a/modules/client/back/models/greuge.json +++ b/modules/client/back/models/greuge.json @@ -2,9 +2,9 @@ "name": "Greuge", "base": "Loggable", "log": { - "model": "ClientLog", - "relation": "client", - "showField": "description" + "model": "ClientLog", + "relation": "client", + "showField": "description" }, "options": { "mysql": { @@ -34,12 +34,7 @@ "greugeTypeFk": { "type": "number", "required": true - }, - "userFk": { - "type": "number", - "required": true } - }, "relations": { "client": { @@ -56,6 +51,11 @@ "type": "belongsTo", "model": "GreugeType", "foreignKey": "greugeTypeFk" + }, + "user": { + "type": "belongsTo", + "model": "Account", + "foreignKey": "userFK" } } } \ No newline at end of file diff --git a/modules/client/front/greuge/index/index.html b/modules/client/front/greuge/index/index.html index cdc9c37d4..44074ed1a 100644 --- a/modules/client/front/greuge/index/index.html +++ b/modules/client/front/greuge/index/index.html @@ -38,7 +38,7 @@ {{::greuge.shipped | date:'dd/MM/yyyy HH:mm' }} - {{::greuge.userFk}} + {{::greuge.user.name}} {{::greuge.description}} diff --git a/modules/client/front/greuge/index/index.js b/modules/client/front/greuge/index/index.js index 2451167a4..7a5ccc531 100644 --- a/modules/client/front/greuge/index/index.js +++ b/modules/client/front/greuge/index/index.js @@ -8,6 +8,12 @@ class Controller extends Section { include: [ { relation: 'greugeType', + scope: { + fields: ['id', 'name'] + }, + }, + { + relation: 'user', scope: { fields: ['id', 'name'] } From c53e309071cadb12f1deca6fa7700248ba8d6afa Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Thu, 10 Nov 2022 08:19:54 +0100 Subject: [PATCH 03/14] Fix typo --- modules/client/back/models/greuge.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/client/back/models/greuge.json b/modules/client/back/models/greuge.json index a694c7552..625bf4e28 100644 --- a/modules/client/back/models/greuge.json +++ b/modules/client/back/models/greuge.json @@ -55,7 +55,7 @@ "user": { "type": "belongsTo", "model": "Account", - "foreignKey": "userFK" + "foreignKey": "userFk" } } } \ No newline at end of file From 8dd6012b1f8e50cc98ae398e96d127fced675e86 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Thu, 10 Nov 2022 08:27:47 +0100 Subject: [PATCH 04/14] Added worker descriptor popover --- modules/client/front/greuge/index/index.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/client/front/greuge/index/index.html b/modules/client/front/greuge/index/index.html index 44074ed1a..80e41e915 100644 --- a/modules/client/front/greuge/index/index.html +++ b/modules/client/front/greuge/index/index.html @@ -38,7 +38,8 @@ {{::greuge.shipped | date:'dd/MM/yyyy HH:mm' }} - {{::greuge.user.name}} + {{::greuge.user.name}} {{::greuge.description}} @@ -59,3 +60,4 @@ vn-bind="+" fixed-bottom-right> + \ No newline at end of file From 8b06243041112365aa58f2f17470af11068c9357 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Thu, 10 Nov 2022 08:36:26 +0100 Subject: [PATCH 05/14] Fix link being the whole column --- modules/client/front/greuge/index/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/client/front/greuge/index/index.html b/modules/client/front/greuge/index/index.html index 80e41e915..459d92fc7 100644 --- a/modules/client/front/greuge/index/index.html +++ b/modules/client/front/greuge/index/index.html @@ -38,8 +38,8 @@ {{::greuge.shipped | date:'dd/MM/yyyy HH:mm' }} - {{::greuge.user.name}} + {{::greuge.user.name}} {{::greuge.description}} From 5c249dcbccacd95131642ddb93f1c58778077ea1 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Tue, 15 Nov 2022 08:24:10 +0100 Subject: [PATCH 06/14] refs #4767 @1h30m --- modules/route/front/descriptor/index.html | 7 +++++++ modules/route/front/descriptor/index.js | 8 ++++++++ modules/route/front/descriptor/index.spec.js | 16 ++++++++++++++++ modules/route/front/descriptor/locale/es.yml | 2 ++ 4 files changed, 33 insertions(+) diff --git a/modules/route/front/descriptor/index.html b/modules/route/front/descriptor/index.html index fc1d3419c..6d6fb082e 100644 --- a/modules/route/front/descriptor/index.html +++ b/modules/route/front/descriptor/index.html @@ -20,6 +20,13 @@ translate> Update volume + + Delete route +
diff --git a/modules/route/front/descriptor/index.js b/modules/route/front/descriptor/index.js index 2dc512b67..aa47044b1 100644 --- a/modules/route/front/descriptor/index.js +++ b/modules/route/front/descriptor/index.js @@ -34,6 +34,14 @@ class Controller extends Descriptor { }); } + deleteCurrentRoute() { + this.$http.delete(`Routes/${this.id}`) + .then(() => { + this.vnApp.showSuccess(this.$t('Route deleted')); + this.$state.go('route.index'); + }); + } + loadData() { const filter = { fields: [ diff --git a/modules/route/front/descriptor/index.spec.js b/modules/route/front/descriptor/index.spec.js index ab996d9b0..f43666c8b 100644 --- a/modules/route/front/descriptor/index.spec.js +++ b/modules/route/front/descriptor/index.spec.js @@ -23,4 +23,20 @@ describe('vnRouteDescriptorPopover', () => { expect(controller.route).toEqual(response); }); }); + + describe('deleteCurrentRoute()', () => { + it(`should perform a delete query to delete the current route`, () => { + const id = 1; + + jest.spyOn(controller.vnApp, 'showSuccess'); + + controller._id = id; + $httpBackend.expectDELETE(`Routes/${id}`).respond(200); + controller.deleteCurrentRoute(); + $httpBackend.flush(); + + expect(controller.route).toBeUndefined(); + expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Route deleted'); + }); + }); }); diff --git a/modules/route/front/descriptor/locale/es.yml b/modules/route/front/descriptor/locale/es.yml index 63fa7202b..23068fbf8 100644 --- a/modules/route/front/descriptor/locale/es.yml +++ b/modules/route/front/descriptor/locale/es.yml @@ -4,4 +4,6 @@ Send route report: Enviar informe de ruta Show route report: Ver informe de ruta Update volume: Actualizar volumen Volume updated: Volumen actualizado +Delete route: Borrar ruta +Route deleted: Ruta borrada Are you sure you want to update the volume?: Estas seguro que quieres actualizar el volumen? \ No newline at end of file From 5acbaf036a521cb6dcd2e971d933dcea7e56665d Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 15 Nov 2022 09:30:36 +0100 Subject: [PATCH 07/14] refs #3557 back and test done --- .../10503-november/00-sale_missingTrash.sql | 23 ++++++ .../ticket/back/methods/sale/missingTrash.js | 70 +++++++++++++++++++ .../methods/sale/specs/missingTrash.spec.js | 35 ++++++++++ modules/ticket/back/models/sale.js | 1 + 4 files changed, 129 insertions(+) create mode 100644 db/changes/10503-november/00-sale_missingTrash.sql create mode 100644 modules/ticket/back/methods/sale/missingTrash.js create mode 100644 modules/ticket/back/methods/sale/specs/missingTrash.spec.js diff --git a/db/changes/10503-november/00-sale_missingTrash.sql b/db/changes/10503-november/00-sale_missingTrash.sql new file mode 100644 index 000000000..f0de6d5cd --- /dev/null +++ b/db/changes/10503-november/00-sale_missingTrash.sql @@ -0,0 +1,23 @@ +DROP PROCEDURE IF EXISTS vn.sale_missingTrash; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_missingTrash`( + vSaleFk BIGINT, + vQuantity INT, + vIsTrash BOOLEAN, + vWarehouseFk INT, + vNewQuantity INT) +/** + * Modifica la cantidad de una sale tirĂ¡ndola a faltas o basura + * + * @param vSaleFk el id de la sale + * @param vQuantity cantidad que se va a tirar a faltas o basura + * @param vIsTrash true si es basura, false si es faltas + * @param vWarehouseFk id warehouse + * @param vNewQuantity cantidad que se queda en el ticket original + */ +BEGIN + CALL vn.collection_missingTrash(vSaleFk ,vQuantity ,vIsTrash ,vWarehouseFk ,vNewQuantity); +END$$ +DELIMITER ; diff --git a/modules/ticket/back/methods/sale/missingTrash.js b/modules/ticket/back/methods/sale/missingTrash.js new file mode 100644 index 000000000..6d4f69178 --- /dev/null +++ b/modules/ticket/back/methods/sale/missingTrash.js @@ -0,0 +1,70 @@ +module.exports = Self => { + Self.remoteMethodCtx('missingTrash', { + description: 'Modify the amount of a sale by throwing it to faults or garbage', + accessType: 'WRITE', + accepts: [ + { + arg: 'saleFk', + type: 'number', + required: true, + description: 'The sale id' + }, + { + arg: 'quantity', + type: 'number', + required: true, + description: 'Quantity that is going to be thrown away' + }, + { + arg: 'isTrash', + type: 'boolean', + required: true, + description: 'True if garbage, false if fault' + }, + { + arg: 'warehouseFk', + type: 'number', + required: true, + description: 'The warehouse id' + }, + { + arg: 'newQuantity', + type: 'number', + required: true, + description: 'Amount remaining on the original ticket' + }, + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/missingTrash`, + verb: 'POST' + } + }); + + Self.missingTrash = async function (ctx, saleFk, quantity, isTrash, warehouseFk, newQuantity, options) { + const myOptions = {}; + let tx; + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const missingTrash = await Self.rawSql(`CALL vn.sale_missingTrash(?, ?, ?, ?, ?)`, + [saleFk, quantity, isTrash, warehouseFk, newQuantity], myOptions); + + if (tx) await tx.commit(); + + return missingTrash; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/ticket/back/methods/sale/specs/missingTrash.spec.js b/modules/ticket/back/methods/sale/specs/missingTrash.spec.js new file mode 100644 index 000000000..62fd74343 --- /dev/null +++ b/modules/ticket/back/methods/sale/specs/missingTrash.spec.js @@ -0,0 +1,35 @@ +const models = require('vn-loopback/server/server').models; + +fdescribe('sale missingTrash()', () => { + it('should modify the amount of a sale by throwing it to faults or garbage', async () => { + const tx = await models.Sale.beginTransaction({}); + + try { + const options = { transaction: tx }; + + const saleFk = 1; + const quantity = 3; + const isTrash = true; + const warehouseFk = 1; + const newQuantity = 2; + + const ctx = { req: { accessToken: { userId: 9 } } }; + + let sale = await models.Sale.findById(saleFk, null, options); + expect(sale.quantity).toEqual(5); + expect(sale.originalQuantity).toBe(null); + + await models.Sale.missingTrash(ctx, saleFk, quantity, isTrash, warehouseFk, newQuantity, options); + + sale = await models.Sale.findById(saleFk, null, options); + expect(sale.quantity).toEqual(2); + expect(sale.originalQuantity).toBe(5); + + await tx.rollback(); + + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/ticket/back/models/sale.js b/modules/ticket/back/models/sale.js index ae247fc24..cb8814e67 100644 --- a/modules/ticket/back/models/sale.js +++ b/modules/ticket/back/models/sale.js @@ -9,6 +9,7 @@ module.exports = Self => { require('../methods/sale/refund')(Self); require('../methods/sale/canEdit')(Self); require('../methods/sale/usesMana')(Self); + require('../methods/sale/missingTrash')(Self); Self.validatesPresenceOf('concept', { message: `Concept cannot be blank` From 3dd43d21aef8412f511839d5ef4f3147c613a8ce Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 15 Nov 2022 09:37:26 +0100 Subject: [PATCH 08/14] fix test --- modules/ticket/back/methods/sale/specs/missingTrash.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/sale/specs/missingTrash.spec.js b/modules/ticket/back/methods/sale/specs/missingTrash.spec.js index 62fd74343..4dbe2588c 100644 --- a/modules/ticket/back/methods/sale/specs/missingTrash.spec.js +++ b/modules/ticket/back/methods/sale/specs/missingTrash.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -fdescribe('sale missingTrash()', () => { +describe('sale missingTrash()', () => { it('should modify the amount of a sale by throwing it to faults or garbage', async () => { const tx = await models.Sale.beginTransaction({}); From 7b3a1bfb22bff5082626b9929ba1bb8b7b3354a0 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Wed, 16 Nov 2022 08:28:12 +0100 Subject: [PATCH 09/14] requested changes --- db/changes/10502-november/00-greuge.userFK_userFk.sql | 1 - db/changes/10503-november/00-greuge.userFK_userFk.sql | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 db/changes/10502-november/00-greuge.userFK_userFk.sql create mode 100644 db/changes/10503-november/00-greuge.userFK_userFk.sql diff --git a/db/changes/10502-november/00-greuge.userFK_userFk.sql b/db/changes/10502-november/00-greuge.userFK_userFk.sql deleted file mode 100644 index 2a5323fa3..000000000 --- a/db/changes/10502-november/00-greuge.userFK_userFk.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE vn.greuge CHANGE userFK userFk int(10) unsigned DEFAULT NULL NULL; \ No newline at end of file diff --git a/db/changes/10503-november/00-greuge.userFK_userFk.sql b/db/changes/10503-november/00-greuge.userFK_userFk.sql new file mode 100644 index 000000000..ec4bf3146 --- /dev/null +++ b/db/changes/10503-november/00-greuge.userFK_userFk.sql @@ -0,0 +1 @@ +ALTER TABLE `vn`.`greuge` CHANGE `userFK` `userFk` int(10) unsigned DEFAULT NULL NULL; \ No newline at end of file From e4a6585b6af91fff3192cf1819a6b4b27d9c3fb0 Mon Sep 17 00:00:00 2001 From: alexandre Date: Wed, 16 Nov 2022 13:46:16 +0100 Subject: [PATCH 10/14] fix test back --- .../10503-november/00-sale_missingTrash.sql | 4 ++++ db/changes/10503-november/delete.keep | 0 .../methods/sale/specs/missingTrash.spec.js | 21 +++++++++---------- 3 files changed, 14 insertions(+), 11 deletions(-) delete mode 100644 db/changes/10503-november/delete.keep diff --git a/db/changes/10503-november/00-sale_missingTrash.sql b/db/changes/10503-november/00-sale_missingTrash.sql index f0de6d5cd..8c1bcaed3 100644 --- a/db/changes/10503-november/00-sale_missingTrash.sql +++ b/db/changes/10503-november/00-sale_missingTrash.sql @@ -21,3 +21,7 @@ BEGIN CALL vn.collection_missingTrash(vSaleFk ,vQuantity ,vIsTrash ,vWarehouseFk ,vNewQuantity); END$$ DELIMITER ; + +INSERT INTO `salix`.`ACL` +(model, property, accessType, permission, principalType, principalId) +VALUES('Sale', 'missingTrash', 'WRITE', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/changes/10503-november/delete.keep b/db/changes/10503-november/delete.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/modules/ticket/back/methods/sale/specs/missingTrash.spec.js b/modules/ticket/back/methods/sale/specs/missingTrash.spec.js index 4dbe2588c..490ad7e0e 100644 --- a/modules/ticket/back/methods/sale/specs/missingTrash.spec.js +++ b/modules/ticket/back/methods/sale/specs/missingTrash.spec.js @@ -7,23 +7,22 @@ describe('sale missingTrash()', () => { try { const options = { transaction: tx }; - const saleFk = 1; - const quantity = 3; + const quantity = 1; const isTrash = true; - const warehouseFk = 1; - const newQuantity = 2; const ctx = { req: { accessToken: { userId: 9 } } }; - let sale = await models.Sale.findById(saleFk, null, options); - expect(sale.quantity).toEqual(5); - expect(sale.originalQuantity).toBe(null); + const sale = await models.Sale.findOne({fields: ['id','quantity', 'originalQuantity', 'ticketFk']}, options); + console.log(sale); + const ticket = await models.Ticket.findById(sale.ticketFk, {fields: ['warehouseFk']}, options); + console.log(ticket); + const newQuantity = sale.quantity-quantity; - await models.Sale.missingTrash(ctx, saleFk, quantity, isTrash, warehouseFk, newQuantity, options); + await models.Sale.missingTrash(ctx, sale.id, quantity, isTrash, ticket.warehouseFk, newQuantity, options); - sale = await models.Sale.findById(saleFk, null, options); - expect(sale.quantity).toEqual(2); - expect(sale.originalQuantity).toBe(5); + const saleAfter = await models.Sale.findById(sale.id, {fields: ['quantity', 'originalQuantity']}, options); + expect(saleAfter.quantity).toEqual(newQuantity); + expect(saleAfter.originalQuantity).toBe(sale.quantity); await tx.rollback(); From 153cb48ff0fa25e505a4825a94408a4372c0318d Mon Sep 17 00:00:00 2001 From: alexandre Date: Thu, 17 Nov 2022 08:55:35 +0100 Subject: [PATCH 11/14] fix test --- db/dump/fixtures.sql | 4 +-- .../ticket/back/methods/sale/missingTrash.js | 2 +- .../methods/sale/specs/missingTrash.spec.js | 35 ++++++++++++++----- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 49cf639ef..98c15075e 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -333,7 +333,7 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city (1109, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, 0, NULL, 0, 0, 9, 0, 1, 'florist'), (1110, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Gotham', 46460, 1111111111, 222222222, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, 0, NULL, 0, 0, NULL, 0, 1, 'florist'), (1111, 'Missing', NULL, 'Missing man', 'Anton', 'The space, Universe far away', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, NULL), - (1112, 'Trash', NULL, 'Garbage man', 'Unknown name', 'New York city, Underground', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, NULL); + (1112, 'Trash', '12345678Z', 'Garbage man', 'Unknown name', 'New York city, Underground', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, NULL); INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`) SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), CONCAT(name, 'Social'), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1 @@ -2701,7 +2701,7 @@ INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`) INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`) VALUES (1, 9); - + INSERT INTO `vn`.`productionConfig` (`isPreviousPreparationRequired`, `ticketPrintedMax`, `ticketTrolleyMax`, `rookieDays`, `notBuyingMonths`, `id`, `isZoneClosedByExpeditionActivated`, `maxNotReadyCollections`, `minTicketsToCloseZone`, `movingTicketDelRoute`, `defaultZone`, `defautlAgencyMode`, `hasUniqueCollectionTime`, `maxCollectionWithoutUser`, `pendingCollectionsOrder`, `pendingCollectionsAge`) VALUES (0, 8, 80, 0, 0, 1, 0, 15, 25, -1, 697, 1328, 0, 1, 8, 6); diff --git a/modules/ticket/back/methods/sale/missingTrash.js b/modules/ticket/back/methods/sale/missingTrash.js index 6d4f69178..4ff37eb1f 100644 --- a/modules/ticket/back/methods/sale/missingTrash.js +++ b/modules/ticket/back/methods/sale/missingTrash.js @@ -44,7 +44,7 @@ module.exports = Self => { } }); - Self.missingTrash = async function (ctx, saleFk, quantity, isTrash, warehouseFk, newQuantity, options) { + Self.missingTrash = async function(ctx, saleFk, quantity, isTrash, warehouseFk, newQuantity, options) { const myOptions = {}; let tx; if (typeof options == 'object') diff --git a/modules/ticket/back/methods/sale/specs/missingTrash.spec.js b/modules/ticket/back/methods/sale/specs/missingTrash.spec.js index 490ad7e0e..dcc59333d 100644 --- a/modules/ticket/back/methods/sale/specs/missingTrash.spec.js +++ b/modules/ticket/back/methods/sale/specs/missingTrash.spec.js @@ -1,31 +1,50 @@ const models = require('vn-loopback/server/server').models; +const LoopBackContext = require('loopback-context'); describe('sale missingTrash()', () => { - it('should modify the amount of a sale by throwing it to faults or garbage', async () => { + const activeCtx = { + accessToken: {userId: 9}, + headers: {origin: 'localhost:5000'}, + __: () => {} + }; + + const ctx = { + req: activeCtx + }; + + beforeEach(() => { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); + }); + + it('should modify the amount of a sale by throwing it to faults or garbage', async() => { const tx = await models.Sale.beginTransaction({}); try { - const options = { transaction: tx }; + const options = {transaction: tx}; const quantity = 1; const isTrash = true; - const ctx = { req: { accessToken: { userId: 9 } } }; + const trashClient = await models.Client.findOne({where: {name: 'Trash'}}, options); + await trashClient.updateAttribute('name', 'BASURA', options); + + const sale = await models.Sale.findOne({fields: ['id', 'quantity', 'originalQuantity', 'ticketFk']} + , options); - const sale = await models.Sale.findOne({fields: ['id','quantity', 'originalQuantity', 'ticketFk']}, options); - console.log(sale); const ticket = await models.Ticket.findById(sale.ticketFk, {fields: ['warehouseFk']}, options); - console.log(ticket); - const newQuantity = sale.quantity-quantity; + + const newQuantity = sale.quantity - quantity; await models.Sale.missingTrash(ctx, sale.id, quantity, isTrash, ticket.warehouseFk, newQuantity, options); const saleAfter = await models.Sale.findById(sale.id, {fields: ['quantity', 'originalQuantity']}, options); + expect(saleAfter.quantity).toEqual(newQuantity); expect(saleAfter.originalQuantity).toBe(sale.quantity); await tx.rollback(); - } catch (e) { await tx.rollback(); throw e; From fd58eaf8388daa990a071e19a876461a2c20f484 Mon Sep 17 00:00:00 2001 From: alexandre Date: Fri, 18 Nov 2022 09:36:38 +0100 Subject: [PATCH 12/14] drop procedure --- .../00-collection_missingTrash.sql | 1 + .../10503-november/00-sale_missingTrash.sql | 27 ------- db/dump/fixtures.sql | 2 +- .../ticket/back/methods/sale/missingTrash.js | 70 ------------------- .../methods/sale/specs/missingTrash.spec.js | 53 -------------- modules/ticket/back/models/sale.js | 1 - 6 files changed, 2 insertions(+), 152 deletions(-) create mode 100644 db/changes/10503-november/00-collection_missingTrash.sql delete mode 100644 db/changes/10503-november/00-sale_missingTrash.sql delete mode 100644 modules/ticket/back/methods/sale/missingTrash.js delete mode 100644 modules/ticket/back/methods/sale/specs/missingTrash.spec.js diff --git a/db/changes/10503-november/00-collection_missingTrash.sql b/db/changes/10503-november/00-collection_missingTrash.sql new file mode 100644 index 000000000..d4467c699 --- /dev/null +++ b/db/changes/10503-november/00-collection_missingTrash.sql @@ -0,0 +1 @@ +DROP PROCEDURE IF EXISTS `vn`.`collection_missingTrash`; diff --git a/db/changes/10503-november/00-sale_missingTrash.sql b/db/changes/10503-november/00-sale_missingTrash.sql deleted file mode 100644 index 8c1bcaed3..000000000 --- a/db/changes/10503-november/00-sale_missingTrash.sql +++ /dev/null @@ -1,27 +0,0 @@ -DROP PROCEDURE IF EXISTS vn.sale_missingTrash; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_missingTrash`( - vSaleFk BIGINT, - vQuantity INT, - vIsTrash BOOLEAN, - vWarehouseFk INT, - vNewQuantity INT) -/** - * Modifica la cantidad de una sale tirĂ¡ndola a faltas o basura - * - * @param vSaleFk el id de la sale - * @param vQuantity cantidad que se va a tirar a faltas o basura - * @param vIsTrash true si es basura, false si es faltas - * @param vWarehouseFk id warehouse - * @param vNewQuantity cantidad que se queda en el ticket original - */ -BEGIN - CALL vn.collection_missingTrash(vSaleFk ,vQuantity ,vIsTrash ,vWarehouseFk ,vNewQuantity); -END$$ -DELIMITER ; - -INSERT INTO `salix`.`ACL` -(model, property, accessType, permission, principalType, principalId) -VALUES('Sale', 'missingTrash', 'WRITE', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 98c15075e..a436c7572 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -333,7 +333,7 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city (1109, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, 0, NULL, 0, 0, 9, 0, 1, 'florist'), (1110, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Gotham', 46460, 1111111111, 222222222, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, 0, NULL, 0, 0, NULL, 0, 1, 'florist'), (1111, 'Missing', NULL, 'Missing man', 'Anton', 'The space, Universe far away', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, NULL), - (1112, 'Trash', '12345678Z', 'Garbage man', 'Unknown name', 'New York city, Underground', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, NULL); + (1112, 'Trash', NULL, 'Garbage man', 'Unknown name', 'New York city, Underground', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, NULL); INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`) SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), CONCAT(name, 'Social'), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1 diff --git a/modules/ticket/back/methods/sale/missingTrash.js b/modules/ticket/back/methods/sale/missingTrash.js deleted file mode 100644 index 4ff37eb1f..000000000 --- a/modules/ticket/back/methods/sale/missingTrash.js +++ /dev/null @@ -1,70 +0,0 @@ -module.exports = Self => { - Self.remoteMethodCtx('missingTrash', { - description: 'Modify the amount of a sale by throwing it to faults or garbage', - accessType: 'WRITE', - accepts: [ - { - arg: 'saleFk', - type: 'number', - required: true, - description: 'The sale id' - }, - { - arg: 'quantity', - type: 'number', - required: true, - description: 'Quantity that is going to be thrown away' - }, - { - arg: 'isTrash', - type: 'boolean', - required: true, - description: 'True if garbage, false if fault' - }, - { - arg: 'warehouseFk', - type: 'number', - required: true, - description: 'The warehouse id' - }, - { - arg: 'newQuantity', - type: 'number', - required: true, - description: 'Amount remaining on the original ticket' - }, - ], - returns: { - type: ['object'], - root: true - }, - http: { - path: `/missingTrash`, - verb: 'POST' - } - }); - - Self.missingTrash = async function(ctx, saleFk, quantity, isTrash, warehouseFk, newQuantity, options) { - const myOptions = {}; - let tx; - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - - try { - const missingTrash = await Self.rawSql(`CALL vn.sale_missingTrash(?, ?, ?, ?, ?)`, - [saleFk, quantity, isTrash, warehouseFk, newQuantity], myOptions); - - if (tx) await tx.commit(); - - return missingTrash; - } catch (e) { - if (tx) await tx.rollback(); - throw e; - } - }; -}; diff --git a/modules/ticket/back/methods/sale/specs/missingTrash.spec.js b/modules/ticket/back/methods/sale/specs/missingTrash.spec.js deleted file mode 100644 index dcc59333d..000000000 --- a/modules/ticket/back/methods/sale/specs/missingTrash.spec.js +++ /dev/null @@ -1,53 +0,0 @@ -const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); - -describe('sale missingTrash()', () => { - const activeCtx = { - accessToken: {userId: 9}, - headers: {origin: 'localhost:5000'}, - __: () => {} - }; - - const ctx = { - req: activeCtx - }; - - beforeEach(() => { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - }); - - it('should modify the amount of a sale by throwing it to faults or garbage', async() => { - const tx = await models.Sale.beginTransaction({}); - - try { - const options = {transaction: tx}; - - const quantity = 1; - const isTrash = true; - - const trashClient = await models.Client.findOne({where: {name: 'Trash'}}, options); - await trashClient.updateAttribute('name', 'BASURA', options); - - const sale = await models.Sale.findOne({fields: ['id', 'quantity', 'originalQuantity', 'ticketFk']} - , options); - - const ticket = await models.Ticket.findById(sale.ticketFk, {fields: ['warehouseFk']}, options); - - const newQuantity = sale.quantity - quantity; - - await models.Sale.missingTrash(ctx, sale.id, quantity, isTrash, ticket.warehouseFk, newQuantity, options); - - const saleAfter = await models.Sale.findById(sale.id, {fields: ['quantity', 'originalQuantity']}, options); - - expect(saleAfter.quantity).toEqual(newQuantity); - expect(saleAfter.originalQuantity).toBe(sale.quantity); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); -}); diff --git a/modules/ticket/back/models/sale.js b/modules/ticket/back/models/sale.js index cb8814e67..ae247fc24 100644 --- a/modules/ticket/back/models/sale.js +++ b/modules/ticket/back/models/sale.js @@ -9,7 +9,6 @@ module.exports = Self => { require('../methods/sale/refund')(Self); require('../methods/sale/canEdit')(Self); require('../methods/sale/usesMana')(Self); - require('../methods/sale/missingTrash')(Self); Self.validatesPresenceOf('concept', { message: `Concept cannot be blank` From 67f03469807df1e1025720c9414d4c63b6534fdd Mon Sep 17 00:00:00 2001 From: alexandre Date: Fri, 18 Nov 2022 09:37:38 +0100 Subject: [PATCH 13/14] space fixtures --- db/dump/fixtures.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index a436c7572..c766bdee5 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2701,7 +2701,6 @@ INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`) INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`) VALUES (1, 9); - INSERT INTO `vn`.`productionConfig` (`isPreviousPreparationRequired`, `ticketPrintedMax`, `ticketTrolleyMax`, `rookieDays`, `notBuyingMonths`, `id`, `isZoneClosedByExpeditionActivated`, `maxNotReadyCollections`, `minTicketsToCloseZone`, `movingTicketDelRoute`, `defaultZone`, `defautlAgencyMode`, `hasUniqueCollectionTime`, `maxCollectionWithoutUser`, `pendingCollectionsOrder`, `pendingCollectionsAge`) VALUES (0, 8, 80, 0, 0, 1, 0, 15, 25, -1, 697, 1328, 0, 1, 8, 6); From a952fc0330b61fed1fdd5df994bbe62296c61823 Mon Sep 17 00:00:00 2001 From: alexandre Date: Fri, 18 Nov 2022 09:38:22 +0100 Subject: [PATCH 14/14] space fixtures --- db/dump/fixtures.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index c766bdee5..a436c7572 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2701,6 +2701,7 @@ INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`) INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`) VALUES (1, 9); + INSERT INTO `vn`.`productionConfig` (`isPreviousPreparationRequired`, `ticketPrintedMax`, `ticketTrolleyMax`, `rookieDays`, `notBuyingMonths`, `id`, `isZoneClosedByExpeditionActivated`, `maxNotReadyCollections`, `minTicketsToCloseZone`, `movingTicketDelRoute`, `defaultZone`, `defautlAgencyMode`, `hasUniqueCollectionTime`, `maxCollectionWithoutUser`, `pendingCollectionsOrder`, `pendingCollectionsAge`) VALUES (0, 8, 80, 0, 0, 1, 0, 15, 25, -1, 697, 1328, 0, 1, 8, 6);