From b9d3684db254a75a808f9af08db90f049f986f42 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 26 Apr 2024 15:48:30 +0200 Subject: [PATCH 01/49] feat: refs #6600 add column --- db/versions/11015-silverBamboo/00-addColumnPhotoMotivation.sql | 1 + modules/item/back/models/item.json | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 db/versions/11015-silverBamboo/00-addColumnPhotoMotivation.sql diff --git a/db/versions/11015-silverBamboo/00-addColumnPhotoMotivation.sql b/db/versions/11015-silverBamboo/00-addColumnPhotoMotivation.sql new file mode 100644 index 000000000..9f77dc88e --- /dev/null +++ b/db/versions/11015-silverBamboo/00-addColumnPhotoMotivation.sql @@ -0,0 +1 @@ +ALTER TABLE vn.item ADD COLUMN photoMotivation VARCHAR(255); \ No newline at end of file diff --git a/modules/item/back/models/item.json b/modules/item/back/models/item.json index 9d48dcbfb..7ec1daf7a 100644 --- a/modules/item/back/models/item.json +++ b/modules/item/back/models/item.json @@ -155,6 +155,9 @@ "minQuantity": { "type": "number", "description": "Min quantity" + }, + "photoMotivation":{ + "type": "string" } }, "relations": { From 1f1a49d0a56cb67ca15c207e43347587cfc0c01e Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 17 May 2024 14:20:33 +0200 Subject: [PATCH 02/49] refactor: refs #6889 use addSale --- modules/ticket/back/methods/ticket/addSale.js | 8 ++- .../back/methods/ticket/addSaleByCode.js | 56 ------------------- .../ticket/specs/addSaleByCode.spec.js | 39 ------------- modules/ticket/back/models/ticket-methods.js | 1 - modules/ticket/front/sale/index.js | 2 +- modules/ticket/front/sale/index.spec.js | 2 +- 6 files changed, 7 insertions(+), 101 deletions(-) delete mode 100644 modules/ticket/back/methods/ticket/addSaleByCode.js delete mode 100644 modules/ticket/back/methods/ticket/specs/addSaleByCode.spec.js diff --git a/modules/ticket/back/methods/ticket/addSale.js b/modules/ticket/back/methods/ticket/addSale.js index 826de6e12..8dc7a633c 100644 --- a/modules/ticket/back/methods/ticket/addSale.js +++ b/modules/ticket/back/methods/ticket/addSale.js @@ -10,8 +10,8 @@ module.exports = Self => { http: {source: 'path'} }, { - arg: 'itemId', - type: 'number', + arg: 'barcode', + type: 'any', required: true }, { @@ -29,7 +29,7 @@ module.exports = Self => { } }); - Self.addSale = async(ctx, id, itemId, quantity, options) => { + Self.addSale = async(ctx, id, barcode, quantity, options) => { const $t = ctx.req.__; // $translate const models = Self.app.models; const myOptions = {userId: ctx.req.accessToken.userId}; @@ -46,7 +46,9 @@ module.exports = Self => { try { await models.Ticket.isEditableOrThrow(ctx, id, myOptions); + const itemId = await models.ItemBarcode.toItem(barcode, myOptions); const item = await models.Item.findById(itemId, null, myOptions); + const ticket = await models.Ticket.findById(id, { include: { relation: 'client', diff --git a/modules/ticket/back/methods/ticket/addSaleByCode.js b/modules/ticket/back/methods/ticket/addSaleByCode.js deleted file mode 100644 index ca3d2cb07..000000000 --- a/modules/ticket/back/methods/ticket/addSaleByCode.js +++ /dev/null @@ -1,56 +0,0 @@ -const UserError = require('vn-loopback/util/user-error'); -module.exports = Self => { - Self.remoteMethodCtx('addSaleByCode', { - description: 'Add a collection', - accessType: 'WRITE', - accepts: [ - { - arg: 'barcode', - type: 'string', - required: true - }, { - arg: 'quantity', - type: 'number', - required: true - }, { - arg: 'ticketFk', - type: 'number', - required: true - }, { - arg: 'warehouseFk', - type: 'number', - required: true - }, - - ], - http: { - path: `/addSaleByCode`, - verb: 'POST' - }, - }); - - Self.addSaleByCode = async(ctx, barcode, quantity, ticketFk, warehouseFk, options) => { - const myOptions = {userId: ctx.req.accessToken.userId}; - let tx; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - - try { - const [[item]] = await Self.rawSql('CALL vn.item_getInfo(?,?)', [barcode, warehouseFk], myOptions); - if (!item?.available) throw new UserError('We do not have availability for the selected item'); - - await Self.rawSql('CALL vn.collection_addItem(?, ?, ?)', [item.id, quantity, ticketFk], myOptions); - - if (tx) await tx.commit(); - } catch (e) { - if (tx) await tx.rollback(); - throw e; - } - }; -}; diff --git a/modules/ticket/back/methods/ticket/specs/addSaleByCode.spec.js b/modules/ticket/back/methods/ticket/specs/addSaleByCode.spec.js deleted file mode 100644 index b97139178..000000000 --- a/modules/ticket/back/methods/ticket/specs/addSaleByCode.spec.js +++ /dev/null @@ -1,39 +0,0 @@ -const {models} = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); - -describe('Ticket addSaleByCode()', () => { - const quantity = 3; - const ticketFk = 13; - const warehouseFk = 1; - beforeAll(async() => { - activeCtx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'}, - __: value => value - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - }); - - it('should add a new sale', async() => { - const tx = await models.Ticket.beginTransaction({}); - - try { - const options = {transaction: tx}; - const code = '1111111111'; - - const salesBefore = await models.Sale.find(null, options); - await models.Ticket.addSaleByCode(activeCtx, code, quantity, ticketFk, warehouseFk, options); - const salesAfter = await models.Sale.find(null, options); - - expect(salesAfter.length).toEqual(salesBefore.length + 1); - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); -}); diff --git a/modules/ticket/back/models/ticket-methods.js b/modules/ticket/back/models/ticket-methods.js index 0ae2ce3b4..5582dde5c 100644 --- a/modules/ticket/back/models/ticket-methods.js +++ b/modules/ticket/back/models/ticket-methods.js @@ -46,6 +46,5 @@ module.exports = function(Self) { require('../methods/ticket/invoiceTicketsAndPdf')(Self); require('../methods/ticket/docuwareDownload')(Self); require('../methods/ticket/myLastModified')(Self); - require('../methods/ticket/addSaleByCode')(Self); require('../methods/ticket/clone')(Self); }; diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index 1cd5560a4..7ff8d89e3 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -476,7 +476,7 @@ class Controller extends Section { */ addSale(sale) { const data = { - itemId: sale.itemFk, + barcode: sale.itemFk, quantity: sale.quantity }; const query = `tickets/${this.ticket.id}/addSale`; diff --git a/modules/ticket/front/sale/index.spec.js b/modules/ticket/front/sale/index.spec.js index fb1c925d4..8200d6b89 100644 --- a/modules/ticket/front/sale/index.spec.js +++ b/modules/ticket/front/sale/index.spec.js @@ -659,7 +659,7 @@ describe('Ticket', () => { jest.spyOn(controller, 'resetChanges').mockReturnThis(); const newSale = {itemFk: 4, quantity: 10}; - const expectedParams = {itemId: 4, quantity: 10}; + const expectedParams = {barcode: 4, quantity: 10}; const expectedResult = { id: 30, quantity: 10, From eb503238d737858f100dc53f06af1d28a497fddb Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 27 May 2024 09:07:23 +0200 Subject: [PATCH 03/49] feat refs #7296 routesMonitor.expeditionTruckFk to routesMonitor.roadmapStopFk --- db/dump/fixtures.after.sql | 2 +- db/routines/dipole/procedures/expedition_add.sql | 2 +- db/routines/srt/functions/expedition_getDayMinute.sql | 2 +- db/routines/srt/views/bufferDayMinute.sql | 2 +- db/routines/srt/views/bufferStock.sql | 2 +- db/routines/srt/views/upperStickers.sql | 2 +- db/routines/vn/procedures/conveyorExpedition_Add.sql | 2 +- db/routines/vn/procedures/expedition_StateGet.sql | 2 +- db/routines/vn/procedures/expedition_getState.sql | 2 +- db/routines/vn/procedures/reportLabelCollection_get.sql | 2 +- db/routines/vn/procedures/routeMonitor_calculate.sql | 2 +- db/routines/vn/views/expeditionCommon.sql | 4 ++-- db/routines/vn/views/expeditionPallet_Print.sql | 4 ++-- db/routines/vn/views/expeditionRoute_Monitor.sql | 2 +- db/routines/vn/views/expeditionSticker.sql | 2 +- db/routines/vn/views/expeditionTicket_NoBoxes.sql | 2 +- db/routines/vn/views/expeditionTruck_Control.sql | 4 ++-- db/routines/vn/views/expeditionTruck_Control_Detail.sql | 6 +++--- .../vn/views/expeditionTruck_Control_Detail_Pallet.sql | 6 +++--- print/templates/reports/collection-label/sql/labelsData.sql | 2 +- .../reports/expedition-pallet-label/sql/labelData.sql | 4 ++-- 21 files changed, 29 insertions(+), 29 deletions(-) diff --git a/db/dump/fixtures.after.sql b/db/dump/fixtures.after.sql index fd940d8a6..562ea02d8 100644 --- a/db/dump/fixtures.after.sql +++ b/db/dump/fixtures.after.sql @@ -129,7 +129,7 @@ INSERT INTO vn.itemShelving (id,itemFk,visible,shelvingFk,`grouping`,packing,pac INSERT INTO vn.beach (code,warehouseFk) VALUES ('TEST',1); -INSERT INTO vn.routesMonitor (routeFk,name,beachFk,m3,expeditionTruckFk) VALUES +INSERT INTO vn.routesMonitor (routeFk,name,beachFk,m3,roadmapStopFk) VALUES (1,'TEST','TEST',1.0,1); /* #5483 INSERT INTO vn.ticket (clientFk, warehouseFk, shipped, nickname, refFk, addressFk, workerFk, observations, isSigned, isLabeled, isPrinted, packages, location, `hour`, created, isBlocked, solution, routeFk, priority, hasPriority, companyFk, agencyModeFk, landed, isBoxed, isDeleted, zoneFk, zonePrice, zoneBonus, totalWithVat, totalWithoutVat, weight) diff --git a/db/routines/dipole/procedures/expedition_add.sql b/db/routines/dipole/procedures/expedition_add.sql index e224cd2d2..70bc7930e 100644 --- a/db/routines/dipole/procedures/expedition_add.sql +++ b/db/routines/dipole/procedures/expedition_add.sql @@ -46,7 +46,7 @@ BEGIN JOIN vn.address a ON a.id = t.addressFk JOIN vn.province p ON p.id = a.provinceFk LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk - LEFT JOIN vn.roadmapStop rs ON rs.id = rm.expeditionTruckFk + LEFT JOIN vn.roadmapStop rs ON rs.id = rm.roadmapStopFk LEFT JOIN vn.beach b ON b.code = rm.beachFk LEFT JOIN vn.`zone`z ON z.id = t.zoneFk JOIN vn.agencyMode am ON t.agencyModeFk = am.id diff --git a/db/routines/srt/functions/expedition_getDayMinute.sql b/db/routines/srt/functions/expedition_getDayMinute.sql index 9331f77e5..01ff534f5 100644 --- a/db/routines/srt/functions/expedition_getDayMinute.sql +++ b/db/routines/srt/functions/expedition_getDayMinute.sql @@ -22,7 +22,7 @@ BEGIN LEFT JOIN vn.route r ON r.id = t.routeFk LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk LEFT JOIN vn.routesMonitor rm ON t.routeFk = rm.routeFk - LEFT JOIN vn.roadmapStop rs ON rm.expeditionTruckFk = rs.id + LEFT JOIN vn.roadmapStop rs ON rm.roadmapStopFk = rs.id WHERE e.id = vExpeditionFk; RETURN vDayMinute; diff --git a/db/routines/srt/views/bufferDayMinute.sql b/db/routines/srt/views/bufferDayMinute.sql index 41db2bcf7..d2108e513 100644 --- a/db/routines/srt/views/bufferDayMinute.sql +++ b/db/routines/srt/views/bufferDayMinute.sql @@ -34,7 +34,7 @@ FROM ( ) LEFT JOIN `vn`.`routesMonitor` `rm` ON(`t`.`routeFk` = `rm`.`routeFk`) ) - LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rm`.`expeditionTruckFk` = `rs`.`id`) + LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rm`.`roadmapStopFk` = `rs`.`id`) ) LEFT JOIN `vn`.`zone` `z` ON(`z`.`id` = `t`.`zoneFk`) ) diff --git a/db/routines/srt/views/bufferStock.sql b/db/routines/srt/views/bufferStock.sql index 7494cf0a9..ca04d3c01 100644 --- a/db/routines/srt/views/bufferStock.sql +++ b/db/routines/srt/views/bufferStock.sql @@ -45,7 +45,7 @@ FROM ( ) LEFT JOIN `vn`.`routesMonitor` `rm` ON(`t`.`routeFk` = `rm`.`routeFk`) ) - LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rm`.`expeditionTruckFk` = `rs`.`id`) + LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rm`.`roadmapStopFk` = `rs`.`id`) ) JOIN `srt`.`config` `c` ) diff --git a/db/routines/srt/views/upperStickers.sql b/db/routines/srt/views/upperStickers.sql index a230408d9..1cd72c12b 100644 --- a/db/routines/srt/views/upperStickers.sql +++ b/db/routines/srt/views/upperStickers.sql @@ -32,7 +32,7 @@ FROM ( ) LEFT JOIN `vn`.`routesMonitor` `rm` ON(`t`.`routeFk` = `rm`.`routeFk`) ) - LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rm`.`expeditionTruckFk` = `rs`.`id`) + LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rm`.`roadmapStopFk` = `rs`.`id`) ) JOIN `dipole`.`expedition_PrintOut` `epo` ON(`epo`.`expeditionFk` = `e`.`id`) ) diff --git a/db/routines/vn/procedures/conveyorExpedition_Add.sql b/db/routines/vn/procedures/conveyorExpedition_Add.sql index daaf33f2f..94cbc88e2 100644 --- a/db/routines/vn/procedures/conveyorExpedition_Add.sql +++ b/db/routines/vn/procedures/conveyorExpedition_Add.sql @@ -34,7 +34,7 @@ BEGIN LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk LEFT JOIN vn.agency a ON a.id = am.agencyFk LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk - LEFT JOIN vn.roadmapStop rs ON rs.id = rm.expeditionTruckFk + LEFT JOIN vn.roadmapStop rs ON rs.id = rm.roadmapStopFk JOIN vn.packagingConfig pc WHERE t.warehouseFk IN (60,1,44) AND e.created BETWEEN vStarted AND vEnded diff --git a/db/routines/vn/procedures/expedition_StateGet.sql b/db/routines/vn/procedures/expedition_StateGet.sql index e58ec3afd..c709841eb 100644 --- a/db/routines/vn/procedures/expedition_StateGet.sql +++ b/db/routines/vn/procedures/expedition_StateGet.sql @@ -67,7 +67,7 @@ BEGIN LEFT JOIN vn.route r ON r.id = t.routeFk LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk LEFT JOIN vn.routesMonitor rm ON rm.routeFk = r.id - LEFT JOIN vn.roadmapStop rs ON rs.id = rm.expeditionTruckFk + LEFT JOIN vn.roadmapStop rs ON rs.id = rm.roadmapStopFk WHERE e.id = vExpeditionFk; END$$ diff --git a/db/routines/vn/procedures/expedition_getState.sql b/db/routines/vn/procedures/expedition_getState.sql index f3f94a889..61d65f571 100644 --- a/db/routines/vn/procedures/expedition_getState.sql +++ b/db/routines/vn/procedures/expedition_getState.sql @@ -50,7 +50,7 @@ BEGIN LEFT JOIN vn.route r ON r.id = t.routeFk LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk LEFT JOIN vn.routesMonitor rm ON rm.routeFk = r.id - LEFT JOIN vn.roadmapStop rs ON rs.id = rm.expeditionTruckFk + LEFT JOIN vn.roadmapStop rs ON rs.id = rm.roadmapStopFk WHERE e.id = vExpeditionFk; END$$ diff --git a/db/routines/vn/procedures/reportLabelCollection_get.sql b/db/routines/vn/procedures/reportLabelCollection_get.sql index e7f8f2bc3..f3bcbfa28 100644 --- a/db/routines/vn/procedures/reportLabelCollection_get.sql +++ b/db/routines/vn/procedures/reportLabelCollection_get.sql @@ -47,7 +47,7 @@ BEGIN LEFT JOIN ticketTrolley tt ON tt.ticket = t.id LEFT JOIN zone zo ON t.zoneFk = zo.id LEFT JOIN routesMonitor rm ON rm.routeFk = t.routeFk - LEFT JOIN roadmapStop rs ON rs.id = rm.expeditionTruckFk + LEFT JOIN roadmapStop rs ON rs.id = rm.roadmapStopFk WHERE IF(vIsCollection, tc.collectionFk = vParam, tc.ticketFk = vParam) GROUP BY t.id ORDER BY cc.code; diff --git a/db/routines/vn/procedures/routeMonitor_calculate.sql b/db/routines/vn/procedures/routeMonitor_calculate.sql index 04a31a161..463c176ff 100644 --- a/db/routines/vn/procedures/routeMonitor_calculate.sql +++ b/db/routines/vn/procedures/routeMonitor_calculate.sql @@ -106,7 +106,7 @@ BEGIN SET rm.m3boxes = sub.m3boxes; UPDATE routesMonitor rm - JOIN vn.roadmapStop rs ON rs.id = rm.expeditionTruckFk + JOIN vn.roadmapStop rs ON rs.id = rm.roadmapStopFk SET rm.etd = rs.eta; DROP TEMPORARY TABLE tmp.routesMonitor; diff --git a/db/routines/vn/views/expeditionCommon.sql b/db/routines/vn/views/expeditionCommon.sql index d1ce80880..46765e57c 100644 --- a/db/routines/vn/views/expeditionCommon.sql +++ b/db/routines/vn/views/expeditionCommon.sql @@ -8,7 +8,7 @@ AS SELECT `rs`.`id` AS `truckFk`, `t`.`routeFk` AS `routeFk`, `es`.`id` AS `scanFk`, `e`.`id` AS `expeditionFk`, - `r`.`expeditionTruckFk` AS `expeditionTruckFk`, + `r`.`roadmapStopFk` AS `expeditionTruckFk`, `t`.`warehouseFk` AS `warehouseFk`, `e`.`created` AS `lastPacked`, `t`.`id` AS `ticketFk` @@ -18,7 +18,7 @@ FROM ( ( ( `vn`.`roadmapStop` `rs` - LEFT JOIN `vn`.`routesMonitor` `r` ON(`rs`.`id` = `r`.`expeditionTruckFk`) + LEFT JOIN `vn`.`routesMonitor` `r` ON(`rs`.`id` = `r`.`roadmapStopFk`) ) LEFT JOIN `vn`.`ticket` `t` ON(`r`.`routeFk` = `t`.`routeFk`) ) diff --git a/db/routines/vn/views/expeditionPallet_Print.sql b/db/routines/vn/views/expeditionPallet_Print.sql index c0b8208c3..aab725ebe 100644 --- a/db/routines/vn/views/expeditionPallet_Print.sql +++ b/db/routines/vn/views/expeditionPallet_Print.sql @@ -6,7 +6,7 @@ AS SELECT `rs2`.`description` AS `truck`, `r`.`description` AS `zone`, COUNT(`es`.`id`) AS `eti`, `ep`.`id` AS `palletFk`, - `rs`.`id` <=> `rm`.`expeditionTruckFk` AS `isMatch`, + `rs`.`id` <=> `rm`.`roadmapStopFk` AS `isMatch`, `t`.`warehouseFk` AS `warehouseFk`, IF( `r`.`created` > `util`.`VN_CURDATE`() + INTERVAL 1 DAY, @@ -33,7 +33,7 @@ FROM ( ) LEFT JOIN `vn`.`routesMonitor` `rm` ON(`rm`.`routeFk` = `r`.`id`) ) - LEFT JOIN `vn`.`roadmapStop` `rs2` ON(`rs2`.`id` = `rm`.`expeditionTruckFk`) + LEFT JOIN `vn`.`roadmapStop` `rs2` ON(`rs2`.`id` = `rm`.`roadmapStopFk`) ) GROUP BY `ep`.`id`, `t`.`routeFk` diff --git a/db/routines/vn/views/expeditionRoute_Monitor.sql b/db/routines/vn/views/expeditionRoute_Monitor.sql index cc1f16894..7eef40425 100644 --- a/db/routines/vn/views/expeditionRoute_Monitor.sql +++ b/db/routines/vn/views/expeditionRoute_Monitor.sql @@ -15,7 +15,7 @@ FROM ( `vn`.`route` `r` LEFT JOIN `vn`.`routesMonitor` `rm` ON(`r`.`id` = `rm`.`routeFk`) ) - LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `rm`.`expeditionTruckFk`) + LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `rm`.`roadmapStopFk`) ) JOIN `vn`.`ticket` `t` ON(`t`.`routeFk` = `r`.`id`) ) diff --git a/db/routines/vn/views/expeditionSticker.sql b/db/routines/vn/views/expeditionSticker.sql index 05fbc42a1..ef0743527 100644 --- a/db/routines/vn/views/expeditionSticker.sql +++ b/db/routines/vn/views/expeditionSticker.sql @@ -45,7 +45,7 @@ FROM ( ) LEFT JOIN `vn`.`routesMonitor` `rm` ON(`rm`.`routeFk` = `t`.`routeFk`) ) - LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `rm`.`expeditionTruckFk`) + LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `rm`.`roadmapStopFk`) ) LEFT JOIN `vn`.`beach` `b` ON(`b`.`code` = `rm`.`beachFk`) ) diff --git a/db/routines/vn/views/expeditionTicket_NoBoxes.sql b/db/routines/vn/views/expeditionTicket_NoBoxes.sql index 8acbe17fe..75218c7a9 100644 --- a/db/routines/vn/views/expeditionTicket_NoBoxes.sql +++ b/db/routines/vn/views/expeditionTicket_NoBoxes.sql @@ -13,7 +13,7 @@ FROM ( ) JOIN `vn`.`routesMonitor` `rm` ON(`rm`.`routeFk` = `t`.`routeFk`) ) - JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `rm`.`expeditionTruckFk`) + JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `rm`.`roadmapStopFk`) ) WHERE `e`.`id` IS NULL AND `rs`.`eta` > `util`.`VN_CURDATE`() diff --git a/db/routines/vn/views/expeditionTruck_Control.sql b/db/routines/vn/views/expeditionTruck_Control.sql index 838e1f89e..818ae3ae6 100644 --- a/db/routines/vn/views/expeditionTruck_Control.sql +++ b/db/routines/vn/views/expeditionTruck_Control.sql @@ -11,9 +11,9 @@ AS SELECT `e`.`truckFk` AS `id`, COUNT(DISTINCT `e`.`routeFk`) AS `routes`, COUNT(DISTINCT `e`.`scanFk`) AS `scans`, COUNT(DISTINCT `e`.`expeditionFk`) AS `expeditions`, - sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`, + sum(`e`.`truckFk` <> `e`.`roadmapStopFk`) AS `fallos`, max(`e`.`lastPacked`) AS `lastPacked` FROM `vn`.`expeditionCommon` `e` GROUP BY `e`.`truckFk` -ORDER BY sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) DESC, +ORDER BY sum(`e`.`truckFk` <> `e`.`roadmapStopFk`) DESC, `e`.`eta` diff --git a/db/routines/vn/views/expeditionTruck_Control_Detail.sql b/db/routines/vn/views/expeditionTruck_Control_Detail.sql index 96a5b78e6..51970544b 100644 --- a/db/routines/vn/views/expeditionTruck_Control_Detail.sql +++ b/db/routines/vn/views/expeditionTruck_Control_Detail.sql @@ -7,12 +7,12 @@ AS SELECT `e`.`truckFk` AS `id`, `e`.`palletFk` AS `pallet`, COUNT(DISTINCT `e`.`routeFk`) AS `routes`, COUNT(DISTINCT `e`.`scanFk`) AS `scans`, - COUNT(DISTINCT `e`.`expeditionTruckFk`) AS `destinos`, - sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`, + COUNT(DISTINCT `e`.`roadmapStopFk`) AS `destinos`, + sum(`e`.`truckFk` <> `e`.`roadmapStopFk`) AS `fallos`, max(`e`.`lastPacked`) AS `lastPacked` FROM `vn`.`expeditionCommon` `e` GROUP BY `e`.`truckFk`, `e`.`palletFk` -ORDER BY sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) DESC, +ORDER BY sum(`e`.`truckFk` <> `e`.`roadmapStopFk`) DESC, `e`.`eta`, `e`.`truckFk` diff --git a/db/routines/vn/views/expeditionTruck_Control_Detail_Pallet.sql b/db/routines/vn/views/expeditionTruck_Control_Detail_Pallet.sql index 3f239432d..7e24d6b01 100644 --- a/db/routines/vn/views/expeditionTruck_Control_Detail_Pallet.sql +++ b/db/routines/vn/views/expeditionTruck_Control_Detail_Pallet.sql @@ -8,15 +8,15 @@ AS SELECT `e`.`truckFk` AS `id`, `e`.`routeFk` AS `route`, COUNT(DISTINCT `e`.`scanFk`) AS `scans`, `rs`.`description` AS `destinos`, - sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`, + sum(`e`.`truckFk` <> `e`.`roadmapStopFk`) AS `fallos`, `e`.`expeditionTruckFk` AS `expeditionTruckFk`, max(`e`.`lastPacked`) AS `lastPacked` FROM ( `vn`.`expeditionCommon` `e` - LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `e`.`expeditionTruckFk`) + LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `e`.`roadmapStopFk`) ) GROUP BY `e`.`truckFk`, `e`.`palletFk`, `e`.`routeFk` -ORDER BY sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) DESC, +ORDER BY sum(`e`.`truckFk` <> `e`.`roadmapStopFk`) DESC, `e`.`palletFk` diff --git a/print/templates/reports/collection-label/sql/labelsData.sql b/print/templates/reports/collection-label/sql/labelsData.sql index 2ffa6d8db..c96817b9c 100644 --- a/print/templates/reports/collection-label/sql/labelsData.sql +++ b/print/templates/reports/collection-label/sql/labelsData.sql @@ -35,7 +35,7 @@ SELECT c.itemPackingTypeFk code, LEFT JOIN vn.ticketTrolley tt ON tt.ticket = t.id LEFT JOIN vn.`zone` zo ON t.zoneFk = zo.id LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk - LEFT JOIN vn.roadmapStop rs ON rs.id = rm.expeditionTruckFk + LEFT JOIN vn.roadmapStop rs ON rs.id = rm.roadmapStopFk LEFT JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id JOIN vn.productionConfig pc WHERE t.id IN (?) diff --git a/print/templates/reports/expedition-pallet-label/sql/labelData.sql b/print/templates/reports/expedition-pallet-label/sql/labelData.sql index 385614305..49a4031ae 100644 --- a/print/templates/reports/expedition-pallet-label/sql/labelData.sql +++ b/print/templates/reports/expedition-pallet-label/sql/labelData.sql @@ -5,7 +5,7 @@ SELECT ep.id palletFk, COUNT(es.id) labels, t.warehouseFk warehouseFk, dayname(r.created) `dayName`, - rs.id <=> rm.expeditionTruckFk isMatch + rs.id <=> rm.roadmapStopFk isMatch FROM vn.roadmapStop rs JOIN vn.expeditionPallet ep ON ep.truckFk = rs.id JOIN vn.expeditionScan es ON es.palletFk = ep.id @@ -13,7 +13,7 @@ SELECT ep.id palletFk, JOIN vn.ticket t ON t.id = e.ticketFk JOIN vn.route r ON r.id = t.routeFk LEFT JOIN vn.routesMonitor rm ON rm.routeFk = r.id - LEFT JOIN vn.roadmapStop rs2 ON rs2.id = rm.expeditionTruckFk + LEFT JOIN vn.roadmapStop rs2 ON rs2.id = rm.roadmapStopFk WHERE ep.id = ? GROUP BY ep.id, t.routeFk ORDER BY t.routeFk From aaea0c95f7c71734a070c1028fbc8b099a3fd96c Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 27 May 2024 09:41:28 +0200 Subject: [PATCH 04/49] feat: refs #7296 roadmapStopFk --- db/routines/vn/views/expeditionTruck_Control.sql | 4 ++-- db/routines/vn/views/expeditionTruck_Control_Detail.sql | 6 +++--- .../vn/views/expeditionTruck_Control_Detail_Pallet.sql | 6 +++--- db/versions/11070-turquoiseCordyline/00-firstScript.sql | 1 + 4 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 db/versions/11070-turquoiseCordyline/00-firstScript.sql diff --git a/db/routines/vn/views/expeditionTruck_Control.sql b/db/routines/vn/views/expeditionTruck_Control.sql index 818ae3ae6..838e1f89e 100644 --- a/db/routines/vn/views/expeditionTruck_Control.sql +++ b/db/routines/vn/views/expeditionTruck_Control.sql @@ -11,9 +11,9 @@ AS SELECT `e`.`truckFk` AS `id`, COUNT(DISTINCT `e`.`routeFk`) AS `routes`, COUNT(DISTINCT `e`.`scanFk`) AS `scans`, COUNT(DISTINCT `e`.`expeditionFk`) AS `expeditions`, - sum(`e`.`truckFk` <> `e`.`roadmapStopFk`) AS `fallos`, + sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`, max(`e`.`lastPacked`) AS `lastPacked` FROM `vn`.`expeditionCommon` `e` GROUP BY `e`.`truckFk` -ORDER BY sum(`e`.`truckFk` <> `e`.`roadmapStopFk`) DESC, +ORDER BY sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) DESC, `e`.`eta` diff --git a/db/routines/vn/views/expeditionTruck_Control_Detail.sql b/db/routines/vn/views/expeditionTruck_Control_Detail.sql index 51970544b..96a5b78e6 100644 --- a/db/routines/vn/views/expeditionTruck_Control_Detail.sql +++ b/db/routines/vn/views/expeditionTruck_Control_Detail.sql @@ -7,12 +7,12 @@ AS SELECT `e`.`truckFk` AS `id`, `e`.`palletFk` AS `pallet`, COUNT(DISTINCT `e`.`routeFk`) AS `routes`, COUNT(DISTINCT `e`.`scanFk`) AS `scans`, - COUNT(DISTINCT `e`.`roadmapStopFk`) AS `destinos`, - sum(`e`.`truckFk` <> `e`.`roadmapStopFk`) AS `fallos`, + COUNT(DISTINCT `e`.`expeditionTruckFk`) AS `destinos`, + sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`, max(`e`.`lastPacked`) AS `lastPacked` FROM `vn`.`expeditionCommon` `e` GROUP BY `e`.`truckFk`, `e`.`palletFk` -ORDER BY sum(`e`.`truckFk` <> `e`.`roadmapStopFk`) DESC, +ORDER BY sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) DESC, `e`.`eta`, `e`.`truckFk` diff --git a/db/routines/vn/views/expeditionTruck_Control_Detail_Pallet.sql b/db/routines/vn/views/expeditionTruck_Control_Detail_Pallet.sql index 7e24d6b01..3f239432d 100644 --- a/db/routines/vn/views/expeditionTruck_Control_Detail_Pallet.sql +++ b/db/routines/vn/views/expeditionTruck_Control_Detail_Pallet.sql @@ -8,15 +8,15 @@ AS SELECT `e`.`truckFk` AS `id`, `e`.`routeFk` AS `route`, COUNT(DISTINCT `e`.`scanFk`) AS `scans`, `rs`.`description` AS `destinos`, - sum(`e`.`truckFk` <> `e`.`roadmapStopFk`) AS `fallos`, + sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`, `e`.`expeditionTruckFk` AS `expeditionTruckFk`, max(`e`.`lastPacked`) AS `lastPacked` FROM ( `vn`.`expeditionCommon` `e` - LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `e`.`roadmapStopFk`) + LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `e`.`expeditionTruckFk`) ) GROUP BY `e`.`truckFk`, `e`.`palletFk`, `e`.`routeFk` -ORDER BY sum(`e`.`truckFk` <> `e`.`roadmapStopFk`) DESC, +ORDER BY sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) DESC, `e`.`palletFk` diff --git a/db/versions/11070-turquoiseCordyline/00-firstScript.sql b/db/versions/11070-turquoiseCordyline/00-firstScript.sql new file mode 100644 index 000000000..494080033 --- /dev/null +++ b/db/versions/11070-turquoiseCordyline/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.routesMonitor CHANGE expeditionTruckFk roadmapStopFk int(11) DEFAULT NULL NULL; From 0b648d09af48ca8595f72187d531a01a087ea5aa Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 27 May 2024 11:45:22 +0200 Subject: [PATCH 05/49] feat: refs #7296 roadmapStopFk --- db/routines/vn/procedures/expeditionPallet_build.sql | 6 +++--- db/routines/vn/views/expeditionCommon.sql | 2 +- db/routines/vn/views/expeditionTruck_Control.sql | 4 ++-- .../vn/views/expeditionTruck_Control_Detail.sql | 6 +++--- .../vn/views/expeditionTruck_Control_Detail_Pallet.sql | 10 +++++----- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/db/routines/vn/procedures/expeditionPallet_build.sql b/db/routines/vn/procedures/expeditionPallet_build.sql index 9fbb60100..bea56eae6 100644 --- a/db/routines/vn/procedures/expeditionPallet_build.sql +++ b/db/routines/vn/procedures/expeditionPallet_build.sql @@ -56,13 +56,13 @@ BEGIN LIMIT 1; IF vPalletFk IS NULL THEN - SELECT expeditionTruckFk + SELECT roadmapStopFk INTO vTruckFk FROM ( - SELECT rm.expeditionTruckFk, count(*) n + SELECT rm.roadmapStopFk, count(*) n FROM vn.routesMonitor rm JOIN tExpedition e ON e.routeFk = rm.routeFk - GROUP BY expeditionTruckFk + GROUP BY roadmapStopFk ORDER BY n DESC LIMIT 1) sub; diff --git a/db/routines/vn/views/expeditionCommon.sql b/db/routines/vn/views/expeditionCommon.sql index 46765e57c..fcf36a7d8 100644 --- a/db/routines/vn/views/expeditionCommon.sql +++ b/db/routines/vn/views/expeditionCommon.sql @@ -8,7 +8,7 @@ AS SELECT `rs`.`id` AS `truckFk`, `t`.`routeFk` AS `routeFk`, `es`.`id` AS `scanFk`, `e`.`id` AS `expeditionFk`, - `r`.`roadmapStopFk` AS `expeditionTruckFk`, + `r`.`roadmapStopFk` AS `roadmapStopFk`, `t`.`warehouseFk` AS `warehouseFk`, `e`.`created` AS `lastPacked`, `t`.`id` AS `ticketFk` diff --git a/db/routines/vn/views/expeditionTruck_Control.sql b/db/routines/vn/views/expeditionTruck_Control.sql index 838e1f89e..818ae3ae6 100644 --- a/db/routines/vn/views/expeditionTruck_Control.sql +++ b/db/routines/vn/views/expeditionTruck_Control.sql @@ -11,9 +11,9 @@ AS SELECT `e`.`truckFk` AS `id`, COUNT(DISTINCT `e`.`routeFk`) AS `routes`, COUNT(DISTINCT `e`.`scanFk`) AS `scans`, COUNT(DISTINCT `e`.`expeditionFk`) AS `expeditions`, - sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`, + sum(`e`.`truckFk` <> `e`.`roadmapStopFk`) AS `fallos`, max(`e`.`lastPacked`) AS `lastPacked` FROM `vn`.`expeditionCommon` `e` GROUP BY `e`.`truckFk` -ORDER BY sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) DESC, +ORDER BY sum(`e`.`truckFk` <> `e`.`roadmapStopFk`) DESC, `e`.`eta` diff --git a/db/routines/vn/views/expeditionTruck_Control_Detail.sql b/db/routines/vn/views/expeditionTruck_Control_Detail.sql index 96a5b78e6..51970544b 100644 --- a/db/routines/vn/views/expeditionTruck_Control_Detail.sql +++ b/db/routines/vn/views/expeditionTruck_Control_Detail.sql @@ -7,12 +7,12 @@ AS SELECT `e`.`truckFk` AS `id`, `e`.`palletFk` AS `pallet`, COUNT(DISTINCT `e`.`routeFk`) AS `routes`, COUNT(DISTINCT `e`.`scanFk`) AS `scans`, - COUNT(DISTINCT `e`.`expeditionTruckFk`) AS `destinos`, - sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`, + COUNT(DISTINCT `e`.`roadmapStopFk`) AS `destinos`, + sum(`e`.`truckFk` <> `e`.`roadmapStopFk`) AS `fallos`, max(`e`.`lastPacked`) AS `lastPacked` FROM `vn`.`expeditionCommon` `e` GROUP BY `e`.`truckFk`, `e`.`palletFk` -ORDER BY sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) DESC, +ORDER BY sum(`e`.`truckFk` <> `e`.`roadmapStopFk`) DESC, `e`.`eta`, `e`.`truckFk` diff --git a/db/routines/vn/views/expeditionTruck_Control_Detail_Pallet.sql b/db/routines/vn/views/expeditionTruck_Control_Detail_Pallet.sql index 3f239432d..b7244ecf8 100644 --- a/db/routines/vn/views/expeditionTruck_Control_Detail_Pallet.sql +++ b/db/routines/vn/views/expeditionTruck_Control_Detail_Pallet.sql @@ -8,15 +8,15 @@ AS SELECT `e`.`truckFk` AS `id`, `e`.`routeFk` AS `route`, COUNT(DISTINCT `e`.`scanFk`) AS `scans`, `rs`.`description` AS `destinos`, - sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`, - `e`.`expeditionTruckFk` AS `expeditionTruckFk`, - max(`e`.`lastPacked`) AS `lastPacked` + SUM(`e`.`truckFk` <> `e`.`roadmapStopFk`) AS `fallos`, + `e`.`roadmapStopFk` AS `roadmapStopFk`, + MAX(`e`.`lastPacked`) AS `lastPacked` FROM ( `vn`.`expeditionCommon` `e` - LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `e`.`expeditionTruckFk`) + LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `e`.`roadmapStopFk`) ) GROUP BY `e`.`truckFk`, `e`.`palletFk`, `e`.`routeFk` -ORDER BY sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) DESC, +ORDER BY SUM(`e`.`truckFk` <> `e`.`roadmapStopFk`) DESC, `e`.`palletFk` From 7559875aff5c3a10cd971998dce6dfd549859dc0 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 27 May 2024 12:08:14 +0200 Subject: [PATCH 06/49] feat: refs #7296 roadmapStopFk --- db/versions/11070-turquoiseCordyline/00-firstScript.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/versions/11070-turquoiseCordyline/00-firstScript.sql b/db/versions/11070-turquoiseCordyline/00-firstScript.sql index 494080033..db123eb55 100644 --- a/db/versions/11070-turquoiseCordyline/00-firstScript.sql +++ b/db/versions/11070-turquoiseCordyline/00-firstScript.sql @@ -1 +1,3 @@ ALTER TABLE vn.routesMonitor CHANGE expeditionTruckFk roadmapStopFk int(11) DEFAULT NULL NULL; + +ALTER TABLE vn.routesMonitor ADD COLUMN expeditionTruckFk int(11) AS (roadmapStopFk) VIRTUAL; \ No newline at end of file From 885aa5208aaa9c5c38c5296bc8ed8f03cd1de5ba Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 28 May 2024 17:23:58 +0200 Subject: [PATCH 07/49] feat : refs #6889 wip: check if is productionReviewer or owner --- back/models/collection.json | 10 ++++++++++ .../00-createRoleProductionReviewer.sql | 11 +++++++++++ modules/ticket/back/models/sale.js | 12 +++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 db/versions/11060-tealGalax/00-createRoleProductionReviewer.sql diff --git a/back/models/collection.json b/back/models/collection.json index cb8dc3d7c..8a8afeb89 100644 --- a/back/models/collection.json +++ b/back/models/collection.json @@ -1,6 +1,16 @@ { "name": "Collection", "base": "VnModel", + "properties": { + "id": { + "id": true, + "type": "number", + "required": true + }, + "workerFk": { + "type": "number" + } + }, "options": { "mysql": { "table": "collection" diff --git a/db/versions/11060-tealGalax/00-createRoleProductionReviewer.sql b/db/versions/11060-tealGalax/00-createRoleProductionReviewer.sql new file mode 100644 index 000000000..6c4b8e0d1 --- /dev/null +++ b/db/versions/11060-tealGalax/00-createRoleProductionReviewer.sql @@ -0,0 +1,11 @@ +INSERT INTO account.role + SET name = 'productionReviewer', + description = 'Revisor de producción', + hasLogin = TRUE, + created = util.VN_CURDATE(), + modified = util.VN_CURDATE(), + editorFk = NULL; + +UPDATE salix.ACL + SET principalId = 'productionReviewer' + WHERE property = 'isInPreparing'; \ No newline at end of file diff --git a/modules/ticket/back/models/sale.js b/modules/ticket/back/models/sale.js index 1b4d8e31c..f7af4fc21 100644 --- a/modules/ticket/back/models/sale.js +++ b/modules/ticket/back/models/sale.js @@ -68,6 +68,7 @@ module.exports = Self => { fields: ['family', 'minQuantity'], where: {id: itemId}, }, ctx.options); + if (item.family == 'EMB') return; if (await models.ACL.checkAccessAcl(ctx, 'Sale', 'isInPreparing', '*')) return; @@ -88,7 +89,16 @@ module.exports = Self => { if (await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*')) return; - if (newQuantity < item.minQuantity && newQuantity != available) + // WIP: Check if is owner + const ticketCollection = await models.TicketCollection.findOne({ + include: {relation: 'collection', fields: ['workerFk']}, + where: {ticketFk: ticketId} + }, ctx.options); + + // if(!res) look in SaleGroup.(ask for Sergio to make fixtures for this case) + const isOwner = res.collection.workerFk === ctx.req.accessToken.userId; + + if (newQuantity < item.minQuantity && newQuantity != available && !isOwner) throw new UserError('The amount cannot be less than the minimum'); if (ctx.isNewInstance || isReduction) return; From fc606f7e367b966099de28490cb16b1db69bd6eb Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 29 May 2024 10:22:22 +0200 Subject: [PATCH 08/49] fix: refs #6889 rollback --- modules/ticket/back/models/sale.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/modules/ticket/back/models/sale.js b/modules/ticket/back/models/sale.js index f7af4fc21..1b4d8e31c 100644 --- a/modules/ticket/back/models/sale.js +++ b/modules/ticket/back/models/sale.js @@ -68,7 +68,6 @@ module.exports = Self => { fields: ['family', 'minQuantity'], where: {id: itemId}, }, ctx.options); - if (item.family == 'EMB') return; if (await models.ACL.checkAccessAcl(ctx, 'Sale', 'isInPreparing', '*')) return; @@ -89,16 +88,7 @@ module.exports = Self => { if (await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*')) return; - // WIP: Check if is owner - const ticketCollection = await models.TicketCollection.findOne({ - include: {relation: 'collection', fields: ['workerFk']}, - where: {ticketFk: ticketId} - }, ctx.options); - - // if(!res) look in SaleGroup.(ask for Sergio to make fixtures for this case) - const isOwner = res.collection.workerFk === ctx.req.accessToken.userId; - - if (newQuantity < item.minQuantity && newQuantity != available && !isOwner) + if (newQuantity < item.minQuantity && newQuantity != available) throw new UserError('The amount cannot be less than the minimum'); if (ctx.isNewInstance || isReduction) return; From a32db7840e0467f2d5c2b9a9ce60fef2213822e6 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 29 May 2024 16:54:24 +0200 Subject: [PATCH 09/49] feat: refs #6889 fixtures & models --- db/dump/fixtures.before.sql | 37 ++++++++++++++++--- modules/shelving/back/model-config.json | 6 +++ .../back/models/sectorCollection.json | 24 ++++++++++++ .../models/sectorCollectionSaleGroup.json | 30 +++++++++++++++ modules/ticket/back/models/saleGroup.json | 3 ++ 5 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 modules/shelving/back/models/sectorCollection.json create mode 100644 modules/shelving/back/models/sectorCollectionSaleGroup.json diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 55f79220e..c1ac37798 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -762,7 +762,11 @@ INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeF (30, 1, 8, 1, 1, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL, NULL), (31, 1, 8, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 2 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL, NULL), (32, 1, 8, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 2 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL, NULL), - (33, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 'NY roofs', 122, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL, NULL); + (33, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 'NY roofs', 122, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL, NULL), + (34, 1, 1, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1103, 'BEJAR', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL), + (35, 1, 1, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1102, 'Somewhere in Philippines', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL), + (36, 1, 1, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1102, 'Ant-Man Adventure', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL); + INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `description`) VALUES (1, 11, 1, 'ready'), @@ -808,7 +812,10 @@ INSERT INTO `vn`.`ticketTracking`(`ticketFk`, `stateFk`, `userFk`, `created`) (21, 1, 19, DATE_ADD(util.VN_NOW(), INTERVAL +1 MONTH)), (22, 1, 19, DATE_ADD(util.VN_NOW(), INTERVAL +1 MONTH)), (23, 16, 21, util.VN_NOW()), - (24, 16, 21, util.VN_NOW()); + (24, 16, 21, util.VN_NOW()), + (34, 14, 49, util.VN_NOW()), + (35, 14, 18, util.VN_NOW()), + (36, 14, 18, util.VN_NOW()); INSERT INTO `vn`.`deliveryPoint` (`id`, `name`, `ubication`) VALUES @@ -1068,7 +1075,10 @@ INSERT INTO `vn`.`sale`(`id`, `itemFk`, `ticketFk`, `concept`, `quantity`, `pric (37, 4, 31, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), (36, 4, 30, 'Melee weapon heavy shield 100cm', 20, 1.72, 0, 0, 0, util.VN_CURDATE()), (38, 2, 32, 'Melee weapon combat fist 15cm', 30, 7.07, 0, 0, 0, DATE_ADD(util.VN_CURDATE(), INTERVAL +1 MONTH)), - (39, 1, 32, 'Ranged weapon longbow 200cm', 2, 103.49, 0, 0, 0, util.VN_CURDATE()); + (39, 1, 32, 'Ranged weapon longbow 200cm', 2, 103.49, 0, 0, 0, util.VN_CURDATE()), + (40, 2, 34, 'Melee weapon combat fist 15cm', 10.00, 3.91, 0, 0, 0, util.VN_CURDATE()), + (41, 2, 35, 'Melee weapon combat fist 15cm', 8.00, 3.01, 0, 0, 0, util.VN_CURDATE()), + (42, 2, 36, 'Melee weapon combat fist 15cm', 6.00, 2.50, 0, 0, 0, util.VN_CURDATE()); INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`) VALUES @@ -1247,14 +1257,18 @@ INSERT INTO `vn`.`operator` (`workerFk`, `numberOfWagons`, `trainFk`, `itemPacki INSERT INTO `vn`.`collection`(`id`, `workerFk`, `stateFk`, `created`, `trainFk`) VALUES (1, 1106, 5, DATE_ADD(util.VN_CURDATE(),INTERVAL +1 DAY), 1), - (2, 1106, 14, util.VN_CURDATE(), 1); + (2, 1106, 14, util.VN_CURDATE(), 1), + (4, 49, 5, util.VN_CURDATE(), 1), + (5, 18, 5, util.VN_CURDATE(), 1); INSERT INTO `vn`.`ticketCollection`(`ticketFk`, `collectionFk`, `level`) VALUES (1, 1, 1), (2, 1, NULL), (3, 2, NULL), - (23, 1, NULL); + (23, 1, NULL), + (34, 4, 1), + (35, 5, 1); INSERT INTO `vn`.`genus`(`id`, `name`) VALUES @@ -3705,7 +3719,8 @@ INSERT IGNORE INTO vn.saleGroup SET id = 4, userFk = 1, parkingFk = 9, - sectorFk = 9992; + sectorFk = 9992, + ticketFk = 36; INSERT IGNORE INTO vn.sectorCollectionSaleGroup SET id = 9999, @@ -3807,3 +3822,13 @@ INSERT INTO `vn`.`ledgerCompany` SET INSERT INTO `vn`.`ledgerConfig` SET maxTolerance = 0.01; + +INSERT INTO vn.sectorCollection + SET id = 2, + userFk = 18, + sectorFk = 1; + +INSERT INTO vn.sectorCollectionSaleGroup + SET id = 8, + sectorCollectionFk = 2, + saleGroupFk = 4; diff --git a/modules/shelving/back/model-config.json b/modules/shelving/back/model-config.json index 89a0832b0..6f3ffb5ea 100644 --- a/modules/shelving/back/model-config.json +++ b/modules/shelving/back/model-config.json @@ -11,6 +11,12 @@ "Sector": { "dataSource": "vn" }, + "SectorCollection": { + "dataSource": "vn" + }, + "SectorCollectionSaleGroup": { + "dataSource": "vn" + }, "Train": { "dataSource": "vn" } diff --git a/modules/shelving/back/models/sectorCollection.json b/modules/shelving/back/models/sectorCollection.json new file mode 100644 index 000000000..bf2cc7985 --- /dev/null +++ b/modules/shelving/back/models/sectorCollection.json @@ -0,0 +1,24 @@ +{ + "name": "SectorCollection", + "base": "VnModel", + "options": { + "mysql": { + "table": "sectorCollection" + } + }, + "properties": { + "id": { + "type": "number", + "id": true + }, + "created": { + "type": "date" + }, + "userFk": { + "type": "number" + }, + "sectorFk": { + "type": "number" + } + } +} diff --git a/modules/shelving/back/models/sectorCollectionSaleGroup.json b/modules/shelving/back/models/sectorCollectionSaleGroup.json new file mode 100644 index 000000000..421bdc885 --- /dev/null +++ b/modules/shelving/back/models/sectorCollectionSaleGroup.json @@ -0,0 +1,30 @@ +{ + "name": "SectorCollectionSaleGroup", + "base": "VnModel", + "options": { + "mysql": { + "table": "sectorCollectionSaleGroup" + } + }, + "properties": { + "id": { + "type": "number", + "id": true + }, + "created": { + "type": "date" + } + }, + "relations": { + "sectorCollection": { + "type": "belongsTo", + "model": "SectorCollection", + "foreignKey": "sectorCollectionFk" + }, + "saleGroup": { + "type": "belongsTo", + "model": "SaleGroup", + "foreignKey": "saleGroupFk" + } + } +} diff --git a/modules/ticket/back/models/saleGroup.json b/modules/ticket/back/models/saleGroup.json index d5cf82cb5..aa78b4167 100644 --- a/modules/ticket/back/models/saleGroup.json +++ b/modules/ticket/back/models/saleGroup.json @@ -14,6 +14,9 @@ }, "parkingFk": { "type": "number" + }, + "ticketFk": { + "type": "number" } }, "relations": { From 05e6e10337de5277eb066631ea568c366d58b5c6 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 30 May 2024 10:04:34 +0200 Subject: [PATCH 10/49] fix: refs #6889 fix back tests --- db/dump/fixtures.before.sql | 6 +++--- .../11060-tealGalax/00-createRoleProductionReviewer.sql | 6 +++--- modules/item/back/methods/item/specs/getBalance.spec.js | 2 +- .../back/methods/sales-monitor/specs/salesFilter.spec.js | 2 +- .../back/methods/route/specs/getSuggestedTickets.spec.js | 2 +- modules/ticket/back/methods/ticket/specs/filter.spec.js | 2 +- .../back/methods/ticket/specs/priceDifference.spec.js | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index c1ac37798..e42db7ace 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -763,9 +763,9 @@ INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeF (31, 1, 8, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 2 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL, NULL), (32, 1, 8, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 2 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL, NULL), (33, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 'NY roofs', 122, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL, NULL), - (34, 1, 1, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1103, 'BEJAR', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL), - (35, 1, 1, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1102, 'Somewhere in Philippines', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL), - (36, 1, 1, 1, NULL, util.VN_CURDATE(), util.VN_CURDATE(), 1102, 'Ant-Man Adventure', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL); + (34, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1103, 'BEJAR', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL), + (35, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1102, 'Somewhere in Philippines', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL), + (36, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1102, 'Ant-Man Adventure', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL); INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `description`) VALUES diff --git a/db/versions/11060-tealGalax/00-createRoleProductionReviewer.sql b/db/versions/11060-tealGalax/00-createRoleProductionReviewer.sql index 6c4b8e0d1..b65740cc8 100644 --- a/db/versions/11060-tealGalax/00-createRoleProductionReviewer.sql +++ b/db/versions/11060-tealGalax/00-createRoleProductionReviewer.sql @@ -6,6 +6,6 @@ INSERT INTO account.role modified = util.VN_CURDATE(), editorFk = NULL; -UPDATE salix.ACL - SET principalId = 'productionReviewer' - WHERE property = 'isInPreparing'; \ No newline at end of file +-- UPDATE salix.ACL +-- SET principalId = 'productionReviewer' +-- WHERE property = 'isInPreparing'; \ No newline at end of file diff --git a/modules/item/back/methods/item/specs/getBalance.spec.js b/modules/item/back/methods/item/specs/getBalance.spec.js index 5e5148595..728b5f33e 100644 --- a/modules/item/back/methods/item/specs/getBalance.spec.js +++ b/modules/item/back/methods/item/specs/getBalance.spec.js @@ -64,7 +64,7 @@ describe('item getBalance()', () => { const secondItemBalance = await models.Item.getBalance(ctx, secondFilter, options); expect(firstItemBalance[9].claimFk).toEqual(null); - expect(secondItemBalance[4].claimFk).toEqual(2); + expect(secondItemBalance[7].claimFk).toEqual(2); await tx.rollback(); } catch (e) { diff --git a/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js b/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js index bdafd14e2..c3da7f08b 100644 --- a/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js +++ b/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js @@ -151,7 +151,7 @@ describe('SalesMonitor salesFilter()', () => { const result = await models.SalesMonitor.salesFilter(ctx, filter, options); const firstRow = result[0]; - expect(result.length).toEqual(12); + expect(result.length).toEqual(15); expect(firstRow.alertLevel).not.toEqual(0); await tx.rollback(); diff --git a/modules/route/back/methods/route/specs/getSuggestedTickets.spec.js b/modules/route/back/methods/route/specs/getSuggestedTickets.spec.js index 0acc6c1a7..b4b743de3 100644 --- a/modules/route/back/methods/route/specs/getSuggestedTickets.spec.js +++ b/modules/route/back/methods/route/specs/getSuggestedTickets.spec.js @@ -28,7 +28,7 @@ describe('route getSuggestedTickets()', () => { const result = await models.Route.getSuggestedTickets(routeID, options); - const length = result.length; + const length = result.length; // cambiar agenciaMode de los tickets por el 8 y ver si da algún problema const anyResult = result[Math.floor(Math.random() * Math.floor(length))]; expect(result.length).toEqual(4); diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index e495a41f5..8008acfaf 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -68,7 +68,7 @@ describe('ticket filter()', () => { const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); - expect(result.length).toEqual(7); + expect(result.length).toEqual(10); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js b/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js index e5c06b6dd..b49bbaba0 100644 --- a/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js +++ b/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js @@ -84,7 +84,7 @@ describe('sale priceDifference()', () => { const {items} = await models.Ticket.priceDifference(ctx, options); - expect(items[0].movable).toEqual(410); + expect(items[0].movable).toEqual(386); expect(items[1].movable).toEqual(1810); await tx.rollback(); From 5158017edd64e5adb7ec75b23975cdaa2ca3657d Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 30 May 2024 11:21:42 +0200 Subject: [PATCH 11/49] fix: refs #6889 fix back tests --- .../ticket/back/methods/ticket/specs/priceDifference.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js b/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js index b49bbaba0..7dc1c8ed2 100644 --- a/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js +++ b/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js @@ -42,7 +42,7 @@ describe('sale priceDifference()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 1106}}}; + const ctx = {req: {accessToken: {userId: 1105}}}; ctx.args = { id: 1, landed: Date.vnNew(), From 002111d8d1b0cd37f598ca19b4dd37b26790e244 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 30 May 2024 11:47:12 +0200 Subject: [PATCH 12/49] fix: refs #6889 allocate 'productionReviewer' role to revision dep. workers & check if is owner or reviewer --- .../00-createRoleProductionReviewer.sql | 9 +++++- .../route/specs/getSuggestedTickets.spec.js | 2 +- .../back/methods/ticket/isEditableOrThrow.js | 28 +++++++++++++------ 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/db/versions/11060-tealGalax/00-createRoleProductionReviewer.sql b/db/versions/11060-tealGalax/00-createRoleProductionReviewer.sql index b65740cc8..ad3e2f5b2 100644 --- a/db/versions/11060-tealGalax/00-createRoleProductionReviewer.sql +++ b/db/versions/11060-tealGalax/00-createRoleProductionReviewer.sql @@ -8,4 +8,11 @@ INSERT INTO account.role -- UPDATE salix.ACL -- SET principalId = 'productionReviewer' --- WHERE property = 'isInPreparing'; \ No newline at end of file +-- WHERE property = 'isInPreparing'; + +UPDATE account.user u + JOIN vn.workerDepartment wd ON wd.workerFk = u.id + JOIN vn.department d ON wd.departmentFk = d.id + JOIN account.role r ON r.name = 'productionReviewer' + SET u.role = r.id + WHERE d.name = 'REVISION'; \ No newline at end of file diff --git a/modules/route/back/methods/route/specs/getSuggestedTickets.spec.js b/modules/route/back/methods/route/specs/getSuggestedTickets.spec.js index b4b743de3..0acc6c1a7 100644 --- a/modules/route/back/methods/route/specs/getSuggestedTickets.spec.js +++ b/modules/route/back/methods/route/specs/getSuggestedTickets.spec.js @@ -28,7 +28,7 @@ describe('route getSuggestedTickets()', () => { const result = await models.Route.getSuggestedTickets(routeID, options); - const length = result.length; // cambiar agenciaMode de los tickets por el 8 y ver si da algún problema + const length = result.length; const anyResult = result[Math.floor(Math.random() * Math.floor(length))]; expect(result.length).toEqual(4); diff --git a/modules/ticket/back/methods/ticket/isEditableOrThrow.js b/modules/ticket/back/methods/ticket/isEditableOrThrow.js index 16cff84f1..0adc9e0f9 100644 --- a/modules/ticket/back/methods/ticket/isEditableOrThrow.js +++ b/modules/ticket/back/methods/ticket/isEditableOrThrow.js @@ -8,18 +8,13 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const state = await models.TicketState.findOne({ - where: {ticketFk: id} - }, myOptions); - + const state = await models.TicketState.findOne({where: {ticketFk: id}}, myOptions); const isRoleAdvanced = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*'); + const isProductionReviewer = await models.ACL.checkAccessAcl(ctx, 'Sale', 'isInPreparing', '*'); const canEditWeeklyTicket = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'canEditWeekly', 'WRITE'); const alertLevel = state ? state.alertLevel : null; const ticket = await models.Ticket.findById(id, { - fields: ['clientFk'], - include: { - relation: 'client' - } + fields: ['clientFk'], include: {relation: 'client'} }, myOptions); const isLocked = await models.Ticket.isLocked(id, myOptions); @@ -29,10 +24,25 @@ module.exports = Self => { const isNormalClient = ticket && ticket.client().typeFk == 'normal'; const isEditable = !(alertLevelGreaterThanZero && isNormalClient); + const ticketCollection = await models.TicketCollection.findOne({ + include: {relation: 'collection'}, where: {ticketFk: id} + }, myOptions); + let workerId = ticketCollection?.collection()?.workerFk; + + if (!workerId) { + const saleGroup = await models.SaleGroup.findOne({fields: ['id'], where: {ticketFk: id}}, myOptions); + const sectorCollectionSaleGroup = saleGroup && await models.SectorCollectionSaleGroup.findOne({ + include: {relation: 'sectorCollection'}, where: {saleGroupFk: saleGroup.id} + }, myOptions); + + workerId = sectorCollectionSaleGroup?.sectorCollection()?.userFk; + } + const isOwner = workerId === ctx.req.accessToken.userId; + if (!ticket) throw new ForbiddenError(`The ticket doesn't exist.`); - if (!isEditable && !isRoleAdvanced) + if (!isEditable && !isRoleAdvanced && !isProductionReviewer && !isOwner) throw new ForbiddenError(`This ticket is not editable.`); if (isLocked && !isWeekly) From 8212eb82c7e3e05f08fa5be02b625761b5f3a0d9 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 30 May 2024 14:29:13 +0200 Subject: [PATCH 13/49] refactor: refs #6889 improve file loading logic --- e2e/tests.js | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/e2e/tests.js b/e2e/tests.js index 829056f4c..e53dd8f7c 100644 --- a/e2e/tests.js +++ b/e2e/tests.js @@ -5,6 +5,7 @@ require('regenerator-runtime/runtime'); require('vn-loopback/server/boot/date')(); const getopts = require('getopts'); +const fs = require('fs'); const path = require('path'); const Myt = require('@verdnatura/myt/myt'); const Run = require('@verdnatura/myt/myt-run'); @@ -35,22 +36,9 @@ async function test() { const Jasmine = require('jasmine'); const jasmine = new Jasmine(); - const specFiles = [ - `./e2e/paths/01*/*[sS]pec.js`, - `./e2e/paths/02*/*[sS]pec.js`, - `./e2e/paths/03*/*[sS]pec.js`, - `./e2e/paths/04*/*[sS]pec.js`, - `./e2e/paths/05*/*[sS]pec.js`, - `./e2e/paths/06*/*[sS]pec.js`, - `./e2e/paths/07*/*[sS]pec.js`, - `./e2e/paths/08*/*[sS]pec.js`, - `./e2e/paths/09*/*[sS]pec.js`, - `./e2e/paths/10*/*[sS]pec.js`, - `./e2e/paths/11*/*[sS]pec.js`, - `./e2e/paths/12*/*[sS]pec.js`, - `./e2e/paths/13*/*[sS]pec.js`, - `./e2e/paths/**/*[sS]pec.js` - ]; + const e2ePath = './e2e/paths'; + const specFiles = fs.readdirSync(e2ePath).sort().map(folder => `${e2ePath}/${folder}/*[sS]pec.js`); + specFiles.push(`${e2ePath}/**/*[sS]pec.js`); jasmine.loadConfig({ spec_dir: '.', From 8a54f7c5c7e408e790b360deb33c815651c386e4 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 30 May 2024 14:34:27 +0200 Subject: [PATCH 14/49] refactor: refs #6889 improve file loading logic --- e2e/tests.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/e2e/tests.js b/e2e/tests.js index e53dd8f7c..166d666e2 100644 --- a/e2e/tests.js +++ b/e2e/tests.js @@ -37,8 +37,11 @@ async function test() { const jasmine = new Jasmine(); const e2ePath = './e2e/paths'; - const specFiles = fs.readdirSync(e2ePath).sort().map(folder => `${e2ePath}/${folder}/*[sS]pec.js`); - specFiles.push(`${e2ePath}/**/*[sS]pec.js`); + const file = '*[sS]pec.js'; + const specFiles = fs.readdirSync(e2ePath) + .sort() + .map(folder => `${e2ePath}/${folder}/${file}`) + .concat(`${e2ePath}/**/${file}`); jasmine.loadConfig({ spec_dir: '.', From 38bea60776d2ccc3dd18d7e35b332f26f56cb4d9 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 31 May 2024 09:49:58 +0200 Subject: [PATCH 15/49] refactor: refs #6889 script sql --- .../00-createRoleProductionReviewer.sql | 18 -------- .../11060-tealGalax/00-createRoleReviewer.sql | 46 +++++++++++++++++++ 2 files changed, 46 insertions(+), 18 deletions(-) delete mode 100644 db/versions/11060-tealGalax/00-createRoleProductionReviewer.sql create mode 100644 db/versions/11060-tealGalax/00-createRoleReviewer.sql diff --git a/db/versions/11060-tealGalax/00-createRoleProductionReviewer.sql b/db/versions/11060-tealGalax/00-createRoleProductionReviewer.sql deleted file mode 100644 index ad3e2f5b2..000000000 --- a/db/versions/11060-tealGalax/00-createRoleProductionReviewer.sql +++ /dev/null @@ -1,18 +0,0 @@ -INSERT INTO account.role - SET name = 'productionReviewer', - description = 'Revisor de producción', - hasLogin = TRUE, - created = util.VN_CURDATE(), - modified = util.VN_CURDATE(), - editorFk = NULL; - --- UPDATE salix.ACL --- SET principalId = 'productionReviewer' --- WHERE property = 'isInPreparing'; - -UPDATE account.user u - JOIN vn.workerDepartment wd ON wd.workerFk = u.id - JOIN vn.department d ON wd.departmentFk = d.id - JOIN account.role r ON r.name = 'productionReviewer' - SET u.role = r.id - WHERE d.name = 'REVISION'; \ No newline at end of file diff --git a/db/versions/11060-tealGalax/00-createRoleReviewer.sql b/db/versions/11060-tealGalax/00-createRoleReviewer.sql new file mode 100644 index 000000000..21cb43434 --- /dev/null +++ b/db/versions/11060-tealGalax/00-createRoleReviewer.sql @@ -0,0 +1,46 @@ +use account; + +INSERT INTO account.role + SET name = 'reviewer', + description = 'Revisor de producción', + hasLogin = TRUE, + created = util.VN_CURDATE(), + modified = util.VN_CURDATE(), + editorFk = NULL; + +INSERT IGNORE INTO account.roleInherit( + role, + inheritsFrom +) + SELECT r1.id, + r2.id + FROM account.role r1 + JOIN account.role r2 + WHERE r2.name = 'production' + AND r1.name = 'reviewer' + UNION + SELECT ri.role, + r2.id + FROM account.roleInherit ri + JOIN account.role r1 ON r1.id = ri.role + JOIN account.role r2 ON r2.name = 'reviewer' + WHERE r1.name IN ('claimManager', 'productionBoss') + GROUP BY ri.role; + +DELETE ri + FROM account.roleInherit ri + JOIN account.role r1 ON ri.role = r1.id + JOIN account.role r2 ON ri.inheritsFrom = r2.id + WHERE r1.name = 'replenisher' + AND r2.name = 'buyer'; + +UPDATE salix.ACL + SET principalId = 'reviewer' + WHERE property = 'isInPreparing'; + +UPDATE account.user u + JOIN vn.workerDepartment wd ON wd.workerFk = u.id + JOIN vn.department d ON wd.departmentFk = d.id + JOIN account.role r ON r.name = 'reviewer' + SET u.role = r.id + WHERE d.name IN ('REVISION', 'PREVIA'); \ No newline at end of file From 4772509b677f4916d4e7556434758177a0eedcbb Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 31 May 2024 12:51:06 +0200 Subject: [PATCH 16/49] fix: refs #6889 e2e tests --- db/dump/fixtures.before.sql | 6 ++-- .../11060-tealGalax/00-createRoleReviewer.sql | 28 +++++++++---------- .../05-ticket/01-sale/02_edit_sale.spec.js | 2 +- e2e/tests.js | 23 ++++++++++----- 4 files changed, 35 insertions(+), 24 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index e42db7ace..24225c99a 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -1259,7 +1259,8 @@ INSERT INTO `vn`.`collection`(`id`, `workerFk`, `stateFk`, `created`, `trainFk`) (1, 1106, 5, DATE_ADD(util.VN_CURDATE(),INTERVAL +1 DAY), 1), (2, 1106, 14, util.VN_CURDATE(), 1), (4, 49, 5, util.VN_CURDATE(), 1), - (5, 18, 5, util.VN_CURDATE(), 1); + (5, 18, 5, util.VN_CURDATE(), 1), + (6, 18, 5, util.VN_CURDATE(), 1); INSERT INTO `vn`.`ticketCollection`(`ticketFk`, `collectionFk`, `level`) VALUES @@ -1268,7 +1269,8 @@ INSERT INTO `vn`.`ticketCollection`(`ticketFk`, `collectionFk`, `level`) (3, 2, NULL), (23, 1, NULL), (34, 4, 1), - (35, 5, 1); + (35, 5, 1), + (8, 6, 1); INSERT INTO `vn`.`genus`(`id`, `name`) VALUES diff --git a/db/versions/11060-tealGalax/00-createRoleReviewer.sql b/db/versions/11060-tealGalax/00-createRoleReviewer.sql index 21cb43434..bf2984702 100644 --- a/db/versions/11060-tealGalax/00-createRoleReviewer.sql +++ b/db/versions/11060-tealGalax/00-createRoleReviewer.sql @@ -1,6 +1,6 @@ use account; -INSERT INTO account.role +INSERT INTO role SET name = 'reviewer', description = 'Revisor de producción', hasLogin = TRUE, @@ -8,29 +8,29 @@ INSERT INTO account.role modified = util.VN_CURDATE(), editorFk = NULL; -INSERT IGNORE INTO account.roleInherit( +INSERT INTO roleInherit( role, inheritsFrom ) SELECT r1.id, r2.id - FROM account.role r1 - JOIN account.role r2 - WHERE r2.name = 'production' - AND r1.name = 'reviewer' + FROM role r1 + JOIN role r2 + WHERE r1.name = 'reviewer' + AND r2.name = 'production' UNION SELECT ri.role, r2.id - FROM account.roleInherit ri - JOIN account.role r1 ON r1.id = ri.role - JOIN account.role r2 ON r2.name = 'reviewer' + FROM roleInherit ri + JOIN role r1 ON r1.id = ri.role + JOIN role r2 ON r2.name = 'reviewer' WHERE r1.name IN ('claimManager', 'productionBoss') GROUP BY ri.role; DELETE ri - FROM account.roleInherit ri - JOIN account.role r1 ON ri.role = r1.id - JOIN account.role r2 ON ri.inheritsFrom = r2.id + FROM roleInherit ri + JOIN role r1 ON ri.role = r1.id + JOIN role r2 ON ri.inheritsFrom = r2.id WHERE r1.name = 'replenisher' AND r2.name = 'buyer'; @@ -38,9 +38,9 @@ UPDATE salix.ACL SET principalId = 'reviewer' WHERE property = 'isInPreparing'; -UPDATE account.user u +UPDATE user u JOIN vn.workerDepartment wd ON wd.workerFk = u.id JOIN vn.department d ON wd.departmentFk = d.id - JOIN account.role r ON r.name = 'reviewer' + JOIN role r ON r.name = 'reviewer' SET u.role = r.id WHERE d.name IN ('REVISION', 'PREVIA'); \ No newline at end of file diff --git a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js index 4f54ad860..e0f32fc3a 100644 --- a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js +++ b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js @@ -225,7 +225,7 @@ describe('Ticket Edit sale path', () => { }); it('should show error trying to delete a ticket with a refund', async() => { - await page.loginAndModule('production', 'ticket'); + await page.loginAndModule('salesPerson', 'ticket'); await page.accessToSearchResult('8'); await page.waitToClick(selectors.ticketDescriptor.moreMenu); await page.waitToClick(selectors.ticketDescriptor.moreMenuDeleteTicket); diff --git a/e2e/tests.js b/e2e/tests.js index 166d666e2..829056f4c 100644 --- a/e2e/tests.js +++ b/e2e/tests.js @@ -5,7 +5,6 @@ require('regenerator-runtime/runtime'); require('vn-loopback/server/boot/date')(); const getopts = require('getopts'); -const fs = require('fs'); const path = require('path'); const Myt = require('@verdnatura/myt/myt'); const Run = require('@verdnatura/myt/myt-run'); @@ -36,12 +35,22 @@ async function test() { const Jasmine = require('jasmine'); const jasmine = new Jasmine(); - const e2ePath = './e2e/paths'; - const file = '*[sS]pec.js'; - const specFiles = fs.readdirSync(e2ePath) - .sort() - .map(folder => `${e2ePath}/${folder}/${file}`) - .concat(`${e2ePath}/**/${file}`); + const specFiles = [ + `./e2e/paths/01*/*[sS]pec.js`, + `./e2e/paths/02*/*[sS]pec.js`, + `./e2e/paths/03*/*[sS]pec.js`, + `./e2e/paths/04*/*[sS]pec.js`, + `./e2e/paths/05*/*[sS]pec.js`, + `./e2e/paths/06*/*[sS]pec.js`, + `./e2e/paths/07*/*[sS]pec.js`, + `./e2e/paths/08*/*[sS]pec.js`, + `./e2e/paths/09*/*[sS]pec.js`, + `./e2e/paths/10*/*[sS]pec.js`, + `./e2e/paths/11*/*[sS]pec.js`, + `./e2e/paths/12*/*[sS]pec.js`, + `./e2e/paths/13*/*[sS]pec.js`, + `./e2e/paths/**/*[sS]pec.js` + ]; jasmine.loadConfig({ spec_dir: '.', From ab9c11ef8448fc88f9d0f6407e8215e7088df689 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 31 May 2024 12:56:22 +0200 Subject: [PATCH 17/49] fix: refs #6889 modify fixtures --- db/dump/fixtures.before.sql | 2 +- e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 24225c99a..0b80df5d3 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -1260,7 +1260,7 @@ INSERT INTO `vn`.`collection`(`id`, `workerFk`, `stateFk`, `created`, `trainFk`) (2, 1106, 14, util.VN_CURDATE(), 1), (4, 49, 5, util.VN_CURDATE(), 1), (5, 18, 5, util.VN_CURDATE(), 1), - (6, 18, 5, util.VN_CURDATE(), 1); + (6, 49, 5, util.VN_CURDATE(), 1); INSERT INTO `vn`.`ticketCollection`(`ticketFk`, `collectionFk`, `level`) VALUES diff --git a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js index e0f32fc3a..4f54ad860 100644 --- a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js +++ b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js @@ -225,7 +225,7 @@ describe('Ticket Edit sale path', () => { }); it('should show error trying to delete a ticket with a refund', async() => { - await page.loginAndModule('salesPerson', 'ticket'); + await page.loginAndModule('production', 'ticket'); await page.accessToSearchResult('8'); await page.waitToClick(selectors.ticketDescriptor.moreMenu); await page.waitToClick(selectors.ticketDescriptor.moreMenuDeleteTicket); From ee09617b27c48c399b63517c70c9addf36021d73 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 31 May 2024 13:05:12 +0200 Subject: [PATCH 18/49] fix: refs #6889 e2e tests --- db/dump/fixtures.before.sql | 2 +- e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 0b80df5d3..24225c99a 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -1260,7 +1260,7 @@ INSERT INTO `vn`.`collection`(`id`, `workerFk`, `stateFk`, `created`, `trainFk`) (2, 1106, 14, util.VN_CURDATE(), 1), (4, 49, 5, util.VN_CURDATE(), 1), (5, 18, 5, util.VN_CURDATE(), 1), - (6, 49, 5, util.VN_CURDATE(), 1); + (6, 18, 5, util.VN_CURDATE(), 1); INSERT INTO `vn`.`ticketCollection`(`ticketFk`, `collectionFk`, `level`) VALUES diff --git a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js index 4f54ad860..e0f32fc3a 100644 --- a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js +++ b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js @@ -225,7 +225,7 @@ describe('Ticket Edit sale path', () => { }); it('should show error trying to delete a ticket with a refund', async() => { - await page.loginAndModule('production', 'ticket'); + await page.loginAndModule('salesPerson', 'ticket'); await page.accessToSearchResult('8'); await page.waitToClick(selectors.ticketDescriptor.moreMenu); await page.waitToClick(selectors.ticketDescriptor.moreMenuDeleteTicket); From 836cfcbd07780f3f1267957c32046242838990e3 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 31 May 2024 13:58:26 +0200 Subject: [PATCH 19/49] refactor: refs #6889 sale tests e2e --- modules/ticket/back/models/specs/sale.spec.js | 309 +++++------------- 1 file changed, 87 insertions(+), 222 deletions(-) diff --git a/modules/ticket/back/models/specs/sale.spec.js b/modules/ticket/back/models/specs/sale.spec.js index d078dc8e2..d50c039db 100644 --- a/modules/ticket/back/models/specs/sale.spec.js +++ b/modules/ticket/back/models/specs/sale.spec.js @@ -1,42 +1,36 @@ /* eslint max-len: ["error", { "code": 150 }]*/ - -const models = require('vn-loopback/server/server').models; +const {models} = require('vn-loopback/server/server'); const LoopBackContext = require('loopback-context'); -describe('sale model ', () => { - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; - function getActiveCtx(userId) { - return { - active: { - accessToken: {userId}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - } - }; +fdescribe('sale model ', () => { + const developerId = 9; + const buyerId = 35; + const employeeId = 1; + + const ctx = getCtx(developerId); + let tx; + let options; + + function getCtx(userId, active = false) { + const accessToken = {userId}; + const headers = {origin: 'localhost:5000'}; + if (!active) return {req: {accessToken, headers, __: () => {}}}; + return {active: {accessToken, http: {req: {headers}}}}; } + beforeEach(async() => { + tx = await models.Sale.beginTransaction({}); + options = {transaction: tx}; + }); + + afterEach(async() => await tx.rollback()); + describe('quantity field ', () => { it('should add quantity if the quantity is greater than it should be and is role advanced', async() => { const saleId = 17; - const buyerId = 35; - const ctx = { - req: { - accessToken: {userId: buyerId}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; - const tx = await models.Sale.beginTransaction({}); - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getActiveCtx(buyerId)); + const ctx = getCtx(buyerId); + + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(buyerId, true)); spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, options) => { if (sqlStatement.includes('catalog_calcFromItem')) { sqlStatement = `CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem ENGINE = MEMORY @@ -46,131 +40,74 @@ describe('sale model ', () => { return models.Ticket.rawSql(sqlStatement, params, options); }); - try { - const options = {transaction: tx}; + const isRoleAdvanced = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*'); - const isRoleAdvanced = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*'); + expect(isRoleAdvanced).toEqual(true); - expect(isRoleAdvanced).toEqual(true); + const originalLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, options); - const originalLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, options); + expect(originalLine.quantity).toEqual(30); - expect(originalLine.quantity).toEqual(30); + const newQuantity = originalLine.quantity + 1; + await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); - const newQuantity = originalLine.quantity + 1; - await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); + const modifiedLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, options); - const modifiedLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, options); - - expect(modifiedLine.quantity).toEqual(newQuantity); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + expect(modifiedLine.quantity).toEqual(newQuantity); }); it('should update the quantity of a given sale current line', async() => { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getActiveCtx(9)); + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(developerId, true)); - const tx = await models.Sale.beginTransaction({}); const saleId = 25; const newQuantity = 4; - try { - const options = {transaction: tx}; + const originalLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, options); - const originalLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, options); + expect(originalLine.quantity).toEqual(20); - expect(originalLine.quantity).toEqual(20); + await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); - await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); + const modifiedLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, options); - const modifiedLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, options); - - expect(modifiedLine.quantity).toEqual(newQuantity); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + expect(modifiedLine.quantity).toEqual(newQuantity); }); it('should throw an error if the quantity is negative and it is not a refund ticket', async() => { - const ctx = { - req: { - accessToken: {userId: 1}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getActiveCtx(1)); + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true)); const saleId = 17; const newQuantity = -10; - const tx = await models.Sale.beginTransaction({}); - - let error; try { - const options = {transaction: tx}; - await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); - - await tx.rollback(); } catch (e) { - await tx.rollback(); - error = e; + expect(e).toEqual(new Error('You can only add negative amounts in refund tickets')); } - - expect(error).toEqual(new Error('You can only add negative amounts in refund tickets')); }); it('should update a negative quantity when is a ticket refund', async() => { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getActiveCtx(9)); + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(developerId, true)); - const tx = await models.Sale.beginTransaction({}); const saleId = 32; const newQuantity = -10; - try { - const options = {transaction: tx}; + await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); - await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); + const modifiedLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, options); - const modifiedLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, options); - - expect(modifiedLine.quantity).toEqual(newQuantity); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + expect(modifiedLine.quantity).toEqual(newQuantity); }); it('should throw an error if the quantity is less than the minimum quantity of the item', async() => { - const ctx = { - req: { - accessToken: {userId: 1}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getActiveCtx(1)); + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true)); - const tx = await models.Sale.beginTransaction({}); const itemId = 2; const saleId = 17; const minQuantity = 30; const newQuantity = minQuantity - 1; - let error; try { - const options = {transaction: tx}; - const item = await models.Item.findById(itemId, null, options); await item.updateAttribute('minQuantity', minQuantity, options); spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, options) => { @@ -183,157 +120,90 @@ describe('sale model ', () => { }); await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); - - await tx.rollback(); } catch (e) { - await tx.rollback(); - error = e; + expect(e).toEqual(new Error('The amount cannot be less than the minimum')); } - - expect(error).toEqual(new Error('The amount cannot be less than the minimum')); }); it('should change quantity if has minimum quantity and new quantity is equal than item available', async() => { - const ctx = { - req: { - accessToken: {userId: 1}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getActiveCtx(1)); + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true)); - const tx = await models.Sale.beginTransaction({}); const itemId = 2; const saleId = 17; const minQuantity = 30; const newQuantity = minQuantity - 1; - try { - const options = {transaction: tx}; + const item = await models.Item.findById(itemId, null, options); + await item.updateAttribute('minQuantity', minQuantity, options); + + spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, options) => { + if (sqlStatement.includes('catalog_calcFromItem')) { + sqlStatement = `CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem ENGINE = MEMORY + SELECT ${newQuantity} as available;`; + params = null; + } + return models.Ticket.rawSql(sqlStatement, params, options); + }); + + await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); + }); + + describe('newPrice', () => { + it('should increase quantity if you have enough available and the new price is the same as the previous one', async() => { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true)); + + const itemId = 2; + const saleId = 17; + const minQuantity = 30; + const newQuantity = 31; const item = await models.Item.findById(itemId, null, options); await item.updateAttribute('minQuantity', minQuantity, options); - spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, options) => { if (sqlStatement.includes('catalog_calcFromItem')) { - sqlStatement = `CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem ENGINE = MEMORY - SELECT ${newQuantity} as available;`; + sqlStatement = ` + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem ENGINE = MEMORY SELECT ${newQuantity} as available; + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentPrice ENGINE = MEMORY SELECT 1 as grouping, 7.07 as price;`; params = null; } return models.Ticket.rawSql(sqlStatement, params, options); }); await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); - - describe('newPrice', () => { - it('should increase quantity if you have enough available and the new price is the same as the previous one', async() => { - const ctx = { - req: { - accessToken: {userId: 1}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getActiveCtx(1)); - - const tx = await models.Sale.beginTransaction({}); - const itemId = 2; - const saleId = 17; - const minQuantity = 30; - const newQuantity = 31; - - try { - const options = {transaction: tx}; - - const item = await models.Item.findById(itemId, null, options); - await item.updateAttribute('minQuantity', minQuantity, options); - spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, options) => { - if (sqlStatement.includes('catalog_calcFromItem')) { - sqlStatement = ` - CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem ENGINE = MEMORY SELECT ${newQuantity} as available; - CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentPrice ENGINE = MEMORY SELECT 1 as grouping, 7.07 as price;`; - params = null; - } - return models.Ticket.rawSql(sqlStatement, params, options); - }); - - await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } }); it('should increase quantity when the new price is lower than the previous one', async() => { - const ctx = { - req: { - accessToken: {userId: 1}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getActiveCtx(1)); + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true)); - const tx = await models.Sale.beginTransaction({}); const itemId = 2; const saleId = 17; const minQuantity = 30; const newQuantity = 31; - try { - const options = {transaction: tx}; - - const item = await models.Item.findById(itemId, null, options); - await item.updateAttribute('minQuantity', minQuantity, options); - spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, options) => { - if (sqlStatement.includes('catalog_calcFromItem')) { - sqlStatement = ` + const item = await models.Item.findById(itemId, null, options); + await item.updateAttribute('minQuantity', minQuantity, options); + spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, options) => { + if (sqlStatement.includes('catalog_calcFromItem')) { + sqlStatement = ` CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem ENGINE = MEMORY SELECT ${newQuantity} as available; CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentPrice ENGINE = MEMORY SELECT 1 as grouping, 1 as price;`; - params = null; - } - return models.Ticket.rawSql(sqlStatement, params, options); - }); + params = null; + } + return models.Ticket.rawSql(sqlStatement, params, options); + }); - await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); }); it('should throw error when increase quantity and the new price is higher than the previous one', async() => { - const ctx = { - req: { - accessToken: {userId: 1}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getActiveCtx(1)); + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(employeeId, true)); - const tx = await models.Sale.beginTransaction({}); const itemId = 2; const saleId = 17; const minQuantity = 30; const newQuantity = 31; - let error; try { - const options = {transaction: tx}; - const item = await models.Item.findById(itemId, null, options); await item.updateAttribute('minQuantity', minQuantity, options); spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, options) => { @@ -347,14 +217,9 @@ describe('sale model ', () => { }); await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); - - await tx.rollback(); } catch (e) { - await tx.rollback(); - error = e; + expect(e).toEqual(new Error('The price of the item changed')); } - - expect(error).toEqual(new Error('The price of the item changed')); }); }); }); From dc8696b4224b973f3a31e9aa39cf679dac035c5a Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 31 May 2024 16:31:36 +0200 Subject: [PATCH 20/49] feat: refs #6889 add back tests --- db/dump/fixtures.before.sql | 21 ++- modules/ticket/back/models/specs/sale.spec.js | 170 ++++++++++++++---- 2 files changed, 149 insertions(+), 42 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 24225c99a..6818e7200 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -763,9 +763,10 @@ INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeF (31, 1, 8, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 2 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL, NULL), (32, 1, 8, 1, 1, DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 2 DAY), 1103, 'Phone Box', 123, NULL, 0, 1, 5, 1, util.VN_CURDATE(), NULL, NULL), (33, 1, 7, 1, 6, util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL + 1 DAY), 1102, 'NY roofs', 122, NULL, 0, 3, 5, 1, util.VN_CURDATE(), NULL, NULL), - (34, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1103, 'BEJAR', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL), - (35, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1102, 'Somewhere in Philippines', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL), - (36, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1102, 'Ant-Man Adventure', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL); + (34, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1103, 'BEJAR', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL), + (35, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1102, 'Somewhere in Philippines', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL), + (36, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1102, 'Ant-Man Adventure', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL), + (37, 1, 1, 1, 3, util.VN_CURDATE(), util.VN_CURDATE(), 1110, 'Deadpool swords', 123, NULL, 0, 1, 16, 0, util.VN_CURDATE(), NULL, NULL); INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `description`) VALUES @@ -3834,3 +3835,17 @@ INSERT INTO vn.sectorCollectionSaleGroup SET id = 8, sectorCollectionFk = 2, saleGroupFk = 4; + +INSERT INTO vn.saleGroup (userFk, parkingFk, sectorFk, ticketFk) + VALUES + (1, 1, 1, 37); + +INSERT INTO vn.sectorCollection + SET id = 3, + userFk = 18, + sectorFk = 1; + +INSERT INTO vn.sectorCollectionSaleGroup + SET id = 9, + sectorCollectionFk = 3, + saleGroupFk = 6; \ No newline at end of file diff --git a/modules/ticket/back/models/specs/sale.spec.js b/modules/ticket/back/models/specs/sale.spec.js index d50c039db..1aa40802b 100644 --- a/modules/ticket/back/models/specs/sale.spec.js +++ b/modules/ticket/back/models/specs/sale.spec.js @@ -2,14 +2,24 @@ const {models} = require('vn-loopback/server/server'); const LoopBackContext = require('loopback-context'); -fdescribe('sale model ', () => { +describe('sale model ', () => { const developerId = 9; const buyerId = 35; const employeeId = 1; + const productionId = 49; + const salesPersonId = 18; + const reviewerId = 130; + + const barcode = '4444444444'; + const ticketCollectionProd = 34; + const ticketCollectionSalesPerson = 35; + const previaTicketSalesPerson = 36; + const previaTicketProd = 37; + const notEditableError = 'This ticket is not editable.'; const ctx = getCtx(developerId); let tx; - let options; + let opts; function getCtx(userId, active = false) { const accessToken = {userId}; @@ -20,7 +30,7 @@ fdescribe('sale model ', () => { beforeEach(async() => { tx = await models.Sale.beginTransaction({}); - options = {transaction: tx}; + opts = {transaction: tx}; }); afterEach(async() => await tx.rollback()); @@ -31,27 +41,27 @@ fdescribe('sale model ', () => { const ctx = getCtx(buyerId); spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(buyerId, true)); - spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, options) => { + spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => { if (sqlStatement.includes('catalog_calcFromItem')) { sqlStatement = `CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem ENGINE = MEMORY SELECT 100 as available;`; params = null; } - return models.Ticket.rawSql(sqlStatement, params, options); + return models.Ticket.rawSql(sqlStatement, params, opts); }); const isRoleAdvanced = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*'); expect(isRoleAdvanced).toEqual(true); - const originalLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, options); + const originalLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, opts); expect(originalLine.quantity).toEqual(30); const newQuantity = originalLine.quantity + 1; - await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); + await models.Sale.updateQuantity(ctx, saleId, newQuantity, opts); - const modifiedLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, options); + const modifiedLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, opts); expect(modifiedLine.quantity).toEqual(newQuantity); }); @@ -62,13 +72,13 @@ fdescribe('sale model ', () => { const saleId = 25; const newQuantity = 4; - const originalLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, options); + const originalLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, opts); expect(originalLine.quantity).toEqual(20); - await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); + await models.Sale.updateQuantity(ctx, saleId, newQuantity, opts); - const modifiedLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, options); + const modifiedLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, opts); expect(modifiedLine.quantity).toEqual(newQuantity); }); @@ -80,7 +90,7 @@ fdescribe('sale model ', () => { const newQuantity = -10; try { - await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); + await models.Sale.updateQuantity(ctx, saleId, newQuantity, opts); } catch (e) { expect(e).toEqual(new Error('You can only add negative amounts in refund tickets')); } @@ -92,9 +102,9 @@ fdescribe('sale model ', () => { const saleId = 32; const newQuantity = -10; - await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); + await models.Sale.updateQuantity(ctx, saleId, newQuantity, opts); - const modifiedLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, options); + const modifiedLine = await models.Sale.findOne({where: {id: saleId}, fields: ['quantity']}, opts); expect(modifiedLine.quantity).toEqual(newQuantity); }); @@ -108,18 +118,18 @@ fdescribe('sale model ', () => { const newQuantity = minQuantity - 1; try { - const item = await models.Item.findById(itemId, null, options); - await item.updateAttribute('minQuantity', minQuantity, options); - spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, options) => { + const item = await models.Item.findById(itemId, null, opts); + await item.updateAttribute('minQuantity', minQuantity, opts); + spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => { if (sqlStatement.includes('catalog_calcFromItem')) { sqlStatement = `CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem ENGINE = MEMORY SELECT 100 as available;`; params = null; } - return models.Ticket.rawSql(sqlStatement, params, options); + return models.Ticket.rawSql(sqlStatement, params, opts); }); - await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); + await models.Sale.updateQuantity(ctx, saleId, newQuantity, opts); } catch (e) { expect(e).toEqual(new Error('The amount cannot be less than the minimum')); } @@ -133,19 +143,19 @@ fdescribe('sale model ', () => { const minQuantity = 30; const newQuantity = minQuantity - 1; - const item = await models.Item.findById(itemId, null, options); - await item.updateAttribute('minQuantity', minQuantity, options); + const item = await models.Item.findById(itemId, null, opts); + await item.updateAttribute('minQuantity', minQuantity, opts); - spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, options) => { + spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => { if (sqlStatement.includes('catalog_calcFromItem')) { sqlStatement = `CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem ENGINE = MEMORY SELECT ${newQuantity} as available;`; params = null; } - return models.Ticket.rawSql(sqlStatement, params, options); + return models.Ticket.rawSql(sqlStatement, params, opts); }); - await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); + await models.Sale.updateQuantity(ctx, saleId, newQuantity, opts); }); describe('newPrice', () => { @@ -157,19 +167,19 @@ fdescribe('sale model ', () => { const minQuantity = 30; const newQuantity = 31; - const item = await models.Item.findById(itemId, null, options); - await item.updateAttribute('minQuantity', minQuantity, options); - spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, options) => { + const item = await models.Item.findById(itemId, null, opts); + await item.updateAttribute('minQuantity', minQuantity, opts); + spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => { if (sqlStatement.includes('catalog_calcFromItem')) { sqlStatement = ` CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem ENGINE = MEMORY SELECT ${newQuantity} as available; CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentPrice ENGINE = MEMORY SELECT 1 as grouping, 7.07 as price;`; params = null; } - return models.Ticket.rawSql(sqlStatement, params, options); + return models.Ticket.rawSql(sqlStatement, params, opts); }); - await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); + await models.Sale.updateQuantity(ctx, saleId, newQuantity, opts); }); it('should increase quantity when the new price is lower than the previous one', async() => { @@ -180,19 +190,19 @@ fdescribe('sale model ', () => { const minQuantity = 30; const newQuantity = 31; - const item = await models.Item.findById(itemId, null, options); - await item.updateAttribute('minQuantity', minQuantity, options); - spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, options) => { + const item = await models.Item.findById(itemId, null, opts); + await item.updateAttribute('minQuantity', minQuantity, opts); + spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => { if (sqlStatement.includes('catalog_calcFromItem')) { sqlStatement = ` CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem ENGINE = MEMORY SELECT ${newQuantity} as available; CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentPrice ENGINE = MEMORY SELECT 1 as grouping, 1 as price;`; params = null; } - return models.Ticket.rawSql(sqlStatement, params, options); + return models.Ticket.rawSql(sqlStatement, params, opts); }); - await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); + await models.Sale.updateQuantity(ctx, saleId, newQuantity, opts); }); it('should throw error when increase quantity and the new price is higher than the previous one', async() => { @@ -204,23 +214,105 @@ fdescribe('sale model ', () => { const newQuantity = 31; try { - const item = await models.Item.findById(itemId, null, options); - await item.updateAttribute('minQuantity', minQuantity, options); - spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, options) => { + const item = await models.Item.findById(itemId, null, opts); + await item.updateAttribute('minQuantity', minQuantity, opts); + spyOn(models.Sale, 'rawSql').and.callFake((sqlStatement, params, opts) => { if (sqlStatement.includes('catalog_calcFromItem')) { sqlStatement = ` CREATE OR REPLACE TEMPORARY TABLE tmp.ticketCalculateItem ENGINE = MEMORY SELECT ${newQuantity} as available; CREATE OR REPLACE TEMPORARY TABLE tmp.ticketComponentPrice ENGINE = MEMORY SELECT 1 as grouping, 100000 as price;`; params = null; } - return models.Ticket.rawSql(sqlStatement, params, options); + return models.Ticket.rawSql(sqlStatement, params, opts); }); - await models.Sale.updateQuantity(ctx, saleId, newQuantity, options); + await models.Sale.updateQuantity(ctx, saleId, newQuantity, opts); } catch (e) { expect(e).toEqual(new Error('The price of the item changed')); } }); }); }); + + describe('add a sale from a collection or previa ticket', () => { + it('if is allocated to them and alert level higher than 0 as Production role', async() => { + const ctx = getCtx(productionId); + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(productionId, true)); + + const beforeSalesCollection = await models.Sale.count({ticketFk: ticketCollectionProd}, opts); + await models.Ticket.addSale(ctx, ticketCollectionProd, barcode, 20, opts); + const afterSalesCollection = await models.Sale.count({ticketFk: ticketCollectionProd}, opts); + + expect(afterSalesCollection).toEqual(beforeSalesCollection + 1); + + const beforeSalesPrevia = await models.Sale.count({ticketFk: previaTicketProd}, opts); + await models.Ticket.addSale(ctx, previaTicketProd, barcode, 20, opts); + const afterSalesPrevia = await models.Sale.count({ticketFk: previaTicketProd}, opts); + + expect(afterSalesPrevia).toEqual(beforeSalesPrevia + 1); + }); + + it('should throw an error if is not allocated to them and alert level higher than 0 as Production role', async() => { + const ctx = getCtx(productionId); + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(productionId, true)); + + try { + await models.Ticket.addSale(ctx, ticketCollectionSalesPerson, barcode, 20, opts); + } catch ({message}) { + expect(message).toEqual(notEditableError); + } + + try { + await models.Ticket.addSale(ctx, previaTicketSalesPerson, barcode, 20, opts); + } catch ({message}) { + expect(message).toEqual(notEditableError); + } + }); + + it('if is allocated to them and alert level higher than 0 as salesPerson role', async() => { + const ctx = getCtx(salesPersonId); + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(salesPersonId, true)); + + const beforeSalesCollection = await models.Sale.count({ticketFk: ticketCollectionSalesPerson}, opts); + await models.Ticket.addSale(ctx, ticketCollectionSalesPerson, barcode, 20, opts); + const afterSalesCollection = await models.Sale.count({ticketFk: ticketCollectionSalesPerson}, opts); + + expect(afterSalesCollection).toEqual(beforeSalesCollection + 1); + + const beforeSalesPrevia = await models.Sale.count({ticketFk: previaTicketSalesPerson}, opts); + await models.Ticket.addSale(ctx, previaTicketSalesPerson, barcode, 20, opts); + const afterSalesPrevia = await models.Sale.count({ticketFk: previaTicketSalesPerson}, opts); + + expect(afterSalesPrevia).toEqual(beforeSalesPrevia + 1); + }); + + it('should throw an error if is not allocated to them and alert level higher than 0 as salesPerson role', async() => { + const ctx = getCtx(salesPersonId); + + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(salesPersonId, true)); + + try { + await models.Ticket.addSale(ctx, ticketCollectionProd, barcode, 20, opts); + } catch ({message}) { + expect(message).toEqual(notEditableError); + } + }); + + it('if is a reviewer', async() => { + const ctx = getCtx(reviewerId); + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue(getCtx(reviewerId, true)); + + const beforeSalesCollection = await models.Sale.count({ticketFk: ticketCollectionSalesPerson}, opts); + await models.Ticket.addSale(ctx, ticketCollectionSalesPerson, barcode, 20, opts); + const afterSalesCollection = await models.Sale.count({ticketFk: ticketCollectionSalesPerson}, opts); + + expect(afterSalesCollection).toEqual(beforeSalesCollection + 1); + + const beforeSalesPrevia = await models.Sale.count({ticketFk: previaTicketSalesPerson}, opts); + await models.Ticket.addSale(ctx, previaTicketSalesPerson, barcode, 20, opts); + const afterSalesPrevia = await models.Sale.count({ticketFk: previaTicketSalesPerson}, opts); + + expect(afterSalesPrevia).toEqual(beforeSalesPrevia + 1); + }); + }); }); From 790a637d4d9fd1e5ee0e7fcfe2ea2361d07ca9c5 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 3 Jun 2024 09:25:48 +0200 Subject: [PATCH 21/49] feat: refs #6600 Add photoMotivation column to item table and create itemPhotoComment table --- .../00-addColumnPhotoMotivation.sql | 1 - .../11015-silverBamboo/00-photoMotivation.sql | 9 ++++++++ modules/item/back/model-config.json | 3 +++ modules/item/back/models/item.json | 6 +++++ .../item/back/models/itemPhotoComment.json | 22 +++++++++++++++++++ 5 files changed, 40 insertions(+), 1 deletion(-) delete mode 100644 db/versions/11015-silverBamboo/00-addColumnPhotoMotivation.sql create mode 100644 db/versions/11015-silverBamboo/00-photoMotivation.sql create mode 100644 modules/item/back/models/itemPhotoComment.json diff --git a/db/versions/11015-silverBamboo/00-addColumnPhotoMotivation.sql b/db/versions/11015-silverBamboo/00-addColumnPhotoMotivation.sql deleted file mode 100644 index 9f77dc88e..000000000 --- a/db/versions/11015-silverBamboo/00-addColumnPhotoMotivation.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE vn.item ADD COLUMN photoMotivation VARCHAR(255); \ No newline at end of file diff --git a/db/versions/11015-silverBamboo/00-photoMotivation.sql b/db/versions/11015-silverBamboo/00-photoMotivation.sql new file mode 100644 index 000000000..37cef29ab --- /dev/null +++ b/db/versions/11015-silverBamboo/00-photoMotivation.sql @@ -0,0 +1,9 @@ +ALTER TABLE vn.item ADD COLUMN photoMotivation VARCHAR(255); + +CREATE TABLE vn.itemPhotoComment ( + id int(11) NOT NULL AUTO_INCREMENT, + itemFk int(11) NOT NULL, + PRIMARY KEY (id), + FOREIGN KEY (itemFk) REFERENCES vn.item(id) ON UPDATE CASCADE ON DELETE CASCADE, + UNIQUE (itemFk) +); diff --git a/modules/item/back/model-config.json b/modules/item/back/model-config.json index 40d73f1a6..0cc100f98 100644 --- a/modules/item/back/model-config.json +++ b/modules/item/back/model-config.json @@ -35,6 +35,9 @@ "ItemPackingType": { "dataSource": "vn" }, + "ItemPhotoComment": { + "dataSource": "vn" + }, "ItemTag": { "dataSource": "vn" }, diff --git a/modules/item/back/models/item.json b/modules/item/back/models/item.json index 7ec1daf7a..d7813a0f5 100644 --- a/modules/item/back/models/item.json +++ b/modules/item/back/models/item.json @@ -215,7 +215,13 @@ "type": "hasOne", "model": "Packaging", "foreignKey": "itemFk" + }, + "photoComment": { + "type": "hasOne", + "model": "itemPhotoComment", + "foreignKey": "itemFk" } + }, "scopes": { "withName": { diff --git a/modules/item/back/models/itemPhotoComment.json b/modules/item/back/models/itemPhotoComment.json new file mode 100644 index 000000000..4e2d14c5f --- /dev/null +++ b/modules/item/back/models/itemPhotoComment.json @@ -0,0 +1,22 @@ +{ + "name": "ItemPhotoComment", + "base": "VnModel", + "mixins": { + "Loggable": true + }, + "options": { + "mysql": { + "table": "itemPhotoComment" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Id" + }, + "itemFk": { + "type": "number" + } + } +} \ No newline at end of file From 72630d613ba58d91292bc85ac289b735e9d17865 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 3 Jun 2024 09:32:03 +0200 Subject: [PATCH 22/49] fix: refs #6600 rollback --- .../11015-silverBamboo/00-photoMotivation.sql | 10 +-------- modules/item/back/model-config.json | 3 --- modules/item/back/models/item.json | 6 ----- .../item/back/models/itemPhotoComment.json | 22 ------------------- 4 files changed, 1 insertion(+), 40 deletions(-) delete mode 100644 modules/item/back/models/itemPhotoComment.json diff --git a/db/versions/11015-silverBamboo/00-photoMotivation.sql b/db/versions/11015-silverBamboo/00-photoMotivation.sql index 37cef29ab..366694e12 100644 --- a/db/versions/11015-silverBamboo/00-photoMotivation.sql +++ b/db/versions/11015-silverBamboo/00-photoMotivation.sql @@ -1,9 +1 @@ -ALTER TABLE vn.item ADD COLUMN photoMotivation VARCHAR(255); - -CREATE TABLE vn.itemPhotoComment ( - id int(11) NOT NULL AUTO_INCREMENT, - itemFk int(11) NOT NULL, - PRIMARY KEY (id), - FOREIGN KEY (itemFk) REFERENCES vn.item(id) ON UPDATE CASCADE ON DELETE CASCADE, - UNIQUE (itemFk) -); +ALTER TABLE vn.item ADD COLUMN photoMotivation VARCHAR(255); \ No newline at end of file diff --git a/modules/item/back/model-config.json b/modules/item/back/model-config.json index 0cc100f98..40d73f1a6 100644 --- a/modules/item/back/model-config.json +++ b/modules/item/back/model-config.json @@ -35,9 +35,6 @@ "ItemPackingType": { "dataSource": "vn" }, - "ItemPhotoComment": { - "dataSource": "vn" - }, "ItemTag": { "dataSource": "vn" }, diff --git a/modules/item/back/models/item.json b/modules/item/back/models/item.json index d7813a0f5..7ec1daf7a 100644 --- a/modules/item/back/models/item.json +++ b/modules/item/back/models/item.json @@ -215,13 +215,7 @@ "type": "hasOne", "model": "Packaging", "foreignKey": "itemFk" - }, - "photoComment": { - "type": "hasOne", - "model": "itemPhotoComment", - "foreignKey": "itemFk" } - }, "scopes": { "withName": { diff --git a/modules/item/back/models/itemPhotoComment.json b/modules/item/back/models/itemPhotoComment.json deleted file mode 100644 index 4e2d14c5f..000000000 --- a/modules/item/back/models/itemPhotoComment.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "ItemPhotoComment", - "base": "VnModel", - "mixins": { - "Loggable": true - }, - "options": { - "mysql": { - "table": "itemPhotoComment" - } - }, - "properties": { - "id": { - "type": "number", - "id": true, - "description": "Id" - }, - "itemFk": { - "type": "number" - } - } -} \ No newline at end of file From 1382b24c1d4df1eac0feb9ac9239fa58a01e73b8 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 3 Jun 2024 09:38:35 +0200 Subject: [PATCH 23/49] refactor: refs #6600 add space --- modules/item/back/models/item.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/item/back/models/item.json b/modules/item/back/models/item.json index 7ec1daf7a..10cff3e04 100644 --- a/modules/item/back/models/item.json +++ b/modules/item/back/models/item.json @@ -156,7 +156,7 @@ "type": "number", "description": "Min quantity" }, - "photoMotivation":{ + "photoMotivation": { "type": "string" } }, From 7a92963886d65cdc95acc5a0fa2344ca600d3993 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 3 Jun 2024 10:21:25 +0200 Subject: [PATCH 24/49] fix acls --- db/versions/11083-purpleBamboo/00-firstScript.sql | 3 +++ modules/ticket/front/descriptor-menu/index.html | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 db/versions/11083-purpleBamboo/00-firstScript.sql diff --git a/db/versions/11083-purpleBamboo/00-firstScript.sql b/db/versions/11083-purpleBamboo/00-firstScript.sql new file mode 100644 index 000000000..95e5c30a1 --- /dev/null +++ b/db/versions/11083-purpleBamboo/00-firstScript.sql @@ -0,0 +1,3 @@ + +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + VALUES ('Ticket','refund','WRITE','ALLOW','ROLE','logistic'); diff --git a/modules/ticket/front/descriptor-menu/index.html b/modules/ticket/front/descriptor-menu/index.html index cb7eeb8ee..3583b1202 100644 --- a/modules/ticket/front/descriptor-menu/index.html +++ b/modules/ticket/front/descriptor-menu/index.html @@ -152,7 +152,7 @@ From b1a4b4202859a6f1fc1d5af068b9159eb7e09dac Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 3 Jun 2024 10:29:38 +0200 Subject: [PATCH 25/49] fix: refs #6404 change db language on local --- back/methods/mrw-config/createShipment.js | 2 +- db/dump/db.cnf | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/back/methods/mrw-config/createShipment.js b/back/methods/mrw-config/createShipment.js index dd2ed883a..dd3d7fbd2 100644 --- a/back/methods/mrw-config/createShipment.js +++ b/back/methods/mrw-config/createShipment.js @@ -64,7 +64,7 @@ module.exports = Self => { JOIN ticket t ON e.ticketFk = t.id JOIN agencyMode am ON am.id = t.agencyModeFk JOIN mrwService ms ON ms.agencyModeCodeFk = am.code - LEFT JOIN mrwServiceWeekday mw ON mw.weekdays = DATE_FORMAT(t.shipped, '%a') + LEFT JOIN mrwServiceWeekday mw ON mw.weekdays = DATE_FORMAT(t.shipped + INTERVAL 1 DAY, '%a', 'en_en') JOIN client c ON t.clientFk = c.id JOIN address a ON t.addressFk = a.id LEFT JOIN addressObservation oa ON oa.addressFk = a.id diff --git a/db/dump/db.cnf b/db/dump/db.cnf index 3dafaf514..f59c0eb4b 100644 --- a/db/dump/db.cnf +++ b/db/dump/db.cnf @@ -7,3 +7,6 @@ expire_logs_days = 2 binlog-ignore-db = tmp binlog-ignore-db = PERCONA_SCHEMA + +lc-messages = es_ES +lc_time_names = es_ES From 39dcb7d6a83845229ffced6430ff48cfc0d4ab50 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 3 Jun 2024 10:30:20 +0200 Subject: [PATCH 26/49] fix: refs #6889 check if has collection or sectorCollection --- modules/ticket/back/methods/ticket/isEditableOrThrow.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/ticket/back/methods/ticket/isEditableOrThrow.js b/modules/ticket/back/methods/ticket/isEditableOrThrow.js index 0adc9e0f9..555063093 100644 --- a/modules/ticket/back/methods/ticket/isEditableOrThrow.js +++ b/modules/ticket/back/methods/ticket/isEditableOrThrow.js @@ -27,17 +27,16 @@ module.exports = Self => { const ticketCollection = await models.TicketCollection.findOne({ include: {relation: 'collection'}, where: {ticketFk: id} }, myOptions); - let workerId = ticketCollection?.collection()?.workerFk; + let isOwner = ticketCollection?.collection()?.workerFk === ctx.req.accessToken.userId; - if (!workerId) { + if (!isOwner) { const saleGroup = await models.SaleGroup.findOne({fields: ['id'], where: {ticketFk: id}}, myOptions); const sectorCollectionSaleGroup = saleGroup && await models.SectorCollectionSaleGroup.findOne({ include: {relation: 'sectorCollection'}, where: {saleGroupFk: saleGroup.id} }, myOptions); - workerId = sectorCollectionSaleGroup?.sectorCollection()?.userFk; + isOwner = sectorCollectionSaleGroup?.sectorCollection()?.userFk === ctx.req.accessToken.userId; } - const isOwner = workerId === ctx.req.accessToken.userId; if (!ticket) throw new ForbiddenError(`The ticket doesn't exist.`); From 349914743c6d417e2656e8fbce771c726ef2d330 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 3 Jun 2024 10:48:21 +0200 Subject: [PATCH 27/49] build: increase version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4df55c492..11911398d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "24.22.7", + "version": "24.22.8", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From 85d68890b898b7d3189f487ca2698dd4e9602b62 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 3 Jun 2024 12:11:26 +0200 Subject: [PATCH 28/49] refactor: refs #6701 New table clientRate --- db/routines/vn/triggers/claimRatio_afterInsert.sql | 9 +++++++++ db/versions/11084-whitePalmetto/00-firstScript.sql | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 db/routines/vn/triggers/claimRatio_afterInsert.sql create mode 100644 db/versions/11084-whitePalmetto/00-firstScript.sql diff --git a/db/routines/vn/triggers/claimRatio_afterInsert.sql b/db/routines/vn/triggers/claimRatio_afterInsert.sql new file mode 100644 index 000000000..080e636a2 --- /dev/null +++ b/db/routines/vn/triggers/claimRatio_afterInsert.sql @@ -0,0 +1,9 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimRatio_afterInsert` + AFTER INSERT ON `claimRatio` + FOR EACH ROW +BEGIN + INSERT INTO clientRate(clientFk, `value`) + VALUES(NEW.clientFk, NEW.priceIncreasing); +END$$ +DELIMITER ; diff --git a/db/versions/11084-whitePalmetto/00-firstScript.sql b/db/versions/11084-whitePalmetto/00-firstScript.sql new file mode 100644 index 000000000..c5f841ea4 --- /dev/null +++ b/db/versions/11084-whitePalmetto/00-firstScript.sql @@ -0,0 +1,9 @@ +CREATE TABLE `vn`.`clientRate` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `clientFk` int(11) NOT NULL, + `dated` date NOT NULL DEFAULT current_timestamp(), + `value` decimal(10,2) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `clientRate_unique` (`clientFk`,`dated`), + CONSTRAINT `clientRate_client_FK` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; \ No newline at end of file From d3584691fa1f88e7addef2e15323f61914720be4 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 3 Jun 2024 12:16:33 +0200 Subject: [PATCH 29/49] refactor: refs #6701 Minor change --- db/routines/vn/triggers/claimRatio_afterInsert.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/triggers/claimRatio_afterInsert.sql b/db/routines/vn/triggers/claimRatio_afterInsert.sql index 080e636a2..ca618bb89 100644 --- a/db/routines/vn/triggers/claimRatio_afterInsert.sql +++ b/db/routines/vn/triggers/claimRatio_afterInsert.sql @@ -4,6 +4,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`claimRatio_afterInser FOR EACH ROW BEGIN INSERT INTO clientRate(clientFk, `value`) - VALUES(NEW.clientFk, NEW.priceIncreasing); + VALUES(NEW.clientFk, NEW.priceIncreasing) + ON DUPLICATE KEY UPDATE + `value` = VALUES(`value`); END$$ DELIMITER ; From b9b0651069c1d58003dcfe4e45f738b73cd4ef6b Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 3 Jun 2024 12:38:57 +0200 Subject: [PATCH 30/49] fix: refs #6404 fix agency service selection --- back/methods/mrw-config/createShipment.js | 4 ++-- db/dump/db.cnf | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/back/methods/mrw-config/createShipment.js b/back/methods/mrw-config/createShipment.js index dd3d7fbd2..b5bea648d 100644 --- a/back/methods/mrw-config/createShipment.js +++ b/back/methods/mrw-config/createShipment.js @@ -57,14 +57,14 @@ module.exports = Self => { DATE_FORMAT(t.shipped, '%d/%m/%Y') created, t.shipped, CONCAT( e.ticketFk, LPAD(e.counter, mc.counterWidth, '0')) reference, - LPAD(IF(mw.params IS NULL, ms.serviceType, mw.serviceType), mc.serviceTypeWidth,'0') serviceType, + LPAD(IF(mw.serviceType IS NULL, ms.serviceType, mw.serviceType), mc.serviceTypeWidth,'0') serviceType, IF(mw.weekdays, 'S', 'N') weekDays, oa.description deliveryObservation FROM expedition e JOIN ticket t ON e.ticketFk = t.id JOIN agencyMode am ON am.id = t.agencyModeFk JOIN mrwService ms ON ms.agencyModeCodeFk = am.code - LEFT JOIN mrwServiceWeekday mw ON mw.weekdays = DATE_FORMAT(t.shipped + INTERVAL 1 DAY, '%a', 'en_en') + LEFT JOIN mrwServiceWeekday mw ON mw.weekdays | 1 << WEEKDAY(t.landed) JOIN client c ON t.clientFk = c.id JOIN address a ON t.addressFk = a.id LEFT JOIN addressObservation oa ON oa.addressFk = a.id diff --git a/db/dump/db.cnf b/db/dump/db.cnf index f59c0eb4b..3dafaf514 100644 --- a/db/dump/db.cnf +++ b/db/dump/db.cnf @@ -7,6 +7,3 @@ expire_logs_days = 2 binlog-ignore-db = tmp binlog-ignore-db = PERCONA_SCHEMA - -lc-messages = es_ES -lc_time_names = es_ES From a73c98eebe6551c6a4b3752b05e9674ff36e2a23 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 3 Jun 2024 13:04:09 +0200 Subject: [PATCH 31/49] build(operator): console.log --- modules/worker/back/models/operator.js | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/worker/back/models/operator.js b/modules/worker/back/models/operator.js index d46f3d934..8b562717e 100644 --- a/modules/worker/back/models/operator.js +++ b/modules/worker/back/models/operator.js @@ -17,6 +17,11 @@ module.exports = Self => { const {backupPrinterNotificationDelay} = await models.ProductionConfig.findOne(); if (backupPrinterNotificationDelay) { + console.log('operator delay:', + backupPrinterNotificationDelay, + Date.vnNow(), + new Date(Date.vnNow() - (backupPrinterNotificationDelay * 1000)) + ); const notifications = await models.NotificationQueue.find( {where: {created: {gte: new Date(Date.vnNow() - (backupPrinterNotificationDelay * 1000))}, notificationFk: notificationName, diff --git a/package.json b/package.json index fc8b709c9..b1ec06c69 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "24.24.1", + "version": "24.24.2", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From 35ae728e810006083dabef7c9c9e9cc8eee66845 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 3 Jun 2024 14:19:41 +0200 Subject: [PATCH 32/49] build(operator): console.log --- modules/worker/back/models/operator.js | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/worker/back/models/operator.js b/modules/worker/back/models/operator.js index d46f3d934..9652f3763 100644 --- a/modules/worker/back/models/operator.js +++ b/modules/worker/back/models/operator.js @@ -17,18 +17,25 @@ module.exports = Self => { const {backupPrinterNotificationDelay} = await models.ProductionConfig.findOne(); if (backupPrinterNotificationDelay) { + console.log('operator delay:', + backupPrinterNotificationDelay, + Date.vnNow(), + new Date(Date.vnNow() - (backupPrinterNotificationDelay * 1000)) + ); const notifications = await models.NotificationQueue.find( {where: {created: {gte: new Date(Date.vnNow() - (backupPrinterNotificationDelay * 1000))}, notificationFk: notificationName, status: 'sent' } }); + console.log('notifications: ', notifications); const criteria = {labelerId: labelerFk, sectorId: sectorFk}; const filteredNotifications = notifications.filter(notification => { const paramsObj = JSON.parse(notification.params); return Object.keys(criteria).every(key => criteria[key] === paramsObj?.[key]); }); + console.log('filteredNotifications: ', filteredNotifications); if (filteredNotifications.length >= 1) return; } diff --git a/package.json b/package.json index 4df55c492..11911398d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "24.22.7", + "version": "24.22.8", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From 9775e808a21ba6686b5fa8032daedef63f8e631a Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 3 Jun 2024 14:37:24 +0200 Subject: [PATCH 33/49] build(operator): remove console.log --- modules/worker/back/models/operator.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/modules/worker/back/models/operator.js b/modules/worker/back/models/operator.js index 9652f3763..d46f3d934 100644 --- a/modules/worker/back/models/operator.js +++ b/modules/worker/back/models/operator.js @@ -17,25 +17,18 @@ module.exports = Self => { const {backupPrinterNotificationDelay} = await models.ProductionConfig.findOne(); if (backupPrinterNotificationDelay) { - console.log('operator delay:', - backupPrinterNotificationDelay, - Date.vnNow(), - new Date(Date.vnNow() - (backupPrinterNotificationDelay * 1000)) - ); const notifications = await models.NotificationQueue.find( {where: {created: {gte: new Date(Date.vnNow() - (backupPrinterNotificationDelay * 1000))}, notificationFk: notificationName, status: 'sent' } }); - console.log('notifications: ', notifications); const criteria = {labelerId: labelerFk, sectorId: sectorFk}; const filteredNotifications = notifications.filter(notification => { const paramsObj = JSON.parse(notification.params); return Object.keys(criteria).every(key => criteria[key] === paramsObj?.[key]); }); - console.log('filteredNotifications: ', filteredNotifications); if (filteredNotifications.length >= 1) return; } From c445bcb0baefe40da662d9412f1fe8ca93cde9ac Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 3 Jun 2024 14:39:32 +0200 Subject: [PATCH 34/49] build(operator): remove console.log --- modules/worker/back/models/operator.js | 5 ----- package.json | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/modules/worker/back/models/operator.js b/modules/worker/back/models/operator.js index 8b562717e..d46f3d934 100644 --- a/modules/worker/back/models/operator.js +++ b/modules/worker/back/models/operator.js @@ -17,11 +17,6 @@ module.exports = Self => { const {backupPrinterNotificationDelay} = await models.ProductionConfig.findOne(); if (backupPrinterNotificationDelay) { - console.log('operator delay:', - backupPrinterNotificationDelay, - Date.vnNow(), - new Date(Date.vnNow() - (backupPrinterNotificationDelay * 1000)) - ); const notifications = await models.NotificationQueue.find( {where: {created: {gte: new Date(Date.vnNow() - (backupPrinterNotificationDelay * 1000))}, notificationFk: notificationName, diff --git a/package.json b/package.json index b1ec06c69..be361ce7b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "24.24.2", + "version": "24.24.3", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From bbf027ede5dfc92039cd1bc9e928f46dfed7c9a3 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 3 Jun 2024 15:01:06 +0200 Subject: [PATCH 35/49] fix(operator): neq error --- modules/worker/back/models/operator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/worker/back/models/operator.js b/modules/worker/back/models/operator.js index d46f3d934..70e20af5b 100644 --- a/modules/worker/back/models/operator.js +++ b/modules/worker/back/models/operator.js @@ -20,7 +20,7 @@ module.exports = Self => { const notifications = await models.NotificationQueue.find( {where: {created: {gte: new Date(Date.vnNow() - (backupPrinterNotificationDelay * 1000))}, notificationFk: notificationName, - status: 'sent' + status: {neq: 'error'} } }); From 3875bdb98db13d4006203d7b7caa546d2488ba7c Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 3 Jun 2024 15:01:25 +0200 Subject: [PATCH 36/49] build(operator): remove console.log --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 11911398d..e79f48b46 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "24.22.8", + "version": "24.22.9", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From 0b885ab773d665e1b8ff0cac7445a207d947f7e0 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 3 Jun 2024 15:06:29 +0200 Subject: [PATCH 37/49] build: increase version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e79f48b46..468d13156 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "24.22.9", + "version": "24.22.10", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From 5dd2e3b7d35baea70f944f96b6a3650db60c883f Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 3 Jun 2024 16:45:02 +0200 Subject: [PATCH 38/49] ci(Jenkinsfile): refs #7442 Tag image with build id --- Jenkinsfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 07f235cf7..d3dbfeddb 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -120,7 +120,7 @@ pipeline { steps { script { def packageJson = readJSON file: 'package.json' - env.VERSION = packageJson.version + env.VERSION = "${packageJson.version}-vn${env.BUILD_ID}" } sh 'docker-compose build back' } @@ -158,7 +158,7 @@ pipeline { steps { script { def packageJson = readJSON file: 'package.json' - env.VERSION = packageJson.version + env.VERSION = "${packageJson.version}-vn${env.BUILD_ID}" } sh 'gulp build' sh 'docker-compose build front' @@ -178,7 +178,7 @@ pipeline { steps { script { def packageJson = readJSON file: 'package.json' - env.VERSION = packageJson.version + env.VERSION = "${packageJson.version}-vn${env.BUILD_ID}" } sh 'docker login --username $CREDENTIALS_USR --password $CREDENTIALS_PSW $REGISTRY' sh 'docker-compose push' @@ -212,7 +212,7 @@ pipeline { steps { script { def packageJson = readJSON file: 'package.json' - env.VERSION = packageJson.version + env.VERSION = "${packageJson.version}-vn${env.BUILD_ID}" } withKubeConfig([ serverUrl: "$KUBERNETES_API", From 9a7074d6003de431e992e8489181a79d0b515f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Mon, 3 Jun 2024 20:16:27 +0200 Subject: [PATCH 39/49] hotfix: ledger_next transacciones refs #7523 --- .../vn/procedures/duaInvoiceInBooking.sql | 2 +- db/routines/vn/procedures/duaTaxBooking.sql | 2 +- .../vn/procedures/invoiceIn_booking.sql | 2 +- .../vn/procedures/invoiceOutBooking.sql | 2 +- .../vn/procedures/ledger_doCompensation.sql | 2 +- db/routines/vn/procedures/ledger_next.sql | 41 ++++--------------- db/routines/vn/procedures/ledger_nextTx.sql | 35 ++++++++++++++++ db/routines/vn/procedures/xdiario_new.sql | 2 +- .../vn/triggers/payment_beforeInsert.sql | 2 +- 9 files changed, 50 insertions(+), 40 deletions(-) create mode 100644 db/routines/vn/procedures/ledger_nextTx.sql diff --git a/db/routines/vn/procedures/duaInvoiceInBooking.sql b/db/routines/vn/procedures/duaInvoiceInBooking.sql index 035b4eab1..8b4df6a73 100644 --- a/db/routines/vn/procedures/duaInvoiceInBooking.sql +++ b/db/routines/vn/procedures/duaInvoiceInBooking.sql @@ -44,7 +44,7 @@ BEGIN JOIN dua d ON d.id = de.duaFk WHERE d.id = vDuaFk LIMIT 1; - CALL ledger_next(vFiscalYear, FALSE, vBookEntry); + CALL ledger_nextTx(vFiscalYear, vBookEntry); END IF; OPEN vInvoicesIn; diff --git a/db/routines/vn/procedures/duaTaxBooking.sql b/db/routines/vn/procedures/duaTaxBooking.sql index 8d8effe90..a50a10ca4 100644 --- a/db/routines/vn/procedures/duaTaxBooking.sql +++ b/db/routines/vn/procedures/duaTaxBooking.sql @@ -12,7 +12,7 @@ BEGIN WHERE id = vDuaFk; IF vBookNumber IS NULL OR NOT vBookNumber THEN - CALL ledger_next(YEAR(vBookDated), FALSE, vBookNumber); + CALL ledger_nextTx(YEAR(vBookDated), vBookNumber); END IF; -- Apunte de la aduana diff --git a/db/routines/vn/procedures/invoiceIn_booking.sql b/db/routines/vn/procedures/invoiceIn_booking.sql index cd311ba9d..ef124bb46 100644 --- a/db/routines/vn/procedures/invoiceIn_booking.sql +++ b/db/routines/vn/procedures/invoiceIn_booking.sql @@ -70,7 +70,7 @@ BEGIN SELECT YEAR(bookEntried) INTO vFiscalYear FROM tInvoiceIn LIMIT 1; IF vBookNumber IS NULL THEN - CALL ledger_next(vFiscalYear, FALSE, vBookNumber); + CALL ledger_nextTx(vFiscalYear, vBookNumber); END IF; -- Apunte del proveedor diff --git a/db/routines/vn/procedures/invoiceOutBooking.sql b/db/routines/vn/procedures/invoiceOutBooking.sql index b50b89eaf..9fc1c92b6 100644 --- a/db/routines/vn/procedures/invoiceOutBooking.sql +++ b/db/routines/vn/procedures/invoiceOutBooking.sql @@ -61,7 +61,7 @@ BEGIN WHERE io.id = vInvoice; SELECT YEAR(FECHA) INTO vFiscalYear FROM rs LIMIT 1; - CALL ledger_next(vFiscalYear, FALSE, vBookNumber); + CALL ledger_nextTx(vFiscalYear, vBookNumber); -- Linea del cliente INSERT INTO XDiario( ASIEN, diff --git a/db/routines/vn/procedures/ledger_doCompensation.sql b/db/routines/vn/procedures/ledger_doCompensation.sql index a9e4e4251..391575bac 100644 --- a/db/routines/vn/procedures/ledger_doCompensation.sql +++ b/db/routines/vn/procedures/ledger_doCompensation.sql @@ -28,7 +28,7 @@ BEGIN DECLARE vIsOriginalAClient BOOL; DECLARE vPayMethodCompensation INT; - CALL ledger_next(YEAR(vDated), FALSE, vNewBookEntry); + CALL ledger_nextTx(YEAR(vDated), vNewBookEntry); SELECT COUNT(id) INTO vIsOriginalAClient FROM client diff --git a/db/routines/vn/procedures/ledger_next.sql b/db/routines/vn/procedures/ledger_next.sql index 2d565ff99..0a390ab16 100644 --- a/db/routines/vn/procedures/ledger_next.sql +++ b/db/routines/vn/procedures/ledger_next.sql @@ -1,38 +1,21 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_next`( IN vFiscalYear INT, - IN vIsManageTransaction BOOLEAN, OUT vLastBookEntry INT ) +/** + * Devuelve un número de asiento válido, según el contador de asientos + * tabla vn.ledgerConfig, si no existe lo inicializa a 1 + * No inicia transacción, para transaccionar usar vn.ledger_nextTx + * + * @param vFiscalYear Id del año contable + * @return vLastBookEntry Id del asiento + */ BEGIN - DECLARE vHasStartTransaction BOOLEAN; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - - IF vHasStartTransaction THEN - ROLLBACK TO sp; - RESIGNAL; - ELSE - ROLLBACK; - CALL util.throw ('It has not been possible to generate a new ledger'); - END IF; - END; - IF vFiscalYear IS NULL THEN CALL util.throw('Fiscal year is required'); END IF; - IF NOT vIsManageTransaction THEN - SELECT @@in_transaction INTO vHasStartTransaction; - - IF NOT vHasStartTransaction THEN - START TRANSACTION; - ELSE - SAVEPOINT sp; - END IF; - END IF; - SELECT bookEntry + 1 INTO vLastBookEntry FROM ledgerCompany WHERE fiscalYear = vFiscalYear @@ -48,13 +31,5 @@ BEGIN UPDATE ledgerCompany SET bookEntry = vLastBookEntry WHERE fiscalYear = vFiscalYear; - - IF NOT vIsManageTransaction THEN - IF vHasStartTransaction THEN - RELEASE SAVEPOINT sp; - ELSE - COMMIT; - END IF; - END IF; END$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ledger_nextTx.sql b/db/routines/vn/procedures/ledger_nextTx.sql new file mode 100644 index 000000000..bdc0c3360 --- /dev/null +++ b/db/routines/vn/procedures/ledger_nextTx.sql @@ -0,0 +1,35 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_nextTx`( + IN vFiscalYear INT, + OUT vLastBookEntry INT +) +/** + * Devuelve un número de asiento válido, según el contador de asientos + * tabla vn.ledgerConfig, si no existe lo inicializa a 1 + * Lo hace transaccionando el proceso + * + * @param vFiscalYear Id del año contable + * @return vLastBookEntry Id del asiento + */ +BEGIN + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + IF vFiscalYear IS NULL THEN + CALL util.throw('Fiscal year is required'); + END IF; + + IF @@in_transaction THEN + CALL util.throw('This procedure should not be executed within a transaction'); + END IF; + + START TRANSACTION; + + CALL ledger_next(vFiscalYear, vLastBookEntry); + + COMMIT; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/xdiario_new.sql b/db/routines/vn/procedures/xdiario_new.sql index 83e1afa16..22a26184e 100644 --- a/db/routines/vn/procedures/xdiario_new.sql +++ b/db/routines/vn/procedures/xdiario_new.sql @@ -39,7 +39,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`xdiario_new`( */ BEGIN IF vBookNumber IS NULL THEN - CALL ledger_next(YEAR(vDated), FALSE, vBookNumber); + CALL ledger_nextTx(YEAR(vDated), vBookNumber); END IF; INSERT INTO XDiario diff --git a/db/routines/vn/triggers/payment_beforeInsert.sql b/db/routines/vn/triggers/payment_beforeInsert.sql index 337a54172..af369a69b 100644 --- a/db/routines/vn/triggers/payment_beforeInsert.sql +++ b/db/routines/vn/triggers/payment_beforeInsert.sql @@ -23,7 +23,7 @@ BEGIN FROM supplier WHERE id = NEW.supplierFk; - CALL ledger_next(YEAR(NEW.received), TRUE, vNewBookEntry); + CALL ledger_next(YEAR(NEW.received), vNewBookEntry); INSERT INTO XDiario ( ASIEN, From 03201e1e2c0f2a8f53dd124de482c96b1cdfc7b9 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 4 Jun 2024 09:10:47 +0200 Subject: [PATCH 40/49] fix(ticket): throw error if id is null --- modules/ticket/front/card/index.js | 5 +++++ modules/ticket/front/locale/es.yml | 1 + 2 files changed, 6 insertions(+) diff --git a/modules/ticket/front/card/index.js b/modules/ticket/front/card/index.js index fa4ad4e39..34ab109c5 100644 --- a/modules/ticket/front/card/index.js +++ b/modules/ticket/front/card/index.js @@ -1,5 +1,6 @@ import ngModule from '../module'; import ModuleCard from 'salix/components/module-card'; +import UserError from 'core/lib/user-error'; class Controller extends ModuleCard { reload() { @@ -59,6 +60,10 @@ class Controller extends ModuleCard { ], }; + if (!this.$params.id) { + this.$state.go('ticket.index'); + throw new UserError(`You must select a ticket`); + } return this.$http.get(`Tickets/${this.$params.id}`, {filter}) .then(res => this.onData(res.data)); } diff --git a/modules/ticket/front/locale/es.yml b/modules/ticket/front/locale/es.yml index 748ba210f..2f448c034 100644 --- a/modules/ticket/front/locale/es.yml +++ b/modules/ticket/front/locale/es.yml @@ -64,6 +64,7 @@ You are going to delete this ticket: Vas a eliminar este ticket Ticket deleted. You can undo this action within the first hour: Ticket eliminado. Puedes deshacer esta acción durante la primera hora Search ticket by id or alias: Buscar tickets por identificador o alias ticket: ticket +You must select a ticket: Debes seleccionar un ticket #sections List: Listado From a997ca0c58cd1fd383cdef456af5c469f2267eef Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 4 Jun 2024 10:08:17 +0200 Subject: [PATCH 41/49] build: add new version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index be361ce7b..8b8281e0d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "24.24.3", + "version": "24.26.0", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From 1927fbce4561f6c0e90a23398acb72d02cf80746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 4 Jun 2024 15:39:02 +0200 Subject: [PATCH 42/49] hotfix: ledger_next transacciones refs #7523 --- back/tests.js | 4 ++-- db/.pullinfo.json | 2 +- db/routines/util/procedures/tx_commit.sql | 2 +- db/routines/util/procedures/tx_rollback.sql | 3 ++- db/routines/util/procedures/tx_start.sql | 2 +- db/routines/vn/procedures/ledger_nextTx.sql | 13 ++++--------- .../back/methods/travel/cloneWithEntries.js | 19 ++++++++++--------- .../travel/specs/cloneWithEntries.spec.js | 18 ++++++++---------- 8 files changed, 29 insertions(+), 34 deletions(-) diff --git a/back/tests.js b/back/tests.js index 50698eb92..fba3df4a8 100644 --- a/back/tests.js +++ b/back/tests.js @@ -98,8 +98,8 @@ async function test() { const SpecReporter = require('jasmine-spec-reporter').SpecReporter; runner.addReporter(new SpecReporter({ spec: { - displaySuccessful: opts.ci, - displayPending: opts.ci + displaySuccessful: true, + displayPending: true }, summary: { displayPending: false, diff --git a/db/.pullinfo.json b/db/.pullinfo.json index 0defed845..27d2c7535 100644 --- a/db/.pullinfo.json +++ b/db/.pullinfo.json @@ -9,7 +9,7 @@ }, "vn": { "view": { - "expeditionPallet_Print": "06613719475fcdba8309607c38cc78efc2e348cca7bc96b48dc3ae3c12426f54" + "expeditionPallet_Print": "ced2b84a114fcb99fce05f0c34f4fc03f3fa387bef92621be1bc306608a84345" } } } diff --git a/db/routines/util/procedures/tx_commit.sql b/db/routines/util/procedures/tx_commit.sql index fdf2f3ddb..8eb0c7426 100644 --- a/db/routines/util/procedures/tx_commit.sql +++ b/db/routines/util/procedures/tx_commit.sql @@ -6,7 +6,7 @@ BEGIN * * @param isTx es true si existe transacción asociada */ - IF isTx THEN + IF NOT isTx THEN COMMIT; END IF; END$$ diff --git a/db/routines/util/procedures/tx_rollback.sql b/db/routines/util/procedures/tx_rollback.sql index 96571af2c..e2c089f64 100644 --- a/db/routines/util/procedures/tx_rollback.sql +++ b/db/routines/util/procedures/tx_rollback.sql @@ -6,8 +6,9 @@ BEGIN * * @param isTx es true si existe transacción asociada */ - IF isTx THEN + IF NOT isTx THEN ROLLBACK; + RESIGNAL; END IF; END$$ DELIMITER ; diff --git a/db/routines/util/procedures/tx_start.sql b/db/routines/util/procedures/tx_start.sql index 9d9f16bb7..aa410ff72 100644 --- a/db/routines/util/procedures/tx_start.sql +++ b/db/routines/util/procedures/tx_start.sql @@ -6,7 +6,7 @@ BEGIN * * @param isTx es true si existe transacción asociada */ - IF isTx THEN + IF NOT isTx THEN START TRANSACTION; END IF; END$$ diff --git a/db/routines/vn/procedures/ledger_nextTx.sql b/db/routines/vn/procedures/ledger_nextTx.sql index bdc0c3360..abe96a21e 100644 --- a/db/routines/vn/procedures/ledger_nextTx.sql +++ b/db/routines/vn/procedures/ledger_nextTx.sql @@ -12,24 +12,19 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_nextTx`( * @return vLastBookEntry Id del asiento */ BEGIN + DECLARE vhasTx BOOL DEFAULT @@in_transaction; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - ROLLBACK; + CALL util.tx_rollback(vhasTx); RESIGNAL; END; IF vFiscalYear IS NULL THEN CALL util.throw('Fiscal year is required'); END IF; - - IF @@in_transaction THEN - CALL util.throw('This procedure should not be executed within a transaction'); - END IF; - - START TRANSACTION; + CALL util.tx_start(vhasTx); CALL ledger_next(vFiscalYear, vLastBookEntry); - - COMMIT; + CALL util.tx_commit(vhasTx); END$$ DELIMITER ; \ No newline at end of file diff --git a/modules/travel/back/methods/travel/cloneWithEntries.js b/modules/travel/back/methods/travel/cloneWithEntries.js index e5eb0b06c..12afad6e2 100644 --- a/modules/travel/back/methods/travel/cloneWithEntries.js +++ b/modules/travel/back/methods/travel/cloneWithEntries.js @@ -26,18 +26,17 @@ module.exports = Self => { Self.cloneWithEntries = async(ctx, id, options) => { const conn = Self.dataSource.connector; + let tx; const myOptions = {}; - let tx = options?.transaction; + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } try { - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - const travel = await Self.findById(id, { fields: [ 'id', @@ -89,6 +88,8 @@ module.exports = Self => { 'ref' ] }, myOptions); + + if (tx) await tx.commit(); return newTravel.id; } catch (e) { if (tx) await tx.rollback(); diff --git a/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js b/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js index 950da7bb1..8b3638db9 100644 --- a/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js +++ b/modules/travel/back/methods/travel/specs/cloneWithEntries.spec.js @@ -7,19 +7,22 @@ describe('Travel cloneWithEntries()', () => { const ctx = {req: {accessToken: {userId: currentUserId}}}; let newTravelId; it(`should clone the travel and the containing entries`, async() => { - const tx = await models.Travel.beginTransaction({ - }); + const tx = await models.Travel.beginTransaction({}); const warehouseThree = 3; const agencyModeOne = 1; + let travelRemoved; + try { const options = {transaction: tx}; + newTravelId = await models.Travel.cloneWithEntries(ctx, travelId, options); const travelEntries = await models.Entry.find({ where: { travelFk: newTravelId } }, options); - const newTravel = await models.Travel.findById(travelId); + const newTravel = await models.Travel.findById(travelId, null, options); + travelRemoved = await models.Travel.findById(newTravelId); expect(newTravelId).not.toEqual(travelId); expect(newTravel.ref).toEqual('fifth travel'); @@ -27,14 +30,9 @@ describe('Travel cloneWithEntries()', () => { expect(newTravel.warehouseOutFk).toEqual(warehouseThree); expect(newTravel.agencyModeFk).toEqual(agencyModeOne); expect(travelEntries.length).toBeGreaterThan(0); - await models.Entry.destroyAll({ - travelFk: newTravelId - }, options); - await models.Travel.destroyById(newTravelId, options); - await tx.rollback(); - const travelRemoved = await models.Travel.findById(newTravelId, options); - expect(travelRemoved).toBeNull(); + + await tx.rollback(); } catch (e) { if (tx) await tx.rollback(); throw e; From c57f4db623c4bb8c7f667a7a1adc59d016028057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 4 Jun 2024 15:41:53 +0200 Subject: [PATCH 43/49] hotfix: ledger_next transacciones refs #7523 --- db/.pullinfo.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/.pullinfo.json b/db/.pullinfo.json index 27d2c7535..0defed845 100644 --- a/db/.pullinfo.json +++ b/db/.pullinfo.json @@ -9,7 +9,7 @@ }, "vn": { "view": { - "expeditionPallet_Print": "ced2b84a114fcb99fce05f0c34f4fc03f3fa387bef92621be1bc306608a84345" + "expeditionPallet_Print": "06613719475fcdba8309607c38cc78efc2e348cca7bc96b48dc3ae3c12426f54" } } } From e2adadb8da542398b7a3689906a4bacd4b52a7d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 4 Jun 2024 15:43:32 +0200 Subject: [PATCH 44/49] hotfix: ledger_next transacciones refs #7523 --- back/tests.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/back/tests.js b/back/tests.js index fba3df4a8..50698eb92 100644 --- a/back/tests.js +++ b/back/tests.js @@ -98,8 +98,8 @@ async function test() { const SpecReporter = require('jasmine-spec-reporter').SpecReporter; runner.addReporter(new SpecReporter({ spec: { - displaySuccessful: true, - displayPending: true + displaySuccessful: opts.ci, + displayPending: opts.ci }, summary: { displayPending: false, From a9eb5f7d1ef9cc325b1ab10a23b93610dd35667b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 4 Jun 2024 15:45:54 +0200 Subject: [PATCH 45/49] hotfix: ledger_next transacciones refs #7523 --- db/routines/util/procedures/tx_rollback.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/db/routines/util/procedures/tx_rollback.sql b/db/routines/util/procedures/tx_rollback.sql index e2c089f64..8909a96bb 100644 --- a/db/routines/util/procedures/tx_rollback.sql +++ b/db/routines/util/procedures/tx_rollback.sql @@ -8,7 +8,6 @@ BEGIN */ IF NOT isTx THEN ROLLBACK; - RESIGNAL; END IF; END$$ DELIMITER ; From e4969f70616391f261cfced2107e05f78c530977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 4 Jun 2024 16:43:09 +0200 Subject: [PATCH 46/49] Hotfix: ledger_next transacciones refs #7523 --- db/routines/util/procedures/tx_commit.sql | 6 +++--- db/routines/util/procedures/tx_rollback.sql | 4 ++-- db/routines/util/procedures/tx_start.sql | 6 +++--- db/routines/vn/procedures/ledger_nextTx.sql | 8 ++++---- db/routines/vn/procedures/travel_cloneWithEntries.sql | 10 +++++----- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/db/routines/util/procedures/tx_commit.sql b/db/routines/util/procedures/tx_commit.sql index 8eb0c7426..35f96df8d 100644 --- a/db/routines/util/procedures/tx_commit.sql +++ b/db/routines/util/procedures/tx_commit.sql @@ -1,12 +1,12 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_commit`(isTx BOOL) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_commit`(vIsTx BOOL) BEGIN /** * Confirma los cambios asociados a una transacción. * - * @param isTx es true si existe transacción asociada + * @param vIsTx es true si existe transacción asociada */ - IF NOT isTx THEN + IF vIsTx THEN COMMIT; END IF; END$$ diff --git a/db/routines/util/procedures/tx_rollback.sql b/db/routines/util/procedures/tx_rollback.sql index 8909a96bb..82f771024 100644 --- a/db/routines/util/procedures/tx_rollback.sql +++ b/db/routines/util/procedures/tx_rollback.sql @@ -1,12 +1,12 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_rollback`(isTx BOOL) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_rollback`(vIsTx BOOL) BEGIN /** * Deshace los cambios asociados a una transacción. * * @param isTx es true si existe transacción asociada */ - IF NOT isTx THEN + IF vIsTx THEN ROLLBACK; END IF; END$$ diff --git a/db/routines/util/procedures/tx_start.sql b/db/routines/util/procedures/tx_start.sql index aa410ff72..41f8c94ee 100644 --- a/db/routines/util/procedures/tx_start.sql +++ b/db/routines/util/procedures/tx_start.sql @@ -1,12 +1,12 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_start`(isTx BOOL) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_start`(vIsTx BOOL) BEGIN /** * Inicia una transacción. * - * @param isTx es true si existe transacción asociada + * @param vIsTx es true si existe transacción asociada */ - IF NOT isTx THEN + IF vIsTx THEN START TRANSACTION; END IF; END$$ diff --git a/db/routines/vn/procedures/ledger_nextTx.sql b/db/routines/vn/procedures/ledger_nextTx.sql index abe96a21e..98c157676 100644 --- a/db/routines/vn/procedures/ledger_nextTx.sql +++ b/db/routines/vn/procedures/ledger_nextTx.sql @@ -12,10 +12,10 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_nextTx`( * @return vLastBookEntry Id del asiento */ BEGIN - DECLARE vhasTx BOOL DEFAULT @@in_transaction; + DECLARE vIsRequiredTx BOOL DEFAULT NOT @@in_transaction; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - CALL util.tx_rollback(vhasTx); + CALL util.tx_rollback(vIsRequiredTx); RESIGNAL; END; @@ -23,8 +23,8 @@ BEGIN CALL util.throw('Fiscal year is required'); END IF; - CALL util.tx_start(vhasTx); + CALL util.tx_start(vIsRequiredTx); CALL ledger_next(vFiscalYear, vLastBookEntry); - CALL util.tx_commit(vhasTx); + CALL util.tx_commit(vIsRequiredTx); END$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/travel_cloneWithEntries.sql b/db/routines/vn/procedures/travel_cloneWithEntries.sql index 7cf9ee5ef..c51a68ecd 100644 --- a/db/routines/vn/procedures/travel_cloneWithEntries.sql +++ b/db/routines/vn/procedures/travel_cloneWithEntries.sql @@ -24,8 +24,8 @@ BEGIN DECLARE vEvaNotes VARCHAR(255); DECLARE vDone BOOL; DECLARE vAuxEntryFk INT; - DECLARE vTx BOOLEAN DEFAULT @@in_transaction; - DECLARE vRsEntry CURSOR FOR + DECLARE vDoTx BOOLEAN DEFAULT NOT @@in_transaction; + DECLARE vIsRequiredTx CURSOR FOR SELECT e.id FROM entry e JOIN travel t ON t.id = e.travelFk @@ -35,11 +35,11 @@ BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - CALL util.tx_rollback(vTx); + CALL util.tx_rollback(vIsRequiredTx); RESIGNAL; END; - CALL util.tx_start(vTx); + CALL util.tx_start(vIsRequiredTx); INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk, agencyModeFk, `ref`, isDelivered, isReceived, m3, cargoSupplierFk, kg,clonedFrom) SELECT vDateStart, vDateEnd, vWarehouseInFk, vWarehouseOutFk, vAgencyModeFk, vRef, isDelivered, isReceived, m3,cargoSupplierFk, kg,vTravelFk @@ -76,6 +76,6 @@ BEGIN SET @isModeInventory = FALSE; CLOSE vRsEntry; - CALL util.tx_commit(vTx); + CALL util.tx_commit(vIsRequiredTx); END$$ DELIMITER ; From 35b4255505e0584525785774118282c5c12b7b68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Tue, 4 Jun 2024 16:45:42 +0200 Subject: [PATCH 47/49] Hotfix: ledger_next transacciones refs #7523 --- db/routines/util/procedures/tx_rollback.sql | 2 +- db/routines/vn/procedures/travel_cloneWithEntries.sql | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/db/routines/util/procedures/tx_rollback.sql b/db/routines/util/procedures/tx_rollback.sql index 82f771024..4b00f9ec1 100644 --- a/db/routines/util/procedures/tx_rollback.sql +++ b/db/routines/util/procedures/tx_rollback.sql @@ -4,7 +4,7 @@ BEGIN /** * Deshace los cambios asociados a una transacción. * - * @param isTx es true si existe transacción asociada + * @param vIsTx es true si existe transacción asociada */ IF vIsTx THEN ROLLBACK; diff --git a/db/routines/vn/procedures/travel_cloneWithEntries.sql b/db/routines/vn/procedures/travel_cloneWithEntries.sql index c51a68ecd..e2d086fc8 100644 --- a/db/routines/vn/procedures/travel_cloneWithEntries.sql +++ b/db/routines/vn/procedures/travel_cloneWithEntries.sql @@ -24,8 +24,8 @@ BEGIN DECLARE vEvaNotes VARCHAR(255); DECLARE vDone BOOL; DECLARE vAuxEntryFk INT; - DECLARE vDoTx BOOLEAN DEFAULT NOT @@in_transaction; - DECLARE vIsRequiredTx CURSOR FOR + DECLARE vIsRequiredTx BOOLEAN DEFAULT NOT @@in_transaction; + DECLARE vRsEntry CURSOR FOR SELECT e.id FROM entry e JOIN travel t ON t.id = e.travelFk From 3b4cbe9e6c7b4a4860fbe6dd2b9703dcf8e9c6aa Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 4 Jun 2024 22:59:33 +0200 Subject: [PATCH 48/49] ci(Jenkinsfile): refs #7442 Remove ci from back tests --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index d3dbfeddb..7dccdd0b5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -102,7 +102,7 @@ pipeline { NODE_ENV = '' } steps { - sh 'node back/tests.js --ci --junit --network jenkins' + sh 'node back/tests.js --junit' } post { always { From 143930bc86478d6b74c346430788bd1cfa32bbec Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 5 Jun 2024 07:07:13 +0200 Subject: [PATCH 49/49] fix: warmFix setDeleted checks ticketRequest not answered --- modules/ticket/back/methods/ticket/setDeleted.js | 5 ++++- modules/ticket/back/methods/ticket/specs/setDeleted.spec.js | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/ticket/back/methods/ticket/setDeleted.js b/modules/ticket/back/methods/ticket/setDeleted.js index 9a9fd9056..2afdf44ac 100644 --- a/modules/ticket/back/methods/ticket/setDeleted.js +++ b/modules/ticket/back/methods/ticket/setDeleted.js @@ -71,7 +71,10 @@ module.exports = Self => { // Check for existing purchase requests const hasPurchaseRequests = await models.TicketRequest.count({ ticketFk: id, - isOk: true + or: [ + {isOk: true}, + {isOk: null} + ] }, myOptions); if (hasPurchaseRequests) diff --git a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js index 520a9e403..cb2a21d91 100644 --- a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js @@ -49,7 +49,7 @@ describe('ticket setDeleted()', () => { ctx.req.__ = value => { return value; }; - const ticketId = 23; + const ticketId = 24; const [sectorCollectionBefore] = await models.Ticket.rawSql( `SELECT COUNT(*) numberRows FROM vn.sectorCollection`, [], options); @@ -87,7 +87,7 @@ describe('ticket setDeleted()', () => { const [ticketCollectionOld] = await models.Ticket.rawSql( `SELECT COUNT(*) numberRows FROM vn.ticketCollection`, [], options); - const ticketId = 23; + const ticketId = 34; await models.Ticket.setDeleted(ctx, ticketId, options);