From 3a6d4753dbf9ebb2484416049cfc3b56b66a7cc9 Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 15 Feb 2024 12:48:17 +0100 Subject: [PATCH 001/173] feat: refs #5855 drop temporary table --- db/routines/bi/procedures/claim_ratio_routine.sql | 2 ++ .../cache/procedures/availableNoRaids_refresh.sql | 2 +- db/routines/cache/procedures/available_refresh.sql | 2 +- .../edi/procedures/floramondo_offerRefresh.sql | 11 ++++++----- db/routines/hedera/procedures/item_calcCatalog.sql | 3 ++- .../vn/procedures/copyComponentsFromSaleList.sql | 1 + db/routines/vn/procedures/itemShelvingRadar.sql | 2 +- db/routines/vn/procedures/itemShelving_inventory.sql | 2 ++ db/routines/vn/procedures/item_getMinacum.sql | 2 ++ db/routines/vn/procedures/productionSectorList.sql | 1 + db/routines/vn/procedures/ticket_DelayTruck.sql | 1 + db/routines/vn/procedures/ticket_add.sql | 2 ++ db/routines/vn/procedures/ticket_cloneWeekly.sql | 2 +- db/routines/vn/procedures/zone_getCollisions.sql | 3 ++- 14 files changed, 25 insertions(+), 11 deletions(-) diff --git a/db/routines/bi/procedures/claim_ratio_routine.sql b/db/routines/bi/procedures/claim_ratio_routine.sql index 10cb717cf..4ad028433 100644 --- a/db/routines/bi/procedures/claim_ratio_routine.sql +++ b/db/routines/bi/procedures/claim_ratio_routine.sql @@ -164,5 +164,7 @@ BEGIN ) sub SET cr.recobro = sub.recobro WHERE Id_Cliente IN ( 5189,8942); + + DROP TEMPORARY TABLE tmp.ticket_list; END$$ DELIMITER ; diff --git a/db/routines/cache/procedures/availableNoRaids_refresh.sql b/db/routines/cache/procedures/availableNoRaids_refresh.sql index 383e35436..37715d270 100644 --- a/db/routines/cache/procedures/availableNoRaids_refresh.sql +++ b/db/routines/cache/procedures/availableNoRaids_refresh.sql @@ -117,7 +117,7 @@ proc: BEGIN )sub GROUP BY sub.itemFk; - DROP TEMPORARY TABLE tmp.itemCalc, tItemRange; + DROP TEMPORARY TABLE tmp.itemCalc, tItemRange, tmp.itemList; CALL cache_calc_end (vCalc); END$$ DELIMITER ; diff --git a/db/routines/cache/procedures/available_refresh.sql b/db/routines/cache/procedures/available_refresh.sql index d0939e568..abf023a41 100644 --- a/db/routines/cache/procedures/available_refresh.sql +++ b/db/routines/cache/procedures/available_refresh.sql @@ -121,7 +121,7 @@ proc: BEGIN )sub GROUP BY sub.itemFk; - DROP TEMPORARY TABLE tmp.itemCalc, itemRange; + DROP TEMPORARY TABLE tmp.itemCalc, itemRange, tmp.itemList; CALL cache_calc_end (vCalc); END$$ DELIMITER ; diff --git a/db/routines/edi/procedures/floramondo_offerRefresh.sql b/db/routines/edi/procedures/floramondo_offerRefresh.sql index 26e09ebaf..6fdd1b3bb 100644 --- a/db/routines/edi/procedures/floramondo_offerRefresh.sql +++ b/db/routines/edi/procedures/floramondo_offerRefresh.sql @@ -1,5 +1,5 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`floramondo_offerRefresh`() +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `edi`.`floramondo_offerRefresh`() proc: BEGIN DECLARE vLanded DATETIME; DECLARE vDone INT DEFAULT FALSE; @@ -484,7 +484,8 @@ proc: BEGIN DROP TEMPORARY TABLE edi.offer, - itemToInsert; + itemToInsert, + tmp.buyRecalc; SET @isTriggerDisabled = FALSE; @@ -518,5 +519,5 @@ proc: BEGIN fieldValue = TIMEDIFF(util.VN_NOW(), vStartingTime); DO RELEASE_LOCK('edi.floramondo_offerRefresh'); -END$$ -DELIMITER ; +END$$ +DELIMITER ; diff --git a/db/routines/hedera/procedures/item_calcCatalog.sql b/db/routines/hedera/procedures/item_calcCatalog.sql index 81b3adf5a..6db11c034 100644 --- a/db/routines/hedera/procedures/item_calcCatalog.sql +++ b/db/routines/hedera/procedures/item_calcCatalog.sql @@ -30,6 +30,7 @@ BEGIN tmp.ticketComponentPrice, tmp.ticketComponent, tmp.ticketLot, - tmp.zoneGetShipped; + tmp.zoneGetShipped, + tmp.item; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/copyComponentsFromSaleList.sql b/db/routines/vn/procedures/copyComponentsFromSaleList.sql index 17cf487b1..13487af17 100644 --- a/db/routines/vn/procedures/copyComponentsFromSaleList.sql +++ b/db/routines/vn/procedures/copyComponentsFromSaleList.sql @@ -30,5 +30,6 @@ BEGIN JOIN tmp.saleList s ON s.saleFk = sc.saleFk JOIN tmp.newSaleList ns ON ns.orden = s.orden; + DROP TEMPORARY TABLE IF EXISTS tmp.newSaleList; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingRadar.sql b/db/routines/vn/procedures/itemShelvingRadar.sql index c89a190ae..db56c07a0 100644 --- a/db/routines/vn/procedures/itemShelvingRadar.sql +++ b/db/routines/vn/procedures/itemShelvingRadar.sql @@ -188,7 +188,7 @@ proc:BEGIN SELECT * FROM tmp.itemShelvingRadar; END IF; - DROP TEMPORARY TABLE tmp.itemShelvingRadar; + DROP TEMPORARY TABLE tmp.itemShelvingRadar, tmp.itemOutTime; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelving_inventory.sql b/db/routines/vn/procedures/itemShelving_inventory.sql index ce2934426..89adc0be4 100644 --- a/db/routines/vn/procedures/itemShelving_inventory.sql +++ b/db/routines/vn/procedures/itemShelving_inventory.sql @@ -58,5 +58,7 @@ BEGIN WHERE p.pickingOrder BETWEEN vPickingOrderFrom AND vPickingOrderTo AND p.sectorFk = vSectorFk ORDER BY p.pickingOrder; + + DROP TEMPORARY TABLE IF EXISTS tmp.stockMisfit; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/item_getMinacum.sql b/db/routines/vn/procedures/item_getMinacum.sql index ed987637c..ddf2ae2c6 100644 --- a/db/routines/vn/procedures/item_getMinacum.sql +++ b/db/routines/vn/procedures/item_getMinacum.sql @@ -75,5 +75,7 @@ BEGIN i.quantity amount FROM tmp.itemAtp i HAVING amount != 0; + + DROP TEMPORARY TABLE tmp.itemAtp; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/productionSectorList.sql b/db/routines/vn/procedures/productionSectorList.sql index 5447f10d0..e1445ca52 100644 --- a/db/routines/vn/procedures/productionSectorList.sql +++ b/db/routines/vn/procedures/productionSectorList.sql @@ -104,5 +104,6 @@ BEGIN ) sub; DROP TEMPORARY TABLE tmp.whiteTicket; DROP TEMPORARY TABLE tmp.sectorTypeTicket; + DROP TEMPORARY TABLE tmp.productionBuffer; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_DelayTruck.sql b/db/routines/vn/procedures/ticket_DelayTruck.sql index 7a3170d68..20006fa65 100644 --- a/db/routines/vn/procedures/ticket_DelayTruck.sql +++ b/db/routines/vn/procedures/ticket_DelayTruck.sql @@ -30,5 +30,6 @@ BEGIN END LOOP; CLOSE cur1; + DROP TEMPORARY TABLE tmp.ticket, tmp.productionBuffer; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_add.sql b/db/routines/vn/procedures/ticket_add.sql index 5c3c28081..c85000218 100644 --- a/db/routines/vn/procedures/ticket_add.sql +++ b/db/routines/vn/procedures/ticket_add.sql @@ -65,6 +65,8 @@ BEGIN IF (vZoneFk IS NULL OR vZoneFk = 0) AND vIsRequiredZone THEN CALL util.throw ('NOT_ZONE_WITH_THIS_PARAMETERS'); END IF; + + DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetShipped; END IF; INSERT INTO ticket ( diff --git a/db/routines/vn/procedures/ticket_cloneWeekly.sql b/db/routines/vn/procedures/ticket_cloneWeekly.sql index 6bceb2fdf..f9e8d2cb6 100644 --- a/db/routines/vn/procedures/ticket_cloneWeekly.sql +++ b/db/routines/vn/procedures/ticket_cloneWeekly.sql @@ -197,6 +197,6 @@ BEGIN END; END LOOP; CLOSE rsTicket; - DROP TEMPORARY TABLE IF EXISTS tmp.time; + DROP TEMPORARY TABLE IF EXISTS tmp.time, tmp.zoneGetLanded; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/zone_getCollisions.sql b/db/routines/vn/procedures/zone_getCollisions.sql index f6779e1b7..4f104eaad 100644 --- a/db/routines/vn/procedures/zone_getCollisions.sql +++ b/db/routines/vn/procedures/zone_getCollisions.sql @@ -120,6 +120,7 @@ BEGIN DROP TEMPORARY TABLE geoCollision, tmp.zone, - tmp.zoneNodes; + tmp.zoneNodes, + tmp.zoneOption; END$$ DELIMITER ; From bb86c27202878d487e86e7f07a7511cadf516fcc Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 20 Mar 2024 11:07:55 +0100 Subject: [PATCH 002/173] feat: refs #7116 create table agencyIncoming --- db/routines/bs/procedures/salesByItemTypeDay_add.sql | 2 +- db/versions/10960-silverRoebelini/00-firstScript.sql | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 db/versions/10960-silverRoebelini/00-firstScript.sql diff --git a/db/routines/bs/procedures/salesByItemTypeDay_add.sql b/db/routines/bs/procedures/salesByItemTypeDay_add.sql index 5c12081a0..0f5c5c543 100644 --- a/db/routines/bs/procedures/salesByItemTypeDay_add.sql +++ b/db/routines/bs/procedures/salesByItemTypeDay_add.sql @@ -27,7 +27,7 @@ BEGIN JOIN vn.ticket t ON t.id = s.ticketFk WHERE ic.merchandise AND t.shipped BETWEEN vDateStart AND util.dayEnd(vDateEnd) - GROUP BY it.id, bs.dated; + GROUP BY i.id, bs.dated; INSERT INTO salesByItemTypeDay (itemTypeFk, dated, trash, faults) SELECT it.id itemTypeFk, diff --git a/db/versions/10960-silverRoebelini/00-firstScript.sql b/db/versions/10960-silverRoebelini/00-firstScript.sql new file mode 100644 index 000000000..c72ce10a7 --- /dev/null +++ b/db/versions/10960-silverRoebelini/00-firstScript.sql @@ -0,0 +1,11 @@ +-- Place your SQL code here +CREATE TABLE IF NOT EXISTS `vn`.`agencyIncoming` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `code` varchar(50) DEFAULT NULL, + `description` varchar(50) DEFAULT NULL, + `isOrigin` tinyint(1) DEFAULT NULL, + PRIMARY KEY (`id`) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; \ No newline at end of file From 634bde1c9cf8efd49c2896d0f8c017482c20fcba Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 20 Mar 2024 11:10:06 +0100 Subject: [PATCH 003/173] refs #7116 --- db/routines/bs/procedures/salesByItemTypeDay_add.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/bs/procedures/salesByItemTypeDay_add.sql b/db/routines/bs/procedures/salesByItemTypeDay_add.sql index 0f5c5c543..5c12081a0 100644 --- a/db/routines/bs/procedures/salesByItemTypeDay_add.sql +++ b/db/routines/bs/procedures/salesByItemTypeDay_add.sql @@ -27,7 +27,7 @@ BEGIN JOIN vn.ticket t ON t.id = s.ticketFk WHERE ic.merchandise AND t.shipped BETWEEN vDateStart AND util.dayEnd(vDateEnd) - GROUP BY i.id, bs.dated; + GROUP BY it.id, bs.dated; INSERT INTO salesByItemTypeDay (itemTypeFk, dated, trash, faults) SELECT it.id itemTypeFk, From a5d262671d5c23624d3fb2031daccb4e313dbad1 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 29 Mar 2024 22:19:23 +0100 Subject: [PATCH 004/173] refs #6436 feat: extend BeforeAll --- back/tests-helper.js | 14 ++++++++++++-- back/tests.js | 3 +-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/back/tests-helper.js b/back/tests-helper.js index b88fa1fd6..e4878c4a2 100644 --- a/back/tests-helper.js +++ b/back/tests-helper.js @@ -10,7 +10,7 @@ async function init() { host: process.env.DB_HOST, port: process.env.DB_PORT }); - + customBeforeAll(); const bootOptions = {dataSources}; await new Promise((resolve, reject) => { app.boot(bootOptions, @@ -24,7 +24,16 @@ async function deinit() { console.log('Stopping backend.'); await app.disconnect(); } - +function customBeforeAll() { + Object.assign(beforeAll, { + ctx: { + req: { + accessToken: {userId: 9}, + headers: {origin: 'http://localhost'}, + } + } + }); +} module.exports = { init, deinit @@ -32,3 +41,4 @@ module.exports = { if (require.main === module) init(); + diff --git a/back/tests.js b/back/tests.js index 50698eb92..f446b3483 100644 --- a/back/tests.js +++ b/back/tests.js @@ -84,13 +84,12 @@ async function test() { 'loopback/**/*[sS]pec.js', 'modules/*/back/**/*.[sS]pec.js' ], - helpers: [] + helpers: [`back/tests-helper.js`] }; if (PARALLEL) { const ParallelRunner = require('jasmine/parallel'); runner = new ParallelRunner({numWorkers: 1}); - config.helpers.push(`back/tests-helper.js`); } else { const Jasmine = require('jasmine'); runner = new Jasmine(); From 48cc499f379e1b6645ae24292b4f44de9c643132 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 29 Mar 2024 22:19:36 +0100 Subject: [PATCH 005/173] refs #6436 perf: example to use --- back/methods/collection/spec/getSales.spec.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/back/methods/collection/spec/getSales.spec.js b/back/methods/collection/spec/getSales.spec.js index e6205cc79..f276d07d0 100644 --- a/back/methods/collection/spec/getSales.spec.js +++ b/back/methods/collection/spec/getSales.spec.js @@ -4,15 +4,7 @@ describe('collection getSales()', () => { const collectionOrTicketFk = 999999; const print = true; const source = 'CHECKER'; - - beforeAll(() => { - ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'}, - } - }; - }); + const {ctx} = beforeAll; it('should return a collection with tickets, placements and barcodes settled correctly', async() => { const tx = await models.Collection.beginTransaction({}); From cb55740b68cdfc26948ff38de166fb8ad79fa9c6 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Apr 2024 10:57:53 +0200 Subject: [PATCH 006/173] refs #6436 rollback --- back/tests-helper.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/back/tests-helper.js b/back/tests-helper.js index e4878c4a2..97554ae0d 100644 --- a/back/tests-helper.js +++ b/back/tests-helper.js @@ -10,7 +10,6 @@ async function init() { host: process.env.DB_HOST, port: process.env.DB_PORT }); - customBeforeAll(); const bootOptions = {dataSources}; await new Promise((resolve, reject) => { app.boot(bootOptions, @@ -24,16 +23,7 @@ async function deinit() { console.log('Stopping backend.'); await app.disconnect(); } -function customBeforeAll() { - Object.assign(beforeAll, { - ctx: { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'}, - } - } - }); -} + module.exports = { init, deinit From d6ee5d571e6712f050533427946b91a7d92b6a7f Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Apr 2024 10:58:04 +0200 Subject: [PATCH 007/173] refs #6436 feat: jasmine helper --- back/tests.js | 3 ++- back/vn-jasmine.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 back/vn-jasmine.js diff --git a/back/tests.js b/back/tests.js index f446b3483..2e89cfd05 100644 --- a/back/tests.js +++ b/back/tests.js @@ -84,12 +84,13 @@ async function test() { 'loopback/**/*[sS]pec.js', 'modules/*/back/**/*.[sS]pec.js' ], - helpers: [`back/tests-helper.js`] + helpers: [`back/vn-jasmine.js`] }; if (PARALLEL) { const ParallelRunner = require('jasmine/parallel'); runner = new ParallelRunner({numWorkers: 1}); + config.helpers.push(`back/tests-helper.js`); } else { const Jasmine = require('jasmine'); runner = new Jasmine(); diff --git a/back/vn-jasmine.js b/back/vn-jasmine.js new file mode 100644 index 000000000..88dc55dc0 --- /dev/null +++ b/back/vn-jasmine.js @@ -0,0 +1,48 @@ + +const LoopBackContext = require('loopback-context'); +const DEFAULT_ACCESS_TOKEN = {accessToken: {userId: 9}}; +const DEFAULT_HEADERS = {headers: {origin: 'http://localhost'}}; +const DEFAULT_BEFORE_ALL = { + ctx: { + req: { + ...DEFAULT_ACCESS_TOKEN, + ...DEFAULT_HEADERS + + }, + args: {} + } +}; +const DEFAULT_LOOPBACK_CTX = { + ...DEFAULT_ACCESS_TOKEN, + http: { + req: { + ...DEFAULT_HEADERS + } + }, + args: {} +}; + +function vnBeforeAll(value = DEFAULT_BEFORE_ALL) { + Object.assign(beforeAll, value); +} +function mockBeforeAll(value = DEFAULT_BEFORE_ALL) { + const origin = beforeAll.ctx; + Object.assign(origin, value); + return origin; +} + +const mockLoopBackContext = (value = DEFAULT_LOOPBACK_CTX) => { + const activeCtx = value; + + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); + return activeCtx; +}; +module.exports = { + mockBeforeAll, mockLoopBackContext +}; + +(function init() { + vnBeforeAll(); +})(); From 8ab9063b50b4003b0cb1cea62b81a33deae3454f Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Apr 2024 11:00:55 +0200 Subject: [PATCH 008/173] refs #6436 feat: use mocks --- .../collection/spec/getTickets.spec.js | 10 +--------- .../client/specs/createWithUser.spec.js | 15 ++------------- .../invoice-in/specs/corrective.spec.js | 15 +-------------- .../item-shelving/specs/upsertItem.spec.js | 16 ++-------------- .../back/methods/sale/specs/clone.spec.js | 19 +++++-------------- .../ticket/specs/addSaleByCode.spec.js | 17 +++-------------- .../back/methods/ticket/specs/clone.spec.js | 15 +-------------- .../ticket/specs/transferClient.spec.js | 11 ++--------- 8 files changed, 17 insertions(+), 101 deletions(-) diff --git a/back/methods/collection/spec/getTickets.spec.js b/back/methods/collection/spec/getTickets.spec.js index e6b9e6a17..c066ead8c 100644 --- a/back/methods/collection/spec/getTickets.spec.js +++ b/back/methods/collection/spec/getTickets.spec.js @@ -1,15 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('collection getTickets()', () => { - let ctx; - beforeAll(async() => { - ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - } - }; - }); + const {ctx} = beforeAll; it('should get tickets, sales and barcodes from collection', async() => { const tx = await models.Collection.beginTransaction({}); diff --git a/modules/client/back/methods/client/specs/createWithUser.spec.js b/modules/client/back/methods/client/specs/createWithUser.spec.js index 074cb289a..584c49d5c 100644 --- a/modules/client/back/methods/client/specs/createWithUser.spec.js +++ b/modules/client/back/methods/client/specs/createWithUser.spec.js @@ -1,5 +1,5 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Client Create', () => { const newAccount = { @@ -17,18 +17,7 @@ describe('Client Create', () => { delete newAccountWithoutEmail.email; beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it(`should not find Deadpool as he's not created yet`, async() => { diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js index 1047cd028..ff547f1c8 100644 --- a/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js @@ -1,24 +1,11 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); describe('invoiceIn corrective()', () => { - let ctx; + const {ctx} = beforeAll; let options; let tx; beforeEach(async() => { - ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - }, - args: {} - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: ctx.req - }); - options = {transaction: tx}; tx = await models.Sale.beginTransaction({}); options.transaction = tx; diff --git a/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js b/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js index 9042b743d..e7f2ab015 100644 --- a/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js +++ b/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js @@ -1,26 +1,14 @@ const {models} = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); // #6276 describe('ItemShelving upsertItem()', () => { const warehouseFk = 1; - let ctx; + + const {ctx} = beforeAll; let options; let tx; beforeEach(async() => { - ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - }, - args: {} - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: ctx.req - }); - options = {transaction: tx}; tx = await models.ItemShelving.beginTransaction({}); options.transaction = tx; diff --git a/modules/ticket/back/methods/sale/specs/clone.spec.js b/modules/ticket/back/methods/sale/specs/clone.spec.js index e2220c028..ef2c6a9a3 100644 --- a/modules/ticket/back/methods/sale/specs/clone.spec.js +++ b/modules/ticket/back/methods/sale/specs/clone.spec.js @@ -1,24 +1,15 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext, mockBeforeAll} = require('vn-loopback/../../back/vn-jasmine'); describe('Ticket cloning - clone function', () => { - let ctx; + let ctx = mockBeforeAll({ejemploe: true}); let options; let tx; + beforeAll(async() => { + mockLoopBackContext(); + }); beforeEach(async() => { - ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - }, - args: {} - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: ctx.req - }); - options = {transaction: tx}; tx = await models.Sale.beginTransaction({}); options.transaction = tx; diff --git a/modules/ticket/back/methods/ticket/specs/addSaleByCode.spec.js b/modules/ticket/back/methods/ticket/specs/addSaleByCode.spec.js index b97139178..29af66752 100644 --- a/modules/ticket/back/methods/ticket/specs/addSaleByCode.spec.js +++ b/modules/ticket/back/methods/ticket/specs/addSaleByCode.spec.js @@ -1,22 +1,11 @@ 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 - }); - }); + + const {ctx} = beforeAll; it('should add a new sale', async() => { const tx = await models.Ticket.beginTransaction({}); @@ -26,7 +15,7 @@ describe('Ticket addSaleByCode()', () => { const code = '1111111111'; const salesBefore = await models.Sale.find(null, options); - await models.Ticket.addSaleByCode(activeCtx, code, quantity, ticketFk, warehouseFk, options); + await models.Ticket.addSaleByCode(ctx, code, quantity, ticketFk, warehouseFk, options); const salesAfter = await models.Sale.find(null, options); expect(salesAfter.length).toEqual(salesBefore.length + 1); diff --git a/modules/ticket/back/methods/ticket/specs/clone.spec.js b/modules/ticket/back/methods/ticket/specs/clone.spec.js index 26114bd58..cf222ab8d 100644 --- a/modules/ticket/back/methods/ticket/specs/clone.spec.js +++ b/modules/ticket/back/methods/ticket/specs/clone.spec.js @@ -1,26 +1,13 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); describe('Ticket cloning - clone function', () => { - let ctx; + const {ctx} = beforeAll; let options; let tx; const ticketId = 1; const shipped = Date.vnNew(); beforeEach(async() => { - ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - }, - args: {} - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: ctx.req - }); - options = {transaction: tx}; tx = await models.Ticket.beginTransaction({}); options.transaction = tx; diff --git a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js index 5f1c09776..4aac0833a 100644 --- a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js +++ b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js @@ -4,18 +4,11 @@ describe('Ticket transferClient()', () => { const originalTicketId = 8; const refundTicketId = 24; const clientId = 1; - let ctx; + + const {ctx} = beforeAll; let options; let tx; beforeEach(async() => { - ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - }, - args: {} - }; - options = {transaction: tx}; tx = await models.Ticket.beginTransaction({}); options.transaction = tx; From 914d3b2c67ad4aaceb4968be15d1c40bd669c6da Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 10 Apr 2024 11:41:08 +0200 Subject: [PATCH 009/173] feat: refs #6449 add showId column --- .../10986-pinkChrysanthemum/00-addSummaryId.sql | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 db/versions/10986-pinkChrysanthemum/00-addSummaryId.sql diff --git a/db/versions/10986-pinkChrysanthemum/00-addSummaryId.sql b/db/versions/10986-pinkChrysanthemum/00-addSummaryId.sql new file mode 100644 index 000000000..3dd330c68 --- /dev/null +++ b/db/versions/10986-pinkChrysanthemum/00-addSummaryId.sql @@ -0,0 +1,17 @@ +ALTER TABLE vn.claimLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.clientLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.deviceProductionLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.entryLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.invoiceInLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.itemLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.packingSiteDeviceLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.parkingLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.rateLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.routeLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.shelvingLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.supplierLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.ticketLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.travelLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.userLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.workerLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE vn.zoneLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; \ No newline at end of file From 841a5fcd5b762b293fa1bcc2b28bfcb0afc52c44 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 11 Apr 2024 15:08:33 +0200 Subject: [PATCH 010/173] feat: refs #6449 add summaryId column --- .../00-addSummaryId.sql | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/db/versions/10986-pinkChrysanthemum/00-addSummaryId.sql b/db/versions/10986-pinkChrysanthemum/00-addSummaryId.sql index 3dd330c68..288785191 100644 --- a/db/versions/10986-pinkChrysanthemum/00-addSummaryId.sql +++ b/db/versions/10986-pinkChrysanthemum/00-addSummaryId.sql @@ -1,17 +1,22 @@ -ALTER TABLE vn.claimLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.clientLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.deviceProductionLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.entryLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.invoiceInLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.itemLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.packingSiteDeviceLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.parkingLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.rateLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.routeLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.shelvingLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.supplierLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.ticketLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.travelLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.userLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.workerLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; -ALTER TABLE vn.zoneLog ADD COLUMN IF NOT EXISTS showId BOOLEAN NOT NULL DEFAULT FALSE; \ No newline at end of file +ALTER TABLE vn.claimLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.clientLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.deviceProductionLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.entryLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.invoiceInLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.itemLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.packingSiteDeviceLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.parkingLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.rateLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.routeLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.shelvingLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.supplierLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.ticketLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.travelLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.userLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.workerLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE vn.zoneLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); + +ALTER TABLE account.userLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE account.signInLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE account.roleLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); +ALTER TABLE account.accountLog ADD COLUMN IF NOT EXISTS summaryId varchar(30); \ No newline at end of file From c161c122d01367fd22b6810a487a9ca3f7252a19 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 11 Apr 2024 15:56:17 +0200 Subject: [PATCH 011/173] feat: refs #6449 add column --- modules/ticket/back/models/ticket-log.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/ticket/back/models/ticket-log.json b/modules/ticket/back/models/ticket-log.json index 32b4afd13..97722be96 100644 --- a/modules/ticket/back/models/ticket-log.json +++ b/modules/ticket/back/models/ticket-log.json @@ -39,6 +39,9 @@ }, "changedModelValue": { "type": "string" + }, + "summaryId": { + "type":"string" } } } From a21e3357743fbba4f3648db9c8b31667770c5a46 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 2 May 2024 17:23:04 +0200 Subject: [PATCH 012/173] feat: refs #6449 Add display of item ID in Ticket Logs --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a672e7986..c24cefa4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - (Worker -> time-control) Corrección de errores - (InvoiceOut -> Crear factura) Cuando falla al crear una factura, se devuelve un error +- (Ticket -> Logs) Ahora se muestra el id del item de la línea de venta ## [24.18.01] - 2024-05-07 From 2985e1c9e80dd7ff9b879199b2a9e38d3f13c7e1 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 31 May 2024 13:08:48 +0200 Subject: [PATCH 013/173] feat: roadMap refs #7195 --- back/models/warehouse.json | 33 +++++++++++++------ .../11081-wheatRaphis/00-firstScript.sql | 8 +++++ modules/route/back/models/roadmap.json | 12 +++---- 3 files changed, 37 insertions(+), 16 deletions(-) create mode 100644 db/versions/11081-wheatRaphis/00-firstScript.sql diff --git a/back/models/warehouse.json b/back/models/warehouse.json index dcbf7f2d2..69c74f153 100644 --- a/back/models/warehouse.json +++ b/back/models/warehouse.json @@ -9,21 +9,28 @@ }, "properties": { "id": { - "id": true, - "type": "number", - "forceId": false + "id": true, + "type": "number", + "forceId": false }, "name": { - "type": "string" + "type": "string" }, "code": { - "type": "string" + "type": "string" }, "isInventory": { - "type": "number" + "type": "number" }, - "isManaged":{ - "type": "boolean" + "isManaged": { + "type": "boolean" + } + }, + "relations": { + "address": { + "type": "belongsTo", + "model": "Address", + "foreignKey": "addressFk" } }, "acls": [ @@ -34,5 +41,11 @@ "permission": "ALLOW" } ], - "scope" : {"where": {"isForTicket": {"neq": 0}}} -} + "scope": { + "where": { + "isForTicket": { + "neq": 0 + } + } + } +} \ No newline at end of file diff --git a/db/versions/11081-wheatRaphis/00-firstScript.sql b/db/versions/11081-wheatRaphis/00-firstScript.sql new file mode 100644 index 000000000..70bbaabdb --- /dev/null +++ b/db/versions/11081-wheatRaphis/00-firstScript.sql @@ -0,0 +1,8 @@ +-- Place your SQL code here + +USE vn; + +ALTER TABLE vn.roadmap ADD kmStart mediumint(9) DEFAULT NULL NULL; +ALTER TABLE vn.roadmap ADD kmEnd mediumint(9) DEFAULT NULL NULL; +ALTER TABLE vn.roadmap ADD started DATETIME NULL; +ALTER TABLE vn.roadmap ADD finished DATETIME NULL; diff --git a/modules/route/back/models/roadmap.json b/modules/route/back/models/roadmap.json index 01572d718..ac6cdae9f 100644 --- a/modules/route/back/models/roadmap.json +++ b/modules/route/back/models/roadmap.json @@ -3,7 +3,7 @@ "base": "VnModel", "options": { "mysql": { - "table": "roadmap" + "table": "roadmap" } }, "properties": { @@ -43,8 +43,8 @@ "type": "string" } }, - "relations": { - "worker": { + "relations": { + "worker": { "type": "belongsTo", "model": "Worker", "foreignKey": "id" @@ -57,7 +57,7 @@ "roadmapStop": { "type": "hasMany", "model": "RoadmapStop", - "foreignKey": "roadmapFk" + "foreignKey": "roadMapFk" } - } -} + } +} \ No newline at end of file From 882d5bf036c731a2b74888fcee367d8a554299ff Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 3 Jun 2024 18:39:11 +0200 Subject: [PATCH 014/173] feat: roadMap refs #7195 --- .../roadmapStop/getPalletMatchState.js | 63 +++++++++++++++++++ .../specs/getPalletMatchState.spec.js | 12 ++++ modules/route/back/models/roadmap.json | 12 ++++ modules/route/back/models/roadmapStop.js | 3 + 4 files changed, 90 insertions(+) create mode 100644 modules/route/back/methods/roadmapStop/getPalletMatchState.js create mode 100644 modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js create mode 100644 modules/route/back/models/roadmapStop.js diff --git a/modules/route/back/methods/roadmapStop/getPalletMatchState.js b/modules/route/back/methods/roadmapStop/getPalletMatchState.js new file mode 100644 index 000000000..efed64327 --- /dev/null +++ b/modules/route/back/methods/roadmapStop/getPalletMatchState.js @@ -0,0 +1,63 @@ +module.exports = Self => { + Self.remoteMethod('getPalletMatchState', { + description: 'Get pallet', + accessType: 'WRITE', + accepts: [{ + arg: 'roadMapStopFk', + type: 'number', + required: true, + description: 'The roadmapFk id' + }, + { + arg: 'state', + type: 'string', + required: true, + description: 'State code' + }], + returns: { + type: 'object', + root: true + }, + http: { + path: `/getPalletMatchState`, + verb: 'GET' + } + }); + + Self.getPalletMatchState = async(roadMapStopFk, state, options) => { + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const result = await Self.rawSql(` + WITH tPallet AS( + SELECT ep.truckFk roadMapStop,ep.id pallet, e.id expedition, e.stateTypeFk + FROM vn.expeditionPallet ep + JOIN vn.expeditionScan es ON es.palletFk = ep.id + JOIN expedition e ON e.id = es.expeditionFk + WHERE ep.truckFk = ? + ),totalPalletExpedition AS( + SELECT t.*, COUNT(expedition) totalPalletExpedition + FROM tPallet t + GROUP BY expedition + ),totalPalletExpeditionCode AS( + SELECT t.*, COUNT(expedition) totalPalletExpeditionCode + FROM tPallet t + JOIN vn.expeditionStateType est ON est.id = t.stateTypeFk + WHERE code = ? + GROUP BY expedition + ) + SELECT t.roadMapStop, + t.pallet, + IF (tpe.totalPalletExpedition = tpec.totalPalletExpeditionCode, 'TRUE', 'FALSE') hasMatchStateCode + FROM tPallet t + LEFT JOIN totalPalletExpedition tpe ON tpe.expedition = t.expedition + LEFT JOIN totalPalletExpeditionCode tpec ON tpec.expedition = t.expedition + GROUP BY t.pallet;`, + [roadMapStopFk, state], + myOptions); + + return result; + }; +}; diff --git a/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js b/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js new file mode 100644 index 000000000..ac782561a --- /dev/null +++ b/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js @@ -0,0 +1,12 @@ + +const {models} = require('vn-loopback/server/server'); + +describe('roadMapStop getPalletMatchState()', () => { + fit('should return list of pallet with true or false if state is matched', async() => { + const roadmapStopFk = 1; + const state = 'ON DELIVERY'; + const result = await models.RoadmapStop.getPalletMatchState(roadmapStopFk, state); + + expect(result[0].hasMatchStateCode).toBe('TRUE'); + }); +}); diff --git a/modules/route/back/models/roadmap.json b/modules/route/back/models/roadmap.json index ac6cdae9f..5321af7c3 100644 --- a/modules/route/back/models/roadmap.json +++ b/modules/route/back/models/roadmap.json @@ -41,6 +41,18 @@ }, "driverName": { "type": "string" + }, + "kmStart": { + "type": "number" + }, + "kmEnd": { + "type": "number" + }, + "started": { + "type": "date" + }, + "finished": { + "type": "date" } }, "relations": { diff --git a/modules/route/back/models/roadmapStop.js b/modules/route/back/models/roadmapStop.js new file mode 100644 index 000000000..9e286776d --- /dev/null +++ b/modules/route/back/models/roadmapStop.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/roadmapStop/getPalletMatchState')(Self); +}; From 1c6e881273bb3997c572ea1f8f92fe88d033334e Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 6 Jun 2024 11:45:09 +0200 Subject: [PATCH 015/173] feat: refs #7544 crear evento claim_changeState --- db/routines/vn/events/claim_changeState.sql | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 db/routines/vn/events/claim_changeState.sql diff --git a/db/routines/vn/events/claim_changeState.sql b/db/routines/vn/events/claim_changeState.sql new file mode 100644 index 000000000..c9e4c3cc5 --- /dev/null +++ b/db/routines/vn/events/claim_changeState.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`claim_changeState` + ON SCHEDULE EVERY 1 DAY + STARTS '2024-06-06 07:52:46.000' + ON COMPLETION PRESERVE + ENABLE +DO BEGIN + + DECLARE vClaimStete INT; + + SELECT id INTO vClaimStete + FROM claimState cs + WHERE cs.code = 'canceled' + + UPDATE claim c + JOIN claimState cs ON cs.id = c.claimStateFk + SET c.claimStateFk = vClaimStete + WHERE c.created < util.VN_CURDATE() - INTERVAL 2 MONTH + AND cs.code IN('incomplete','coming','waiting','out') + +END$$ +DELIMITER ; From ef50d493f18602f9c37fddf05ee2e357404f8182 Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 6 Jun 2024 11:54:39 +0200 Subject: [PATCH 016/173] feat: refs #7544 --- db/routines/vn/events/claim_changeState.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/events/claim_changeState.sql b/db/routines/vn/events/claim_changeState.sql index c9e4c3cc5..790ef0c34 100644 --- a/db/routines/vn/events/claim_changeState.sql +++ b/db/routines/vn/events/claim_changeState.sql @@ -10,13 +10,13 @@ DO BEGIN SELECT id INTO vClaimStete FROM claimState cs - WHERE cs.code = 'canceled' + WHERE cs.code = 'canceled'; UPDATE claim c JOIN claimState cs ON cs.id = c.claimStateFk SET c.claimStateFk = vClaimStete WHERE c.created < util.VN_CURDATE() - INTERVAL 2 MONTH - AND cs.code IN('incomplete','coming','waiting','out') + AND cs.code IN('incomplete','coming','waiting','out'); END$$ DELIMITER ; From f0ad012835aa14e67f0e48fc7f04446653dc5288 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 11 Jun 2024 09:39:06 +0200 Subject: [PATCH 018/173] refactor: refs #6436 first wave --- .../collection/spec/setSaleQuantity.spec.js | 14 ++-------- .../specs/getStarredModules.spec.js | 22 +++++----------- .../starred-module/specs/setPosition.spec.js | 24 +++++------------ .../specs/toggleStarredModule.spec.js | 26 ++++++------------- db/.pullinfo.json | 2 +- .../methods/vn-model/specs/crud.spec.js | 14 ++-------- .../vn-model/specs/rewriteDbError.spec.js | 14 ++-------- .../entry/specs/editLatestBuys.spec.js | 15 ++--------- .../invoice-in-due-day/specs/new.spec.js | 9 ++----- .../back/models/specs/supplier.spec.js | 15 ++--------- .../travel/specs/createThermograph.spec.js | 14 ++-------- .../back/methods/worker/specs/new.spec.js | 15 ++--------- 12 files changed, 39 insertions(+), 145 deletions(-) diff --git a/back/methods/collection/spec/setSaleQuantity.spec.js b/back/methods/collection/spec/setSaleQuantity.spec.js index b563f5b19..7abcda36b 100644 --- a/back/methods/collection/spec/setSaleQuantity.spec.js +++ b/back/methods/collection/spec/setSaleQuantity.spec.js @@ -1,19 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('setSaleQuantity()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should change quantity sale', async() => { diff --git a/back/methods/starred-module/specs/getStarredModules.spec.js b/back/methods/starred-module/specs/getStarredModules.spec.js index bf9bd1d73..25b4989fa 100644 --- a/back/methods/starred-module/specs/getStarredModules.spec.js +++ b/back/methods/starred-module/specs/getStarredModules.spec.js @@ -1,22 +1,14 @@ const {models} = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); +// const LoopBackContext = require('loopback-context'); describe('getStarredModules()', () => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - const ctx = {req: activeCtx}; + const {ctx} = beforeAll; - beforeEach(() => { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - }); + // beforeEach(() => { + // spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + // active: ctx + // }); + // }); it(`should return the starred modules for a given user`, async() => { const newStarred = await models.StarredModule.create({workerFk: 9, moduleFk: 'customer', position: 1}); diff --git a/back/methods/starred-module/specs/setPosition.spec.js b/back/methods/starred-module/specs/setPosition.spec.js index a428fcf22..61b99440e 100644 --- a/back/methods/starred-module/specs/setPosition.spec.js +++ b/back/methods/starred-module/specs/setPosition.spec.js @@ -1,24 +1,14 @@ const {models} = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); +// const LoopBackContext = require('loopback-context'); describe('setPosition()', () => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - const ctx = { - req: activeCtx - }; + const {ctx} = beforeAll; - beforeEach(() => { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - }); + // beforeEach(() => { + // spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + // active: activeCtx + // }); + // }); it('should increase the orders module position by replacing it with clients and vice versa', async() => { const tx = await models.StarredModule.beginTransaction({}); diff --git a/back/methods/starred-module/specs/toggleStarredModule.spec.js b/back/methods/starred-module/specs/toggleStarredModule.spec.js index 848c1475a..10dd0492c 100644 --- a/back/methods/starred-module/specs/toggleStarredModule.spec.js +++ b/back/methods/starred-module/specs/toggleStarredModule.spec.js @@ -1,24 +1,14 @@ const {models} = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); +// const LoopBackContext = require('loopback-context'); describe('toggleStarredModule()', () => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - const ctx = { - req: activeCtx - }; + const {ctx} = beforeAll; - beforeEach(() => { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - }); + // beforeEach(() => { + // spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + // active: activeCtx + // }); + // }); it('should create a new starred module and then remove it by calling the method again with same args', async() => { const starredModule = await models.StarredModule.toggleStarredModule(ctx, 'order'); @@ -26,7 +16,7 @@ describe('toggleStarredModule()', () => { expect(starredModules.length).toEqual(1); expect(starredModule.moduleFk).toEqual('order'); - expect(starredModule.workerFk).toEqual(activeCtx.accessToken.userId); + expect(starredModule.workerFk).toEqual(ctx.req.accessToken.userId); expect(starredModule.position).toEqual(starredModules.length); await models.StarredModule.toggleStarredModule(ctx, 'order'); diff --git a/db/.pullinfo.json b/db/.pullinfo.json index f4afbc5fb..0defed845 100644 --- a/db/.pullinfo.json +++ b/db/.pullinfo.json @@ -9,7 +9,7 @@ }, "vn": { "view": { - "expeditionPallet_Print": "288cbd6e8289df083ed5eb1a2c808f7a82ba4c90c8ad9781104808a7a54471fb" + "expeditionPallet_Print": "06613719475fcdba8309607c38cc78efc2e348cca7bc96b48dc3ae3c12426f54" } } } diff --git a/loopback/common/methods/vn-model/specs/crud.spec.js b/loopback/common/methods/vn-model/specs/crud.spec.js index 56af72bd9..d120db92a 100644 --- a/loopback/common/methods/vn-model/specs/crud.spec.js +++ b/loopback/common/methods/vn-model/specs/crud.spec.js @@ -1,19 +1,9 @@ const app = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Model crud()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); let insertId; const barcodeModel = app.models.ItemBarcode; diff --git a/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js b/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js index a3dba14d7..e3c24e74a 100644 --- a/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js +++ b/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js @@ -1,19 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Model rewriteDbError()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should extend rewriteDbError properties to any model passed', () => { diff --git a/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js b/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js index 885171ed5..bff758eea 100644 --- a/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js +++ b/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js @@ -1,20 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Buy editLatestsBuys()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should change the value of a given column for the selected buys', async() => { diff --git a/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js b/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js index f21dad9f2..02a43d4af 100644 --- a/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js @@ -1,14 +1,9 @@ -const LoopBackContext = require('loopback-context'); const models = require('vn-loopback/server/server').models; +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('invoiceInDueDay new()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should correctly create a new due day', async() => { diff --git a/modules/supplier/back/models/specs/supplier.spec.js b/modules/supplier/back/models/specs/supplier.spec.js index 05d78240d..2c0d1910f 100644 --- a/modules/supplier/back/models/specs/supplier.spec.js +++ b/modules/supplier/back/models/specs/supplier.spec.js @@ -1,5 +1,5 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('loopback model Supplier', () => { let supplierOne; @@ -8,18 +8,7 @@ describe('loopback model Supplier', () => { beforeAll(async() => { supplierOne = await models.Supplier.findById(1); supplierTwo = await models.Supplier.findById(442); - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); describe('payMethodFk', () => { diff --git a/modules/travel/back/methods/travel/specs/createThermograph.spec.js b/modules/travel/back/methods/travel/specs/createThermograph.spec.js index e812eae70..9c93d6d52 100644 --- a/modules/travel/back/methods/travel/specs/createThermograph.spec.js +++ b/modules/travel/back/methods/travel/specs/createThermograph.spec.js @@ -1,19 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Travel createThermograph()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); const travelId = 3; const currentUserId = 1102; diff --git a/modules/worker/back/methods/worker/specs/new.spec.js b/modules/worker/back/methods/worker/specs/new.spec.js index 66959e0a7..186e003cf 100644 --- a/modules/worker/back/methods/worker/specs/new.spec.js +++ b/modules/worker/back/methods/worker/specs/new.spec.js @@ -1,20 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Worker new', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); const employeeId = 1; From b3fa8697574edb4e18be1237ec79181808258bea Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 11 Jun 2024 10:00:30 +0200 Subject: [PATCH 019/173] refactor: refs #6436 second wave --- .../specs/getStarredModules.spec.js | 7 ------ .../starred-module/specs/setPosition.spec.js | 7 ------ .../specs/toggleStarredModule.spec.js | 7 ------ .../back/methods/claim/specs/filter.spec.js | 10 +------- .../claim/specs/regularizeClaim.spec.js | 14 ++--------- .../methods/claim/specs/updateClaim.spec.js | 15 ++---------- .../claim/specs/updateClaimAction.spec.js | 14 ++--------- .../agency-term/specs/createInvoiceIn.spec.js | 17 ++------------ .../back/methods/route/specs/clone.spec.js | 15 ++---------- .../methods/route/specs/guessPriority.spec.js | 23 ++++++++----------- .../route/specs/updateWorkCenter.spec.js | 14 ++--------- 11 files changed, 23 insertions(+), 120 deletions(-) diff --git a/back/methods/starred-module/specs/getStarredModules.spec.js b/back/methods/starred-module/specs/getStarredModules.spec.js index 25b4989fa..cce353f93 100644 --- a/back/methods/starred-module/specs/getStarredModules.spec.js +++ b/back/methods/starred-module/specs/getStarredModules.spec.js @@ -1,15 +1,8 @@ const {models} = require('vn-loopback/server/server'); -// const LoopBackContext = require('loopback-context'); describe('getStarredModules()', () => { const {ctx} = beforeAll; - // beforeEach(() => { - // spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - // active: ctx - // }); - // }); - it(`should return the starred modules for a given user`, async() => { const newStarred = await models.StarredModule.create({workerFk: 9, moduleFk: 'customer', position: 1}); const starredModules = await models.StarredModule.getStarredModules(ctx); diff --git a/back/methods/starred-module/specs/setPosition.spec.js b/back/methods/starred-module/specs/setPosition.spec.js index 61b99440e..495bc8384 100644 --- a/back/methods/starred-module/specs/setPosition.spec.js +++ b/back/methods/starred-module/specs/setPosition.spec.js @@ -1,15 +1,8 @@ const {models} = require('vn-loopback/server/server'); -// const LoopBackContext = require('loopback-context'); describe('setPosition()', () => { const {ctx} = beforeAll; - // beforeEach(() => { - // spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - // active: activeCtx - // }); - // }); - it('should increase the orders module position by replacing it with clients and vice versa', async() => { const tx = await models.StarredModule.beginTransaction({}); diff --git a/back/methods/starred-module/specs/toggleStarredModule.spec.js b/back/methods/starred-module/specs/toggleStarredModule.spec.js index 10dd0492c..d5a5c8ab3 100644 --- a/back/methods/starred-module/specs/toggleStarredModule.spec.js +++ b/back/methods/starred-module/specs/toggleStarredModule.spec.js @@ -1,15 +1,8 @@ const {models} = require('vn-loopback/server/server'); -// const LoopBackContext = require('loopback-context'); describe('toggleStarredModule()', () => { const {ctx} = beforeAll; - // beforeEach(() => { - // spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - // active: activeCtx - // }); - // }); - it('should create a new starred module and then remove it by calling the method again with same args', async() => { const starredModule = await models.StarredModule.toggleStarredModule(ctx, 'order'); let starredModules = await models.StarredModule.getStarredModules(ctx); diff --git a/modules/claim/back/methods/claim/specs/filter.spec.js b/modules/claim/back/methods/claim/specs/filter.spec.js index 872f49aa3..b55e554b9 100644 --- a/modules/claim/back/methods/claim/specs/filter.spec.js +++ b/modules/claim/back/methods/claim/specs/filter.spec.js @@ -2,15 +2,7 @@ const app = require('vn-loopback/server/server'); const models = require('vn-loopback/server/server').models; describe('claim filter()', () => { - let ctx; - beforeEach(() => { - ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - } - }; - }); + const {ctx} = beforeAll; it('should return 1 result filtering by id', async() => { const tx = await app.models.Claim.beginTransaction({}); diff --git a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js index 95c356374..224adc997 100644 --- a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js @@ -1,5 +1,5 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('claim regularizeClaim()', () => { const userId = 18; @@ -41,17 +41,7 @@ describe('claim regularizeClaim()', () => { } beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should send a chat message with value "Trash" and then change claim state to resolved', async() => { diff --git a/modules/claim/back/methods/claim/specs/updateClaim.spec.js b/modules/claim/back/methods/claim/specs/updateClaim.spec.js index b7725e7f8..5c8f08132 100644 --- a/modules/claim/back/methods/claim/specs/updateClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/updateClaim.spec.js @@ -1,22 +1,11 @@ const app = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); const i18n = require('i18n'); describe('Update Claim', () => { let url; let claimStatesMap = {}; beforeAll(async() => { - url = await app.models.Url.getUrl(); - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); const claimStates = await app.models.ClaimState.find(); claimStatesMap = claimStates.reduce((acc, state) => ({...acc, [state.code]: state.id}), {}); }); diff --git a/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js b/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js index 99436fed6..c939f59de 100644 --- a/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js +++ b/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js @@ -1,19 +1,9 @@ const app = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Update Claim', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); const newDate = Date.vnNew(); const original = { diff --git a/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js b/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js index d3a0755ef..a625605d2 100644 --- a/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js +++ b/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js @@ -1,21 +1,8 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +// const LoopBackContext = require('loopback-context'); describe('AgencyTerm createInvoiceIn()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; - beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - }); + const {ctx} = beforeAll; const rows = [ { routeFk: 2, diff --git a/modules/route/back/methods/route/specs/clone.spec.js b/modules/route/back/methods/route/specs/clone.spec.js index 496ae1c89..98240488c 100644 --- a/modules/route/back/methods/route/specs/clone.spec.js +++ b/modules/route/back/methods/route/specs/clone.spec.js @@ -1,20 +1,9 @@ const app = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('route clone()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); const createdDate = Date.vnNew(); diff --git a/modules/route/back/methods/route/specs/guessPriority.spec.js b/modules/route/back/methods/route/specs/guessPriority.spec.js index 902647ba1..d73db6379 100644 --- a/modules/route/back/methods/route/specs/guessPriority.spec.js +++ b/modules/route/back/methods/route/specs/guessPriority.spec.js @@ -1,20 +1,17 @@ const app = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); +// const LoopBackContext = require('loopback-context'); describe('route guessPriority()', () => { const targetRouteId = 7; let routeTicketsToRestore; - const activeCtx = { - accessToken: {userId: 9}, - __: () => {} - }; + const {ctx} = beforeAll; - beforeAll(() => { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - }); + // beforeAll(() => { + // spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + // active: activeCtx + // }); + // }); afterAll(async() => { let restoreFixtures = []; @@ -25,9 +22,9 @@ describe('route guessPriority()', () => { }); it('should call guessPriority() then check all tickets in that route have their priorities defined', async() => { - const ctx = { - req: activeCtx - }; + // const ctx = { + // req: activeCtx + // }; routeTicketsToRestore = await app.models.Ticket.find({where: {routeFk: targetRouteId}}); await app.models.Route.guessPriority(ctx, targetRouteId); diff --git a/modules/route/back/methods/route/specs/updateWorkCenter.spec.js b/modules/route/back/methods/route/specs/updateWorkCenter.spec.js index a1c716299..315460d4a 100644 --- a/modules/route/back/methods/route/specs/updateWorkCenter.spec.js +++ b/modules/route/back/methods/route/specs/updateWorkCenter.spec.js @@ -1,19 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('route updateWorkCenter()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); const routeId = 1; From 093eaeb4751a150f2414ced30c93c18bf02bae83 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 11 Jun 2024 10:45:46 +0200 Subject: [PATCH 020/173] refactor: refs #6436 third wave --- .../client/specs/addressesPropagateRe.spec.js | 15 ++------------- .../methods/client/specs/createAddress.spec.js | 15 ++------------- .../methods/client/specs/updateAddress.spec.js | 15 ++------------- modules/client/back/models/specs/address.spec.js | 15 ++------------- .../fixed-price/specs/upsertFixedPrice.spec.js | 14 ++------------ .../item/back/methods/item/specs/clone.spec.js | 14 ++------------ .../back/methods/item/specs/getBalance.spec.js | 7 ++----- modules/item/back/methods/item/specs/new.spec.js | 15 ++------------- .../back/methods/item/specs/updateTaxes.spec.js | 14 ++------------ .../zone/back/methods/zone/specs/clone.spec.js | 14 ++------------ .../back/methods/zone/specs/exclusionGeo.spec.js | 14 ++------------ .../methods/zone/specs/toggleIsIncluded.spec.js | 15 +++------------ 12 files changed, 25 insertions(+), 142 deletions(-) diff --git a/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js b/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js index 74d80b964..ec4ebe471 100644 --- a/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js +++ b/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js @@ -1,20 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Client addressesPropagateRe', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should propagate the isEqualizated on both addresses of Mr Wayne and set hasToInvoiceByAddress to false', async() => { diff --git a/modules/client/back/methods/client/specs/createAddress.spec.js b/modules/client/back/methods/client/specs/createAddress.spec.js index ae179cf6c..0556ce2cf 100644 --- a/modules/client/back/methods/client/specs/createAddress.spec.js +++ b/modules/client/back/methods/client/specs/createAddress.spec.js @@ -1,5 +1,5 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Address createAddress', () => { const clientFk = 1101; @@ -8,18 +8,7 @@ describe('Address createAddress', () => { const customAgentOneId = 1; beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should throw a non uee member error if no incoterms is defined', async() => { diff --git a/modules/client/back/methods/client/specs/updateAddress.spec.js b/modules/client/back/methods/client/specs/updateAddress.spec.js index 6f02323c5..dd5142af0 100644 --- a/modules/client/back/methods/client/specs/updateAddress.spec.js +++ b/modules/client/back/methods/client/specs/updateAddress.spec.js @@ -1,5 +1,5 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Address updateAddress', () => { const clientId = 1101; @@ -15,18 +15,7 @@ describe('Address updateAddress', () => { }; beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should throw the non uee member error if no incoterms is defined', async() => { diff --git a/modules/client/back/models/specs/address.spec.js b/modules/client/back/models/specs/address.spec.js index f0b421d35..4baa1bdca 100644 --- a/modules/client/back/models/specs/address.spec.js +++ b/modules/client/back/models/specs/address.spec.js @@ -1,23 +1,12 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('loopback model address', () => { let createdAddressId; const clientId = 1101; - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - beforeAll(() => { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); afterAll(async() => { diff --git a/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js b/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js index 823406500..36a15849c 100644 --- a/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js +++ b/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js @@ -1,5 +1,5 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('upsertFixedPrice()', () => { const now = Date.vnNew(); @@ -8,17 +8,7 @@ describe('upsertFixedPrice()', () => { beforeAll(async() => { originalFixedPrice = await models.FixedPrice.findById(fixedPriceId); - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it(`should toggle the hasMinPrice boolean if there's a minPrice and update the rest of the data`, async() => { diff --git a/modules/item/back/methods/item/specs/clone.spec.js b/modules/item/back/methods/item/specs/clone.spec.js index 01210677e..1a479cd84 100644 --- a/modules/item/back/methods/item/specs/clone.spec.js +++ b/modules/item/back/methods/item/specs/clone.spec.js @@ -1,20 +1,10 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('item clone()', () => { let nextItemId; beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); beforeEach(async() => { diff --git a/modules/item/back/methods/item/specs/getBalance.spec.js b/modules/item/back/methods/item/specs/getBalance.spec.js index 728b5f33e..d1bb65b75 100644 --- a/modules/item/back/methods/item/specs/getBalance.spec.js +++ b/modules/item/back/methods/item/specs/getBalance.spec.js @@ -2,17 +2,14 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); describe('item getBalance()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; it('should return the balance lines of a client type loses in which one has highlighted true', async() => { const tx = await models.Item.beginTransaction({}); const options = {transaction: tx}; try { - const activeCtx = { - accessToken: {userId: 9}, - }; spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx + active: ctx }); const losesClientId = 1111; const ticket = await models.Ticket.findById(7, null, options); diff --git a/modules/item/back/methods/item/specs/new.spec.js b/modules/item/back/methods/item/specs/new.spec.js index 2ffaf87a5..7a3612ebc 100644 --- a/modules/item/back/methods/item/specs/new.spec.js +++ b/modules/item/back/methods/item/specs/new.spec.js @@ -1,20 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('item new()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should create a new item, adding the name as a tag', async() => { diff --git a/modules/item/back/methods/item/specs/updateTaxes.spec.js b/modules/item/back/methods/item/specs/updateTaxes.spec.js index 793e43de8..49f95c1ed 100644 --- a/modules/item/back/methods/item/specs/updateTaxes.spec.js +++ b/modules/item/back/methods/item/specs/updateTaxes.spec.js @@ -1,19 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('item updateTaxes()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should throw an error if the taxClassFk is blank', async() => { diff --git a/modules/zone/back/methods/zone/specs/clone.spec.js b/modules/zone/back/methods/zone/specs/clone.spec.js index 1b7393912..465abdc9c 100644 --- a/modules/zone/back/methods/zone/specs/clone.spec.js +++ b/modules/zone/back/methods/zone/specs/clone.spec.js @@ -1,19 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('agency clone()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should clone a zone', async() => { diff --git a/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js b/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js index fbe96fc5f..746be502f 100644 --- a/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js +++ b/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js @@ -1,19 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('zone exclusionGeo()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); const zoneId = 1; const today = Date.vnNew(); diff --git a/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js b/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js index 2da176330..39986498e 100644 --- a/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js +++ b/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js @@ -1,18 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); + describe('zone toggleIsIncluded()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should return the created location with isIncluded true', async() => { From 96366c475ad4b465108eca76401ac16e664ebf4c Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 11 Jun 2024 10:48:28 +0200 Subject: [PATCH 021/173] fix: refs 6449 update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fc8cfc13..68868d17a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - feat: refs #7438 Added volume to item_valuateInventory by:guillermo - feat: refs #7438 Requested changes and little changes by:guillermo - refs #6281 feat:buyFk in itemShelving by:sergiodt +- feat: refs #6449 item ID is displayed in the sale line by:jorgep ### Changed 📦 @@ -90,7 +91,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - (Worker -> time-control) Corrección de errores - (InvoiceOut -> Crear factura) Cuando falla al crear una factura, se devuelve un error -- (Ticket -> Logs) Ahora se muestra el id del item de la línea de venta - (Worker -> Ver albarán) Ya no aparece la página en blanco ### Changed From bd45352215ef383240669ccbfc4c16a6b5cf789b Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 11 Jun 2024 12:02:15 +0200 Subject: [PATCH 022/173] refactor: refs #6436 fourth wave --- .../item/back/methods/item/specs/new.spec.js | 5 +--- .../back/methods/tag/specs/onSubmit.spec.js | 14 ++--------- .../specs/deleteExpeditions.spec.js | 13 ++--------- .../expedition/specs/moveExpeditions.spec.js | 14 ++--------- .../back/methods/sale/specs/canEdit.spec.js | 14 ++--------- .../methods/sale/specs/deleteSales.spec.js | 14 ++--------- .../back/methods/sale/specs/reserve.spec.js | 14 ++--------- .../methods/sale/specs/updateConcept.spec.js | 14 ++--------- .../ticket-request/specs/confirm.spec.js | 23 ++----------------- .../ticket/specs/componentUpdate.spec.js | 14 ++--------- .../back/methods/ticket/specs/merge.spec.js | 14 ++--------- .../ticket/specs/updateDiscount.spec.js | 14 ++--------- .../models/specs/ticket-packaging.spec.js | 14 ++--------- 13 files changed, 25 insertions(+), 156 deletions(-) diff --git a/modules/item/back/methods/item/specs/new.spec.js b/modules/item/back/methods/item/specs/new.spec.js index 7a3612ebc..5611b28ab 100644 --- a/modules/item/back/methods/item/specs/new.spec.js +++ b/modules/item/back/methods/item/specs/new.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('item new()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + const {ctx} = beforeAll; it('should create a new item, adding the name as a tag', async() => { const tx = await models.Item.beginTransaction({}); diff --git a/modules/item/back/methods/tag/specs/onSubmit.spec.js b/modules/item/back/methods/tag/specs/onSubmit.spec.js index 1e96d9e81..1830aafcf 100644 --- a/modules/item/back/methods/tag/specs/onSubmit.spec.js +++ b/modules/item/back/methods/tag/specs/onSubmit.spec.js @@ -1,19 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('tag onSubmit()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should delete a tag', async() => { diff --git a/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js index bf8bafe34..2c34c994b 100644 --- a/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js +++ b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js @@ -1,18 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket deleteExpeditions()', () => { - let ctx; beforeAll(async() => { - ctx = { - accessToken: {userId: 9}, - req: { - headers: {origin: 'http://localhost'} - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: ctx - }); + mockLoopBackContext(); }); it('should delete the selected expeditions', async() => { diff --git a/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js index 5f211543e..27b20bcd2 100644 --- a/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js +++ b/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js @@ -1,19 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket moveExpeditions()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should move the selected expeditions to new ticket', async() => { diff --git a/modules/ticket/back/methods/sale/specs/canEdit.spec.js b/modules/ticket/back/methods/sale/specs/canEdit.spec.js index 200ea24cc..3185b01e7 100644 --- a/modules/ticket/back/methods/sale/specs/canEdit.spec.js +++ b/modules/ticket/back/methods/sale/specs/canEdit.spec.js @@ -1,20 +1,10 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale canEdit()', () => { const employeeId = 1; beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); describe('sale not exists', () => { diff --git a/modules/ticket/back/methods/sale/specs/deleteSales.spec.js b/modules/ticket/back/methods/sale/specs/deleteSales.spec.js index 3d3e06e22..8d0e4bd4e 100644 --- a/modules/ticket/back/methods/sale/specs/deleteSales.spec.js +++ b/modules/ticket/back/methods/sale/specs/deleteSales.spec.js @@ -1,19 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale deleteSales()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should throw an error if the ticket of the given sales is not editable', async() => { diff --git a/modules/ticket/back/methods/sale/specs/reserve.spec.js b/modules/ticket/back/methods/sale/specs/reserve.spec.js index 7ba5999b3..37ebf10ab 100644 --- a/modules/ticket/back/methods/sale/specs/reserve.spec.js +++ b/modules/ticket/back/methods/sale/specs/reserve.spec.js @@ -1,5 +1,5 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale reserve()', () => { const ctx = { @@ -11,17 +11,7 @@ describe('sale reserve()', () => { }; beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should throw an error if the ticket can not be modified', async() => { diff --git a/modules/ticket/back/methods/sale/specs/updateConcept.spec.js b/modules/ticket/back/methods/sale/specs/updateConcept.spec.js index 1b42e7140..0610e9eab 100644 --- a/modules/ticket/back/methods/sale/specs/updateConcept.spec.js +++ b/modules/ticket/back/methods/sale/specs/updateConcept.spec.js @@ -1,19 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale updateConcept()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); const ctx = {req: {accessToken: {userId: 9}}}; diff --git a/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js b/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js index 668a991f4..8a1130e7d 100644 --- a/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js +++ b/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js @@ -1,29 +1,10 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket-request confirm()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); - let ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - } - }; - ctx.req.__ = value => { - return value; - }; it(`should throw an error if the item doesn't exist`, async() => { const tx = await models.TicketRequest.beginTransaction({}); diff --git a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js index 8abb1a4a1..b138b88ea 100644 --- a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js +++ b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js @@ -1,5 +1,5 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket componentUpdate()', () => { const userID = 1101; @@ -17,17 +17,7 @@ describe('ticket componentUpdate()', () => { let componentValue; beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); const deliveryComponenet = await models.Component.findOne({where: {code: 'delivery'}}); deliveryComponentId = deliveryComponenet.id; componentOfSaleSeven = `SELECT value diff --git a/modules/ticket/back/methods/ticket/specs/merge.spec.js b/modules/ticket/back/methods/ticket/specs/merge.spec.js index 646b9739f..702b496af 100644 --- a/modules/ticket/back/methods/ticket/specs/merge.spec.js +++ b/modules/ticket/back/methods/ticket/specs/merge.spec.js @@ -1,5 +1,5 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket merge()', () => { const tickets = { @@ -11,17 +11,7 @@ describe('ticket merge()', () => { }; beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); const ctx = { diff --git a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js index 41de1fd6e..c0c5333ba 100644 --- a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js +++ b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js @@ -1,19 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale updateDiscount()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); const originalSaleId = 8; diff --git a/modules/ticket/back/models/specs/ticket-packaging.spec.js b/modules/ticket/back/models/specs/ticket-packaging.spec.js index 6d59456a3..97a936018 100644 --- a/modules/ticket/back/models/specs/ticket-packaging.spec.js +++ b/modules/ticket/back/models/specs/ticket-packaging.spec.js @@ -1,19 +1,9 @@ const app = require('vn-loopback/server/server'); -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket model TicketTracking', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); let ticketTrackingId; From 665d03f0480601e3aa97d9f915b5cb66d902f015 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 11 Jun 2024 12:35:44 +0200 Subject: [PATCH 023/173] refactor: refs #6436 user-config and some sections tests --- .../user-config/specs/getUserConfig.spec.js | 2 +- .../back/methods/client/specs/getCard.spec.js | 2 +- .../back/methods/client/specs/getDebt.spec.js | 2 +- .../back/methods/client/specs/sendSms.spec.js | 2 +- .../back/methods/client/specs/summary.spec.js | 2 +- .../methods/entry/specs/importBuysPreview.spec.js | 7 ++----- .../back/methods/invoiceOut/specs/book.spec.js | 2 +- .../methods/order-row/specs/addToOrder.spec.js | 2 +- .../order/back/methods/order/specs/filter.spec.js | 6 +----- modules/order/back/methods/order/specs/new.spec.js | 2 +- .../back/methods/order/specs/newFromTicket.spec.js | 2 +- .../specs/addExpeditionState.spec.js | 2 +- .../methods/sale/specs/recalculatePrice.spec.js | 3 +-- .../back/methods/sale/specs/updateConcept.spec.js | 7 +------ .../back/methods/ticket-request/specs/deny.spec.js | 14 ++------------ .../thermograph/specs/createThermograph.spec.js | 2 +- 16 files changed, 18 insertions(+), 41 deletions(-) diff --git a/back/methods/user-config/specs/getUserConfig.spec.js b/back/methods/user-config/specs/getUserConfig.spec.js index 8b510a706..c27018b07 100644 --- a/back/methods/user-config/specs/getUserConfig.spec.js +++ b/back/methods/user-config/specs/getUserConfig.spec.js @@ -1,12 +1,12 @@ const models = require('vn-loopback/server/server').models; describe('userConfig getUserConfig()', () => { + const {ctx} = beforeAll; it(`should return the configuration data of a given user`, async() => { const tx = await models.Item.beginTransaction({}); const options = {transaction: tx}; try { - const ctx = {req: {accessToken: {userId: 9}}}; const result = await models.UserConfig.getUserConfig(ctx, options); expect(result.warehouseFk).toEqual(1); diff --git a/modules/client/back/methods/client/specs/getCard.spec.js b/modules/client/back/methods/client/specs/getCard.spec.js index 962e0a2d4..1082b4009 100644 --- a/modules/client/back/methods/client/specs/getCard.spec.js +++ b/modules/client/back/methods/client/specs/getCard.spec.js @@ -1,11 +1,11 @@ const models = require('vn-loopback/server/server').models; describe('Client getCard()', () => { + const {ctx} = beforeAll; it('should receive a formated card of Bruce Wayne', async() => { const tx = await models.Client.beginTransaction({}); try { - const ctx = {req: {accessToken: {userId: 9}}}; const options = {transaction: tx}; const id = 1101; diff --git a/modules/client/back/methods/client/specs/getDebt.spec.js b/modules/client/back/methods/client/specs/getDebt.spec.js index b3b5286c0..7fc76ee94 100644 --- a/modules/client/back/methods/client/specs/getDebt.spec.js +++ b/modules/client/back/methods/client/specs/getDebt.spec.js @@ -1,9 +1,9 @@ const models = require('vn-loopback/server/server').models; describe('client getDebt()', () => { + const {ctx} = beforeAll; it('should return the client debt', async() => { const tx = await models.Client.beginTransaction({}); - const ctx = {req: {accessToken: {userId: 9}}}; try { const options = {transaction: tx}; diff --git a/modules/client/back/methods/client/specs/sendSms.spec.js b/modules/client/back/methods/client/specs/sendSms.spec.js index df680c55f..b6cb55062 100644 --- a/modules/client/back/methods/client/specs/sendSms.spec.js +++ b/modules/client/back/methods/client/specs/sendSms.spec.js @@ -1,12 +1,12 @@ const models = require('vn-loopback/server/server').models; describe('client sendSms()', () => { + const {ctx} = beforeAll; it('should now send a message and log it', async() => { const tx = await models.Client.beginTransaction({}); try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}}; const id = 1101; const destination = 222222222; const message = 'this is the message created in a test'; diff --git a/modules/client/back/methods/client/specs/summary.spec.js b/modules/client/back/methods/client/specs/summary.spec.js index 227f4c398..d15d183c6 100644 --- a/modules/client/back/methods/client/specs/summary.spec.js +++ b/modules/client/back/methods/client/specs/summary.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('client summary()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; it('should return a summary object containing data', async() => { const clientId = 1101; const tx = await models.Client.beginTransaction({}); diff --git a/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js b/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js index c860e228e..bab46ad59 100644 --- a/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js +++ b/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js @@ -1,13 +1,10 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); -const activeCtx = {accessToken: {userId: 9}}; +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('entry importBuysPreview()', () => { const entryId = 1; beforeAll(async() => { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should return the buys with the calculated packagingFk', async() => { diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js index 3af7542ca..29e21a27c 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('invoiceOut book()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; const invoiceOutId = 5; it('should update the booked property', async() => { diff --git a/modules/order/back/methods/order-row/specs/addToOrder.spec.js b/modules/order/back/methods/order-row/specs/addToOrder.spec.js index 96544a1a9..327c86db0 100644 --- a/modules/order/back/methods/order-row/specs/addToOrder.spec.js +++ b/modules/order/back/methods/order-row/specs/addToOrder.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('order addToOrder()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; const orderId = 8; it('should add a row to a given order', async() => { const tx = await models.Order.beginTransaction({}); diff --git a/modules/order/back/methods/order/specs/filter.spec.js b/modules/order/back/methods/order/specs/filter.spec.js index 68de7fe04..95cb488c8 100644 --- a/modules/order/back/methods/order/specs/filter.spec.js +++ b/modules/order/back/methods/order/specs/filter.spec.js @@ -1,11 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('order filter()', () => { - const ctx = { - req: {accessToken: {userId: 9}}, - args: {}, - params: {} - }; + const {ctx} = beforeAll; it('should call the filter method with a basic search', async() => { const myCtx = Object.assign({}, ctx); diff --git a/modules/order/back/methods/order/specs/new.spec.js b/modules/order/back/methods/order/specs/new.spec.js index c43527f66..6ed1fa4ae 100644 --- a/modules/order/back/methods/order/specs/new.spec.js +++ b/modules/order/back/methods/order/specs/new.spec.js @@ -2,7 +2,7 @@ const models = require('vn-loopback/server/server').models; const UserError = require('vn-loopback/util/user-error'); describe('order new()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; it('should throw an error if the client isnt active', async() => { const tx = await models.Order.beginTransaction({}); diff --git a/modules/order/back/methods/order/specs/newFromTicket.spec.js b/modules/order/back/methods/order/specs/newFromTicket.spec.js index c509552fe..a592877cf 100644 --- a/modules/order/back/methods/order/specs/newFromTicket.spec.js +++ b/modules/order/back/methods/order/specs/newFromTicket.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('order newFromTicket()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; it('should create a new order from an existing ticket', async() => { const tx = await models.Order.beginTransaction({}); diff --git a/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js b/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js index 6c7739006..ce9049a95 100644 --- a/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js +++ b/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('expeditionState addExpeditionState()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; it('should update the expedition states', async() => { const tx = await models.ExpeditionState.beginTransaction({}); try { diff --git a/modules/ticket/back/methods/sale/specs/recalculatePrice.spec.js b/modules/ticket/back/methods/sale/specs/recalculatePrice.spec.js index 0fc68dee7..3c871dd6c 100644 --- a/modules/ticket/back/methods/sale/specs/recalculatePrice.spec.js +++ b/modules/ticket/back/methods/sale/specs/recalculatePrice.spec.js @@ -1,6 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('sale recalculatePrice()', () => { + const {ctx} = beforeAll; it('should update the sale price', async() => { const tx = await models.Sale.beginTransaction({}); const sales = [ @@ -10,7 +11,6 @@ describe('sale recalculatePrice()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}}; const response = await models.Sale.recalculatePrice(ctx, sales, options); expect(response[0].affectedRows).toBeDefined(); @@ -30,7 +30,6 @@ describe('sale recalculatePrice()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}}; const immutableSale = [{id: 1, ticketFk: 1}]; await models.Sale.recalculatePrice(ctx, immutableSale, options); diff --git a/modules/ticket/back/methods/sale/specs/updateConcept.spec.js b/modules/ticket/back/methods/sale/specs/updateConcept.spec.js index 0610e9eab..be6ad77a3 100644 --- a/modules/ticket/back/methods/sale/specs/updateConcept.spec.js +++ b/modules/ticket/back/methods/sale/specs/updateConcept.spec.js @@ -1,12 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale updateConcept()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); - - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; const saleId = 25; it('should throw if ID was undefined', async() => { diff --git a/modules/ticket/back/methods/ticket-request/specs/deny.spec.js b/modules/ticket/back/methods/ticket-request/specs/deny.spec.js index 875a75921..1259f1284 100644 --- a/modules/ticket/back/methods/ticket-request/specs/deny.spec.js +++ b/modules/ticket/back/methods/ticket-request/specs/deny.spec.js @@ -1,19 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket-request deny()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should return the denied ticket request', async() => { diff --git a/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js b/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js index 90855bf81..49eeb86c2 100644 --- a/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js +++ b/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js @@ -5,7 +5,7 @@ describe('Termograph createThermograph()', () => { const model = 'DISPOSABLE'; const temperatureFk = 'COOL'; const warehouseId = 1; - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; it(`should create a thermograph which is saved in both thermograph and travelThermograph`, async() => { const tx = await models.Thermograph.beginTransaction({}); From 9f9063567a957f9442ab64c23b2e0f6be39f032b Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 11 Jun 2024 12:40:07 +0200 Subject: [PATCH 024/173] refactor: refs #7505 item_getVisible refactor --- .../cache/procedures/visible_refresh.sql | 5 +- db/routines/vn/procedures/item_GetVisible.sql | 43 ------------- db/routines/vn/procedures/item_getVisible.sql | 49 ++++++++++++++ .../vn/procedures/multipleInventory.sql | 64 ++++++------------- 4 files changed, 70 insertions(+), 91 deletions(-) delete mode 100644 db/routines/vn/procedures/item_GetVisible.sql create mode 100644 db/routines/vn/procedures/item_getVisible.sql diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index 63b42dfd9..954b8ff23 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -20,11 +20,12 @@ proc: BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible (PRIMARY KEY (item_id)) ENGINE = MEMORY - SELECT item_id, amount stock, amount visible FROM `cache`.stock + SELECT item_id, amount stock, amount visible + FROM `cache`.stock WHERE warehouse_id = v_warehouse; -- Calculamos los movimientos confirmados de hoy - CALL vn.item_GetVisible(v_warehouse, NULL); + CALL vn.item_getVisible(v_warehouse, util.VN_CURDATE(), NULL); DELETE FROM visible WHERE calc_id = v_calc; INSERT INTO visible (calc_id, item_id,visible) diff --git a/db/routines/vn/procedures/item_GetVisible.sql b/db/routines/vn/procedures/item_GetVisible.sql deleted file mode 100644 index ca5e43107..000000000 --- a/db/routines/vn/procedures/item_GetVisible.sql +++ /dev/null @@ -1,43 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_GetVisible`(vWarehouse SMALLINT, vItem INT) -BEGIN - DECLARE vTomorrow DATETIME DEFAULT TIMESTAMPADD(DAY, 1, util.VN_CURDATE()); - - INSERT INTO tmp.itemVisible (item_id, visible) - SELECT item_id, SUM(amount) amount - FROM ( - SELECT i.itemFk AS item_id, quantity AS amount - FROM itemTicketOut i - LEFT JOIN ticketState ts ON ts.ticketFk = i.ticketFk - JOIN state s ON s.id = ts.stateFk - LEFT JOIN (SELECT DISTINCT saleFk - FROM saleTracking st - JOIN state s ON s.id = st.stateFk - WHERE st.created > util.VN_CURDATE() - AND (s.isPicked OR st.isChecked) - ) stPrevious ON `stPrevious`.`saleFk` = i.saleFk - WHERE i.warehouseFk = vWarehouse - AND (vItem IS NULL OR i.itemFk = vItem) - AND (s.isPicked OR i.reserved OR stPrevious.saleFk ) - AND i.shipped >= util.VN_CURDATE() AND i.shipped < vTomorrow - UNION ALL - SELECT iei.itemFk, quantity - FROM itemEntryIn iei - WHERE (iei.isReceived != FALSE /*OR ip.modificationDate > util.VN_CURDATE()*/) - AND iei.landed >= util.VN_CURDATE() AND iei.landed < vTomorrow - AND iei.warehouseInFk = vWarehouse - AND (vItem IS NULL OR iei.itemFk = vItem) - AND iei.isVirtualStock is FALSE - UNION ALL - SELECT itemFk, quantity - FROM itemEntryOut - WHERE isDelivered != FALSE - AND shipped >= util.VN_CURDATE() AND shipped < vTomorrow - AND warehouseOutFk = vWarehouse - AND (vItem IS NULL OR itemFk = vItem) - ) t - GROUP BY item_id - ON DUPLICATE KEY UPDATE - visible = IFNULL(stock,0) + VALUES(visible); -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/item_getVisible.sql b/db/routines/vn/procedures/item_getVisible.sql new file mode 100644 index 000000000..0516b9d06 --- /dev/null +++ b/db/routines/vn/procedures/item_getVisible.sql @@ -0,0 +1,49 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getVisible`( + vWarehouseFk INT, + vDated INT, + vItemFk INT +) +BEGIN + DECLARE vTomorrow DATETIME DEFAULT vDated + INTERVAL 1 DAY; + + INSERT INTO tmp.itemVisible (item_id, visible) + SELECT itemFk, SUM(quantity) + FROM ( + SELECT i.itemFk, i.quantity + FROM itemTicketOut i + LEFT JOIN ticketState ts ON ts.ticketFk = i.ticketFk + JOIN `state` s ON s.id = ts.stateFk + LEFT JOIN ( + SELECT DISTINCT st.saleFk + FROM saleTracking st + JOIN state s ON s.id = st.stateFk + WHERE st.created > vDated + AND (s.isPicked OR st.isChecked) + ) stPrevious ON `stPrevious`.`saleFk` = i.saleFk + WHERE i.warehouseFk = vWarehouseFk + AND (vItemFk IS NULL OR i.itemFk = vItemFk) + AND (s.isPicked OR i.reserved OR stPrevious.saleFk) + AND i.shipped >= vDated AND i.shipped < vTomorrow + UNION ALL + SELECT itemFk, quantity + FROM itemEntryIn + WHERE isReceived + AND landed >= vDated AND landed < vTomorrow + AND warehouseInFk = vWarehouseFk + AND (vItemFk IS NULL OR itemFk = vItemFk) + AND NOT isVirtualStock + UNION ALL + SELECT itemFk, quantity + FROM itemEntryOut + WHERE isDelivered + AND shipped >= vDated + AND shipped < vTomorrow + AND warehouseOutFk = vWarehouseFk + AND (vItemFk IS NULL OR itemFk = vItemFk) + ) t + GROUP BY itemFk + ON DUPLICATE KEY UPDATE + visible = IFNULL(stock, 0) + VALUES(visible); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index 2a28aa9a0..4d5c5d366 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -1,9 +1,9 @@ -DELIMITER $$ +DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`multipleInventory`( vDate DATE, vWarehouseFk TINYINT, vMaxDays TINYINT -) +) proc: BEGIN DECLARE vDateTomorrow DATE DEFAULT vDate + INTERVAL 1 DAY; DECLARE vDateFrom DATE DEFAULT vDate; @@ -78,47 +78,18 @@ proc: BEGIN ai.sd = sub.Subtotal; -- Cálculo del visible - UPDATE tmp.itemInventory ai - JOIN ( - SELECT itemFk Id_Article, SUM(quantity) Subtotal - FROM ( - SELECT s.itemFk, s.quantity - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN warehouse w ON w.id = t.warehouseFk - WHERE t.shipped >= vDate - AND t.shipped < vDateTomorrow - AND (NOT isPicked AND NOT t.isLabeled AND t.refFk IS NULL) - AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk - AND w.isComparative - UNION ALL - SELECT b.itemFk, - b.quantity - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - JOIN warehouse w ON w.id = t.warehouseInFk - WHERE t.landed = vDate - AND NOT t.isReceived - AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid - AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk - AND w.isComparative - UNION ALL - SELECT b.itemFk, b.quantity - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - JOIN warehouse w ON w.id = t.warehouseOutFk - WHERE t.shipped = vDate - AND NOT t.isReceived - AND NOT e.isExcludedFromAvailable - AND NOT e.isRaid - AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk - AND w.isComparative - ) sub2 - GROUP BY itemFk - ) sub ON ai.id = sub.Id_Article - SET ai.visible = ai.visible + sub.Subtotal; + CALL `cache`.stock_refresh(false); + + CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible + (PRIMARY KEY (item_id)) + ENGINE = MEMORY + SELECT item_id, amount stock, amount visible FROM `cache`.stock + WHERE warehouse_id = vWarehouseFk; + + CALL vn.item_getVisible(vWarehouseFk, util.VN_CURDATE(), NULL); + UPDATE tmp.itemInventory it + JOIN tmp.itemVisible iv ON iv.item_id = it.id + SET it.visible = iv.visible; -- Calculo del disponible CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc @@ -189,6 +160,7 @@ proc: BEGIN DROP TEMPORARY TABLE tmp.itemTravel, tmp.itemCalc, - tmp.itemAtp; -END$$ -DELIMITER ; + tmp.itemAtp, + tmp.itemVisible; +END$$ +DELIMITER ; From a9aad7406aec4e0065069c2db4598a65d930bf3c Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 11 Jun 2024 12:51:36 +0200 Subject: [PATCH 025/173] refactor: refs #7505 Minor change --- db/routines/vn/procedures/multipleInventory.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index 4d5c5d366..05f25268c 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -87,9 +87,9 @@ proc: BEGIN WHERE warehouse_id = vWarehouseFk; CALL vn.item_getVisible(vWarehouseFk, util.VN_CURDATE(), NULL); - UPDATE tmp.itemInventory it - JOIN tmp.itemVisible iv ON iv.item_id = it.id - SET it.visible = iv.visible; + UPDATE tmp.itemInventory it + JOIN tmp.itemVisible iv ON iv.item_id = it.id + SET it.visible = iv.visible; -- Calculo del disponible CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc From 944355d54f619ee0c14115e606d0bf443784b420 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 11 Jun 2024 13:17:19 +0200 Subject: [PATCH 026/173] refactor: refs #6436 end first wave of changes in modules --- .../expedition/specs/moveExpeditions.spec.js | 14 +++----------- .../methods/ticket/specs/isEditableOrThrow.spec.js | 4 +--- .../ticket/back/methods/ticket/specs/merge.spec.js | 12 +----------- .../ticket/specs/recalculateComponents.spec.js | 3 +-- .../back/methods/ticket/specs/sendSms.spec.js | 2 +- .../back/methods/calendar/specs/absences.spec.js | 2 +- .../methods/department/specs/getLeaves.spec.js | 2 +- .../methods/worker/specs/mySubordinates.spec.js | 2 +- .../agency/specs/getAgenciesWithWarehouse.spec.js | 2 +- .../back/methods/agency/specs/landsThatDay.spec.js | 2 +- .../zone/back/methods/zone/specs/getEvents.spec.js | 2 +- .../zone/back/methods/zone/specs/getLeaves.spec.js | 2 +- .../zone/specs/getUpcomingDeliveries.spec.js | 2 +- 13 files changed, 15 insertions(+), 36 deletions(-) diff --git a/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js index 27b20bcd2..621992c5d 100644 --- a/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js +++ b/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js @@ -1,19 +1,11 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket moveExpeditions()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + const {ctx} = beforeAll; it('should move the selected expeditions to new ticket', async() => { const tx = await models.Expedition.beginTransaction({}); - const ctx = { - req: {accessToken: {userId: 9}}, - args: {}, - params: {} - }; - const myCtx = Object.assign({}, ctx); + const myCtx = ctx; try { const options = {transaction: tx}; @@ -28,7 +20,7 @@ describe('ticket moveExpeditions()', () => { }; - const ticket = await models.Expedition.moveExpeditions(myCtx, options); + const ticket = await models.Expedition.moveExpeditions(ctx, options); const newestTicketIdInFixtures = 27; diff --git a/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js b/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js index bdf547325..e78812bfe 100644 --- a/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js +++ b/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js @@ -1,14 +1,12 @@ const models = require('vn-loopback/server/server').models; describe('ticket isEditableOrThrow()', () => { + const {ctx} = beforeAll; it('should throw an error as the ticket does not exist', async() => { const tx = await models.Ticket.beginTransaction({}); let error; try { const options = {transaction: tx}; - const ctx = { - req: {accessToken: {userId: 9}} - }; await models.Ticket.isEditableOrThrow(ctx, 9999, options); await tx.rollback(); diff --git a/modules/ticket/back/methods/ticket/specs/merge.spec.js b/modules/ticket/back/methods/ticket/specs/merge.spec.js index 702b496af..21d4e5c75 100644 --- a/modules/ticket/back/methods/ticket/specs/merge.spec.js +++ b/modules/ticket/back/methods/ticket/specs/merge.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket merge()', () => { + const {ctx} = beforeAll; const tickets = { originId: 13, destinationId: 12, @@ -10,16 +10,6 @@ describe('ticket merge()', () => { workerFk: 1 }; - beforeAll(async() => { - mockLoopBackContext(); - }); - - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost:5000'}, - } - }; ctx.req.__ = value => { return value; }; diff --git a/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js b/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js index d358a79f5..5c3811583 100644 --- a/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js +++ b/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js @@ -3,6 +3,7 @@ const ForbiddenError = require('vn-loopback/util/forbiddenError'); describe('ticket recalculateComponents()', () => { const ticketId = 11; + const {ctx} = beforeAll; it('should update the ticket components', async() => { const tx = await models.Ticket.beginTransaction({}); @@ -10,7 +11,6 @@ describe('ticket recalculateComponents()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}}; const response = await models.Ticket.recalculateComponents(ctx, ticketId, options); expect(response.affectedRows).toBeDefined(); @@ -29,7 +29,6 @@ describe('ticket recalculateComponents()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}}; const immutableTicketId = 1; await models.Ticket.recalculateComponents(ctx, immutableTicketId, options); diff --git a/modules/ticket/back/methods/ticket/specs/sendSms.spec.js b/modules/ticket/back/methods/ticket/specs/sendSms.spec.js index afc1ada54..b79e41d37 100644 --- a/modules/ticket/back/methods/ticket/specs/sendSms.spec.js +++ b/modules/ticket/back/methods/ticket/specs/sendSms.spec.js @@ -1,13 +1,13 @@ const models = require('vn-loopback/server/server').models; describe('ticket sendSms()', () => { + const {ctx} = beforeAll; it('should send a message and log it', async() => { const tx = await models.Ticket.beginTransaction({}); try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}}; const id = 11; const destination = 222222222; const message = 'this is the message created in a test'; diff --git a/modules/worker/back/methods/calendar/specs/absences.spec.js b/modules/worker/back/methods/calendar/specs/absences.spec.js index b27c9549c..0e6f21a5f 100644 --- a/modules/worker/back/methods/calendar/specs/absences.spec.js +++ b/modules/worker/back/methods/calendar/specs/absences.spec.js @@ -1,6 +1,7 @@ const app = require('vn-loopback/server/server'); describe('Worker absences()', () => { + const {ctx} = beforeAll; it('should get the absence calendar for a full year contract', async() => { const ctx = {req: {accessToken: {userId: 1106}}}; const workerId = 1106; @@ -20,7 +21,6 @@ describe('Worker absences()', () => { it('should get the absence calendar for a permanent contract', async() => { const businessId = 1106; - const ctx = {req: {accessToken: {userId: 9}}}; const now = Date.vnNew(); const year = now.getFullYear(); diff --git a/modules/worker/back/methods/department/specs/getLeaves.spec.js b/modules/worker/back/methods/department/specs/getLeaves.spec.js index fb7c84ff4..d7e934d20 100644 --- a/modules/worker/back/methods/department/specs/getLeaves.spec.js +++ b/modules/worker/back/methods/department/specs/getLeaves.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('department getLeaves()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; it('should return the department and the childs containing the search value', async() => { let result = await models.Department.getLeaves(ctx, null, 'INFORMATICA'); diff --git a/modules/worker/back/methods/worker/specs/mySubordinates.spec.js b/modules/worker/back/methods/worker/specs/mySubordinates.spec.js index 7eb118d9c..ecd668603 100644 --- a/modules/worker/back/methods/worker/specs/mySubordinates.spec.js +++ b/modules/worker/back/methods/worker/specs/mySubordinates.spec.js @@ -1,8 +1,8 @@ const app = require('vn-loopback/server/server'); describe('worker mySubordinates()', () => { + const {ctx} = beforeAll; it('should return an array of subordinates greather than 1', async() => { - let ctx = {req: {accessToken: {userId: 9}}}; let result = await app.models.Worker.mySubordinates(ctx); expect(result.length).toBeGreaterThan(1); diff --git a/modules/zone/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js b/modules/zone/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js index f760559cb..27a48a848 100644 --- a/modules/zone/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js +++ b/modules/zone/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js @@ -1,8 +1,8 @@ const app = require('vn-loopback/server/server'); describe('Agency getAgenciesWithWarehouse()', () => { + const {ctx} = beforeAll; const today = Date.vnNew(); - const ctx = {req: {accessToken: {userId: 9}}}; it('should return the agencies that can handle the given delivery request', async() => { const tx = await app.models.Zone.beginTransaction({}); diff --git a/modules/zone/back/methods/agency/specs/landsThatDay.spec.js b/modules/zone/back/methods/agency/specs/landsThatDay.spec.js index 1ec675071..27e71bc6f 100644 --- a/modules/zone/back/methods/agency/specs/landsThatDay.spec.js +++ b/modules/zone/back/methods/agency/specs/landsThatDay.spec.js @@ -1,7 +1,7 @@ const {models} = require('vn-loopback/server/server'); describe('Agency landsThatDay()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; const today = Date.vnNew(); it('should return a list of agencies that can land a shipment on a day for an address', async() => { const tx = await models.Agency.beginTransaction({}); diff --git a/modules/zone/back/methods/zone/specs/getEvents.spec.js b/modules/zone/back/methods/zone/specs/getEvents.spec.js index c1dee3e0f..3c9dd76f2 100644 --- a/modules/zone/back/methods/zone/specs/getEvents.spec.js +++ b/modules/zone/back/methods/zone/specs/getEvents.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('zone getEvents()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; it('should return all events for the specified geo and agency mode', async() => { const tx = await models.Zone.beginTransaction({}); diff --git a/modules/zone/back/methods/zone/specs/getLeaves.spec.js b/modules/zone/back/methods/zone/specs/getLeaves.spec.js index 9342a0b50..4b8ab926c 100644 --- a/modules/zone/back/methods/zone/specs/getLeaves.spec.js +++ b/modules/zone/back/methods/zone/specs/getLeaves.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('zone getLeaves()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; it('should return the country and the childs containing the search value', async() => { const tx = await models.Zone.beginTransaction({}); diff --git a/modules/zone/back/methods/zone/specs/getUpcomingDeliveries.spec.js b/modules/zone/back/methods/zone/specs/getUpcomingDeliveries.spec.js index fe542fbf3..cf2a070f3 100644 --- a/modules/zone/back/methods/zone/specs/getUpcomingDeliveries.spec.js +++ b/modules/zone/back/methods/zone/specs/getUpcomingDeliveries.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('zone getUpcomingDeliveries()', () => { - const ctx = {req: {accessToken: {userId: 9}}}; + const {ctx} = beforeAll; it('should check returns data', async() => { const tx = await models.Zone.beginTransaction({}); From 4f10a93584f309711d455d9081dfee2df9e80ae1 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 11 Jun 2024 13:36:46 +0200 Subject: [PATCH 027/173] refactor: refs #7505 Minor change --- db/routines/vn/procedures/multipleInventory.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index 05f25268c..630301b94 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -86,7 +86,7 @@ proc: BEGIN SELECT item_id, amount stock, amount visible FROM `cache`.stock WHERE warehouse_id = vWarehouseFk; - CALL vn.item_getVisible(vWarehouseFk, util.VN_CURDATE(), NULL); + CALL item_getVisible(vWarehouseFk, util.VN_CURDATE(), NULL); UPDATE tmp.itemInventory it JOIN tmp.itemVisible iv ON iv.item_id = it.id SET it.visible = iv.visible; From 3bd596e5fd91d63a5c10f62fc45bd8805063d9ca Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 11 Jun 2024 13:53:41 +0200 Subject: [PATCH 028/173] refactor: refs #7505 Added description --- db/routines/vn/procedures/item_getVisible.sql | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/db/routines/vn/procedures/item_getVisible.sql b/db/routines/vn/procedures/item_getVisible.sql index 0516b9d06..2294d8903 100644 --- a/db/routines/vn/procedures/item_getVisible.sql +++ b/db/routines/vn/procedures/item_getVisible.sql @@ -5,6 +5,14 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getVisible`( vItemFk INT ) BEGIN +/** + * Calcula el visible de un artículo o de todos. + * + * @param vWarehouse Warehouse id + * @param vDated Max date to filter + * @param vItemFk Item id + * @param tmp.itemVisible(item_id, stock, visible) + */ DECLARE vTomorrow DATETIME DEFAULT vDated + INTERVAL 1 DAY; INSERT INTO tmp.itemVisible (item_id, visible) From aa0e06cfec4be89f54eb2828f115fc8ae800d54e Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 11 Jun 2024 14:00:59 +0200 Subject: [PATCH 029/173] refactor: refs #7505 Changed name --- db/routines/cache/procedures/visible_refresh.sql | 2 +- .../vn/procedures/{item_getVisible.sql => item_calcVisible.sql} | 2 +- db/routines/vn/procedures/multipleInventory.sql | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename db/routines/vn/procedures/{item_getVisible.sql => item_calcVisible.sql} (99%) diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index 954b8ff23..b200e86f2 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -25,7 +25,7 @@ proc: BEGIN WHERE warehouse_id = v_warehouse; -- Calculamos los movimientos confirmados de hoy - CALL vn.item_getVisible(v_warehouse, util.VN_CURDATE(), NULL); + CALL vn.item_calcVisible(v_warehouse, util.VN_CURDATE(), NULL); DELETE FROM visible WHERE calc_id = v_calc; INSERT INTO visible (calc_id, item_id,visible) diff --git a/db/routines/vn/procedures/item_getVisible.sql b/db/routines/vn/procedures/item_calcVisible.sql similarity index 99% rename from db/routines/vn/procedures/item_getVisible.sql rename to db/routines/vn/procedures/item_calcVisible.sql index 2294d8903..f7eee661b 100644 --- a/db/routines/vn/procedures/item_getVisible.sql +++ b/db/routines/vn/procedures/item_calcVisible.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getVisible`( +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_calcVisible`( vWarehouseFk INT, vDated INT, vItemFk INT diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index 630301b94..b201bcaae 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -86,7 +86,7 @@ proc: BEGIN SELECT item_id, amount stock, amount visible FROM `cache`.stock WHERE warehouse_id = vWarehouseFk; - CALL item_getVisible(vWarehouseFk, util.VN_CURDATE(), NULL); + CALL item_calcVisible(vWarehouseFk, util.VN_CURDATE(), NULL); UPDATE tmp.itemInventory it JOIN tmp.itemVisible iv ON iv.item_id = it.id SET it.visible = iv.visible; From 2b45c2c61a897562ee2e765d01ca7320e6246590 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 12 Jun 2024 08:25:50 +0200 Subject: [PATCH 030/173] feat: refs #6436 new test changes, rollback order/filter and /ticket/clone --- .../methods/application/spec/execute.spec.js | 18 +++------------- .../entry/specs/addFromPackaging.spec.js | 16 +++----------- .../methods/invoice-in/specs/clone.spec.js | 21 +++++-------------- .../specs/getAlternative.spec.js | 7 ++----- .../methods/item/specs/regularize.spec.js | 14 ++----------- .../back/methods/order/specs/filter.spec.js | 6 +++++- .../supplier/specs/updateFiscalData.spec.js | 1 - .../specs/deleteExpeditions.spec.js | 6 ++---- .../back/methods/sale/specs/clone.spec.js | 19 ++++++++++++----- 9 files changed, 36 insertions(+), 72 deletions(-) diff --git a/loopback/common/methods/application/spec/execute.spec.js b/loopback/common/methods/application/spec/execute.spec.js index 1a0a8ace9..b697dbef9 100644 --- a/loopback/common/methods/application/spec/execute.spec.js +++ b/loopback/common/methods/application/spec/execute.spec.js @@ -2,18 +2,9 @@ const models = require('vn-loopback/server/server').models; describe('Application execute()/executeProc()/executeFunc()', () => { const userWithoutPrivileges = 1; - const userWithPrivileges = 9; const userWithInheritedPrivileges = 120; let tx; - - function getCtx(userId) { - return { - req: { - accessToken: {userId}, - headers: {origin: 'http://localhost'} - } - }; - } + const {ctx} = beforeAll; beforeEach(async() => { tx = await models.Application.beginTransaction({}); @@ -42,7 +33,7 @@ describe('Application execute()/executeProc()/executeFunc()', () => { }); it('should throw error when execute procedure and not have privileges', async() => { - const ctx = getCtx(userWithoutPrivileges); + const ctx = {req: {accessToken: {userId: userWithoutPrivileges}}}; let error; try { @@ -66,7 +57,6 @@ describe('Application execute()/executeProc()/executeFunc()', () => { }); it('should execute procedure and get data', async() => { - const ctx = getCtx(userWithPrivileges); try { const options = {transaction: tx}; @@ -90,7 +80,6 @@ describe('Application execute()/executeProc()/executeFunc()', () => { describe('Application executeProc()', () => { it('should execute procedure and get data (executeProc)', async() => { - const ctx = getCtx(userWithPrivileges); try { const options = {transaction: tx}; @@ -115,7 +104,6 @@ describe('Application execute()/executeProc()/executeFunc()', () => { describe('Application executeFunc()', () => { it('should execute function and get data', async() => { - const ctx = getCtx(userWithPrivileges); try { const options = {transaction: tx}; @@ -137,7 +125,7 @@ describe('Application execute()/executeProc()/executeFunc()', () => { }); it('should execute function and get data with user with inherited privileges', async() => { - const ctx = getCtx(userWithInheritedPrivileges); + const ctx = {req: {accessToken: {userId: userWithInheritedPrivileges}}}; try { const options = {transaction: tx}; diff --git a/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js b/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js index 1b0d4656f..21940d57e 100644 --- a/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js +++ b/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js @@ -1,5 +1,5 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('entry addFromPackaging()', () => { const supplier = 442; @@ -8,21 +8,11 @@ describe('entry addFromPackaging()', () => { yesterday.setDate(today.getDate() - 1); beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 49}, - http: { - req: { - headers: {origin: 'http://localhost'}, - }, - }, - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx, - }); + mockLoopBackContext(); }); it('should create an incoming travel', async() => { - const ctx = {args: {isTravelReception: true, supplier}}; + const ctx = {accessToken: {userId: 49}, args: {isTravelReception: true, supplier}}; const tx = await models.Entry.beginTransaction({}); const options = {transaction: tx}; diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/clone.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/clone.spec.js index 436306aab..9fef506d4 100644 --- a/modules/invoiceIn/back/methods/invoice-in/specs/clone.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in/specs/clone.spec.js @@ -1,24 +1,11 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); describe('invoiceIn clone()', () => { - let ctx; + const {ctx} = beforeAll; let options; let tx; beforeEach(async() => { - ctx = { - req: { - accessToken: {userId: 1}, - headers: {origin: 'http://localhost'} - }, - args: {} - }; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: ctx.req - }); - options = {transaction: tx}; tx = await models.Sale.beginTransaction({}); options.transaction = tx; @@ -28,7 +15,8 @@ describe('invoiceIn clone()', () => { await tx.rollback(); }); - it('should return the cloned invoiceIn and also clone invoiceInDueDays and invoiceInTaxes if there are any referencing the invoiceIn', async() => { + it('should return the cloned invoiceIn and also clone invoiceInDueDays ' + + 'and invoiceInTaxes if there are any referencing the invoiceIn', async() => { const clone = await models.InvoiceIn.clone(ctx, 1, false, options); expect(clone.supplierRef).toEqual('1234(2)'); @@ -51,7 +39,8 @@ describe('invoiceIn clone()', () => { expect(invoiceInDueDay.length).toEqual(2); }); - it('should return the cloned invoiceIn and also clone invoiceInIntrastat and invoiceInTaxes if it is rectificative', async() => { + it('should return the cloned invoiceIn and also clone invoiceInIntrastat ' + + 'and invoiceInTaxes if it is rectificative', async() => { const clone = await models.InvoiceIn.clone(ctx, 1, true, options); expect(clone.supplierRef).toEqual('1234(2)'); diff --git a/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js b/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js index 3f4917477..3082cabd1 100644 --- a/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js +++ b/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js @@ -1,12 +1,9 @@ const {models} = require('vn-loopback/server/server'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('itemShelving getAlternative()', () => { beforeAll(async() => { - ctx = { - req: { - headers: {origin: 'http://localhost'}, - } - }; + mockLoopBackContext(); }); it('should return a list of items without alternatives', async() => { diff --git a/modules/item/back/methods/item/specs/regularize.spec.js b/modules/item/back/methods/item/specs/regularize.spec.js index e7df9a003..b61dec995 100644 --- a/modules/item/back/methods/item/specs/regularize.spec.js +++ b/modules/item/back/methods/item/specs/regularize.spec.js @@ -1,19 +1,9 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); +const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('regularize()', () => { beforeAll(async() => { - const activeCtx = { - accessToken: {userId: 18}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); + mockLoopBackContext(); }); it('should create a new ticket and add a line', async() => { diff --git a/modules/order/back/methods/order/specs/filter.spec.js b/modules/order/back/methods/order/specs/filter.spec.js index 95cb488c8..68de7fe04 100644 --- a/modules/order/back/methods/order/specs/filter.spec.js +++ b/modules/order/back/methods/order/specs/filter.spec.js @@ -1,7 +1,11 @@ const models = require('vn-loopback/server/server').models; describe('order filter()', () => { - const {ctx} = beforeAll; + const ctx = { + req: {accessToken: {userId: 9}}, + args: {}, + params: {} + }; it('should call the filter method with a basic search', async() => { const myCtx = Object.assign({}, ctx); diff --git a/modules/supplier/back/methods/supplier/specs/updateFiscalData.spec.js b/modules/supplier/back/methods/supplier/specs/updateFiscalData.spec.js index 7cb95f840..f1efbbbba 100644 --- a/modules/supplier/back/methods/supplier/specs/updateFiscalData.spec.js +++ b/modules/supplier/back/methods/supplier/specs/updateFiscalData.spec.js @@ -3,7 +3,6 @@ const LoopBackContext = require('loopback-context'); describe('Supplier updateFiscalData()', () => { const supplierId = 1; - const administrativeId = 5; const buyerId = 35; const name = 'NEW PLANTS'; diff --git a/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js index 2c34c994b..b72334142 100644 --- a/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js +++ b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js @@ -1,10 +1,8 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); +// const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket deleteExpeditions()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + const {ctx} = beforeAll; it('should delete the selected expeditions', async() => { const tx = await models.Expedition.beginTransaction({}); diff --git a/modules/ticket/back/methods/sale/specs/clone.spec.js b/modules/ticket/back/methods/sale/specs/clone.spec.js index ef2c6a9a3..e2220c028 100644 --- a/modules/ticket/back/methods/sale/specs/clone.spec.js +++ b/modules/ticket/back/methods/sale/specs/clone.spec.js @@ -1,15 +1,24 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext, mockBeforeAll} = require('vn-loopback/../../back/vn-jasmine'); +const LoopBackContext = require('loopback-context'); describe('Ticket cloning - clone function', () => { - let ctx = mockBeforeAll({ejemploe: true}); + let ctx; let options; let tx; - beforeAll(async() => { - mockLoopBackContext(); - }); beforeEach(async() => { + ctx = { + req: { + accessToken: {userId: 9}, + headers: {origin: 'http://localhost'} + }, + args: {} + }; + + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: ctx.req + }); + options = {transaction: tx}; tx = await models.Sale.beginTransaction({}); options.transaction = tx; From 84a51d3e8d0163ed7f83fa90d358922fc4366cc7 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 12 Jun 2024 12:23:37 +0200 Subject: [PATCH 031/173] feat: refs #6436 changed tests --- back/methods/collection/spec/setSaleQuantity.spec.js | 6 +++--- back/tests.js | 11 +++++++++-- back/vn-jasmine.js | 2 ++ loopback/common/methods/vn-model/specs/crud.spec.js | 6 +++--- .../methods/vn-model/specs/rewriteDbError.spec.js | 6 +++--- .../back/methods/claim/specs/regularizeClaim.spec.js | 6 +++--- .../methods/claim/specs/updateClaimAction.spec.js | 6 +++--- .../methods/client/specs/addressesPropagateRe.spec.js | 9 +++++---- .../back/methods/client/specs/createAddress.spec.js | 6 +++--- .../back/methods/client/specs/createWithUser.spec.js | 6 +++--- .../back/methods/client/specs/updateAddress.spec.js | 6 +++--- modules/client/back/models/specs/address.spec.js | 6 +++--- .../back/methods/entry/specs/addFromPackaging.spec.js | 6 +++--- .../back/methods/entry/specs/editLatestBuys.spec.js | 6 +++--- .../methods/entry/specs/importBuysPreview.spec.js | 6 +++--- .../back/methods/invoice-in-due-day/specs/new.spec.js | 6 +++--- .../item-shelving/specs/getAlternative.spec.js | 6 +++--- modules/item/back/methods/item/specs/clone.spec.js | 6 +++--- .../item/back/methods/item/specs/regularize.spec.js | 6 +++--- .../item/back/methods/item/specs/updateTaxes.spec.js | 6 +++--- modules/item/back/methods/tag/specs/onSubmit.spec.js | 6 +++--- modules/order/back/methods/order/specs/filter.spec.js | 9 ++++----- .../methods/agency-term/specs/createInvoiceIn.spec.js | 1 - modules/route/back/methods/route/specs/clone.spec.js | 6 +++--- .../back/methods/route/specs/guessPriority.spec.js | 11 ----------- .../back/methods/route/specs/updateWorkCenter.spec.js | 6 +++--- .../expedition/specs/deleteExpeditions.spec.js | 1 - .../ticket/back/methods/sale/specs/canEdit.spec.js | 6 +++--- modules/ticket/back/methods/sale/specs/clone.spec.js | 1 - .../back/methods/sale/specs/deleteSales.spec.js | 6 +++--- .../ticket/back/methods/sale/specs/reserve.spec.js | 6 +++--- .../back/methods/ticket-request/specs/confirm.spec.js | 6 +++--- .../back/methods/ticket-request/specs/deny.spec.js | 6 +++--- .../back/methods/ticket/specs/updateDiscount.spec.js | 6 +++--- .../ticket/back/models/specs/ticket-packaging.spec.js | 6 +++--- .../methods/travel/specs/createThermograph.spec.js | 6 +++--- modules/worker/back/methods/worker/specs/new.spec.js | 6 +++--- modules/zone/back/methods/zone/specs/clone.spec.js | 6 +++--- .../zone/back/methods/zone/specs/exclusionGeo.spec.js | 6 +++--- .../back/methods/zone/specs/toggleIsIncluded.spec.js | 6 +++--- 40 files changed, 116 insertions(+), 121 deletions(-) diff --git a/back/methods/collection/spec/setSaleQuantity.spec.js b/back/methods/collection/spec/setSaleQuantity.spec.js index 7abcda36b..e26e25115 100644 --- a/back/methods/collection/spec/setSaleQuantity.spec.js +++ b/back/methods/collection/spec/setSaleQuantity.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('setSaleQuantity()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should change quantity sale', async() => { const tx = await models.Ticket.beginTransaction({}); diff --git a/back/tests.js b/back/tests.js index 2e89cfd05..bfbe9e681 100644 --- a/back/tests.js +++ b/back/tests.js @@ -84,7 +84,10 @@ async function test() { 'loopback/**/*[sS]pec.js', 'modules/*/back/**/*.[sS]pec.js' ], - helpers: [`back/vn-jasmine.js`] + helpers: [`back/vn-jasmine.js`], + asyncHelpers: {miHelperAsync + + } }; if (PARALLEL) { @@ -114,10 +117,14 @@ async function test() { if (opts.ci) runner.jasmine.DEFAULT_TIMEOUT_INTERVAL = SPEC_TIMEOUT; - // runner.loadConfigFile('back/jasmine.json'); runner.loadConfig(config); process.env.SPEC_IS_RUNNING = true; await runner.execute(); } test(); +function miHelperAsync() { + return new Promise((resolve, reject) => { + resolve('Resultado del helper'); + }); +} diff --git a/back/vn-jasmine.js b/back/vn-jasmine.js index 88dc55dc0..1c022637e 100644 --- a/back/vn-jasmine.js +++ b/back/vn-jasmine.js @@ -45,4 +45,6 @@ module.exports = { (function init() { vnBeforeAll(); + describe.$inject = () => { + }; })(); diff --git a/loopback/common/methods/vn-model/specs/crud.spec.js b/loopback/common/methods/vn-model/specs/crud.spec.js index d120db92a..a8923aed8 100644 --- a/loopback/common/methods/vn-model/specs/crud.spec.js +++ b/loopback/common/methods/vn-model/specs/crud.spec.js @@ -2,9 +2,9 @@ const app = require('vn-loopback/server/server'); const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Model crud()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); let insertId; const barcodeModel = app.models.ItemBarcode; diff --git a/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js b/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js index e3c24e74a..d89508383 100644 --- a/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js +++ b/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Model rewriteDbError()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should extend rewriteDbError properties to any model passed', () => { const exampleModel = models.ItemTag; diff --git a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js index 224adc997..879979829 100644 --- a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js @@ -40,9 +40,9 @@ describe('claim regularizeClaim()', () => { return await models.ClaimEnd.create(claimEnds, options); } - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should send a chat message with value "Trash" and then change claim state to resolved', async() => { const tx = await models.Claim.beginTransaction({}); diff --git a/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js b/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js index c939f59de..506c80abb 100644 --- a/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js +++ b/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js @@ -2,9 +2,9 @@ const app = require('vn-loopback/server/server'); const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Update Claim', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); const newDate = Date.vnNew(); const original = { ticketFk: 3, diff --git a/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js b/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js index ec4ebe471..be2732bdb 100644 --- a/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js +++ b/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js @@ -2,11 +2,12 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Client addressesPropagateRe', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); - it('should propagate the isEqualizated on both addresses of Mr Wayne and set hasToInvoiceByAddress to false', async() => { + it('should propagate the isEqualizated on both addresses of Mr Wayne' + + ' and set hasToInvoiceByAddress to false', async() => { const tx = await models.Client.beginTransaction({}); try { diff --git a/modules/client/back/methods/client/specs/createAddress.spec.js b/modules/client/back/methods/client/specs/createAddress.spec.js index 0556ce2cf..9c827a40e 100644 --- a/modules/client/back/methods/client/specs/createAddress.spec.js +++ b/modules/client/back/methods/client/specs/createAddress.spec.js @@ -7,9 +7,9 @@ describe('Address createAddress', () => { const incotermsFk = 'FAS'; const customAgentOneId = 1; - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should throw a non uee member error if no incoterms is defined', async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/methods/client/specs/createWithUser.spec.js b/modules/client/back/methods/client/specs/createWithUser.spec.js index cee8e0b38..47f2d34ce 100644 --- a/modules/client/back/methods/client/specs/createWithUser.spec.js +++ b/modules/client/back/methods/client/specs/createWithUser.spec.js @@ -16,9 +16,9 @@ describe('Client Create', () => { const newAccountWithoutEmail = JSON.parse(JSON.stringify(newAccount)); delete newAccountWithoutEmail.email; - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it(`should not find deadpool as he's not created yet`, async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/methods/client/specs/updateAddress.spec.js b/modules/client/back/methods/client/specs/updateAddress.spec.js index dd5142af0..d0c5e4d88 100644 --- a/modules/client/back/methods/client/specs/updateAddress.spec.js +++ b/modules/client/back/methods/client/specs/updateAddress.spec.js @@ -14,9 +14,9 @@ describe('Address updateAddress', () => { } }; - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should throw the non uee member error if no incoterms is defined', async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/models/specs/address.spec.js b/modules/client/back/models/specs/address.spec.js index 4baa1bdca..d390d045c 100644 --- a/modules/client/back/models/specs/address.spec.js +++ b/modules/client/back/models/specs/address.spec.js @@ -5,9 +5,9 @@ describe('loopback model address', () => { let createdAddressId; const clientId = 1101; - beforeAll(() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); afterAll(async() => { const client = await models.Client.findById(clientId); diff --git a/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js b/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js index 21940d57e..865e59bca 100644 --- a/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js +++ b/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js @@ -7,9 +7,9 @@ describe('entry addFromPackaging()', () => { const yesterday = new Date(today); yesterday.setDate(today.getDate() - 1); - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should create an incoming travel', async() => { const ctx = {accessToken: {userId: 49}, args: {isTravelReception: true, supplier}}; diff --git a/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js b/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js index bff758eea..04c38078b 100644 --- a/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js +++ b/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Buy editLatestsBuys()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should change the value of a given column for the selected buys', async() => { const tx = await models.Buy.beginTransaction({}); diff --git a/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js b/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js index bab46ad59..57adaf2dd 100644 --- a/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js +++ b/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js @@ -3,9 +3,9 @@ const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('entry importBuysPreview()', () => { const entryId = 1; - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should return the buys with the calculated packagingFk', async() => { const tx = await models.Entry.beginTransaction({}); diff --git a/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js b/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js index 02a43d4af..9a996d103 100644 --- a/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('invoiceInDueDay new()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should correctly create a new due day', async() => { const userId = 9; diff --git a/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js b/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js index 3082cabd1..006842eca 100644 --- a/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js +++ b/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js @@ -2,9 +2,9 @@ const {models} = require('vn-loopback/server/server'); const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('itemShelving getAlternative()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should return a list of items without alternatives', async() => { const shelvingFk = 'HEJ'; diff --git a/modules/item/back/methods/item/specs/clone.spec.js b/modules/item/back/methods/item/specs/clone.spec.js index 1a479cd84..e252c910c 100644 --- a/modules/item/back/methods/item/specs/clone.spec.js +++ b/modules/item/back/methods/item/specs/clone.spec.js @@ -3,9 +3,9 @@ const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('item clone()', () => { let nextItemId; - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); beforeEach(async() => { let query = `SELECT i1.id + 1 as id FROM vn.item i1 diff --git a/modules/item/back/methods/item/specs/regularize.spec.js b/modules/item/back/methods/item/specs/regularize.spec.js index b61dec995..097d61d5c 100644 --- a/modules/item/back/methods/item/specs/regularize.spec.js +++ b/modules/item/back/methods/item/specs/regularize.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('regularize()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should create a new ticket and add a line', async() => { const tx = await models.Item.beginTransaction({}); diff --git a/modules/item/back/methods/item/specs/updateTaxes.spec.js b/modules/item/back/methods/item/specs/updateTaxes.spec.js index 49f95c1ed..3d0f1ce33 100644 --- a/modules/item/back/methods/item/specs/updateTaxes.spec.js +++ b/modules/item/back/methods/item/specs/updateTaxes.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('item updateTaxes()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should throw an error if the taxClassFk is blank', async() => { const tx = await models.Item.beginTransaction({}); diff --git a/modules/item/back/methods/tag/specs/onSubmit.spec.js b/modules/item/back/methods/tag/specs/onSubmit.spec.js index 1830aafcf..be77b0248 100644 --- a/modules/item/back/methods/tag/specs/onSubmit.spec.js +++ b/modules/item/back/methods/tag/specs/onSubmit.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('tag onSubmit()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should delete a tag', async() => { const tx = await models.Item.beginTransaction({}); diff --git a/modules/order/back/methods/order/specs/filter.spec.js b/modules/order/back/methods/order/specs/filter.spec.js index 68de7fe04..a2ec88577 100644 --- a/modules/order/back/methods/order/specs/filter.spec.js +++ b/modules/order/back/methods/order/specs/filter.spec.js @@ -1,11 +1,10 @@ +const {mockLoopBackContext} = require('../../../../../../back/vn-jasmine'); + const models = require('vn-loopback/server/server').models; describe('order filter()', () => { - const ctx = { - req: {accessToken: {userId: 9}}, - args: {}, - params: {} - }; + let ctx; + beforeAll(() => ctx = mockLoopBackContext()); it('should call the filter method with a basic search', async() => { const myCtx = Object.assign({}, ctx); diff --git a/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js b/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js index a625605d2..dbe9d0e1e 100644 --- a/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js +++ b/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js @@ -1,5 +1,4 @@ const models = require('vn-loopback/server/server').models; -// const LoopBackContext = require('loopback-context'); describe('AgencyTerm createInvoiceIn()', () => { const {ctx} = beforeAll; diff --git a/modules/route/back/methods/route/specs/clone.spec.js b/modules/route/back/methods/route/specs/clone.spec.js index 98240488c..b9ad7751c 100644 --- a/modules/route/back/methods/route/specs/clone.spec.js +++ b/modules/route/back/methods/route/specs/clone.spec.js @@ -2,9 +2,9 @@ const app = require('vn-loopback/server/server'); const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('route clone()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); const createdDate = Date.vnNew(); it('should throw an error if the amount of ids pased to the clone function do no match the database', async() => { diff --git a/modules/route/back/methods/route/specs/guessPriority.spec.js b/modules/route/back/methods/route/specs/guessPriority.spec.js index d73db6379..34fa510e1 100644 --- a/modules/route/back/methods/route/specs/guessPriority.spec.js +++ b/modules/route/back/methods/route/specs/guessPriority.spec.js @@ -1,18 +1,10 @@ const app = require('vn-loopback/server/server'); -// const LoopBackContext = require('loopback-context'); describe('route guessPriority()', () => { const targetRouteId = 7; let routeTicketsToRestore; - const {ctx} = beforeAll; - // beforeAll(() => { - // spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - // active: activeCtx - // }); - // }); - afterAll(async() => { let restoreFixtures = []; routeTicketsToRestore.forEach(ticket => { @@ -22,9 +14,6 @@ describe('route guessPriority()', () => { }); it('should call guessPriority() then check all tickets in that route have their priorities defined', async() => { - // const ctx = { - // req: activeCtx - // }; routeTicketsToRestore = await app.models.Ticket.find({where: {routeFk: targetRouteId}}); await app.models.Route.guessPriority(ctx, targetRouteId); diff --git a/modules/route/back/methods/route/specs/updateWorkCenter.spec.js b/modules/route/back/methods/route/specs/updateWorkCenter.spec.js index 315460d4a..4d5fbcbdc 100644 --- a/modules/route/back/methods/route/specs/updateWorkCenter.spec.js +++ b/modules/route/back/methods/route/specs/updateWorkCenter.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('route updateWorkCenter()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); const routeId = 1; it('should set the commission work center if the worker has workCenter', async() => { diff --git a/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js index b72334142..4134b28b8 100644 --- a/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js +++ b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js @@ -1,5 +1,4 @@ const models = require('vn-loopback/server/server').models; -// const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket deleteExpeditions()', () => { const {ctx} = beforeAll; diff --git a/modules/ticket/back/methods/sale/specs/canEdit.spec.js b/modules/ticket/back/methods/sale/specs/canEdit.spec.js index 3185b01e7..668b1c273 100644 --- a/modules/ticket/back/methods/sale/specs/canEdit.spec.js +++ b/modules/ticket/back/methods/sale/specs/canEdit.spec.js @@ -3,9 +3,9 @@ const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale canEdit()', () => { const employeeId = 1; - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); describe('sale not exists', () => { it('should return error if sale not exists', async() => { diff --git a/modules/ticket/back/methods/sale/specs/clone.spec.js b/modules/ticket/back/methods/sale/specs/clone.spec.js index e2220c028..8767c2857 100644 --- a/modules/ticket/back/methods/sale/specs/clone.spec.js +++ b/modules/ticket/back/methods/sale/specs/clone.spec.js @@ -14,7 +14,6 @@ describe('Ticket cloning - clone function', () => { }, args: {} }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ active: ctx.req }); diff --git a/modules/ticket/back/methods/sale/specs/deleteSales.spec.js b/modules/ticket/back/methods/sale/specs/deleteSales.spec.js index 8d0e4bd4e..8dc261b13 100644 --- a/modules/ticket/back/methods/sale/specs/deleteSales.spec.js +++ b/modules/ticket/back/methods/sale/specs/deleteSales.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale deleteSales()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should throw an error if the ticket of the given sales is not editable', async() => { const tx = await models.Sale.beginTransaction({}); diff --git a/modules/ticket/back/methods/sale/specs/reserve.spec.js b/modules/ticket/back/methods/sale/specs/reserve.spec.js index 37ebf10ab..009d7b711 100644 --- a/modules/ticket/back/methods/sale/specs/reserve.spec.js +++ b/modules/ticket/back/methods/sale/specs/reserve.spec.js @@ -10,9 +10,9 @@ describe('sale reserve()', () => { } }; - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should throw an error if the ticket can not be modified', async() => { const tx = await models.Sale.beginTransaction({}); diff --git a/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js b/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js index 8a1130e7d..396834df2 100644 --- a/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js +++ b/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket-request confirm()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it(`should throw an error if the item doesn't exist`, async() => { const tx = await models.TicketRequest.beginTransaction({}); diff --git a/modules/ticket/back/methods/ticket-request/specs/deny.spec.js b/modules/ticket/back/methods/ticket-request/specs/deny.spec.js index 1259f1284..aef07bd1b 100644 --- a/modules/ticket/back/methods/ticket-request/specs/deny.spec.js +++ b/modules/ticket/back/methods/ticket-request/specs/deny.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket-request deny()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should return the denied ticket request', async() => { const tx = await models.TicketRequest.beginTransaction({}); diff --git a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js index c0c5333ba..01e6e64bb 100644 --- a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js +++ b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale updateDiscount()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); const originalSaleId = 8; it('should throw an error if no sales were selected', async() => { diff --git a/modules/ticket/back/models/specs/ticket-packaging.spec.js b/modules/ticket/back/models/specs/ticket-packaging.spec.js index 97a936018..7ff863cff 100644 --- a/modules/ticket/back/models/specs/ticket-packaging.spec.js +++ b/modules/ticket/back/models/specs/ticket-packaging.spec.js @@ -2,9 +2,9 @@ const app = require('vn-loopback/server/server'); const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket model TicketTracking', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); let ticketTrackingId; afterAll(async() => { diff --git a/modules/travel/back/methods/travel/specs/createThermograph.spec.js b/modules/travel/back/methods/travel/specs/createThermograph.spec.js index 9c93d6d52..2b0ae48f4 100644 --- a/modules/travel/back/methods/travel/specs/createThermograph.spec.js +++ b/modules/travel/back/methods/travel/specs/createThermograph.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Travel createThermograph()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); const travelId = 3; const currentUserId = 1102; const thermographId = '138350-0'; diff --git a/modules/worker/back/methods/worker/specs/new.spec.js b/modules/worker/back/methods/worker/specs/new.spec.js index b16efb16a..04540b9b7 100644 --- a/modules/worker/back/methods/worker/specs/new.spec.js +++ b/modules/worker/back/methods/worker/specs/new.spec.js @@ -10,9 +10,9 @@ describe('Worker new', () => { let tx; let opts; - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); describe('should return error', () => { beforeEach(async() => { diff --git a/modules/zone/back/methods/zone/specs/clone.spec.js b/modules/zone/back/methods/zone/specs/clone.spec.js index 465abdc9c..292aeb2ac 100644 --- a/modules/zone/back/methods/zone/specs/clone.spec.js +++ b/modules/zone/back/methods/zone/specs/clone.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('agency clone()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should clone a zone', async() => { const tx = await models.Zone.beginTransaction({}); diff --git a/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js b/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js index 746be502f..dc2eeb8a8 100644 --- a/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js +++ b/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('zone exclusionGeo()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); const zoneId = 1; const today = Date.vnNew(); diff --git a/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js b/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js index 39986498e..480c8b7ef 100644 --- a/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js +++ b/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js @@ -2,9 +2,9 @@ const models = require('vn-loopback/server/server').models; const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('zone toggleIsIncluded()', () => { - beforeAll(async() => { - mockLoopBackContext(); - }); + beforeAll(() => + mockLoopBackContext() + ); it('should return the created location with isIncluded true', async() => { const tx = await models.Zone.beginTransaction({}); From 324d7ef7aecc40664e8808436c0224edde59bf94 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 12 Jun 2024 14:54:43 +0200 Subject: [PATCH 032/173] refactor: refs #6436 changed test config --- back/tests.js | 8 -------- back/vn-jasmine.js | 2 -- 2 files changed, 10 deletions(-) diff --git a/back/tests.js b/back/tests.js index bfbe9e681..2527367c2 100644 --- a/back/tests.js +++ b/back/tests.js @@ -85,9 +85,6 @@ async function test() { 'modules/*/back/**/*.[sS]pec.js' ], helpers: [`back/vn-jasmine.js`], - asyncHelpers: {miHelperAsync - - } }; if (PARALLEL) { @@ -123,8 +120,3 @@ async function test() { } test(); -function miHelperAsync() { - return new Promise((resolve, reject) => { - resolve('Resultado del helper'); - }); -} diff --git a/back/vn-jasmine.js b/back/vn-jasmine.js index 1c022637e..88dc55dc0 100644 --- a/back/vn-jasmine.js +++ b/back/vn-jasmine.js @@ -45,6 +45,4 @@ module.exports = { (function init() { vnBeforeAll(); - describe.$inject = () => { - }; })(); From 61a588b57c35264508078ca61d5cc4bd04675678 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 14 Jun 2024 08:39:57 +0200 Subject: [PATCH 033/173] refactor: refs #6436 fixed test --- back/methods/collection/spec/getSales.spec.js | 2 +- .../collection/spec/getTickets.spec.js | 2 +- .../collection/spec/setSaleQuantity.spec.js | 5 +- .../specs/getStarredModules.spec.js | 2 +- .../starred-module/specs/setPosition.spec.js | 2 +- .../specs/toggleStarredModule.spec.js | 2 +- .../user-config/specs/getUserConfig.spec.js | 2 +- back/models/specs/mailAliasAccount.spec.js | 5 +- back/vn-jasmine.js | 50 ++++++++------- .../methods/application/spec/execute.spec.js | 2 +- .../methods/vn-model/specs/crud.spec.js | 5 +- .../vn-model/specs/rewriteDbError.spec.js | 5 +- .../back/methods/claim/specs/filter.spec.js | 2 +- .../claim/specs/regularizeClaim.spec.js | 13 +--- .../methods/claim/specs/updateClaim.spec.js | 3 +- .../claim/specs/updateClaimAction.spec.js | 5 +- .../client/specs/addressesPropagateRe.spec.js | 5 +- .../client/specs/createAddress.spec.js | 5 +- .../client/specs/createWithUser.spec.js | 6 +- .../back/methods/client/specs/getCard.spec.js | 2 +- .../back/methods/client/specs/getDebt.spec.js | 2 +- .../back/methods/client/specs/sendSms.spec.js | 2 +- .../back/methods/client/specs/summary.spec.js | 2 +- .../client/specs/updateAddress.spec.js | 6 +- .../client/back/models/specs/address.spec.js | 5 +- .../entry/specs/addFromPackaging.spec.js | 5 +- .../entry/specs/editLatestBuys.spec.js | 5 +- .../entry/specs/importBuysPreview.spec.js | 5 +- .../invoice-in-due-day/specs/new.spec.js | 5 +- .../methods/invoice-in/specs/clone.spec.js | 2 +- .../invoice-in/specs/corrective.spec.js | 2 +- .../methods/invoiceOut/specs/book.spec.js | 2 +- .../specs/upsertFixedPrice.spec.js | 3 +- .../specs/getAlternative.spec.js | 5 +- .../item-shelving/specs/upsertItem.spec.js | 2 +- .../back/methods/item/specs/clone.spec.js | 5 +- .../methods/item/specs/getBalance.spec.js | 2 +- .../item/back/methods/item/specs/new.spec.js | 2 +- .../methods/item/specs/regularize.spec.js | 6 +- .../methods/item/specs/updateTaxes.spec.js | 5 +- .../back/methods/tag/specs/onSubmit.spec.js | 5 +- .../order-row/specs/addToOrder.spec.js | 2 +- .../back/methods/order/specs/filter.spec.js | 5 +- .../back/methods/order/specs/new.spec.js | 2 +- .../methods/order/specs/newFromTicket.spec.js | 2 +- .../agency-term/specs/createInvoiceIn.spec.js | 2 +- .../back/methods/route/specs/clone.spec.js | 5 +- .../methods/route/specs/guessPriority.spec.js | 2 +- .../route/specs/updateWorkCenter.spec.js | 5 +- .../supplier/specs/consumption.spec.js | 2 +- .../back/models/specs/supplier.spec.js | 3 +- .../specs/addExpeditionState.spec.js | 2 +- .../specs/deleteExpeditions.spec.js | 2 +- .../expedition/specs/moveExpeditions.spec.js | 2 +- .../back/methods/sale/specs/canEdit.spec.js | 5 +- .../back/methods/sale/specs/clone.spec.js | 16 +---- .../methods/sale/specs/deleteSales.spec.js | 21 +------ .../sale/specs/recalculatePrice.spec.js | 2 +- .../back/methods/sale/specs/reserve.spec.js | 5 +- .../methods/sale/specs/updateConcept.spec.js | 2 +- .../ticket-request/specs/confirm.spec.js | 6 +- .../methods/ticket-request/specs/deny.spec.js | 20 +----- .../back/methods/ticket/specs/clone.spec.js | 2 +- .../ticket/specs/componentUpdate.spec.js | 63 +++---------------- .../back/methods/ticket/specs/filter.spec.js | 51 ++++++++++----- .../ticket/specs/getTicketsAdvance.spec.js | 11 ++-- .../ticket/specs/getTicketsFuture.spec.js | 25 ++++---- .../ticket/specs/isEditableOrThrow.spec.js | 2 +- .../back/methods/ticket/specs/merge.spec.js | 6 +- .../specs/recalculateComponents.spec.js | 2 +- .../back/methods/ticket/specs/sendSms.spec.js | 2 +- .../methods/ticket/specs/setDeleted.spec.js | 42 +------------ .../back/methods/ticket/specs/state.spec.js | 22 +++---- .../ticket/specs/transferClient.spec.js | 2 +- .../ticket/specs/updateDiscount.spec.js | 50 ++------------- .../models/specs/ticket-packaging.spec.js | 5 +- modules/ticket/back/models/ticket-request.js | 2 +- .../specs/createThermograph.spec.js | 2 +- .../travel/specs/createThermograph.spec.js | 5 +- .../methods/calendar/specs/absences.spec.js | 2 +- .../department/specs/getLeaves.spec.js | 2 +- .../worker/specs/createAbsence.spec.js | 3 +- .../worker/specs/mySubordinates.spec.js | 2 +- .../back/methods/worker/specs/new.spec.js | 5 +- .../specs/getAgenciesWithWarehouse.spec.js | 2 +- .../methods/agency/specs/landsThatDay.spec.js | 2 +- .../back/methods/zone/specs/clone.spec.js | 5 +- .../methods/zone/specs/exclusionGeo.spec.js | 5 +- .../back/methods/zone/specs/getEvents.spec.js | 2 +- .../back/methods/zone/specs/getLeaves.spec.js | 2 +- .../zone/specs/getUpcomingDeliveries.spec.js | 2 +- .../zone/specs/toggleIsIncluded.spec.js | 5 +- 92 files changed, 197 insertions(+), 452 deletions(-) diff --git a/back/methods/collection/spec/getSales.spec.js b/back/methods/collection/spec/getSales.spec.js index f276d07d0..520657ec1 100644 --- a/back/methods/collection/spec/getSales.spec.js +++ b/back/methods/collection/spec/getSales.spec.js @@ -4,7 +4,7 @@ describe('collection getSales()', () => { const collectionOrTicketFk = 999999; const print = true; const source = 'CHECKER'; - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should return a collection with tickets, placements and barcodes settled correctly', async() => { const tx = await models.Collection.beginTransaction({}); diff --git a/back/methods/collection/spec/getTickets.spec.js b/back/methods/collection/spec/getTickets.spec.js index c066ead8c..646f44223 100644 --- a/back/methods/collection/spec/getTickets.spec.js +++ b/back/methods/collection/spec/getTickets.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('collection getTickets()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should get tickets, sales and barcodes from collection', async() => { const tx = await models.Collection.beginTransaction({}); diff --git a/back/methods/collection/spec/setSaleQuantity.spec.js b/back/methods/collection/spec/setSaleQuantity.spec.js index e26e25115..00ddae0fe 100644 --- a/back/methods/collection/spec/setSaleQuantity.spec.js +++ b/back/methods/collection/spec/setSaleQuantity.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('setSaleQuantity()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should change quantity sale', async() => { const tx = await models.Ticket.beginTransaction({}); diff --git a/back/methods/starred-module/specs/getStarredModules.spec.js b/back/methods/starred-module/specs/getStarredModules.spec.js index cce353f93..afe1dd9c2 100644 --- a/back/methods/starred-module/specs/getStarredModules.spec.js +++ b/back/methods/starred-module/specs/getStarredModules.spec.js @@ -1,7 +1,7 @@ const {models} = require('vn-loopback/server/server'); describe('getStarredModules()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it(`should return the starred modules for a given user`, async() => { const newStarred = await models.StarredModule.create({workerFk: 9, moduleFk: 'customer', position: 1}); diff --git a/back/methods/starred-module/specs/setPosition.spec.js b/back/methods/starred-module/specs/setPosition.spec.js index 495bc8384..c99206e56 100644 --- a/back/methods/starred-module/specs/setPosition.spec.js +++ b/back/methods/starred-module/specs/setPosition.spec.js @@ -1,7 +1,7 @@ const {models} = require('vn-loopback/server/server'); describe('setPosition()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should increase the orders module position by replacing it with clients and vice versa', async() => { const tx = await models.StarredModule.beginTransaction({}); diff --git a/back/methods/starred-module/specs/toggleStarredModule.spec.js b/back/methods/starred-module/specs/toggleStarredModule.spec.js index d5a5c8ab3..d506abc33 100644 --- a/back/methods/starred-module/specs/toggleStarredModule.spec.js +++ b/back/methods/starred-module/specs/toggleStarredModule.spec.js @@ -1,7 +1,7 @@ const {models} = require('vn-loopback/server/server'); describe('toggleStarredModule()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should create a new starred module and then remove it by calling the method again with same args', async() => { const starredModule = await models.StarredModule.toggleStarredModule(ctx, 'order'); diff --git a/back/methods/user-config/specs/getUserConfig.spec.js b/back/methods/user-config/specs/getUserConfig.spec.js index c27018b07..bbfb98ef7 100644 --- a/back/methods/user-config/specs/getUserConfig.spec.js +++ b/back/methods/user-config/specs/getUserConfig.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('userConfig getUserConfig()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it(`should return the configuration data of a given user`, async() => { const tx = await models.Item.beginTransaction({}); const options = {transaction: tx}; diff --git a/back/models/specs/mailAliasAccount.spec.js b/back/models/specs/mailAliasAccount.spec.js index 8f0278a50..0f4cbdbb1 100644 --- a/back/models/specs/mailAliasAccount.spec.js +++ b/back/models/specs/mailAliasAccount.spec.js @@ -1,12 +1,13 @@ const models = require('vn-loopback/server/server').models; describe('loopback model MailAliasAccount', () => { + const ctx = beforeAll.getCtx(); it('should add a mail Alias', async() => { const tx = await models.MailAliasAccount.beginTransaction({}); let error; try { - const options = {transaction: tx, accessToken: {userId: 9}}; + const options = {transaction: tx, ctx}; await models.MailAliasAccount.create({mailAlias: 2, account: 5}, options); await tx.rollback(); @@ -23,7 +24,7 @@ describe('loopback model MailAliasAccount', () => { let error; try { - const options = {transaction: tx, accessToken: {userId: 9}}; + const options = {transaction: tx, ctx}; await models.MailAliasAccount.create({mailAlias: 3, account: 5}, options); await tx.rollback(); diff --git a/back/vn-jasmine.js b/back/vn-jasmine.js index 88dc55dc0..c2d8a497c 100644 --- a/back/vn-jasmine.js +++ b/back/vn-jasmine.js @@ -1,41 +1,47 @@ const LoopBackContext = require('loopback-context'); -const DEFAULT_ACCESS_TOKEN = {accessToken: {userId: 9}}; +const getAccessToken = (userId = 9) => { + return {accessToken: {userId}}; +}; const DEFAULT_HEADERS = {headers: {origin: 'http://localhost'}}; -const DEFAULT_BEFORE_ALL = { - ctx: { +const default_before_all = userId => { + return { req: { - ...DEFAULT_ACCESS_TOKEN, - ...DEFAULT_HEADERS + ...getAccessToken(userId), + ...DEFAULT_HEADERS, + ...{__: value => value} }, args: {} - } + }; }; -const DEFAULT_LOOPBACK_CTX = { - ...DEFAULT_ACCESS_TOKEN, - http: { - req: { - ...DEFAULT_HEADERS - } - }, - args: {} +const default_loopback_ctx = userId => { + return { + ...getAccessToken(userId), + ...default_before_all(userId), + http: { + ...default_before_all(userId) + }, + args: {} + }; }; -function vnBeforeAll(value = DEFAULT_BEFORE_ALL) { - Object.assign(beforeAll, value); +function vnBeforeAll() { + Object.assign(beforeAll, {getCtx: default_before_all}); + Object.assign(beforeAll, {mockLoopBackContext}); } -function mockBeforeAll(value = DEFAULT_BEFORE_ALL) { +function mockBeforeAll(value = default_before_all) { const origin = beforeAll.ctx; Object.assign(origin, value); return origin; } -const mockLoopBackContext = (value = DEFAULT_LOOPBACK_CTX) => { - const activeCtx = value; - - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx +const mockLoopBackContext = userId => { + const activeCtx = default_loopback_ctx(userId); + beforeAll(() => { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); }); return activeCtx; }; diff --git a/loopback/common/methods/application/spec/execute.spec.js b/loopback/common/methods/application/spec/execute.spec.js index b697dbef9..ca4efd9cc 100644 --- a/loopback/common/methods/application/spec/execute.spec.js +++ b/loopback/common/methods/application/spec/execute.spec.js @@ -4,7 +4,7 @@ describe('Application execute()/executeProc()/executeFunc()', () => { const userWithoutPrivileges = 1; const userWithInheritedPrivileges = 120; let tx; - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); beforeEach(async() => { tx = await models.Application.beginTransaction({}); diff --git a/loopback/common/methods/vn-model/specs/crud.spec.js b/loopback/common/methods/vn-model/specs/crud.spec.js index a8923aed8..28b256ad8 100644 --- a/loopback/common/methods/vn-model/specs/crud.spec.js +++ b/loopback/common/methods/vn-model/specs/crud.spec.js @@ -1,10 +1,7 @@ const app = require('vn-loopback/server/server'); -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Model crud()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); let insertId; const barcodeModel = app.models.ItemBarcode; diff --git a/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js b/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js index d89508383..84c0784c9 100644 --- a/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js +++ b/loopback/common/methods/vn-model/specs/rewriteDbError.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Model rewriteDbError()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should extend rewriteDbError properties to any model passed', () => { const exampleModel = models.ItemTag; diff --git a/modules/claim/back/methods/claim/specs/filter.spec.js b/modules/claim/back/methods/claim/specs/filter.spec.js index b55e554b9..1ef808e9d 100644 --- a/modules/claim/back/methods/claim/specs/filter.spec.js +++ b/modules/claim/back/methods/claim/specs/filter.spec.js @@ -2,7 +2,7 @@ const app = require('vn-loopback/server/server'); const models = require('vn-loopback/server/server').models; describe('claim filter()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should return 1 result filtering by id', async() => { const tx = await app.models.Claim.beginTransaction({}); diff --git a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js index 879979829..55d76ed7a 100644 --- a/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/regularizeClaim.spec.js @@ -1,18 +1,11 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('claim regularizeClaim()', () => { const userId = 18; - const ctx = { - req: { - accessToken: {userId: userId}, - headers: {origin: 'http://localhost'} - } - }; + const ctx = beforeAll.mockLoopBackContext(userId); ctx.req.__ = (value, params) => { return params.nickname; }; - const chatModel = models.Chat; const claimId = 1; const ticketId = 1; @@ -40,10 +33,6 @@ describe('claim regularizeClaim()', () => { return await models.ClaimEnd.create(claimEnds, options); } - beforeAll(() => - mockLoopBackContext() - ); - it('should send a chat message with value "Trash" and then change claim state to resolved', async() => { const tx = await models.Claim.beginTransaction({}); diff --git a/modules/claim/back/methods/claim/specs/updateClaim.spec.js b/modules/claim/back/methods/claim/specs/updateClaim.spec.js index 5c8f08132..e1eec59d1 100644 --- a/modules/claim/back/methods/claim/specs/updateClaim.spec.js +++ b/modules/claim/back/methods/claim/specs/updateClaim.spec.js @@ -1,11 +1,10 @@ const app = require('vn-loopback/server/server'); -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); const i18n = require('i18n'); describe('Update Claim', () => { let url; let claimStatesMap = {}; + beforeAll.mockLoopBackContext(); beforeAll(async() => { - mockLoopBackContext(); const claimStates = await app.models.ClaimState.find(); claimStatesMap = claimStates.reduce((acc, state) => ({...acc, [state.code]: state.id}), {}); }); diff --git a/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js b/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js index 506c80abb..bc081ed08 100644 --- a/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js +++ b/modules/claim/back/methods/claim/specs/updateClaimAction.spec.js @@ -1,10 +1,7 @@ const app = require('vn-loopback/server/server'); -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Update Claim', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); const newDate = Date.vnNew(); const original = { ticketFk: 3, diff --git a/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js b/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js index be2732bdb..1a186f93c 100644 --- a/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js +++ b/modules/client/back/methods/client/specs/addressesPropagateRe.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Client addressesPropagateRe', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should propagate the isEqualizated on both addresses of Mr Wayne' + ' and set hasToInvoiceByAddress to false', async() => { diff --git a/modules/client/back/methods/client/specs/createAddress.spec.js b/modules/client/back/methods/client/specs/createAddress.spec.js index 9c827a40e..f4901ff93 100644 --- a/modules/client/back/methods/client/specs/createAddress.spec.js +++ b/modules/client/back/methods/client/specs/createAddress.spec.js @@ -1,5 +1,4 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Address createAddress', () => { const clientFk = 1101; @@ -7,9 +6,7 @@ describe('Address createAddress', () => { const incotermsFk = 'FAS'; const customAgentOneId = 1; - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should throw a non uee member error if no incoterms is defined', async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/methods/client/specs/createWithUser.spec.js b/modules/client/back/methods/client/specs/createWithUser.spec.js index 47f2d34ce..5b1ff5da9 100644 --- a/modules/client/back/methods/client/specs/createWithUser.spec.js +++ b/modules/client/back/methods/client/specs/createWithUser.spec.js @@ -1,6 +1,4 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); - describe('Client Create', () => { const newAccount = { userName: 'deadpool', @@ -16,9 +14,7 @@ describe('Client Create', () => { const newAccountWithoutEmail = JSON.parse(JSON.stringify(newAccount)); delete newAccountWithoutEmail.email; - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it(`should not find deadpool as he's not created yet`, async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/methods/client/specs/getCard.spec.js b/modules/client/back/methods/client/specs/getCard.spec.js index 1082b4009..49e5ed5a4 100644 --- a/modules/client/back/methods/client/specs/getCard.spec.js +++ b/modules/client/back/methods/client/specs/getCard.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('Client getCard()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should receive a formated card of Bruce Wayne', async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/methods/client/specs/getDebt.spec.js b/modules/client/back/methods/client/specs/getDebt.spec.js index 7fc76ee94..d89d671a3 100644 --- a/modules/client/back/methods/client/specs/getDebt.spec.js +++ b/modules/client/back/methods/client/specs/getDebt.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('client getDebt()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should return the client debt', async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/methods/client/specs/sendSms.spec.js b/modules/client/back/methods/client/specs/sendSms.spec.js index b6cb55062..bba9f83ce 100644 --- a/modules/client/back/methods/client/specs/sendSms.spec.js +++ b/modules/client/back/methods/client/specs/sendSms.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('client sendSms()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should now send a message and log it', async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/methods/client/specs/summary.spec.js b/modules/client/back/methods/client/specs/summary.spec.js index d15d183c6..fe2af8028 100644 --- a/modules/client/back/methods/client/specs/summary.spec.js +++ b/modules/client/back/methods/client/specs/summary.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('client summary()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should return a summary object containing data', async() => { const clientId = 1101; const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/methods/client/specs/updateAddress.spec.js b/modules/client/back/methods/client/specs/updateAddress.spec.js index d0c5e4d88..68981f8b7 100644 --- a/modules/client/back/methods/client/specs/updateAddress.spec.js +++ b/modules/client/back/methods/client/specs/updateAddress.spec.js @@ -1,6 +1,4 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); - describe('Address updateAddress', () => { const clientId = 1101; const addressId = 1; @@ -14,9 +12,7 @@ describe('Address updateAddress', () => { } }; - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should throw the non uee member error if no incoterms is defined', async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/client/back/models/specs/address.spec.js b/modules/client/back/models/specs/address.spec.js index d390d045c..3eae1b1bf 100644 --- a/modules/client/back/models/specs/address.spec.js +++ b/modules/client/back/models/specs/address.spec.js @@ -1,13 +1,10 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('loopback model address', () => { let createdAddressId; const clientId = 1101; - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); afterAll(async() => { const client = await models.Client.findById(clientId); diff --git a/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js b/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js index 865e59bca..0c8d2729b 100644 --- a/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js +++ b/modules/entry/back/methods/entry/specs/addFromPackaging.spec.js @@ -1,5 +1,4 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('entry addFromPackaging()', () => { const supplier = 442; @@ -7,9 +6,7 @@ describe('entry addFromPackaging()', () => { const yesterday = new Date(today); yesterday.setDate(today.getDate() - 1); - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should create an incoming travel', async() => { const ctx = {accessToken: {userId: 49}, args: {isTravelReception: true, supplier}}; diff --git a/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js b/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js index 04c38078b..f319c112a 100644 --- a/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js +++ b/modules/entry/back/methods/entry/specs/editLatestBuys.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Buy editLatestsBuys()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should change the value of a given column for the selected buys', async() => { const tx = await models.Buy.beginTransaction({}); diff --git a/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js b/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js index 57adaf2dd..fb3268901 100644 --- a/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js +++ b/modules/entry/back/methods/entry/specs/importBuysPreview.spec.js @@ -1,11 +1,8 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('entry importBuysPreview()', () => { const entryId = 1; - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should return the buys with the calculated packagingFk', async() => { const tx = await models.Entry.beginTransaction({}); diff --git a/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js b/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js index 9a996d103..2105cd9c0 100644 --- a/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('invoiceInDueDay new()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should correctly create a new due day', async() => { const userId = 9; diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/clone.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/clone.spec.js index 9fef506d4..cf1e0ac2d 100644 --- a/modules/invoiceIn/back/methods/invoice-in/specs/clone.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in/specs/clone.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('invoiceIn clone()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); let options; let tx; diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js index ff547f1c8..c63f02439 100644 --- a/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in/specs/corrective.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('invoiceIn corrective()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); let options; let tx; diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js index 29e21a27c..bebc9a8e4 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('invoiceOut book()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); const invoiceOutId = 5; it('should update the booked property', async() => { diff --git a/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js b/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js index 36a15849c..335159de5 100644 --- a/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js +++ b/modules/item/back/methods/fixed-price/specs/upsertFixedPrice.spec.js @@ -1,14 +1,13 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('upsertFixedPrice()', () => { const now = Date.vnNew(); const fixedPriceId = 1; let originalFixedPrice; + beforeAll.mockLoopBackContext(); beforeAll(async() => { originalFixedPrice = await models.FixedPrice.findById(fixedPriceId); - mockLoopBackContext(); }); it(`should toggle the hasMinPrice boolean if there's a minPrice and update the rest of the data`, async() => { diff --git a/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js b/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js index 006842eca..3b0a65e61 100644 --- a/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js +++ b/modules/item/back/methods/item-shelving/specs/getAlternative.spec.js @@ -1,10 +1,7 @@ const {models} = require('vn-loopback/server/server'); -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('itemShelving getAlternative()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should return a list of items without alternatives', async() => { const shelvingFk = 'HEJ'; diff --git a/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js b/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js index 18a8a6e0e..f01cb985d 100644 --- a/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js +++ b/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js @@ -3,7 +3,7 @@ const {models} = require('vn-loopback/server/server'); describe('ItemShelving upsertItem()', () => { const warehouseFk = 1; - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); let options; let tx; diff --git a/modules/item/back/methods/item/specs/clone.spec.js b/modules/item/back/methods/item/specs/clone.spec.js index e252c910c..5bb5fe560 100644 --- a/modules/item/back/methods/item/specs/clone.spec.js +++ b/modules/item/back/methods/item/specs/clone.spec.js @@ -1,11 +1,8 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('item clone()', () => { let nextItemId; - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); beforeEach(async() => { let query = `SELECT i1.id + 1 as id FROM vn.item i1 diff --git a/modules/item/back/methods/item/specs/getBalance.spec.js b/modules/item/back/methods/item/specs/getBalance.spec.js index d1bb65b75..bae0997bb 100644 --- a/modules/item/back/methods/item/specs/getBalance.spec.js +++ b/modules/item/back/methods/item/specs/getBalance.spec.js @@ -2,7 +2,7 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); describe('item getBalance()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should return the balance lines of a client type loses in which one has highlighted true', async() => { const tx = await models.Item.beginTransaction({}); const options = {transaction: tx}; diff --git a/modules/item/back/methods/item/specs/new.spec.js b/modules/item/back/methods/item/specs/new.spec.js index 5611b28ab..11570ffb9 100644 --- a/modules/item/back/methods/item/specs/new.spec.js +++ b/modules/item/back/methods/item/specs/new.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('item new()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should create a new item, adding the name as a tag', async() => { const tx = await models.Item.beginTransaction({}); diff --git a/modules/item/back/methods/item/specs/regularize.spec.js b/modules/item/back/methods/item/specs/regularize.spec.js index 097d61d5c..4e94d5d6d 100644 --- a/modules/item/back/methods/item/specs/regularize.spec.js +++ b/modules/item/back/methods/item/specs/regularize.spec.js @@ -1,17 +1,13 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('regularize()', () => { - beforeAll(() => - mockLoopBackContext() - ); + const ctx = beforeAll.mockLoopBackContext(18); it('should create a new ticket and add a line', async() => { const tx = await models.Item.beginTransaction({}); const options = {transaction: tx}; try { - const ctx = {req: {accessToken: {userId: 18}}}; const itemId = 1; const warehouseId = 1; const quantity = 11; diff --git a/modules/item/back/methods/item/specs/updateTaxes.spec.js b/modules/item/back/methods/item/specs/updateTaxes.spec.js index 3d0f1ce33..828a5fec9 100644 --- a/modules/item/back/methods/item/specs/updateTaxes.spec.js +++ b/modules/item/back/methods/item/specs/updateTaxes.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('item updateTaxes()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should throw an error if the taxClassFk is blank', async() => { const tx = await models.Item.beginTransaction({}); diff --git a/modules/item/back/methods/tag/specs/onSubmit.spec.js b/modules/item/back/methods/tag/specs/onSubmit.spec.js index be77b0248..e92a5fcdf 100644 --- a/modules/item/back/methods/tag/specs/onSubmit.spec.js +++ b/modules/item/back/methods/tag/specs/onSubmit.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('tag onSubmit()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should delete a tag', async() => { const tx = await models.Item.beginTransaction({}); diff --git a/modules/order/back/methods/order-row/specs/addToOrder.spec.js b/modules/order/back/methods/order-row/specs/addToOrder.spec.js index 327c86db0..2bc78ffef 100644 --- a/modules/order/back/methods/order-row/specs/addToOrder.spec.js +++ b/modules/order/back/methods/order-row/specs/addToOrder.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('order addToOrder()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); const orderId = 8; it('should add a row to a given order', async() => { const tx = await models.Order.beginTransaction({}); diff --git a/modules/order/back/methods/order/specs/filter.spec.js b/modules/order/back/methods/order/specs/filter.spec.js index a2ec88577..9e644bb2d 100644 --- a/modules/order/back/methods/order/specs/filter.spec.js +++ b/modules/order/back/methods/order/specs/filter.spec.js @@ -1,10 +1,7 @@ -const {mockLoopBackContext} = require('../../../../../../back/vn-jasmine'); - const models = require('vn-loopback/server/server').models; describe('order filter()', () => { - let ctx; - beforeAll(() => ctx = mockLoopBackContext()); + const ctx = beforeAll.getCtx(); it('should call the filter method with a basic search', async() => { const myCtx = Object.assign({}, ctx); diff --git a/modules/order/back/methods/order/specs/new.spec.js b/modules/order/back/methods/order/specs/new.spec.js index 6ed1fa4ae..779de6ada 100644 --- a/modules/order/back/methods/order/specs/new.spec.js +++ b/modules/order/back/methods/order/specs/new.spec.js @@ -2,7 +2,7 @@ const models = require('vn-loopback/server/server').models; const UserError = require('vn-loopback/util/user-error'); describe('order new()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should throw an error if the client isnt active', async() => { const tx = await models.Order.beginTransaction({}); diff --git a/modules/order/back/methods/order/specs/newFromTicket.spec.js b/modules/order/back/methods/order/specs/newFromTicket.spec.js index a592877cf..d927a0338 100644 --- a/modules/order/back/methods/order/specs/newFromTicket.spec.js +++ b/modules/order/back/methods/order/specs/newFromTicket.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('order newFromTicket()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should create a new order from an existing ticket', async() => { const tx = await models.Order.beginTransaction({}); diff --git a/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js b/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js index dbe9d0e1e..24ffa9cd7 100644 --- a/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js +++ b/modules/route/back/methods/agency-term/specs/createInvoiceIn.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('AgencyTerm createInvoiceIn()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); const rows = [ { routeFk: 2, diff --git a/modules/route/back/methods/route/specs/clone.spec.js b/modules/route/back/methods/route/specs/clone.spec.js index b9ad7751c..a064e35ba 100644 --- a/modules/route/back/methods/route/specs/clone.spec.js +++ b/modules/route/back/methods/route/specs/clone.spec.js @@ -1,10 +1,7 @@ const app = require('vn-loopback/server/server'); -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('route clone()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); const createdDate = Date.vnNew(); it('should throw an error if the amount of ids pased to the clone function do no match the database', async() => { diff --git a/modules/route/back/methods/route/specs/guessPriority.spec.js b/modules/route/back/methods/route/specs/guessPriority.spec.js index 34fa510e1..522801f43 100644 --- a/modules/route/back/methods/route/specs/guessPriority.spec.js +++ b/modules/route/back/methods/route/specs/guessPriority.spec.js @@ -3,7 +3,7 @@ const app = require('vn-loopback/server/server'); describe('route guessPriority()', () => { const targetRouteId = 7; let routeTicketsToRestore; - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); afterAll(async() => { let restoreFixtures = []; diff --git a/modules/route/back/methods/route/specs/updateWorkCenter.spec.js b/modules/route/back/methods/route/specs/updateWorkCenter.spec.js index 4d5fbcbdc..b4b9253f8 100644 --- a/modules/route/back/methods/route/specs/updateWorkCenter.spec.js +++ b/modules/route/back/methods/route/specs/updateWorkCenter.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('route updateWorkCenter()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); const routeId = 1; it('should set the commission work center if the worker has workCenter', async() => { diff --git a/modules/supplier/back/methods/supplier/specs/consumption.spec.js b/modules/supplier/back/methods/supplier/specs/consumption.spec.js index 0b4d6f82c..4c729f64a 100644 --- a/modules/supplier/back/methods/supplier/specs/consumption.spec.js +++ b/modules/supplier/back/methods/supplier/specs/consumption.spec.js @@ -1,8 +1,8 @@ const app = require('vn-loopback/server/server'); describe('supplier consumption() filter', () => { + const ctx = beforeAll.getCtx(); it('should return a list of entries from the supplier 2', async() => { - const ctx = {req: {accessToken: {userId: 9}}, args: {}}; const filter = { where: { supplierFk: 2 diff --git a/modules/supplier/back/models/specs/supplier.spec.js b/modules/supplier/back/models/specs/supplier.spec.js index 2c0d1910f..4e9bd3253 100644 --- a/modules/supplier/back/models/specs/supplier.spec.js +++ b/modules/supplier/back/models/specs/supplier.spec.js @@ -1,14 +1,13 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('loopback model Supplier', () => { let supplierOne; let supplierTwo; + beforeAll.mockLoopBackContext(); beforeAll(async() => { supplierOne = await models.Supplier.findById(1); supplierTwo = await models.Supplier.findById(442); - mockLoopBackContext(); }); describe('payMethodFk', () => { diff --git a/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js b/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js index ce9049a95..747352286 100644 --- a/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js +++ b/modules/ticket/back/methods/expedition-state/specs/addExpeditionState.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('expeditionState addExpeditionState()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should update the expedition states', async() => { const tx = await models.ExpeditionState.beginTransaction({}); try { diff --git a/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js index 4134b28b8..4b17f98b7 100644 --- a/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js +++ b/modules/ticket/back/methods/expedition/specs/deleteExpeditions.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('ticket deleteExpeditions()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should delete the selected expeditions', async() => { const tx = await models.Expedition.beginTransaction({}); diff --git a/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js b/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js index 621992c5d..c1c7c2c12 100644 --- a/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js +++ b/modules/ticket/back/methods/expedition/specs/moveExpeditions.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('ticket moveExpeditions()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should move the selected expeditions to new ticket', async() => { const tx = await models.Expedition.beginTransaction({}); diff --git a/modules/ticket/back/methods/sale/specs/canEdit.spec.js b/modules/ticket/back/methods/sale/specs/canEdit.spec.js index 668b1c273..168bd28fb 100644 --- a/modules/ticket/back/methods/sale/specs/canEdit.spec.js +++ b/modules/ticket/back/methods/sale/specs/canEdit.spec.js @@ -1,11 +1,8 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale canEdit()', () => { const employeeId = 1; - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); describe('sale not exists', () => { it('should return error if sale not exists', async() => { diff --git a/modules/ticket/back/methods/sale/specs/clone.spec.js b/modules/ticket/back/methods/sale/specs/clone.spec.js index 8767c2857..5b0dc84a7 100644 --- a/modules/ticket/back/methods/sale/specs/clone.spec.js +++ b/modules/ticket/back/methods/sale/specs/clone.spec.js @@ -1,23 +1,11 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); - describe('Ticket cloning - clone function', () => { - let ctx; + const ctx = beforeAll.getCtx(); + beforeAll.mockLoopBackContext(); let options; let tx; beforeEach(async() => { - ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - }, - args: {} - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: ctx.req - }); - options = {transaction: tx}; tx = await models.Sale.beginTransaction({}); options.transaction = tx; diff --git a/modules/ticket/back/methods/sale/specs/deleteSales.spec.js b/modules/ticket/back/methods/sale/specs/deleteSales.spec.js index 8dc261b13..ba14310a1 100644 --- a/modules/ticket/back/methods/sale/specs/deleteSales.spec.js +++ b/modules/ticket/back/methods/sale/specs/deleteSales.spec.js @@ -1,10 +1,8 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale deleteSales()', () => { - beforeAll(() => - mockLoopBackContext() - ); + const ctx = beforeAll.getCtx(); + beforeAll.mockLoopBackContext(); it('should throw an error if the ticket of the given sales is not editable', async() => { const tx = await models.Sale.beginTransaction({}); @@ -13,14 +11,6 @@ describe('sale deleteSales()', () => { try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; - const sales = [{id: 1, instance: 0}, {id: 2, instance: 1}]; const ticketId = 2; @@ -41,13 +31,6 @@ describe('sale deleteSales()', () => { try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; const sale = await models.Sale.findOne({where: {id: 9}}, options); sale.id = null; const newSale = await models.Sale.create(sale, options); diff --git a/modules/ticket/back/methods/sale/specs/recalculatePrice.spec.js b/modules/ticket/back/methods/sale/specs/recalculatePrice.spec.js index 3c871dd6c..b97060a3d 100644 --- a/modules/ticket/back/methods/sale/specs/recalculatePrice.spec.js +++ b/modules/ticket/back/methods/sale/specs/recalculatePrice.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('sale recalculatePrice()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should update the sale price', async() => { const tx = await models.Sale.beginTransaction({}); const sales = [ diff --git a/modules/ticket/back/methods/sale/specs/reserve.spec.js b/modules/ticket/back/methods/sale/specs/reserve.spec.js index 009d7b711..e39f636cc 100644 --- a/modules/ticket/back/methods/sale/specs/reserve.spec.js +++ b/modules/ticket/back/methods/sale/specs/reserve.spec.js @@ -1,5 +1,4 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale reserve()', () => { const ctx = { @@ -10,9 +9,7 @@ describe('sale reserve()', () => { } }; - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should throw an error if the ticket can not be modified', async() => { const tx = await models.Sale.beginTransaction({}); diff --git a/modules/ticket/back/methods/sale/specs/updateConcept.spec.js b/modules/ticket/back/methods/sale/specs/updateConcept.spec.js index be6ad77a3..8e3538fc3 100644 --- a/modules/ticket/back/methods/sale/specs/updateConcept.spec.js +++ b/modules/ticket/back/methods/sale/specs/updateConcept.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('sale updateConcept()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); const saleId = 25; it('should throw if ID was undefined', async() => { diff --git a/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js b/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js index 396834df2..3fe174e46 100644 --- a/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js +++ b/modules/ticket/back/methods/ticket-request/specs/confirm.spec.js @@ -1,10 +1,8 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket-request confirm()', () => { - beforeAll(() => - mockLoopBackContext() - ); + const ctx = beforeAll.getCtx(); + beforeAll.mockLoopBackContext(); it(`should throw an error if the item doesn't exist`, async() => { const tx = await models.TicketRequest.beginTransaction({}); diff --git a/modules/ticket/back/methods/ticket-request/specs/deny.spec.js b/modules/ticket/back/methods/ticket-request/specs/deny.spec.js index aef07bd1b..9920bd4d3 100644 --- a/modules/ticket/back/methods/ticket-request/specs/deny.spec.js +++ b/modules/ticket/back/methods/ticket-request/specs/deny.spec.js @@ -1,29 +1,15 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket-request deny()', () => { - beforeAll(() => - mockLoopBackContext() - ); + const ctx = beforeAll.getCtx(); + beforeAll.mockLoopBackContext(); it('should return the denied ticket request', async() => { const tx = await models.TicketRequest.beginTransaction({}); try { const options = {transaction: tx}; - - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'} - }, - args: {id: 4, observation: 'my observation'}, - }; - - ctx.req.__ = value => { - return value; - }; - + ctx.args = {id: 4, observation: 'my observation'}; const result = await models.TicketRequest.deny(ctx, options); expect(result.id).toEqual(4); diff --git a/modules/ticket/back/methods/ticket/specs/clone.spec.js b/modules/ticket/back/methods/ticket/specs/clone.spec.js index cf222ab8d..ccc0dcdf3 100644 --- a/modules/ticket/back/methods/ticket/specs/clone.spec.js +++ b/modules/ticket/back/methods/ticket/specs/clone.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('Ticket cloning - clone function', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); let options; let tx; const ticketId = 1; diff --git a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js index b138b88ea..15dd5e4ce 100644 --- a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js +++ b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js @@ -1,8 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket componentUpdate()', () => { - const userID = 1101; + const ctx = beforeAll.getCtx(1101); const ticketID = 11; const today = Date.vnNew(); const tomorrow = Date.vnNew(); @@ -16,8 +15,8 @@ describe('ticket componentUpdate()', () => { let componentOfSaleEight; let componentValue; + beforeAll.mockLoopBackContext(); beforeAll(async() => { - mockLoopBackContext(); const deliveryComponenet = await models.Component.findOne({where: {code: 'delivery'}}); deliveryComponentId = deliveryComponenet.id; componentOfSaleSeven = `SELECT value @@ -54,16 +53,7 @@ describe('ticket componentUpdate()', () => { isWithoutNegatives: false }; - let ctx = { - args: args, - req: { - accessToken: {userId: userID}, - headers: {origin: 'http://localhost'}, - __: value => { - return value; - } - } - }; + ctx.args = args; await models.Ticket.componentUpdate(ctx, options); [componentValue] = await models.SaleComponent.rawSql(componentOfSaleSeven, null, options); @@ -103,16 +93,7 @@ describe('ticket componentUpdate()', () => { isWithoutNegatives: false }; - const ctx = { - args: args, - req: { - accessToken: {userId: userID}, - headers: {origin: 'http://localhost'}, - __: value => { - return value; - } - } - }; + ctx.args = args; const observationTypeDelivery = await models.ObservationType.findOne({ where: {code: 'delivery'} }, options); @@ -142,6 +123,7 @@ describe('ticket componentUpdate()', () => { }); it('should change warehouse and without negatives', async() => { + const ctx = beforeAll.getCtx(9); const tx = await models.SaleComponent.beginTransaction({}); try { @@ -168,17 +150,7 @@ describe('ticket componentUpdate()', () => { option: 'renewPrices', isWithoutNegatives: true }; - - const ctx = { - args: args, - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'}, - __: value => { - return value; - } - } - }; + ctx.args = args; const oldTicket = await models.Ticket.findById(ticketID, null, options); @@ -200,6 +172,7 @@ describe('ticket componentUpdate()', () => { }); describe('componentUpdate() keepPrice', () => { + const ctx = beforeAll.getCtx(); it('should change shipped and keep price', async() => { const tx = await models.Ticket.beginTransaction({}); @@ -229,16 +202,7 @@ describe('ticket componentUpdate()', () => { keepPrice: true }; - const ctx = { - args: args, - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'}, - __: value => { - return value; - } - } - }; + ctx.args = args; const beforeSale = await models.Sale.findById(saleId, null, options); await models.Ticket.componentUpdate(ctx, options); @@ -282,16 +246,7 @@ describe('ticket componentUpdate()', () => { keepPrice: false }; - const ctx = { - args: args, - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost'}, - __: value => { - return value; - } - } - }; + ctx.args = args; const beforeSale = await models.Sale.findById(saleId, null, options); await models.Ticket.componentUpdate(ctx, options); diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index 8008acfaf..b162ce81f 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -1,13 +1,13 @@ const models = require('vn-loopback/server/server').models; describe('ticket filter()', () => { + const ctx = beforeAll.getCtx(); it('should return the tickets matching the filter', async() => { const tx = await models.Ticket.beginTransaction({}); try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {}}; const filter = {order: 'id DESC'}; const result = await models.Ticket.filter(ctx, filter, options); @@ -31,11 +31,12 @@ describe('ticket filter()', () => { const today = Date.vnNew(); today.setHours(23, 59, 59, 59); - const ctx = {req: {accessToken: {userId: 9}}, args: { + const args = { problems: true, from: yesterday, to: today - }}; + }; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -60,11 +61,12 @@ describe('ticket filter()', () => { const today = Date.vnNew(); today.setHours(23, 59, 59, 59); - const ctx = {req: {accessToken: {userId: 9}}, args: { + const args = { problems: false, from: yesterday, to: today - }}; + }; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -83,7 +85,8 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {problems: null}}; + const args = {problems: null}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -102,7 +105,8 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {orderFk: 11}}; + const args = {orderFk: 11}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); const firstRow = result[0]; @@ -123,7 +127,8 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {pending: true}}; + const args = {pending: true}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -146,7 +151,8 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {pending: false}}; + const args = {pending: false}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); const firstRow = result[0]; @@ -167,11 +173,13 @@ describe('ticket filter()', () => { it('should return the tickets from the worker team', async() => { const tx = await models.Ticket.beginTransaction({}); + const ctx = beforeAll.getCtx(18); try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 18}}, args: {myTeam: true}}; + const args = {myTeam: true}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -185,12 +193,14 @@ describe('ticket filter()', () => { }); it('should return the tickets that are not from the worker team', async() => { + const ctx = beforeAll.getCtx(18); const tx = await models.Ticket.beginTransaction({}); try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 18}}, args: {myTeam: false}}; + const args = {myTeam: false}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -204,12 +214,14 @@ describe('ticket filter()', () => { }); it('should return the tickets belonging to the collection id 1', async() => { + const ctx = beforeAll.getCtx(18); const tx = await models.Ticket.beginTransaction({}); try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 18}}, args: {collectionFk: 1}}; + const args = {collectionFk: 1}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -228,7 +240,8 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {hasRoute: true}}; + const args = {hasRoute: true}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -247,7 +260,8 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {hasRoute: false}}; + const args = {hasRoute: false}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -266,7 +280,8 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {hasRoute: null}}; + const args = {hasRoute: null}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -285,7 +300,8 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {hasInvoice: true}}; + const args = {hasInvoice: true}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); @@ -304,7 +320,8 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 9}}, args: {hasInvoice: null}}; + const args = {hasInvoice: null}; + ctx.args = args; const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); diff --git a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js index 5a3209a6d..488cd1fc2 100644 --- a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js +++ b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js @@ -1,6 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('TicketFuture getTicketsAdvance()', () => { + const ctx = beforeAll.getCtx(); const today = Date.vnNew(); today.setHours(0, 0, 0, 0); let tomorrow = Date.vnNew(); @@ -18,7 +19,7 @@ describe('TicketFuture getTicketsAdvance()', () => { warehouseFk: 1, }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsAdvance(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -42,7 +43,7 @@ describe('TicketFuture getTicketsAdvance()', () => { isFullMovable: true }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsAdvance(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -67,7 +68,7 @@ describe('TicketFuture getTicketsAdvance()', () => { isFullMovable: false }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsAdvance(ctx, options); expect(result.length).toEqual(0); @@ -92,7 +93,7 @@ describe('TicketFuture getTicketsAdvance()', () => { ipt: 'V' }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsAdvance(ctx, options); expect(result.length).toBeGreaterThan(5); @@ -117,7 +118,7 @@ describe('TicketFuture getTicketsAdvance()', () => { tfIpt: 'V' }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsAdvance(ctx, options); expect(result.length).toBeGreaterThan(5); diff --git a/modules/ticket/back/methods/ticket/specs/getTicketsFuture.spec.js b/modules/ticket/back/methods/ticket/specs/getTicketsFuture.spec.js index 44896493f..4b28f34ea 100644 --- a/modules/ticket/back/methods/ticket/specs/getTicketsFuture.spec.js +++ b/modules/ticket/back/methods/ticket/specs/getTicketsFuture.spec.js @@ -1,6 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('ticket getTicketsFuture()', () => { + const ctx = beforeAll.getCtx(); const today = Date.vnNew(); today.setHours(0, 0, 0, 0); @@ -16,7 +17,7 @@ describe('ticket getTicketsFuture()', () => { warehouseFk: 1, }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -40,7 +41,7 @@ describe('ticket getTicketsFuture()', () => { problems: true }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -65,7 +66,7 @@ describe('ticket getTicketsFuture()', () => { problems: false }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toEqual(0); @@ -90,7 +91,7 @@ describe('ticket getTicketsFuture()', () => { problems: null }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -115,7 +116,7 @@ describe('ticket getTicketsFuture()', () => { state: 'OK' }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -140,7 +141,7 @@ describe('ticket getTicketsFuture()', () => { futureState: 'OK' }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -165,7 +166,7 @@ describe('ticket getTicketsFuture()', () => { ipt: null }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -190,7 +191,7 @@ describe('ticket getTicketsFuture()', () => { ipt: 'H' }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -215,7 +216,7 @@ describe('ticket getTicketsFuture()', () => { futureIpt: null }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -240,7 +241,7 @@ describe('ticket getTicketsFuture()', () => { futureIpt: 'H' }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -265,7 +266,7 @@ describe('ticket getTicketsFuture()', () => { id: 13 }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); @@ -290,7 +291,7 @@ describe('ticket getTicketsFuture()', () => { futureId: 12 }; - const ctx = {req: {accessToken: {userId: 9}}, args}; + ctx.args = args; const result = await models.Ticket.getTicketsFuture(ctx, options); expect(result.length).toBeGreaterThan(0); diff --git a/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js b/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js index e78812bfe..883b0de2e 100644 --- a/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js +++ b/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('ticket isEditableOrThrow()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should throw an error as the ticket does not exist', async() => { const tx = await models.Ticket.beginTransaction({}); let error; diff --git a/modules/ticket/back/methods/ticket/specs/merge.spec.js b/modules/ticket/back/methods/ticket/specs/merge.spec.js index 21d4e5c75..68f9d3393 100644 --- a/modules/ticket/back/methods/ticket/specs/merge.spec.js +++ b/modules/ticket/back/methods/ticket/specs/merge.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('ticket merge()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); const tickets = { originId: 13, destinationId: 12, @@ -10,10 +10,6 @@ describe('ticket merge()', () => { workerFk: 1 }; - ctx.req.__ = value => { - return value; - }; - it('should merge two tickets', async() => { const tx = await models.Ticket.beginTransaction({}); diff --git a/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js b/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js index 5c3811583..f9c7284f5 100644 --- a/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js +++ b/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js @@ -3,7 +3,7 @@ const ForbiddenError = require('vn-loopback/util/forbiddenError'); describe('ticket recalculateComponents()', () => { const ticketId = 11; - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should update the ticket components', async() => { const tx = await models.Ticket.beginTransaction({}); diff --git a/modules/ticket/back/methods/ticket/specs/sendSms.spec.js b/modules/ticket/back/methods/ticket/specs/sendSms.spec.js index b79e41d37..2a7b82ea0 100644 --- a/modules/ticket/back/methods/ticket/specs/sendSms.spec.js +++ b/modules/ticket/back/methods/ticket/specs/sendSms.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('ticket sendSms()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should send a message and log it', async() => { const tx = await models.Ticket.beginTransaction({}); diff --git a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js index cb2a21d91..ed9347714 100644 --- a/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js +++ b/modules/ticket/back/methods/ticket/specs/setDeleted.spec.js @@ -1,17 +1,8 @@ const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); describe('ticket setDeleted()', () => { - const userId = 1106; - const activeCtx = { - accessToken: {userId: userId}, - }; - - beforeEach(() => { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - }); + const ctx = beforeAll.getCtx(); + beforeAll.mockLoopBackContext(); it('should throw an error if the given ticket has a claim', async() => { const tx = await models.Ticket.beginTransaction({}); @@ -20,7 +11,6 @@ describe('ticket setDeleted()', () => { try { const options = {transaction: tx}; - const ctx = {req: activeCtx}; const ticketId = 16; await models.Ticket.setDeleted(ctx, ticketId, options); @@ -40,15 +30,6 @@ describe('ticket setDeleted()', () => { try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost:5000'}, - } - }; - ctx.req.__ = value => { - return value; - }; const ticketId = 24; const [sectorCollectionBefore] = await models.Ticket.rawSql( `SELECT COUNT(*) numberRows @@ -75,15 +56,6 @@ describe('ticket setDeleted()', () => { try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost:5000'}, - } - }; - ctx.req.__ = value => { - return value; - }; const [ticketCollectionOld] = await models.Ticket.rawSql( `SELECT COUNT(*) numberRows FROM vn.ticketCollection`, [], options); @@ -110,16 +82,6 @@ describe('ticket setDeleted()', () => { try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'http://localhost:5000'}, - } - }; - ctx.req.__ = value => { - return value; - }; - const ticketId = 8; await models.Ticket.setDeleted(ctx, ticketId, options); diff --git a/modules/ticket/back/methods/ticket/specs/state.spec.js b/modules/ticket/back/methods/ticket/specs/state.spec.js index d908aa2ef..3042633c6 100644 --- a/modules/ticket/back/methods/ticket/specs/state.spec.js +++ b/modules/ticket/back/methods/ticket/specs/state.spec.js @@ -2,14 +2,10 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); describe('ticket state()', () => { + const ctx = beforeAll.getCtx(); const salesPersonId = 18; const employeeId = 1; const productionId = 49; - const activeCtx = { - accessToken: {userId: 9}, - __: value => value - }; - const ctx = {req: activeCtx}; const now = Date.vnNew(); const sampleTicket = { shipped: now, @@ -33,7 +29,7 @@ describe('ticket state()', () => { beforeAll(async() => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx + active: ctx }); }); @@ -45,7 +41,7 @@ describe('ticket state()', () => { try { const options = {transaction: tx}; - activeCtx.accessToken.userId = salesPersonId; + ctx.req.accessToken.userId = salesPersonId; await models.Ticket.state(ctx, {ticketFk: 2, stateFk: 3}, options); @@ -66,7 +62,7 @@ describe('ticket state()', () => { try { const options = {transaction: tx}; - activeCtx.accessToken.userId = employeeId; + ctx.req.accessToken.userId = employeeId; await models.Ticket.state(ctx, {ticketFk: 11, stateFk: 13}, options); @@ -88,7 +84,7 @@ describe('ticket state()', () => { const ticket = await models.Ticket.create(sampleTicket, options); - activeCtx.accessToken.userId = productionId; + ctx.req.accessToken.userId = productionId; const stateOk = await models.State.findOne({where: {code: 'OK'}}, options); const params = {ticketFk: ticket.id, stateFk: stateOk.id}; @@ -114,7 +110,7 @@ describe('ticket state()', () => { const options = {transaction: tx}; const ticket = await models.Ticket.create(sampleTicket, options); - activeCtx.accessToken.userId = salesPersonId; + ctx.req.accessToken.userId = salesPersonId; const assignedState = await models.State.findOne({where: {code: 'PICKER_DESIGNED'}}, options); const paramsAssigned = {ticketFk: ticket.id, stateFk: assignedState.id, userFk: 1}; const resAssigned = await models.Ticket.state(ctx, paramsAssigned, options); @@ -125,7 +121,7 @@ describe('ticket state()', () => { expect(resAssigned.userFk).toBe(1); expect(resAssigned.id).toBeDefined(); - activeCtx.accessToken.userId = productionId; + ctx.req.accessToken.userId = productionId; const packedState = await models.State.findOne({where: {code: 'PACKED'}}, options); const paramsPacked = {ticketFk: ticket.id, stateFk: packedState.id, userFk: salesPersonId}; const resPacked = await models.Ticket.state(ctx, paramsPacked, options); @@ -147,7 +143,7 @@ describe('ticket state()', () => { const options = {transaction: tx}; const ticket = await models.Ticket.create(sampleTicket, options); - activeCtx.accessToken.userId = salesPersonId; + ctx.req.accessToken.userId = salesPersonId; const sampleSale = { ticketFk: ticket.id, @@ -167,7 +163,7 @@ describe('ticket state()', () => { expect(resAssigned.userFk).toBe(1); expect(resAssigned.id).toBeDefined(); - activeCtx.accessToken.userId = productionId; + ctx.req.accessToken.userId = productionId; const packedState = await models.State.findOne({where: {code: 'PACKED'}}, options); const paramsPacked = {ticketFk: ticket.id, stateFk: packedState.id, userFk: salesPersonId}; const resPacked = await models.Ticket.state(ctx, paramsPacked, options); diff --git a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js index 4aac0833a..01fd8fcbe 100644 --- a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js +++ b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js @@ -5,7 +5,7 @@ describe('Ticket transferClient()', () => { const refundTicketId = 24; const clientId = 1; - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); let options; let tx; beforeEach(async() => { diff --git a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js index 01e6e64bb..272387a30 100644 --- a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js +++ b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js @@ -1,10 +1,8 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('sale updateDiscount()', () => { - beforeAll(() => - mockLoopBackContext() - ); + const ctx = beforeAll.getCtx(); + beforeAll.mockLoopBackContext(); const originalSaleId = 8; it('should throw an error if no sales were selected', async() => { @@ -14,13 +12,6 @@ describe('sale updateDiscount()', () => { try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; const ticketId = 11; const sales = []; const newDiscount = 10; @@ -43,13 +34,6 @@ describe('sale updateDiscount()', () => { try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; const ticketId = 11; const sales = [1, 14]; const newDiscount = 10; @@ -72,13 +56,6 @@ describe('sale updateDiscount()', () => { try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; const ticketId = 1; const sales = [1]; const newDiscount = 100; @@ -96,17 +73,11 @@ describe('sale updateDiscount()', () => { it('should update the discount if the salesPerson has mana and manaCode = "mana"', async() => { const tx = await models.Ticket.beginTransaction({}); + const ctx = beforeAll.getCtx(18); try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 18}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; const ticketId = 11; const sales = [originalSaleId]; const newDiscount = 100; @@ -141,17 +112,11 @@ describe('sale updateDiscount()', () => { it('should update the discount if the salesPerson has mana and manaCode = "manaClaim"', async() => { const tx = await models.Ticket.beginTransaction({}); + const ctx = beforeAll.getCtx(18); try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 18}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; const ticketId = 11; const sales = [originalSaleId]; const newDiscount = 100; @@ -190,13 +155,6 @@ describe('sale updateDiscount()', () => { try { const options = {transaction: tx}; - const ctx = { - req: { - accessToken: {userId: 9}, - headers: {origin: 'localhost:5000'}, - __: () => {} - } - }; const ticketId = 11; const sales = [originalSaleId]; const newDiscount = 100; diff --git a/modules/ticket/back/models/specs/ticket-packaging.spec.js b/modules/ticket/back/models/specs/ticket-packaging.spec.js index 7ff863cff..5e0ca82db 100644 --- a/modules/ticket/back/models/specs/ticket-packaging.spec.js +++ b/modules/ticket/back/models/specs/ticket-packaging.spec.js @@ -1,10 +1,7 @@ const app = require('vn-loopback/server/server'); -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('ticket model TicketTracking', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); let ticketTrackingId; afterAll(async() => { diff --git a/modules/ticket/back/models/ticket-request.js b/modules/ticket/back/models/ticket-request.js index 622cd7696..30d6a5454 100644 --- a/modules/ticket/back/models/ticket-request.js +++ b/modules/ticket/back/models/ticket-request.js @@ -19,7 +19,7 @@ module.exports = function(Self) { instance.requesterFk = worker.id; const httpCtx = {req: loopBackContext.active}; - const httpRequest = httpCtx.req.http .req; + const httpRequest = httpCtx.req.http.req; const $t = httpRequest.__; if (attenderFk) { diff --git a/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js b/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js index 49eeb86c2..71b9fcccb 100644 --- a/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js +++ b/modules/travel/back/methods/thermograph/specs/createThermograph.spec.js @@ -5,7 +5,7 @@ describe('Termograph createThermograph()', () => { const model = 'DISPOSABLE'; const temperatureFk = 'COOL'; const warehouseId = 1; - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it(`should create a thermograph which is saved in both thermograph and travelThermograph`, async() => { const tx = await models.Thermograph.beginTransaction({}); diff --git a/modules/travel/back/methods/travel/specs/createThermograph.spec.js b/modules/travel/back/methods/travel/specs/createThermograph.spec.js index 2b0ae48f4..f70e27368 100644 --- a/modules/travel/back/methods/travel/specs/createThermograph.spec.js +++ b/modules/travel/back/methods/travel/specs/createThermograph.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Travel createThermograph()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); const travelId = 3; const currentUserId = 1102; const thermographId = '138350-0'; diff --git a/modules/worker/back/methods/calendar/specs/absences.spec.js b/modules/worker/back/methods/calendar/specs/absences.spec.js index 0e6f21a5f..f369d1dca 100644 --- a/modules/worker/back/methods/calendar/specs/absences.spec.js +++ b/modules/worker/back/methods/calendar/specs/absences.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); describe('Worker absences()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should get the absence calendar for a full year contract', async() => { const ctx = {req: {accessToken: {userId: 1106}}}; const workerId = 1106; diff --git a/modules/worker/back/methods/department/specs/getLeaves.spec.js b/modules/worker/back/methods/department/specs/getLeaves.spec.js index d7e934d20..2feb6b461 100644 --- a/modules/worker/back/methods/department/specs/getLeaves.spec.js +++ b/modules/worker/back/methods/department/specs/getLeaves.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('department getLeaves()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should return the department and the childs containing the search value', async() => { let result = await models.Department.getLeaves(ctx, null, 'INFORMATICA'); diff --git a/modules/worker/back/methods/worker/specs/createAbsence.spec.js b/modules/worker/back/methods/worker/specs/createAbsence.spec.js index aadaca99b..fcb1c1633 100644 --- a/modules/worker/back/methods/worker/specs/createAbsence.spec.js +++ b/modules/worker/back/methods/worker/specs/createAbsence.spec.js @@ -133,7 +133,8 @@ describe('Worker createAbsence()', () => { expect(error.message).toEqual(`Cannot add holidays on this day`); }); - it(`should throw an error when adding a absence if the worker has hours recorded that day and not is a half absence`, async() => { + it(`should throw an error when adding a absence if the worker ` + + `has hours recorded that day and not is a half absence`, async() => { const ctx = { req: {accessToken: {userId: 19}}, args: { diff --git a/modules/worker/back/methods/worker/specs/mySubordinates.spec.js b/modules/worker/back/methods/worker/specs/mySubordinates.spec.js index ecd668603..7443827ce 100644 --- a/modules/worker/back/methods/worker/specs/mySubordinates.spec.js +++ b/modules/worker/back/methods/worker/specs/mySubordinates.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); describe('worker mySubordinates()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should return an array of subordinates greather than 1', async() => { let result = await app.models.Worker.mySubordinates(ctx); diff --git a/modules/worker/back/methods/worker/specs/new.spec.js b/modules/worker/back/methods/worker/specs/new.spec.js index 04540b9b7..d9e843064 100644 --- a/modules/worker/back/methods/worker/specs/new.spec.js +++ b/modules/worker/back/methods/worker/specs/new.spec.js @@ -1,5 +1,4 @@ const {models} = require('vn-loopback/server/server'); -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('Worker new', () => { const developerId = 9; @@ -10,9 +9,7 @@ describe('Worker new', () => { let tx; let opts; - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); describe('should return error', () => { beforeEach(async() => { diff --git a/modules/zone/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js b/modules/zone/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js index 27a48a848..931a5c707 100644 --- a/modules/zone/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js +++ b/modules/zone/back/methods/agency/specs/getAgenciesWithWarehouse.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); describe('Agency getAgenciesWithWarehouse()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); const today = Date.vnNew(); it('should return the agencies that can handle the given delivery request', async() => { const tx = await app.models.Zone.beginTransaction({}); diff --git a/modules/zone/back/methods/agency/specs/landsThatDay.spec.js b/modules/zone/back/methods/agency/specs/landsThatDay.spec.js index 27e71bc6f..cd587a329 100644 --- a/modules/zone/back/methods/agency/specs/landsThatDay.spec.js +++ b/modules/zone/back/methods/agency/specs/landsThatDay.spec.js @@ -1,7 +1,7 @@ const {models} = require('vn-loopback/server/server'); describe('Agency landsThatDay()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); const today = Date.vnNew(); it('should return a list of agencies that can land a shipment on a day for an address', async() => { const tx = await models.Agency.beginTransaction({}); diff --git a/modules/zone/back/methods/zone/specs/clone.spec.js b/modules/zone/back/methods/zone/specs/clone.spec.js index 292aeb2ac..3a8783f21 100644 --- a/modules/zone/back/methods/zone/specs/clone.spec.js +++ b/modules/zone/back/methods/zone/specs/clone.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('agency clone()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should clone a zone', async() => { const tx = await models.Zone.beginTransaction({}); diff --git a/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js b/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js index dc2eeb8a8..bd4438204 100644 --- a/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js +++ b/modules/zone/back/methods/zone/specs/exclusionGeo.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('zone exclusionGeo()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); const zoneId = 1; const today = Date.vnNew(); diff --git a/modules/zone/back/methods/zone/specs/getEvents.spec.js b/modules/zone/back/methods/zone/specs/getEvents.spec.js index 3c9dd76f2..80388d009 100644 --- a/modules/zone/back/methods/zone/specs/getEvents.spec.js +++ b/modules/zone/back/methods/zone/specs/getEvents.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('zone getEvents()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should return all events for the specified geo and agency mode', async() => { const tx = await models.Zone.beginTransaction({}); diff --git a/modules/zone/back/methods/zone/specs/getLeaves.spec.js b/modules/zone/back/methods/zone/specs/getLeaves.spec.js index 4b8ab926c..fde56be35 100644 --- a/modules/zone/back/methods/zone/specs/getLeaves.spec.js +++ b/modules/zone/back/methods/zone/specs/getLeaves.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('zone getLeaves()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should return the country and the childs containing the search value', async() => { const tx = await models.Zone.beginTransaction({}); diff --git a/modules/zone/back/methods/zone/specs/getUpcomingDeliveries.spec.js b/modules/zone/back/methods/zone/specs/getUpcomingDeliveries.spec.js index cf2a070f3..08d8601bc 100644 --- a/modules/zone/back/methods/zone/specs/getUpcomingDeliveries.spec.js +++ b/modules/zone/back/methods/zone/specs/getUpcomingDeliveries.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; describe('zone getUpcomingDeliveries()', () => { - const {ctx} = beforeAll; + const ctx = beforeAll.getCtx(); it('should check returns data', async() => { const tx = await models.Zone.beginTransaction({}); diff --git a/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js b/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js index 480c8b7ef..81d02193e 100644 --- a/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js +++ b/modules/zone/back/methods/zone/specs/toggleIsIncluded.spec.js @@ -1,10 +1,7 @@ const models = require('vn-loopback/server/server').models; -const {mockLoopBackContext} = require('vn-loopback/../../back/vn-jasmine'); describe('zone toggleIsIncluded()', () => { - beforeAll(() => - mockLoopBackContext() - ); + beforeAll.mockLoopBackContext(); it('should return the created location with isIncluded true', async() => { const tx = await models.Zone.beginTransaction({}); From ee75068e9c0eaadc3b2c09f61600d522f8658992 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 14 Jun 2024 08:57:11 +0200 Subject: [PATCH 034/173] refactor: refs #6436 fixed test --- back/methods/starred-module/specs/setPosition.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/back/methods/starred-module/specs/setPosition.spec.js b/back/methods/starred-module/specs/setPosition.spec.js index c99206e56..63addeffc 100644 --- a/back/methods/starred-module/specs/setPosition.spec.js +++ b/back/methods/starred-module/specs/setPosition.spec.js @@ -2,6 +2,7 @@ const {models} = require('vn-loopback/server/server'); describe('setPosition()', () => { const ctx = beforeAll.getCtx(); + beforeAll.mockLoopBackContext(); it('should increase the orders module position by replacing it with clients and vice versa', async() => { const tx = await models.StarredModule.beginTransaction({}); From d3f23a6d7a97d4288863200550733484f28e3c87 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 14 Jun 2024 09:04:18 +0200 Subject: [PATCH 035/173] fix: refs #6436 fix filter test --- modules/ticket/back/methods/ticket/specs/filter.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index b162ce81f..1d050931b 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -8,6 +8,7 @@ describe('ticket filter()', () => { try { const options = {transaction: tx}; + const ctx = {req: {accessToken: {userId: 9}}, args: {}}; const filter = {order: 'id DESC'}; const result = await models.Ticket.filter(ctx, filter, options); From a42562b0ca1d572d8c9dca5d4864ec8eaee47b48 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 19 Jun 2024 10:01:32 +0200 Subject: [PATCH 036/173] fear: refs #5855 claim_ratio_routine --- db/routines/bi/procedures/claim_ratio_routine.sql | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/db/routines/bi/procedures/claim_ratio_routine.sql b/db/routines/bi/procedures/claim_ratio_routine.sql index e22162fff..bd273a2c9 100644 --- a/db/routines/bi/procedures/claim_ratio_routine.sql +++ b/db/routines/bi/procedures/claim_ratio_routine.sql @@ -55,8 +55,8 @@ BEGIN -- Recobros - DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; - CREATE TEMPORARY TABLE tmp.ticket_list + DROP TEMPORARY TABLE IF EXISTS tTicket_list; + CREATE TEMPORARY TABLE tTicket_list (PRIMARY KEY (Id_Ticket)) SELECT DISTINCT t.id Id_Ticket FROM vn.saleComponent sc @@ -74,7 +74,7 @@ BEGIN DELETE g.* FROM vn.greuge g - JOIN tmp.ticket_list t ON g.ticketFk = t.Id_Ticket + JOIN tTicket_list t ON g.ticketFk = t.Id_Ticket WHERE g.greugeTypeFk = 2; INSERT INTO vn.greuge(clientFk, description, amount,shipped, @@ -87,7 +87,7 @@ BEGIN ,tt.Id_Ticket FROM vn.sale s JOIN vn.ticket t ON t.id = s.ticketFk - JOIN tmp.ticket_list tt ON tt.Id_Ticket = t.id + JOIN tTicket_list tt ON tt.Id_Ticket = t.id JOIN vn.saleComponent sc ON sc.saleFk = s.id AND sc.componentFk = 17 GROUP BY t.id @@ -95,7 +95,7 @@ BEGIN UPDATE vn.saleComponent sc JOIN vn.sale s ON s.id = sc.saleFk - JOIN tmp.ticket_list tt ON tt.Id_Ticket = s.ticketFk + JOIN tTicket_list tt ON tt.Id_Ticket = s.ticketFk SET sc.isGreuge = 1 WHERE sc.componentFk = 17; @@ -164,6 +164,6 @@ BEGIN SET cr.recobro = sub.recobro WHERE Id_Cliente IN ( 5189,8942); - DROP TEMPORARY TABLE tmp.ticket_list; + DROP TEMPORARY TABLE tTicket_list; END$$ DELIMITER ; From 0128dfd967d6cebf6a0206c4ce4a064fa1638592 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 19 Jun 2024 11:30:50 +0200 Subject: [PATCH 037/173] feat: refs #5855 changes required --- db/routines/edi/procedures/floramondo_offerRefresh.sql | 3 +-- db/routines/vn/procedures/copyComponentsFromSaleList.sql | 8 ++++---- db/routines/vn/procedures/ticket_DelayTruck.sql | 8 ++++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/db/routines/edi/procedures/floramondo_offerRefresh.sql b/db/routines/edi/procedures/floramondo_offerRefresh.sql index 312de7ffb..18d3f8b7e 100644 --- a/db/routines/edi/procedures/floramondo_offerRefresh.sql +++ b/db/routines/edi/procedures/floramondo_offerRefresh.sql @@ -484,8 +484,7 @@ proc: BEGIN DROP TEMPORARY TABLE edi.offer, - itemToInsert, - tmp.buyRecalc; + itemToInsert; SET @isTriggerDisabled = FALSE; diff --git a/db/routines/vn/procedures/copyComponentsFromSaleList.sql b/db/routines/vn/procedures/copyComponentsFromSaleList.sql index 13487af17..ab75486d1 100644 --- a/db/routines/vn/procedures/copyComponentsFromSaleList.sql +++ b/db/routines/vn/procedures/copyComponentsFromSaleList.sql @@ -16,9 +16,9 @@ BEGIN SET @order = 0; - DROP TEMPORARY TABLE IF EXISTS tmp.newSaleList; + DROP TEMPORARY TABLE IF EXISTS tNewSaleList; - CREATE TEMPORARY TABLE tmp.newSaleList + CREATE TEMPORARY TABLE tNewSaleList SELECT id as saleFk, @order := @order + 1 as orden FROM vn.sale WHERE ticketFk = vTargetTicketFk @@ -28,8 +28,8 @@ BEGIN SELECT ns.saleFk, sc.componentFk, sc.value FROM vn.saleComponent sc JOIN tmp.saleList s ON s.saleFk = sc.saleFk - JOIN tmp.newSaleList ns ON ns.orden = s.orden; + JOIN tNewSaleList ns ON ns.orden = s.orden; - DROP TEMPORARY TABLE IF EXISTS tmp.newSaleList; + DROP TEMPORARY TABLE IF EXISTS tNewSaleList; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_DelayTruck.sql b/db/routines/vn/procedures/ticket_DelayTruck.sql index 2fb98d07d..81896dd8e 100644 --- a/db/routines/vn/procedures/ticket_DelayTruck.sql +++ b/db/routines/vn/procedures/ticket_DelayTruck.sql @@ -3,14 +3,14 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_DelayTruck`( BEGIN DECLARE done INT DEFAULT FALSE; DECLARE vTicketFk INT; - DECLARE cur1 CURSOR FOR SELECT ticketFk FROM tmp.ticket; + DECLARE cur1 CURSOR FOR SELECT ticketFk FROM tTicket; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; CALL vn.productionControl(vWarehouserFk,0) ; - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket + DROP TEMPORARY TABLE IF EXISTS tTicket; + CREATE TEMPORARY TABLE tTicket SELECT ticketFk FROM tmp.productionBuffer JOIN alertLevel al ON al.code = 'FREE' @@ -31,6 +31,6 @@ BEGIN END LOOP; CLOSE cur1; - DROP TEMPORARY TABLE tmp.ticket, tmp.productionBuffer; + DROP TEMPORARY TABLE tTicket, tmp.productionBuffer; END$$ DELIMITER ; From 9022f6211639d163a4049962077d0d0d7acff180 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 24 Jun 2024 08:03:43 +0200 Subject: [PATCH 038/173] feat: refs #5855 changes required --- db/routines/vn/procedures/copyComponentsFromSaleList.sql | 2 +- db/routines/vn/procedures/itemShelving_inventory.sql | 2 +- db/routines/vn/procedures/ticket_add.sql | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/copyComponentsFromSaleList.sql b/db/routines/vn/procedures/copyComponentsFromSaleList.sql index ab75486d1..8db8409f1 100644 --- a/db/routines/vn/procedures/copyComponentsFromSaleList.sql +++ b/db/routines/vn/procedures/copyComponentsFromSaleList.sql @@ -30,6 +30,6 @@ BEGIN JOIN tmp.saleList s ON s.saleFk = sc.saleFk JOIN tNewSaleList ns ON ns.orden = s.orden; - DROP TEMPORARY TABLE IF EXISTS tNewSaleList; + DROP TEMPORARY TABLE tNewSaleList; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelving_inventory.sql b/db/routines/vn/procedures/itemShelving_inventory.sql index 6d780c342..f4b8ae165 100644 --- a/db/routines/vn/procedures/itemShelving_inventory.sql +++ b/db/routines/vn/procedures/itemShelving_inventory.sql @@ -60,6 +60,6 @@ BEGIN AND p.sectorFk = vSectorFk ORDER BY p.pickingOrder; - DROP TEMPORARY TABLE IF EXISTS tmp.stockMisfit; + DROP TEMPORARY TABLE tmp.stockMisfit; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_add.sql b/db/routines/vn/procedures/ticket_add.sql index c85000218..d9b68997c 100644 --- a/db/routines/vn/procedures/ticket_add.sql +++ b/db/routines/vn/procedures/ticket_add.sql @@ -66,7 +66,7 @@ BEGIN CALL util.throw ('NOT_ZONE_WITH_THIS_PARAMETERS'); END IF; - DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetShipped; + DROP TEMPORARY TABLE tmp.zoneGetShipped; END IF; INSERT INTO ticket ( From 2797a731c548b83185af42abebf9044c39ce0b07 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 25 Jun 2024 12:00:49 +0200 Subject: [PATCH 039/173] refs #6952 subName --- .../reports/delivery-note/delivery-note.html | 3 ++- .../reports/delivery-note/locale/en.yml | 5 +++-- .../reports/delivery-note/locale/es.yml | 5 +++-- .../reports/delivery-note/locale/fr.yml | 7 ++++--- .../reports/delivery-note/locale/pt.yml | 5 +++-- .../reports/delivery-note/sql/sales.sql | 19 ++++++++++--------- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/print/templates/reports/delivery-note/delivery-note.html b/print/templates/reports/delivery-note/delivery-note.html index 92dd1b126..540a80a3a 100644 --- a/print/templates/reports/delivery-note/delivery-note.html +++ b/print/templates/reports/delivery-note/delivery-note.html @@ -81,6 +81,7 @@ {{sale.tag5}} {{sale.value5}} {{sale.tag6}} {{sale.value6}} {{sale.tag7}} {{sale.value7}} + {{$t('producer')}} {{ sale.subName }} @@ -249,4 +250,4 @@ v-bind:center-text="client.socialName" v-bind="$props"> - \ No newline at end of file + diff --git a/print/templates/reports/delivery-note/locale/en.yml b/print/templates/reports/delivery-note/locale/en.yml index 5902da8b3..84b31e494 100644 --- a/print/templates/reports/delivery-note/locale/en.yml +++ b/print/templates/reports/delivery-note/locale/en.yml @@ -20,6 +20,7 @@ vatType: VAT Type digitalSignature: Digital signature plantPassport: Plant passport packages: Packages +producer: Producer services: title: Services theader: @@ -44,7 +45,7 @@ taxes: taxBase: Tax base tax: Tax fee: Fee - tfoot: + tfoot: subtotal: Subtotal total: Total -observations: Observations \ No newline at end of file +observations: Observations diff --git a/print/templates/reports/delivery-note/locale/es.yml b/print/templates/reports/delivery-note/locale/es.yml index d87198f45..891e59d77 100644 --- a/print/templates/reports/delivery-note/locale/es.yml +++ b/print/templates/reports/delivery-note/locale/es.yml @@ -15,6 +15,7 @@ discount: Dto. vat: IVA amount: Importe total: Total +producer: Productor subtotal: Subtotal vatType: Tipo de IVA digitalSignature: Firma digital @@ -45,7 +46,7 @@ taxes: taxBase: Base imp. tax: Tasa fee: Cuota - tfoot: + tfoot: subtotal: Subtotal total: Total -observations: Observaciones \ No newline at end of file +observations: Observaciones diff --git a/print/templates/reports/delivery-note/locale/fr.yml b/print/templates/reports/delivery-note/locale/fr.yml index 603623a47..87cd2bcde 100644 --- a/print/templates/reports/delivery-note/locale/fr.yml +++ b/print/templates/reports/delivery-note/locale/fr.yml @@ -14,7 +14,8 @@ price: PRIX/u discount: Remise vat: TVA amount: Montant -total: Total +producer: producteur +total: Total subtotal: Total partiel vatType: Type de TVA digitalSignature: Signature numérique @@ -45,7 +46,7 @@ taxes: taxBase: Base imposable tax: Taxe fee: Quote - tfoot: + tfoot: subtotal: Total partiel total: Total -observations: Observations \ No newline at end of file +observations: Observations diff --git a/print/templates/reports/delivery-note/locale/pt.yml b/print/templates/reports/delivery-note/locale/pt.yml index fb49d230b..be39eb3f0 100644 --- a/print/templates/reports/delivery-note/locale/pt.yml +++ b/print/templates/reports/delivery-note/locale/pt.yml @@ -14,6 +14,7 @@ price: PVP/u discount: Dto. vat: IVA amount: Importe +producer: Produtor total: Total subtotal: Sub-total vatType: Tipo de IVA @@ -45,7 +46,7 @@ taxes: taxBase: Tributável tax: Taxa fee: Compartilhado - tfoot: + tfoot: subtotal: Subtotal total: Total -observations: Observações \ No newline at end of file +observations: Observações diff --git a/print/templates/reports/delivery-note/sql/sales.sql b/print/templates/reports/delivery-note/sql/sales.sql index c449030cf..4cbffa12f 100644 --- a/print/templates/reports/delivery-note/sql/sales.sql +++ b/print/templates/reports/delivery-note/sql/sales.sql @@ -1,4 +1,4 @@ -SELECT +SELECT s.id, s.itemFk, s.concept, @@ -15,12 +15,13 @@ SELECT s.ticketFk, tcl.code vatType, ib.ediBotanic botanical, - i.tag5, + i.tag5, i.value5, - i.tag6, - i.value6, - i.tag7, - i.value7 + i.tag6, + i.value6, + i.tag7, + i.value7, + i.subName FROM vn.sale s LEFT JOIN saleComponent sc ON sc.saleFk = s.id LEFT JOIN component cr ON cr.id = sc.componentFk @@ -32,12 +33,12 @@ FROM vn.sale s LEFT JOIN supplier sp ON sp.id = t.companyFk LEFT JOIN itemType it ON it.id = i.typeFk LEFT JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id - AND itc.countryFk = sp.countryFk + LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id + AND itc.countryFk = sp.countryFk LEFT JOIN taxClass tcl ON tcl.id = itc.taxClassFk LEFT JOIN itemBotanicalWithGenus ib ON ib.itemFk = i.id AND ic.code = 'plant' AND ib.ediBotanic IS NOT NULL WHERE s.ticketFk = ? GROUP BY s.id -ORDER BY (it.isPackaging), s.concept, s.itemFk \ No newline at end of file +ORDER BY (it.isPackaging), s.concept, s.itemFk From b4afb883fc71e335ef41572d2dbc77c1126f0536 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 26 Jun 2024 09:35:18 +0200 Subject: [PATCH 040/173] feat(salix): refs #6436 #6436 remove unnecessary object.assign --- back/vn-jasmine.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/back/vn-jasmine.js b/back/vn-jasmine.js index c2d8a497c..2b981c6d9 100644 --- a/back/vn-jasmine.js +++ b/back/vn-jasmine.js @@ -27,13 +27,7 @@ const default_loopback_ctx = userId => { }; function vnBeforeAll() { - Object.assign(beforeAll, {getCtx: default_before_all}); - Object.assign(beforeAll, {mockLoopBackContext}); -} -function mockBeforeAll(value = default_before_all) { - const origin = beforeAll.ctx; - Object.assign(origin, value); - return origin; + Object.assign(beforeAll, {getCtx: default_before_all, mockLoopBackContext}); } const mockLoopBackContext = userId => { @@ -46,7 +40,7 @@ const mockLoopBackContext = userId => { return activeCtx; }; module.exports = { - mockBeforeAll, mockLoopBackContext + mockLoopBackContext }; (function init() { From cbd46330b31d8efcbab8ce2b116dd8f048cd8eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 27 Jun 2024 13:01:42 +0200 Subject: [PATCH 041/173] feat: Turn issues into calculated columns refs#7213 --- .../functions/ticket_isProblemCalcNeeded.sql | 27 +++ db/routines/vn/procedures/buyUltimate.sql | 34 +-- .../vn/procedures/buyUltimateFromInterval.sql | 195 ++++++++++-------- db/routines/vn/procedures/sale_setProblem.sql | 9 +- .../sale_setProblemComponentLack.sql | 8 +- ...ale_setProblemComponentLackByComponent.sql | 8 +- .../vn/procedures/sale_setProblemRounding.sql | 9 +- .../vn/procedures/ticket_setProblem.sql | 12 +- .../vn/procedures/ticket_setProblemFreeze.sql | 8 +- .../procedures/ticket_setProblemRequest.sql | 6 +- .../vn/procedures/ticket_setProblemRisk.sql | 17 +- .../procedures/ticket_setProblemRounding.sql | 7 +- .../ticket_setProblemTaxDataChecked.sql | 6 +- .../procedures/ticket_setProblemTooLittle.sql | 8 +- .../ticket_setProblemTooLittleItemCost.sql | 6 +- 15 files changed, 234 insertions(+), 126 deletions(-) create mode 100644 db/routines/vn/functions/ticket_isProblemCalcNeeded.sql diff --git a/db/routines/vn/functions/ticket_isProblemCalcNeeded.sql b/db/routines/vn/functions/ticket_isProblemCalcNeeded.sql new file mode 100644 index 000000000..4974a8c76 --- /dev/null +++ b/db/routines/vn/functions/ticket_isProblemCalcNeeded.sql @@ -0,0 +1,27 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_isProblemCalcNeeded`( + vSelf INT +) + RETURNS BOOL + DETERMINISTIC +BEGIN +/** + * Check if the ticket requires to update column vn.ticket.problem + * + * @param vSelf Id ticket + * @return BOOL + */ + DECLARE vIsProblemCalcNeeded BOOL; + + SELECT COUNT(*) INTO vIsProblemCalcNeeded + FROM ticket t + JOIN client c ON c.id = t.clientFk + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + WHERE t.id = vSelf + AND dm.code IN ('AGENCY','DELIVERY','PICKUP') + AND c.typeFk = 'normal'; + + RETURN vIsProblemCalcNeeded; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/buyUltimate.sql b/db/routines/vn/procedures/buyUltimate.sql index 4346ef640..98b16cbc0 100644 --- a/db/routines/vn/procedures/buyUltimate.sql +++ b/db/routines/vn/procedures/buyUltimate.sql @@ -1,5 +1,8 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimate`(vWarehouseFk SMALLINT, vDated DATE) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimate`( + vWarehouseFk SMALLINT, + vDated DATE +) BEGIN /** * Calcula las últimas compras realizadas hasta una fecha @@ -19,21 +22,22 @@ BEGIN FROM cache.last_buy WHERE warehouse_id = vWarehouseFk OR vWarehouseFk IS NULL; - CALL buyUltimateFromInterval(vWarehouseFk, util.VN_CURDATE(), vDated); + IF vDated >= util.VN_CURDATE() THEN + CALL buyUltimateFromInterval(vWarehouseFk, util.VN_CURDATE(), vDated); - REPLACE INTO tmp.buyUltimate - SELECT itemFk, buyFk, warehouseFk, landed landing - FROM tmp.buyUltimateFromInterval - WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) - AND landed <= vDated - AND NOT isIgnored; - - INSERT IGNORE INTO tmp.buyUltimate - SELECT itemFk, buyFk, warehouseFk, landed landing - FROM tmp.buyUltimateFromInterval - WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) - AND landed > vDated - ORDER BY isIgnored = FALSE DESC; + REPLACE INTO tmp.buyUltimate + SELECT itemFk, buyFk, warehouseFk, landed landing + FROM tmp.buyUltimateFromInterval + WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) + AND landed <= vDated + AND NOT isIgnored; + INSERT IGNORE INTO tmp.buyUltimate + SELECT itemFk, buyFk, warehouseFk, landed landing + FROM tmp.buyUltimateFromInterval + WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) + AND landed > vDated + ORDER BY isIgnored = FALSE DESC; + END IF; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/buyUltimateFromInterval.sql b/db/routines/vn/procedures/buyUltimateFromInterval.sql index e264b500d..5879b58e1 100644 --- a/db/routines/vn/procedures/buyUltimateFromInterval.sql +++ b/db/routines/vn/procedures/buyUltimateFromInterval.sql @@ -1,5 +1,9 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimateFromInterval`(vWarehouseFk SMALLINT, vStarted DATE, vEnded DATE) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buyUltimateFromInterval`( + vWarehouseFk SMALLINT, + vStarted DATE, + vEnded DATE +) BEGIN /** * Calcula las últimas compras realizadas @@ -21,12 +25,13 @@ BEGIN -- Item DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimateFromInterval; CREATE TEMPORARY TABLE tmp.buyUltimateFromInterval - (PRIMARY KEY (itemFk, warehouseFk), INDEX(buyFk), INDEX(landed), INDEX(warehouseFk), INDEX(itemFk)) + (PRIMARY KEY (itemFk, warehouseFk), + INDEX(buyFk), INDEX(landed), INDEX(warehouseFk), INDEX(itemFk)) ENGINE = MEMORY SELECT itemFk, warehouseFk, buyFk, - MAX(landed) landed, + landed, isIgnored FROM (SELECT b.itemFk, t.warehouseInFk warehouseFk, @@ -45,93 +50,117 @@ BEGIN INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) - SELECT - b.itemFk, - t.warehouseInFk warehouseFk, - b.id buyFk, - t.landed, - b.isIgnored - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed > vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.price2 > 0 - AND NOT b.isIgnored - GROUP BY itemFk, warehouseInFk; + SELECT itemFk, + warehouseFk, + buyFk, + landed, + isIgnored + FROM (SELECT b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed, + b.isIgnored + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed > vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.price2 > 0 + AND NOT b.isIgnored + ORDER BY NOT b.isIgnored DESC, t.landed DESC, b.id DESC + LIMIT 10000000000000000000) sub + GROUP BY itemFk, warehouseFk; INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) - SELECT - b.itemFk, - t.warehouseInFk warehouseFk, - b.id buyFk, - t.landed, - b.isIgnored - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed BETWEEN vStarted AND vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.quantity = 0 - GROUP BY itemFk, warehouseInFk; + SELECT itemFk, + warehouseFk, + buyFk, + landed, + isIgnored + FROM (SELECT b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed, + b.isIgnored + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vStarted AND vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.quantity = 0 + ORDER BY NOT b.isIgnored DESC, t.landed DESC, b.id DESC + LIMIT 10000000000000000000) sub + GROUP BY itemFk, warehouseFk; -- ItemOriginal INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) SELECT itemFk, - warehouseFk, - buyFk, - MAX(landed) landed, - isIgnored - FROM (SELECT b.itemFk, - t.warehouseInFk warehouseFk, - b.id buyFk, - t.landed, - itemOriginalFk, - b.isIgnored - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed BETWEEN vStarted AND vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.price2 > 0 - AND NOT b.isIgnored - AND b.quantity > 0 - AND itemOriginalFk - ORDER BY t.landed DESC, b.id DESC - LIMIT 10000000000000000000) sub - GROUP BY itemOriginalFk, warehouseFk; + warehouseFk, + buyFk, + landed, + isIgnored + FROM (SELECT b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed, + itemOriginalFk, + b.isIgnored + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vStarted AND vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.price2 > 0 + AND NOT b.isIgnored + AND b.quantity > 0 + AND itemOriginalFk + ORDER BY t.landed DESC, b.id DESC + LIMIT 10000000000000000000) sub + GROUP BY itemFk, warehouseFk; + INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) + SELECT itemFk, + warehouseFk, + buyFk, + landed, + isIgnored + FROM (SELECT b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed, + b.isIgnored + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed > vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.price2 > 0 + AND NOT b.isIgnored + AND itemOriginalFk + ORDER BY t.landed DESC, b.id DESC + LIMIT 10000000000000000000) sub + GROUP BY itemFk, warehouseFk; INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) - SELECT - b.itemFk, - t.warehouseInFk warehouseFk, - b.id buyFk, - t.landed, - b.isIgnored - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed > vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.price2 > 0 - AND NOT b.isIgnored - AND itemOriginalFk - GROUP BY itemOriginalFk, warehouseInFk; - - INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed, isIgnored) - SELECT - b.itemFk, - t.warehouseInFk warehouseFk, - b.id buyFk, - t.landed, - b.isIgnored - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed BETWEEN vStarted AND vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.quantity = 0 - AND itemOriginalFk - GROUP BY itemOriginalFk, warehouseInFk; + SELECT itemFk, + warehouseFk, + buyFk, + landed, + isIgnored + FROM + (SELECT b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed, + b.isIgnored + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vStarted AND vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.quantity = 0 + AND itemOriginalFk + ORDER BY t.landed DESC, b.id DESC + LIMIT 10000000000000000000) sub + GROUP BY itemFk, warehouseFk; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/sale_setProblem.sql b/db/routines/vn/procedures/sale_setProblem.sql index 20319cc3f..1ba7a1353 100644 --- a/db/routines/vn/procedures/sale_setProblem.sql +++ b/db/routines/vn/procedures/sale_setProblem.sql @@ -6,8 +6,15 @@ BEGIN /** * Update column sale.problem with a problem code * @param vProblemCode Code to set or unset - * @table tmp.sale(saleFk, hasProblem) + * @table tmp.sale(saleFk, hasProblem, isProblemCalcNeeded) */ + UPDATE tmp.sale ts + JOIN sale s ON s.id = ts.saleFk + SET s.problem = NULL + WHERE NOT ts.isProblemCalcNeeded; + + DELETE FROM tmp.sale WHERE NOT isProblemCalcNeeded; + UPDATE sale s JOIN tmp.sale ts ON ts.saleFk = s.id SET s.problem = CONCAT( diff --git a/db/routines/vn/procedures/sale_setProblemComponentLack.sql b/db/routines/vn/procedures/sale_setProblemComponentLack.sql index 363663a00..aa5f5f1be 100644 --- a/db/routines/vn/procedures/sale_setProblemComponentLack.sql +++ b/db/routines/vn/procedures/sale_setProblemComponentLack.sql @@ -10,9 +10,13 @@ BEGIN * @param vSelf Id del sale */ CREATE OR REPLACE TEMPORARY TABLE tmp.sale - (INDEX(saleFk)) + (INDEX(saleFk, isProblemCalcNeeded)) ENGINE = MEMORY - SELECT vSelf saleFk, sale_hasComponentLack(vSelf) hasProblem; + SELECT vSelf saleFk, + sale_hasComponentLack(vSelf) hasProblem, + ticket_isProblemCalcNeeded(ticketFk) isProblemCalcNeeded + FROM sale + WHERE id = vSelf; CALL sale_setProblem('hasComponentLack'); diff --git a/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql b/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql index b911327dd..2ee49b656 100644 --- a/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql +++ b/db/routines/vn/procedures/sale_setProblemComponentLackByComponent.sql @@ -10,11 +10,13 @@ BEGIN * @param vComponentFk Id component */ CREATE OR REPLACE TEMPORARY TABLE tmp.sale - (INDEX(saleFk)) + (INDEX(saleFk, isProblemCalcNeeded)) ENGINE = MEMORY - SELECT saleFk, sale_hasComponentLack(saleFk)hasProblem + SELECT saleFk, + sale_hasComponentLack(saleFk) hasProblem, + ticket_isProblemCalcNeeded(ticketFk) isProblemCalcNeeded FROM ( - SELECT s.id saleFk + SELECT s.id saleFk, s.ticketFk FROM ticket t JOIN sale s ON s.ticketFk = t.id LEFT JOIN saleComponent sc ON sc.saleFk = s.id diff --git a/db/routines/vn/procedures/sale_setProblemRounding.sql b/db/routines/vn/procedures/sale_setProblemRounding.sql index f14cd408f..f58d00799 100644 --- a/db/routines/vn/procedures/sale_setProblemRounding.sql +++ b/db/routines/vn/procedures/sale_setProblemRounding.sql @@ -11,9 +11,10 @@ BEGIN DECLARE vWarehouseFk INT; DECLARE vShipped DATE; DECLARE vQuantity INT; + DECLARE vIsProblemCalcNeeded BOOL; - SELECT s.itemFk, t.warehouseFk, t.shipped, s.quantity - INTO vItemFk, vWarehouseFk, vShipped, vQuantity + SELECT s.itemFk, t.warehouseFk, t.shipped, s.quantity, ticket_isProblemCalcNeeded(t.id) + INTO vItemFk, vWarehouseFk, vShipped, vQuantity, vIsProblemCalcNeeded FROM sale s JOIN ticket t ON t.id = s.ticketFk WHERE s.id = vSelf; @@ -21,7 +22,9 @@ BEGIN CALL buyUltimate(vWarehouseFk, vShipped); CREATE OR REPLACE TEMPORARY TABLE tmp.sale - SELECT vSelf saleFk, MOD(vQuantity, b.`grouping`) hasProblem + SELECT vSelf saleFk, + MOD(vQuantity, b.`grouping`) hasProblem, + vIsProblemCalcNeeded isProblemCalcNeeded FROM tmp.buyUltimate bu JOIN buy b ON b.id = bu.buyFk WHERE bu.itemFk = vItemFk; diff --git a/db/routines/vn/procedures/ticket_setProblem.sql b/db/routines/vn/procedures/ticket_setProblem.sql index bab8f1f52..a75cb91ed 100644 --- a/db/routines/vn/procedures/ticket_setProblem.sql +++ b/db/routines/vn/procedures/ticket_setProblem.sql @@ -4,11 +4,19 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblem`( ) BEGIN /** - * Update column ticket.problem with a problem code + * Update column ticket.problem with a problem code and SET NULL when + * the problem is not requiered * * @param vProblemCode Code to set or unset - * @table tmp.ticket(ticketFk, hasProblem) + * @table tmp.ticket(ticketFk, hasProblem, isProblemCalcNeeded) */ + UPDATE ticket t + JOIN tmp.ticket tt ON tt.ticketFk = t.id + SET t.problem = NULL + WHERE NOT tt.isProblemCalcNeeded; + + DELETE FROM tmp.ticket WHERE NOT isProblemCalcNeeded; + UPDATE ticket t JOIN tmp.ticket tt ON tt.ticketFk = t.id SET t.problem = CONCAT( diff --git a/db/routines/vn/procedures/ticket_setProblemFreeze.sql b/db/routines/vn/procedures/ticket_setProblemFreeze.sql index 560bce612..1de939ba7 100644 --- a/db/routines/vn/procedures/ticket_setProblemFreeze.sql +++ b/db/routines/vn/procedures/ticket_setProblemFreeze.sql @@ -9,9 +9,11 @@ BEGIN * @param vClientFk Id Cliente, if NULL all clients */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) + (INDEX(ticketFk, isProblemCalcNeeded)) ENGINE = MEMORY - SELECT t.id ticketFk, FALSE hasProblem + SELECT t.id ticketFk, + FALSE hasProblem, + ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded FROM ticket t WHERE t.shipped >= util.VN_CURDATE() AND (vClientFk IS NULL OR t.clientFk = vClientFk); @@ -21,7 +23,7 @@ BEGIN JOIN client c ON c.id = ti.clientFk SET t.hasProblem = TRUE WHERE c.isFreezed; - + CALL ticket_setProblem('isFreezed'); DROP TEMPORARY TABLE tmp.ticket; diff --git a/db/routines/vn/procedures/ticket_setProblemRequest.sql b/db/routines/vn/procedures/ticket_setProblemRequest.sql index 19bba5b76..687facfc7 100644 --- a/db/routines/vn/procedures/ticket_setProblemRequest.sql +++ b/db/routines/vn/procedures/ticket_setProblemRequest.sql @@ -9,9 +9,11 @@ BEGIN * @param vSelf Id ticket, if NULL ALL tickets */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) + (INDEX(ticketFk, isProblemCalcNeeded)) ENGINE = MEMORY - SELECT t.id ticketFk, FALSE hasProblem + SELECT t.id ticketFk, + FALSE hasProblem, + ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded FROM ticket t WHERE t.shipped >= util.VN_CURDATE() AND (vSelf IS NULL OR t.id = vSelf); diff --git a/db/routines/vn/procedures/ticket_setProblemRisk.sql b/db/routines/vn/procedures/ticket_setProblemRisk.sql index 5f73ee838..efa5b10e2 100644 --- a/db/routines/vn/procedures/ticket_setProblemRisk.sql +++ b/db/routines/vn/procedures/ticket_setProblemRisk.sql @@ -10,21 +10,30 @@ BEGIN */ DECLARE vHasRisk BOOL; DECLARE vHasHighRisk BOOL; + DECLARE vIsProblemCalcNeeded BOOL; - SELECT t.risk > (c.credit + 10), ((t.risk - cc.riskTolerance) > (c.credit + 10)) - INTO vHasRisk, vHasHighRisk + SELECT t.risk > (c.credit + 10), + (t.risk - cc.riskTolerance) > (c.credit + 10), + ticket_isProblemCalcNeeded(t.id) + INTO vHasRisk, vHasHighRisk, vIsProblemCalcNeeded FROM client c JOIN ticket t ON t.clientFk = c.id JOIN clientConfig cc WHERE t.id = vSelf; CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - SELECT vSelf ticketFk, vHasRisk hasProblem; + ENGINE = MEMORY + SELECT vSelf ticketFk, + vHasRisk hasProblem, + vIsProblemCalcNeeded isProblemCalcNeeded; CALL ticket_setProblem('hasRisk'); CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - SELECT vSelf ticketFk, vHasHighRisk hasProblem; + ENGINE = MEMORY + SELECT vSelf ticketFk, + vHasHighRisk hasProblem, + vIsProblemCalcNeeded isProblemCalcNeeded; CALL ticket_setProblem('hasHighRisk'); diff --git a/db/routines/vn/procedures/ticket_setProblemRounding.sql b/db/routines/vn/procedures/ticket_setProblemRounding.sql index 81294325c..fb580eacf 100644 --- a/db/routines/vn/procedures/ticket_setProblemRounding.sql +++ b/db/routines/vn/procedures/ticket_setProblemRounding.sql @@ -18,8 +18,11 @@ BEGIN CALL buyUltimate(vWarehouseFk, vDated); - CREATE OR REPLACE TEMPORARY TABLE tmp.sale - SELECT s.id saleFk , MOD(s.quantity, b.`grouping`) hasProblem + CREATE OR REPLACE TEMPORARY TABLE tmp.sale + (INDEX(saleFk, isProblemCalcNeeded)) + SELECT s.id saleFk , + MOD(s.quantity, b.`grouping`) hasProblem, + ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded FROM ticket t JOIN sale s ON s.ticketFk = t.id JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk diff --git a/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql b/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql index 00918426b..9877b5acc 100644 --- a/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql +++ b/db/routines/vn/procedures/ticket_setProblemTaxDataChecked.sql @@ -9,9 +9,11 @@ BEGIN * @param vClientFk Id cliente, if NULL all clients */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) + (INDEX(ticketFk, isProblemCalcNeeded)) ENGINE = MEMORY - SELECT t.id ticketFk, IF(c.isTaxDataChecked, FALSE, TRUE) hasProblem + SELECT t.id ticketFk, + IF(c.isTaxDataChecked, FALSE, TRUE) hasProblem, + ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded FROM ticket t JOIN client c ON c.id = t.clientFk WHERE t.shipped >= util.VN_CURDATE() diff --git a/db/routines/vn/procedures/ticket_setProblemTooLittle.sql b/db/routines/vn/procedures/ticket_setProblemTooLittle.sql index 98a0787af..48cc47809 100644 --- a/db/routines/vn/procedures/ticket_setProblemTooLittle.sql +++ b/db/routines/vn/procedures/ticket_setProblemTooLittle.sql @@ -8,13 +8,17 @@ BEGIN * * @param vSelf Id del ticket */ + CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) + (INDEX(ticketFk, isProblemCalcNeeded)) ENGINE = MEMORY - SELECT vSelf ticketFk, ticket_isTooLittle(vSelf) hasProblem; + SELECT vSelf ticketFk, + ticket_isTooLittle(vSelf) hasProblem, + ticket_isProblemCalcNeeded(vSelf) isProblemCalcNeeded; CALL ticket_setProblem('isTooLittle'); DROP TEMPORARY TABLE tmp.ticket; + END$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql b/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql index cd1f42783..1f41c0716 100644 --- a/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql +++ b/db/routines/vn/procedures/ticket_setProblemTooLittleItemCost.sql @@ -10,7 +10,7 @@ BEGIN * @param vItemFk Id del item, NULL ALL items */ CREATE OR REPLACE TEMPORARY TABLE tmp.ticket - (INDEX(ticketFk)) + (INDEX(ticketFk, isProblemCalcNeeded)) ENGINE = MEMORY WITH tickets AS( SELECT t.id ticketFk @@ -19,7 +19,9 @@ BEGIN WHERE t.shipped >= util.VN_CURDATE() AND (s.itemFk = vItemFk OR vItemFk IS NULL) GROUP BY t.id - )SELECT ticketFk, ticket_isTooLittle(ticketFk) hasProblem + )SELECT ticketFk, + ticket_isTooLittle(ticketFk) hasProblem, + ticket_isProblemCalcNeeded(t.id) isProblemCalcNeeded FROM tickets; CALL ticket_setProblem('isTooLittle'); From 8b617df13d6846670a9c5db69ee96b3f0a5a2ba6 Mon Sep 17 00:00:00 2001 From: robert Date: Fri, 28 Jun 2024 09:59:55 +0200 Subject: [PATCH 042/173] feat: refs #7116 create table --- db/versions/10960-silverRoebelini/00-firstScript.sql | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/db/versions/10960-silverRoebelini/00-firstScript.sql b/db/versions/10960-silverRoebelini/00-firstScript.sql index c72ce10a7..264e30791 100644 --- a/db/versions/10960-silverRoebelini/00-firstScript.sql +++ b/db/versions/10960-silverRoebelini/00-firstScript.sql @@ -1,10 +1,7 @@ -- Place your SQL code here CREATE TABLE IF NOT EXISTS `vn`.`agencyIncoming` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `code` varchar(50) DEFAULT NULL, - `description` varchar(50) DEFAULT NULL, - `isOrigin` tinyint(1) DEFAULT NULL, - PRIMARY KEY (`id`) + `agencyModeFk` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`agencyModeFk`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 From 00f3755de74a06fee0e4e38af775e16b59c60413 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 1 Jul 2024 07:46:49 +0200 Subject: [PATCH 043/173] feat: refs #7116 agencyIncoming --- db/versions/10960-silverRoebelini/00-firstScript.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/10960-silverRoebelini/00-firstScript.sql b/db/versions/10960-silverRoebelini/00-firstScript.sql index 264e30791..75fc5277f 100644 --- a/db/versions/10960-silverRoebelini/00-firstScript.sql +++ b/db/versions/10960-silverRoebelini/00-firstScript.sql @@ -1,6 +1,6 @@ -- Place your SQL code here CREATE TABLE IF NOT EXISTS `vn`.`agencyIncoming` ( - `agencyModeFk` int(11) NOT NULL AUTO_INCREMENT, + `agencyModeFk` int(11) NOT NULL, PRIMARY KEY (`agencyModeFk`) ) ENGINE=InnoDB From a23f485296c594c23779a8879ba9cc3e1b4a781e Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 1 Jul 2024 11:11:16 +0200 Subject: [PATCH 044/173] refactor: refs #7424 Component type refactor --- db/routines/bi/procedures/rutasAnalyze.sql | 2 +- .../bi/views/tarifa_componentes_series.sql | 2 +- db/routines/vn/procedures/sale_PriceFix.sql | 2 +- .../procedures/ticket_checkNoComponents.sql | 3 +- .../procedures/ticket_getFromFloramondo.sql | 4 +- db/routines/vn/views/saleCost.sql | 2 +- .../vn/views/sale_freightComponent.sql | 2 +- .../11119-tealGerbera/00-firstScript.sql | 9 ++ .../ticket/back/models/component-type.json | 2 +- modules/ticket/front/component/index.html | 2 +- modules/ticket/front/component/index.js | 2 +- .../reports/delivery-note/sql/sales.sql | 85 +++++++++---------- 12 files changed, 63 insertions(+), 54 deletions(-) create mode 100644 db/versions/11119-tealGerbera/00-firstScript.sql diff --git a/db/routines/bi/procedures/rutasAnalyze.sql b/db/routines/bi/procedures/rutasAnalyze.sql index 5f0d55c7a..e277968bf 100644 --- a/db/routines/bi/procedures/rutasAnalyze.sql +++ b/db/routines/bi/procedures/rutasAnalyze.sql @@ -59,7 +59,7 @@ BEGIN JOIN vn.saleComponent sc ON sc.saleFk = s.id JOIN vn.component c ON c.id = sc.componentFk JOIN vn.componentType ct ON ct.id = c.typeFk - WHERE ct.code = 'FREIGHT' + WHERE ct.code = 'freight' AND r.created BETWEEN vDatedFrom AND vDatedTo GROUP BY r.id ) sub ON sub.routeFk = r.Id_Ruta diff --git a/db/routines/bi/views/tarifa_componentes_series.sql b/db/routines/bi/views/tarifa_componentes_series.sql index f231ae420..ed2f8e29a 100644 --- a/db/routines/bi/views/tarifa_componentes_series.sql +++ b/db/routines/bi/views/tarifa_componentes_series.sql @@ -2,7 +2,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bi`.`tarifa_componentes_series` AS SELECT `ct`.`id` AS `tarifa_componentes_series_id`, - `ct`.`type` AS `Serie`, + `ct`.`name` AS `Serie`, `ct`.`isBase` AS `base`, `ct`.`isMargin` AS `margen` FROM `vn`.`componentType` `ct` diff --git a/db/routines/vn/procedures/sale_PriceFix.sql b/db/routines/vn/procedures/sale_PriceFix.sql index 8ffa77070..5f956cba8 100644 --- a/db/routines/vn/procedures/sale_PriceFix.sql +++ b/db/routines/vn/procedures/sale_PriceFix.sql @@ -8,7 +8,7 @@ BEGIN JOIN vn.component c ON c.id = sc.componentFk JOIN vn.componentType ct ON ct.id = c.typeFk WHERE s.ticketFk = vTicketFk - AND ct.`type` = 'otros'; + AND ct.code = 'other'; UPDATE vn.sale s JOIN ( diff --git a/db/routines/vn/procedures/ticket_checkNoComponents.sql b/db/routines/vn/procedures/ticket_checkNoComponents.sql index 28fe333f0..b03427192 100644 --- a/db/routines/vn/procedures/ticket_checkNoComponents.sql +++ b/db/routines/vn/procedures/ticket_checkNoComponents.sql @@ -20,7 +20,8 @@ BEGIN JOIN itemCategory ic ON ic.id = tp.categoryFk JOIN saleComponent sc ON sc.saleFk = s.id JOIN component c ON c.id = sc.componentFk - JOIN componentType ct ON ct.id = c.typeFk AND ct.id = 1 + JOIN componentType ct ON ct.id = c.typeFk + AND ct.code = 'cost' WHERE t.shipped BETWEEN vShippedFrom AND vShippedTo AND ic.merchandise; diff --git a/db/routines/vn/procedures/ticket_getFromFloramondo.sql b/db/routines/vn/procedures/ticket_getFromFloramondo.sql index 4d83d6dda..5f2bedbb1 100644 --- a/db/routines/vn/procedures/ticket_getFromFloramondo.sql +++ b/db/routines/vn/procedures/ticket_getFromFloramondo.sql @@ -66,7 +66,7 @@ BEGIN JOIN vn.componentType ct ON ct.id = c.typeFk JOIN vn.sale s ON s.id = sc.saleFk JOIN tmp.ticket t ON t.ticketFk = s.ticketFk - WHERE ct.code = 'FREIGHT' + WHERE ct.code = 'freight' GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk SET tf.freight = sb.freight; @@ -88,7 +88,7 @@ BEGIN -- Margin UPDATE tmp.ticketFloramondo tf - JOIN (SELECT SUM(IF(ct.code = 'COST',sc.value, 0)) cost, + JOIN (SELECT SUM(IF(ct.code = 'cost',sc.value, 0)) cost, SUM(IF(ct.isMargin, sc.value, 0)) margin, t.ticketFk FROM vn.saleComponent sc diff --git a/db/routines/vn/views/saleCost.sql b/db/routines/vn/views/saleCost.sql index 27265aa93..304b9e3a3 100644 --- a/db/routines/vn/views/saleCost.sql +++ b/db/routines/vn/views/saleCost.sql @@ -19,4 +19,4 @@ FROM ( ) JOIN `vn`.`componentType` `ct` ON(`ct`.`id` = `c`.`typeFk`) ) -WHERE `ct`.`type` = 'coste' +WHERE `ct`.`code` = 'cost' diff --git a/db/routines/vn/views/sale_freightComponent.sql b/db/routines/vn/views/sale_freightComponent.sql index 7a329e0ee..269a8cca1 100644 --- a/db/routines/vn/views/sale_freightComponent.sql +++ b/db/routines/vn/views/sale_freightComponent.sql @@ -16,6 +16,6 @@ FROM ( ) JOIN `vn`.`componentType` `ct` ON( `ct`.`id` = `c`.`typeFk` - AND `ct`.`type` = 'agencia' + AND `ct`.`code` = 'freight' ) ) diff --git a/db/versions/11119-tealGerbera/00-firstScript.sql b/db/versions/11119-tealGerbera/00-firstScript.sql new file mode 100644 index 000000000..40b3b0424 --- /dev/null +++ b/db/versions/11119-tealGerbera/00-firstScript.sql @@ -0,0 +1,9 @@ +ALTER TABLE vn.componentType + CHANGE code code varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL NULL AFTER id; +ALTER TABLE vn.componentType + CHANGE `type` name varchar(45) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL; +UPDATE IGNORE vn.componentType + SET code = LOWER(code); +UPDATE IGNORE vn.componentType + SET code = 'other' + WHERE id = 12; \ No newline at end of file diff --git a/modules/ticket/back/models/component-type.json b/modules/ticket/back/models/component-type.json index 26daf5216..735227a35 100644 --- a/modules/ticket/back/models/component-type.json +++ b/modules/ticket/back/models/component-type.json @@ -12,7 +12,7 @@ "type": "number", "description": "Identifier" }, - "type": { + "name": { "type": "string" }, "isBase":{ diff --git a/modules/ticket/front/component/index.html b/modules/ticket/front/component/index.html index 39b54b461..2a3a80f3e 100644 --- a/modules/ticket/front/component/index.html +++ b/modules/ticket/front/component/index.html @@ -51,7 +51,7 @@ ng-repeat="saleComponent in sale.components track by saleComponent.componentFk" class="components"> - {{::saleComponent.component.componentType.type}} + {{::saleComponent.component.componentType.name}} {{::saleComponent.component.name}} diff --git a/modules/ticket/front/component/index.js b/modules/ticket/front/component/index.js index 3f262f457..aa755e808 100644 --- a/modules/ticket/front/component/index.js +++ b/modules/ticket/front/component/index.js @@ -20,7 +20,7 @@ class Controller extends Section { include: { relation: 'componentType', scope: { - fields: ['type', 'isBase'] + fields: ['name', 'isBase'] } } } diff --git a/print/templates/reports/delivery-note/sql/sales.sql b/print/templates/reports/delivery-note/sql/sales.sql index c449030cf..636bbc228 100644 --- a/print/templates/reports/delivery-note/sql/sales.sql +++ b/print/templates/reports/delivery-note/sql/sales.sql @@ -1,43 +1,42 @@ -SELECT - s.id, - s.itemFk, - s.concept, - s.quantity, - s.price, - s.price - SUM(IF(ctr.id = 6, sc.value, 0)) netPrice, - s.discount, - i.size, - i.stems, - i.category, - it.id itemTypeId, - o.code AS origin, - i.inkFk, - s.ticketFk, - tcl.code vatType, - ib.ediBotanic botanical, - i.tag5, - i.value5, - i.tag6, - i.value6, - i.tag7, - i.value7 -FROM vn.sale s - LEFT JOIN saleComponent sc ON sc.saleFk = s.id - LEFT JOIN component cr ON cr.id = sc.componentFk - LEFT JOIN componentType ctr ON ctr.id = cr.typeFk - LEFT JOIN item i ON i.id = s.itemFk - LEFT JOIN ticket t ON t.id = s.ticketFk - LEFT JOIN origin o ON o.id = i.originFk - LEFT JOIN country c ON c.id = o.countryFk - LEFT JOIN supplier sp ON sp.id = t.companyFk - LEFT JOIN itemType it ON it.id = i.typeFk - LEFT JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id - AND itc.countryFk = sp.countryFk - LEFT JOIN taxClass tcl ON tcl.id = itc.taxClassFk - LEFT JOIN itemBotanicalWithGenus ib ON ib.itemFk = i.id - AND ic.code = 'plant' - AND ib.ediBotanic IS NOT NULL -WHERE s.ticketFk = ? -GROUP BY s.id -ORDER BY (it.isPackaging), s.concept, s.itemFk \ No newline at end of file +SELECT s.id, + s.itemFk, + s.concept, + s.quantity, + s.price, + s.price - SUM(IF(ctr.code = 'freight', sc.value, 0)) netPrice, + s.discount, + i.size, + i.stems, + i.category, + it.id itemTypeId, + o.code origin, + i.inkFk, + s.ticketFk, + tcl.code vatType, + ib.ediBotanic botanical, + i.tag5, + i.value5, + i.tag6, + i.value6, + i.tag7, + i.value7 + FROM vn.sale s + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + LEFT JOIN component cr ON cr.id = sc.componentFk + LEFT JOIN componentType ctr ON ctr.id = cr.typeFk + LEFT JOIN item i ON i.id = s.itemFk + LEFT JOIN ticket t ON t.id = s.ticketFk + LEFT JOIN origin o ON o.id = i.originFk + LEFT JOIN country c ON c.id = o.countryFk + LEFT JOIN supplier sp ON sp.id = t.companyFk + LEFT JOIN itemType it ON it.id = i.typeFk + LEFT JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id + AND itc.countryFk = sp.countryFk + LEFT JOIN taxClass tcl ON tcl.id = itc.taxClassFk + LEFT JOIN itemBotanicalWithGenus ib ON ib.itemFk = i.id + AND ic.code = 'plant' + AND ib.ediBotanic IS NOT NULL + WHERE s.ticketFk = ? + GROUP BY s.id + ORDER BY (it.isPackaging), s.concept, s.itemFk \ No newline at end of file From 0240734a4b99c4003ce909e7aeba121e2c062b8f Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 1 Jul 2024 11:50:37 +0200 Subject: [PATCH 045/173] refs #6897 fix filter --- modules/entry/back/methods/entry/filter.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 1cd12b737..f3f14e7c1 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -173,7 +173,8 @@ module.exports = Self => { s.name AS supplierName, s.nickname AS supplierAlias, co.code AS companyCode, - cu.code AS currencyCode + cu.code AS currencyCode, + t.ref AS travelRef FROM vn.entry e JOIN vn.supplier s ON s.id = e.supplierFk JOIN vn.travel t ON t.id = e.travelFk From 9e5f416d55bc2b159c99c33498da8ed0d33b0967 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 1 Jul 2024 12:06:30 +0200 Subject: [PATCH 046/173] refactor: refs #7418 Item type refactor --- db/dump/fixtures.before.sql | 1 - db/routines/vn2008/views/Tipos.sql | 7 +------ db/versions/11120-brownTulip/00-firstScript.sql | 6 ++++++ 3 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 db/versions/11120-brownTulip/00-firstScript.sql diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 27f84bdfb..61d46d133 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3232,7 +3232,6 @@ INSERT IGNORE INTO vn.itemType workerFk = 103, isInventory = TRUE, life = 10, - density = 250, itemPackingTypeFk = NULL, temperatureFk = 'warm'; diff --git a/db/routines/vn2008/views/Tipos.sql b/db/routines/vn2008/views/Tipos.sql index 4cde954f1..5b96c1766 100644 --- a/db/routines/vn2008/views/Tipos.sql +++ b/db/routines/vn2008/views/Tipos.sql @@ -9,14 +9,9 @@ AS SELECT `it`.`id` AS `tipo_id`, `it`.`workerFk` AS `Id_Trabajador`, `it`.`life` AS `life`, `it`.`isPackaging` AS `isPackaging`, - `it`.`density` AS `density`, `it`.`isInventory` AS `inventory`, `it`.`created` AS `odbc_date`, `it`.`making` AS `confeccion`, `it`.`temperatureFk` AS `Temperatura`, - `it`.`promo` AS `promo`, - `it`.`maneuver` AS `maneuver`, - `it`.`target` AS `target`, - `it`.`topMargin` AS `top_margin`, - `it`.`profit` AS `profit` + `it`.`promo` AS `promo` FROM `vn`.`itemType` `it` diff --git a/db/versions/11120-brownTulip/00-firstScript.sql b/db/versions/11120-brownTulip/00-firstScript.sql new file mode 100644 index 000000000..c4ded80bb --- /dev/null +++ b/db/versions/11120-brownTulip/00-firstScript.sql @@ -0,0 +1,6 @@ +ALTER TABLE vn.itemType + CHANGE maneuver maneuver__ double DEFAULT 0.21 NOT NULL COMMENT '@deprecated 2024-07-01 refs #7418', + CHANGE target target__ double DEFAULT 0.15 NOT NULL COMMENT '@deprecated 2024-07-01 refs #7418', + CHANGE topMargin topMargin__ double DEFAULT 0.3 NOT NULL COMMENT '@deprecated 2024-07-01 refs #7418', + CHANGE profit profit__ double DEFAULT 0.02 NOT NULL COMMENT '@deprecated 2024-07-01 refs #7418', + CHANGE density density__ double DEFAULT 167 NOT NULL COMMENT '@deprecated 2024-07-01 refs #7418 Almacena el valor por defecto de la densidad en kg/m3 para el calculo de los portes aereos, en articulos se guarda la correcta'; \ No newline at end of file From 2ed31ee1d3702df9a7e3f31571b91f50f13e2b9e Mon Sep 17 00:00:00 2001 From: ivanm Date: Mon, 1 Jul 2024 13:26:59 +0200 Subject: [PATCH 047/173] refs #7651 Add editorFk and triggers --- .../account/triggers/mailAliasAccount_beforeInsert.sql | 8 ++++++++ .../account/triggers/mailAliasAccount_beforeUpdate.sql | 8 ++++++++ db/versions/11121-silverAralia/00-firstScript.sql | 4 ++++ 3 files changed, 20 insertions(+) create mode 100644 db/routines/account/triggers/mailAliasAccount_beforeInsert.sql create mode 100644 db/routines/account/triggers/mailAliasAccount_beforeUpdate.sql create mode 100644 db/versions/11121-silverAralia/00-firstScript.sql diff --git a/db/routines/account/triggers/mailAliasAccount_beforeInsert.sql b/db/routines/account/triggers/mailAliasAccount_beforeInsert.sql new file mode 100644 index 000000000..a435832f2 --- /dev/null +++ b/db/routines/account/triggers/mailAliasAccount_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`mailAliasAccount_beforeInsert` + BEFORE INSERT ON `mailAliasAccount` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/account/triggers/mailAliasAccount_beforeUpdate.sql b/db/routines/account/triggers/mailAliasAccount_beforeUpdate.sql new file mode 100644 index 000000000..471a34900 --- /dev/null +++ b/db/routines/account/triggers/mailAliasAccount_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`mailAliasAccount_beforeUpdate` + BEFORE UPDATE ON `mailAliasAccount` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/versions/11121-silverAralia/00-firstScript.sql b/db/versions/11121-silverAralia/00-firstScript.sql new file mode 100644 index 000000000..e74ca2e95 --- /dev/null +++ b/db/versions/11121-silverAralia/00-firstScript.sql @@ -0,0 +1,4 @@ +ALTER TABLE account.mailAliasAccount + ADD editorFk INT UNSIGNED NULL, + ADD CONSTRAINT mailAliasAccount_editorFk FOREIGN KEY (editorFk) + REFERENCES account.`user`(id); \ No newline at end of file From f47197cd8085bb9a762fb98998bd3f8c6b2f3ca6 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Jul 2024 14:06:28 +0200 Subject: [PATCH 048/173] Merge branch '7648_customerEntries' into 7648_dev_customerEntries --- .../11118-limeCymbidium/00-firstScript.sql | 10 ++++++ modules/entry/back/methods/entry/buyLabel.js | 3 +- modules/entry/back/methods/entry/filter.js | 8 +++-- modules/entry/back/methods/entry/getBuys.js | 34 +++++++++++++++---- .../back/methods/entry/specs/filter.spec.js | 18 ++++++---- .../back/methods/entry/specs/getBuys.spec.js | 9 ++++- .../back/methods/supplier/isSupplier.js | 28 +++++++++++++++ modules/supplier/back/models/supplier.js | 1 + 8 files changed, 95 insertions(+), 16 deletions(-) create mode 100644 db/versions/11118-limeCymbidium/00-firstScript.sql create mode 100644 modules/supplier/back/methods/supplier/isSupplier.js diff --git a/db/versions/11118-limeCymbidium/00-firstScript.sql b/db/versions/11118-limeCymbidium/00-firstScript.sql new file mode 100644 index 000000000..52ab2acbd --- /dev/null +++ b/db/versions/11118-limeCymbidium/00-firstScript.sql @@ -0,0 +1,10 @@ +-- Place your SQL code here +-- Auto-generated SQL script #202406281423 +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + VALUES ('Entry','filter','READ','ALLOW','ROLE','$authenticated'); + +-- Auto-generated SQL script #202406281452 +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + VALUES ('Entry','getBuys','READ','ALLOW','ROLE','$authenticated'); +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + VALUES ('Entry','buyLabel','READ','ALLOW','ROLE','$authenticated'); diff --git a/modules/entry/back/methods/entry/buyLabel.js b/modules/entry/back/methods/entry/buyLabel.js index 650b05c97..d9b0ebf1d 100644 --- a/modules/entry/back/methods/entry/buyLabel.js +++ b/modules/entry/back/methods/entry/buyLabel.js @@ -29,7 +29,8 @@ module.exports = Self => { http: { path: '/:id/buy-label', verb: 'GET' - } + }, + accessScopes: ['DEFAULT', 'read:multimedia'] }); Self.buyLabel = (ctx, id) => Self.printReport(ctx, id, 'buy-label'); diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 1cd12b737..7d287b842 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -112,7 +112,7 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - + const isSupplier = await Self.app.models.Supplier.isSupplier(ctx, options); const conn = Self.dataSource.connector; const where = buildFilter(ctx.args, (param, value) => { switch (param) { @@ -146,7 +146,11 @@ module.exports = Self => { } }); filter = mergeFilters(ctx.args.filter, {where}); - + delete filter.order; + if (isSupplier) { + if (!filter.where) filter.where = {}; + filter.where.supplierFk = ctx.req.accessToken.userId; + } const stmts = []; let stmt; stmt = new ParameterizedSQL( diff --git a/modules/entry/back/methods/entry/getBuys.js b/modules/entry/back/methods/entry/getBuys.js index 0ed77e8d1..cfb065b83 100644 --- a/modules/entry/back/methods/entry/getBuys.js +++ b/modules/entry/back/methods/entry/getBuys.js @@ -1,7 +1,10 @@ +const ForbiddenError = require('vn-loopback/util/forbiddenError'); +const UserError = require('vn-loopback/util/user-error'); + const mergeFilters = require('vn-loopback/util/filter').mergeFilters; module.exports = Self => { - Self.remoteMethod('getBuys', { + Self.remoteMethodCtx('getBuys', { description: 'Returns buys for one entry', accessType: 'READ', accepts: [{ @@ -27,13 +30,18 @@ module.exports = Self => { } }); - Self.getBuys = async(id, filter, options) => { + Self.getBuys = async(ctx, id, filter, options) => { const models = Self.app.models; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); + const isSupplier = await Self.app.models.Supplier.isSupplier(ctx, options); + if (isSupplier) { + const isEntryOwner = (await Self.findById(id)).supplierFk === ctx.req.accessToken.userId; + if (! isEntryOwner) throw new UserError('Access Denied'); + } let defaultFilter = { where: {entryFk: id}, fields: [ @@ -49,9 +57,23 @@ module.exports = Self => { 'buyingValue', 'price2', 'price3', - 'printedStickers' + 'printedStickers', + 'entryFk' ], - include: { + include: [{ + relation: 'entry', + scope: { + fields: [ + 'id', 'supplierFk' + ], + include: { + relation: 'supplier', scope: { + fields: ['id'] + } + } + } + }, + { relation: 'item', scope: { fields: [ @@ -82,9 +104,9 @@ module.exports = Self => { } } } - } + }] }; - + delete filter.order; defaultFilter = mergeFilters(defaultFilter, filter); return models.Buy.find(defaultFilter, myOptions); diff --git a/modules/entry/back/methods/entry/specs/filter.spec.js b/modules/entry/back/methods/entry/specs/filter.spec.js index 28763bc81..e116d1c5f 100644 --- a/modules/entry/back/methods/entry/specs/filter.spec.js +++ b/modules/entry/back/methods/entry/specs/filter.spec.js @@ -9,7 +9,8 @@ describe('Entry filter()', () => { const ctx = { args: { search: 1 - } + }, + req: {accessToken: {userId: 9}} }; const result = await models.Entry.filter(ctx, options); @@ -32,7 +33,8 @@ describe('Entry filter()', () => { const ctx = { args: { currencyFk: 1 - } + }, + req: {accessToken: {userId: 9}} }; const result = await models.Entry.filter(ctx, options); @@ -54,7 +56,8 @@ describe('Entry filter()', () => { const ctx = { args: { supplierFk: 2 - } + }, + req: {accessToken: {userId: 9}} }; const result = await models.Entry.filter(ctx, options); @@ -76,7 +79,8 @@ describe('Entry filter()', () => { const ctx = { args: { companyFk: 442 - } + }, + req: {accessToken: {userId: 9}} }; const result = await models.Entry.filter(ctx, options); @@ -98,7 +102,8 @@ describe('Entry filter()', () => { const ctx = { args: { isBooked: true, - } + }, + req: {accessToken: {userId: 9}} }; const result = await models.Entry.filter(ctx, options); @@ -121,7 +126,8 @@ describe('Entry filter()', () => { args: { reference: 'movement', travelFk: '2' - } + }, + req: {accessToken: {userId: 9}} }; const result = await models.Entry.filter(ctx, options); diff --git a/modules/entry/back/methods/entry/specs/getBuys.spec.js b/modules/entry/back/methods/entry/specs/getBuys.spec.js index cf4462e48..44b2ff5bc 100644 --- a/modules/entry/back/methods/entry/specs/getBuys.spec.js +++ b/modules/entry/back/methods/entry/specs/getBuys.spec.js @@ -7,7 +7,14 @@ describe('entry getBuys()', () => { const options = {transaction: tx}; try { - const result = await models.Entry.getBuys(entryId, options); + const ctx = { + args: { + search: 1 + }, + req: {accessToken: {userId: 2}} + }; + + const result = await models.Entry.getBuys(ctx, entryId, options); const length = result.length; const anyResult = result[Math.floor(Math.random() * Math.floor(length))]; diff --git a/modules/supplier/back/methods/supplier/isSupplier.js b/modules/supplier/back/methods/supplier/isSupplier.js new file mode 100644 index 000000000..d13f304a8 --- /dev/null +++ b/modules/supplier/back/methods/supplier/isSupplier.js @@ -0,0 +1,28 @@ +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethodCtx('isSupplier', { + description: 'Check is supplierFk exists as supplier', + accessType: 'READ', + returns: { + type: 'boolean', + root: true + }, + http: { + path: `/isSupplier`, + verb: 'GET' + } + }); + + Self.isSupplier = async(ctx, options) => { + const myOptions = {validate: false}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const userId = ctx.req.accessToken.userId; + const exists = await Self.findById(userId); + + return !!exists; + }; +}; diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 2d3ffef3e..6094602b6 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -12,6 +12,7 @@ module.exports = Self => { require('../methods/supplier/campaignMetricsEmail')(Self); require('../methods/supplier/newSupplier')(Self); require('../methods/supplier/getItemsPackaging')(Self); + require('../methods/supplier/isSupplier')(Self); Self.validatesPresenceOf('name', { message: 'The social name cannot be empty' From f0326860baaac84570a1e261cb1738860760bf4a Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Jul 2024 14:07:46 +0200 Subject: [PATCH 049/173] feat(salix): refs #7648 #7648 add new fields --- modules/entry/back/methods/entry/filter.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 7d287b842..929df8bd9 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -177,10 +177,15 @@ module.exports = Self => { s.name AS supplierName, s.nickname AS supplierAlias, co.code AS companyCode, - cu.code AS currencyCode + cu.code AS currencyCode, + t.shipped AS shipped, + t.landed AS landed, + t.warehouseInFk AS warehouseId, + w.name AS warehouseName FROM vn.entry e JOIN vn.supplier s ON s.id = e.supplierFk JOIN vn.travel t ON t.id = e.travelFk + JOIN vn.warehouse w ON w.id = t.warehouseInFk JOIN vn.company co ON co.id = e.companyFk JOIN vn.currency cu ON cu.id = e.currencyFk` ); From 29aecd62a527c203430e0b84ad3ffe466d4bff9f Mon Sep 17 00:00:00 2001 From: ivanm Date: Mon, 1 Jul 2024 14:51:32 +0200 Subject: [PATCH 050/173] refs #7651 add afterDelete trigger --- .../triggers/mailAliasAccount_afterDelete.sql | 12 ++++++++++++ db/versions/11121-silverAralia/00-firstScript.sql | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 db/routines/account/triggers/mailAliasAccount_afterDelete.sql diff --git a/db/routines/account/triggers/mailAliasAccount_afterDelete.sql b/db/routines/account/triggers/mailAliasAccount_afterDelete.sql new file mode 100644 index 000000000..83af7169c --- /dev/null +++ b/db/routines/account/triggers/mailAliasAccount_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `account`.`mailAliasAccount_afterDelete` + AFTER DELETE ON `mailAliasAccount` + FOR EACH ROW +BEGIN + INSERT INTO userLog + SET `action` = 'delete', + `changedModel` = 'MailAliasAccount', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/versions/11121-silverAralia/00-firstScript.sql b/db/versions/11121-silverAralia/00-firstScript.sql index e74ca2e95..20b0e8195 100644 --- a/db/versions/11121-silverAralia/00-firstScript.sql +++ b/db/versions/11121-silverAralia/00-firstScript.sql @@ -1,4 +1,4 @@ ALTER TABLE account.mailAliasAccount - ADD editorFk INT UNSIGNED NULL, + ADD editorFk INT(10) UNSIGNED DEFAULT NULL, ADD CONSTRAINT mailAliasAccount_editorFk FOREIGN KEY (editorFk) REFERENCES account.`user`(id); \ No newline at end of file From d9742afc9b4fdaaf143fe91c227527e684d3c931 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 1 Jul 2024 17:45:45 +0200 Subject: [PATCH 051/173] feat roadmap refs #7195 --- modules/route/back/models/roadmapStop.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/route/back/models/roadmapStop.json b/modules/route/back/models/roadmapStop.json index 74b02cd7a..93eae0113 100644 --- a/modules/route/back/models/roadmapStop.json +++ b/modules/route/back/models/roadmapStop.json @@ -3,7 +3,7 @@ "base": "VnModel", "options": { "mysql": { - "table": "roadmapStop" + "table": "roadmapStop" } }, "properties": { @@ -28,16 +28,16 @@ "type": "number" } }, - "relations": { - "roadmap": { + "relations": { + "roadmap": { "type": "belongsTo", "model": "Roadmap", "foreignKey": "roadmapFk" }, "address": { "type": "belongsTo", - "model": "Address", + "model": "RoadmapAddress", "foreignKey": "addressFk" } - } -} + } +} \ No newline at end of file From a0185dca0486a339ba41ab8822ff4e767e19be1b Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Jul 2024 18:39:21 +0200 Subject: [PATCH 052/173] feat(salix): refs #7648 #7648 new supplier role --- .../11118-limeCymbidium/00-firstScript.sql | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/db/versions/11118-limeCymbidium/00-firstScript.sql b/db/versions/11118-limeCymbidium/00-firstScript.sql index 52ab2acbd..7f9a2432d 100644 --- a/db/versions/11118-limeCymbidium/00-firstScript.sql +++ b/db/versions/11118-limeCymbidium/00-firstScript.sql @@ -1,10 +1,15 @@ --- Place your SQL code here --- Auto-generated SQL script #202406281423 -INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) - VALUES ('Entry','filter','READ','ALLOW','ROLE','$authenticated'); --- Auto-generated SQL script #202406281452 -INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) +INSERT IGNORE INTO salix.ACL (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) + VALUES ('Entry','filter','READ','ALLOW','ROLE','supplier'); + +INSERT IGNORE INTO salix.ACL (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) VALUES ('Entry','getBuys','READ','ALLOW','ROLE','$authenticated'); -INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + +INSERT IGNORE INTO salix.ACL (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) VALUES ('Entry','buyLabel','READ','ALLOW','ROLE','$authenticated'); + +INSERT IGNORE INTO `account`.`role` (`name`,`description`,`hasLogin`,`created`,`modified`) + VALUES ('supplier','Proveedores',1,'2017-10-10 14:58:58.000','2017-10-10 14:59:20.000'); +SET @supplierFk =LAST_INSERT_ID(); +INSERT IGNORE INTO account.roleInherit (`role`,`inheritsFrom`) + VALUES (@supplierFk,2); From f27bdec75822835be3db77ff496f686d524a826d Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 1 Jul 2024 21:14:27 +0200 Subject: [PATCH 053/173] feat(salix): refs #7648 #7648 changes requested --- .../11118-limeCymbidium/00-firstScript.sql | 9 ++++-- loopback/common/methods/schema/model-info.js | 1 + modules/entry/back/methods/entry/filter.js | 4 +-- modules/entry/back/methods/entry/getBuys.js | 8 +++--- .../back/methods/supplier/isSupplier.js | 28 ------------------- modules/supplier/back/models/supplier.js | 1 - 6 files changed, 14 insertions(+), 37 deletions(-) delete mode 100644 modules/supplier/back/methods/supplier/isSupplier.js diff --git a/db/versions/11118-limeCymbidium/00-firstScript.sql b/db/versions/11118-limeCymbidium/00-firstScript.sql index 7f9a2432d..0ed1337a0 100644 --- a/db/versions/11118-limeCymbidium/00-firstScript.sql +++ b/db/versions/11118-limeCymbidium/00-firstScript.sql @@ -3,13 +3,18 @@ INSERT IGNORE INTO salix.ACL (`model`,`property`,`accessType`,`permission`,`prin VALUES ('Entry','filter','READ','ALLOW','ROLE','supplier'); INSERT IGNORE INTO salix.ACL (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) - VALUES ('Entry','getBuys','READ','ALLOW','ROLE','$authenticated'); + VALUES ('Entry','getBuys','READ','ALLOW','ROLE','supplier'); INSERT IGNORE INTO salix.ACL (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) - VALUES ('Entry','buyLabel','READ','ALLOW','ROLE','$authenticated'); + VALUES ('Entry','buyLabel','READ','ALLOW','ROLE','supplier'); INSERT IGNORE INTO `account`.`role` (`name`,`description`,`hasLogin`,`created`,`modified`) VALUES ('supplier','Proveedores',1,'2017-10-10 14:58:58.000','2017-10-10 14:59:20.000'); SET @supplierFk =LAST_INSERT_ID(); INSERT IGNORE INTO account.roleInherit (`role`,`inheritsFrom`) VALUES (@supplierFk,2); + +UPDATE salix.ACL + SET principalId='$authenticated' + WHERE id=264; + diff --git a/loopback/common/methods/schema/model-info.js b/loopback/common/methods/schema/model-info.js index 0648deb80..74d764475 100644 --- a/loopback/common/methods/schema/model-info.js +++ b/loopback/common/methods/schema/model-info.js @@ -92,6 +92,7 @@ module.exports = Self => { const locale = modelLocale && modelLocale.get(lang); json[modelName] = { + http: model.sharedClass.http.path, properties: model.definition.rawProperties, validations: jsonValidations, locale diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 929df8bd9..2a127b496 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -112,7 +112,6 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const isSupplier = await Self.app.models.Supplier.isSupplier(ctx, options); const conn = Self.dataSource.connector; const where = buildFilter(ctx.args, (param, value) => { switch (param) { @@ -146,7 +145,8 @@ module.exports = Self => { } }); filter = mergeFilters(ctx.args.filter, {where}); - delete filter.order; + const userId = ctx.req.accessToken.userId; + const isSupplier = await Self.app.models.Supplier.findById(userId, options); if (isSupplier) { if (!filter.where) filter.where = {}; filter.where.supplierFk = ctx.req.accessToken.userId; diff --git a/modules/entry/back/methods/entry/getBuys.js b/modules/entry/back/methods/entry/getBuys.js index cfb065b83..e392ba3ce 100644 --- a/modules/entry/back/methods/entry/getBuys.js +++ b/modules/entry/back/methods/entry/getBuys.js @@ -31,16 +31,17 @@ module.exports = Self => { }); Self.getBuys = async(ctx, id, filter, options) => { + const userId = ctx.req.accessToken.userId; const models = Self.app.models; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); - const isSupplier = await Self.app.models.Supplier.isSupplier(ctx, options); + const isSupplier = await Self.app.models.Supplier.findById(userId, options); if (isSupplier) { - const isEntryOwner = (await Self.findById(id)).supplierFk === ctx.req.accessToken.userId; + const isEntryOwner = (await Self.findById(id)).supplierFk === userId; - if (! isEntryOwner) throw new UserError('Access Denied'); + if (!isEntryOwner) throw new UserError('Access Denied'); } let defaultFilter = { where: {entryFk: id}, @@ -106,7 +107,6 @@ module.exports = Self => { } }] }; - delete filter.order; defaultFilter = mergeFilters(defaultFilter, filter); return models.Buy.find(defaultFilter, myOptions); diff --git a/modules/supplier/back/methods/supplier/isSupplier.js b/modules/supplier/back/methods/supplier/isSupplier.js deleted file mode 100644 index d13f304a8..000000000 --- a/modules/supplier/back/methods/supplier/isSupplier.js +++ /dev/null @@ -1,28 +0,0 @@ -const UserError = require('vn-loopback/util/user-error'); - -module.exports = Self => { - Self.remoteMethodCtx('isSupplier', { - description: 'Check is supplierFk exists as supplier', - accessType: 'READ', - returns: { - type: 'boolean', - root: true - }, - http: { - path: `/isSupplier`, - verb: 'GET' - } - }); - - Self.isSupplier = async(ctx, options) => { - const myOptions = {validate: false}; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - const userId = ctx.req.accessToken.userId; - const exists = await Self.findById(userId); - - return !!exists; - }; -}; diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 6094602b6..2d3ffef3e 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -12,7 +12,6 @@ module.exports = Self => { require('../methods/supplier/campaignMetricsEmail')(Self); require('../methods/supplier/newSupplier')(Self); require('../methods/supplier/getItemsPackaging')(Self); - require('../methods/supplier/isSupplier')(Self); Self.validatesPresenceOf('name', { message: 'The social name cannot be empty' From 08cf79b09bc68104a2547e95e1f4b165b8ac6ea8 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 2 Jul 2024 08:39:42 +0200 Subject: [PATCH 054/173] feat roadmap refs #7195 --- .../back/methods/roadmapStop/getPalletMatchState.js | 9 ++++----- .../roadmapStop/specs/getPalletMatchState.spec.js | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/modules/route/back/methods/roadmapStop/getPalletMatchState.js b/modules/route/back/methods/roadmapStop/getPalletMatchState.js index efed64327..138d62411 100644 --- a/modules/route/back/methods/roadmapStop/getPalletMatchState.js +++ b/modules/route/back/methods/roadmapStop/getPalletMatchState.js @@ -1,6 +1,6 @@ module.exports = Self => { Self.remoteMethod('getPalletMatchState', { - description: 'Get pallet', + description: 'Get list of pallet from roadMapStop with true or false if state is matched', accessType: 'WRITE', accepts: [{ arg: 'roadMapStopFk', @@ -32,7 +32,7 @@ module.exports = Self => { const result = await Self.rawSql(` WITH tPallet AS( - SELECT ep.truckFk roadMapStop,ep.id pallet, e.id expedition, e.stateTypeFk + SELECT ep.id pallet, e.id expedition, e.stateTypeFk FROM vn.expeditionPallet ep JOIN vn.expeditionScan es ON es.palletFk = ep.id JOIN expedition e ON e.id = es.expeditionFk @@ -48,9 +48,8 @@ module.exports = Self => { WHERE code = ? GROUP BY expedition ) - SELECT t.roadMapStop, - t.pallet, - IF (tpe.totalPalletExpedition = tpec.totalPalletExpeditionCode, 'TRUE', 'FALSE') hasMatchStateCode + SELECT t.pallet, + tpe.totalPalletExpedition = tpec.totalPalletExpeditionCode hasMatchStateCode FROM tPallet t LEFT JOIN totalPalletExpedition tpe ON tpe.expedition = t.expedition LEFT JOIN totalPalletExpeditionCode tpec ON tpec.expedition = t.expedition diff --git a/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js b/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js index ac782561a..3e89bd528 100644 --- a/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js +++ b/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js @@ -2,11 +2,11 @@ const {models} = require('vn-loopback/server/server'); describe('roadMapStop getPalletMatchState()', () => { - fit('should return list of pallet with true or false if state is matched', async() => { + it('should return list of pallet with true or false if state is matched', async() => { const roadmapStopFk = 1; const state = 'ON DELIVERY'; const result = await models.RoadmapStop.getPalletMatchState(roadmapStopFk, state); - expect(result[0].hasMatchStateCode).toBe('TRUE'); + expect(result[0].hasMatchStateCode).toBe(1); }); }); From 89a394a10def74e4b9c11cd3986bf7b91b24aab2 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 2 Jul 2024 09:52:18 +0200 Subject: [PATCH 055/173] test(salix): refs #7648 #7648 entry.filter --- modules/entry/back/methods/entry/filter.js | 2 +- .../back/methods/entry/specs/filter.spec.js | 82 +++++++++++++++---- 2 files changed, 65 insertions(+), 19 deletions(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 2a127b496..700d251a2 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -149,7 +149,7 @@ module.exports = Self => { const isSupplier = await Self.app.models.Supplier.findById(userId, options); if (isSupplier) { if (!filter.where) filter.where = {}; - filter.where.supplierFk = ctx.req.accessToken.userId; + filter.where[`e.supplierFk`] = ctx.req.accessToken.userId; } const stmts = []; let stmt; diff --git a/modules/entry/back/methods/entry/specs/filter.spec.js b/modules/entry/back/methods/entry/specs/filter.spec.js index e116d1c5f..76dc7b786 100644 --- a/modules/entry/back/methods/entry/specs/filter.spec.js +++ b/modules/entry/back/methods/entry/specs/filter.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -describe('Entry filter()', () => { +fdescribe('Entry filter()', () => { it('should return the entry matching "search"', async() => { const tx = await models.Entry.beginTransaction({}); const options = {transaction: tx}; @@ -48,27 +48,73 @@ describe('Entry filter()', () => { } }); - it('should return the entry matching the supplier', async() => { - const tx = await models.Entry.beginTransaction({}); - const options = {transaction: tx}; + describe('should return the entry matching the supplier', () => { + it('when userId is supplier ', async() => { + const tx = await models.Entry.beginTransaction({}); + const options = {transaction: tx}; - try { - const ctx = { - args: { - supplierFk: 2 - }, - req: {accessToken: {userId: 9}} - }; + try { + const ctx = { + args: {}, + req: {accessToken: {userId: 2}} + }; - const result = await models.Entry.filter(ctx, options); + const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(6); + expect(result.length).toEqual(6); - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('when userId is supplier fetching other supplier', async() => { + const tx = await models.Entry.beginTransaction({}); + const options = {transaction: tx}; + + try { + const ctx = { + args: { + supplierFk: 1 + }, + req: {accessToken: {userId: 2}} + }; + + const result = await models.Entry.filter(ctx, options); + + expect(result.length).toEqual(6); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('when userId is not supplier', async() => { + const tx = await models.Entry.beginTransaction({}); + const options = {transaction: tx}; + + try { + const ctx = { + args: { + supplierFk: 2 + }, + req: {accessToken: {userId: 9}} + }; + + const result = await models.Entry.filter(ctx, options); + + expect(result.length).toEqual(6); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); it('should return the entry matching the company', async() => { From 30520cbe4895357a1026e236a0d8caa90442e6bf Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 2 Jul 2024 10:06:26 +0200 Subject: [PATCH 056/173] test(salix): refs #7648 #7648 getBuys.filter --- .../back/methods/entry/specs/getBuys.spec.js | 93 ++++++++++++++----- 1 file changed, 72 insertions(+), 21 deletions(-) diff --git a/modules/entry/back/methods/entry/specs/getBuys.spec.js b/modules/entry/back/methods/entry/specs/getBuys.spec.js index 44b2ff5bc..801cd6f1a 100644 --- a/modules/entry/back/methods/entry/specs/getBuys.spec.js +++ b/modules/entry/back/methods/entry/specs/getBuys.spec.js @@ -1,31 +1,82 @@ +const UserError = require('vn-loopback/util/user-error'); const models = require('vn-loopback/server/server').models; -describe('entry getBuys()', () => { +fdescribe('entry getBuys()', () => { const entryId = 4; - it('should get the buys and items of an entry', async() => { - const tx = await models.Entry.beginTransaction({}); - const options = {transaction: tx}; + describe('should get the buys and items of an entry ', () => { + it('when is supplier and entry owner', async() => { + const tx = await models.Entry.beginTransaction({}); + const options = {transaction: tx}; - try { - const ctx = { - args: { - search: 1 - }, - req: {accessToken: {userId: 2}} - }; + try { + const ctx = { + args: { + search: 1 + }, + req: {accessToken: {userId: 2}} + }; - const result = await models.Entry.getBuys(ctx, entryId, options); + const result = await models.Entry.getBuys(ctx, entryId, options); - const length = result.length; - const anyResult = result[Math.floor(Math.random() * Math.floor(length))]; + const length = result.length; + const anyResult = result[Math.floor(Math.random() * Math.floor(length))]; - expect(result.length).toEqual(4); - expect(anyResult.item).toBeDefined(); + expect(result.length).toEqual(4); + expect(anyResult.item).toBeDefined(); - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('when is supplier but not entry owner', async() => { + const tx = await models.Entry.beginTransaction({}); + const options = {transaction: tx}; + const entryId = 1; + try { + const ctx = { + args: { + search: 1 + }, + req: {accessToken: {userId: 2}} + }; + + const result = await models.Entry.getBuys(ctx, entryId, options); + + expect(result).toBeUndefined(); + } catch (error) { + expect(error).toBeInstanceOf(UserError); + expect(error.message).toBe('Access Denied'); + } + }); + + it('when is not supplier', async() => { + const tx = await models.Entry.beginTransaction({}); + const options = {transaction: tx}; + + try { + const ctx = { + args: { + search: 1 + }, + req: {accessToken: {userId: 9}} + }; + + const result = await models.Entry.getBuys(ctx, entryId, options); + + const length = result.length; + const anyResult = result[Math.floor(Math.random() * Math.floor(length))]; + + expect(result.length).toEqual(4); + expect(anyResult.item).toBeDefined(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); }); From 08612fc70cccafdc802673e96032cc3787913842 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 2 Jul 2024 10:07:23 +0200 Subject: [PATCH 057/173] perf(salix): refs #7648 #7648 fixtures and firstScript --- db/dump/fixtures.before.sql | 3 +++ db/versions/11118-limeCymbidium/00-firstScript.sql | 1 + 2 files changed, 4 insertions(+) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 27f84bdfb..b27bc8ef6 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3913,3 +3913,6 @@ INSERT INTO dipole.expedition_PrintOut (expeditionFk, ticketFk, addressFk, stree truckName, clientFk, phone, province, agency, m3, workerCode, itemFk, quantity, longName, shelvingFk, comments) VALUES(1, 1, 0, ' ', ' ', ' ', ' ', 0, '2001-01-01 00:00:00', 1, 0, ' ', ' ', 0, NULL, '', NULL, 0.000, NULL, 10, NULL, NULL, 'NCC', NULL); +UPDATE account.`user` + SET `role`=131 + WHERE id=2; diff --git a/db/versions/11118-limeCymbidium/00-firstScript.sql b/db/versions/11118-limeCymbidium/00-firstScript.sql index 0ed1337a0..3921a8a13 100644 --- a/db/versions/11118-limeCymbidium/00-firstScript.sql +++ b/db/versions/11118-limeCymbidium/00-firstScript.sql @@ -18,3 +18,4 @@ UPDATE salix.ACL SET principalId='$authenticated' WHERE id=264; + From 3539b5a33e906cc182ae4468929a43790b76a53d Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 2 Jul 2024 10:08:51 +0200 Subject: [PATCH 058/173] test(salix): refs #7648 #7648 remove fdescribe --- modules/entry/back/methods/entry/specs/filter.spec.js | 2 +- modules/entry/back/methods/entry/specs/getBuys.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/entry/back/methods/entry/specs/filter.spec.js b/modules/entry/back/methods/entry/specs/filter.spec.js index 76dc7b786..9d954cdc4 100644 --- a/modules/entry/back/methods/entry/specs/filter.spec.js +++ b/modules/entry/back/methods/entry/specs/filter.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -fdescribe('Entry filter()', () => { +describe('Entry filter()', () => { it('should return the entry matching "search"', async() => { const tx = await models.Entry.beginTransaction({}); const options = {transaction: tx}; diff --git a/modules/entry/back/methods/entry/specs/getBuys.spec.js b/modules/entry/back/methods/entry/specs/getBuys.spec.js index 801cd6f1a..cb7f7cb80 100644 --- a/modules/entry/back/methods/entry/specs/getBuys.spec.js +++ b/modules/entry/back/methods/entry/specs/getBuys.spec.js @@ -1,7 +1,7 @@ const UserError = require('vn-loopback/util/user-error'); const models = require('vn-loopback/server/server').models; -fdescribe('entry getBuys()', () => { +describe('entry getBuys()', () => { const entryId = 4; describe('should get the buys and items of an entry ', () => { it('when is supplier and entry owner', async() => { From 7f213a7435550314bb71556a89c6f97062ef681e Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 2 Jul 2024 12:02:44 +0200 Subject: [PATCH 059/173] refs #6952 fix producer --- print/templates/reports/delivery-note/delivery-note.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/print/templates/reports/delivery-note/delivery-note.html b/print/templates/reports/delivery-note/delivery-note.html index 540a80a3a..c1701e084 100644 --- a/print/templates/reports/delivery-note/delivery-note.html +++ b/print/templates/reports/delivery-note/delivery-note.html @@ -81,7 +81,7 @@ {{sale.tag5}} {{sale.value5}} {{sale.tag6}} {{sale.value6}} {{sale.tag7}} {{sale.value7}} - {{$t('producer')}} {{ sale.subName }} + {{$t('producer')}} {{ sale.subName }} From e1b6ba4276dff0aa80476c9dfc33e33dfcd5b8d1 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 2 Jul 2024 12:03:21 +0200 Subject: [PATCH 060/173] feat roadmap refs #7195 --- .../back/methods/roadmapStop/getPalletMatchState.js | 10 +++++----- .../roadmapStop/specs/getPalletMatchState.spec.js | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/route/back/methods/roadmapStop/getPalletMatchState.js b/modules/route/back/methods/roadmapStop/getPalletMatchState.js index 138d62411..828dbb689 100644 --- a/modules/route/back/methods/roadmapStop/getPalletMatchState.js +++ b/modules/route/back/methods/roadmapStop/getPalletMatchState.js @@ -1,12 +1,12 @@ module.exports = Self => { Self.remoteMethod('getPalletMatchState', { - description: 'Get list of pallet from roadMapStop with true or false if state is matched', + description: 'Get list of pallet from truckFk with true or false if state is matched', accessType: 'WRITE', accepts: [{ - arg: 'roadMapStopFk', + arg: 'truckFk', type: 'number', required: true, - description: 'The roadmapFk id' + description: 'The truckFk id' }, { arg: 'state', @@ -24,7 +24,7 @@ module.exports = Self => { } }); - Self.getPalletMatchState = async(roadMapStopFk, state, options) => { + Self.getPalletMatchState = async(truckFk, state, options) => { const myOptions = {}; if (typeof options == 'object') @@ -54,7 +54,7 @@ module.exports = Self => { LEFT JOIN totalPalletExpedition tpe ON tpe.expedition = t.expedition LEFT JOIN totalPalletExpeditionCode tpec ON tpec.expedition = t.expedition GROUP BY t.pallet;`, - [roadMapStopFk, state], + [truckFk, state], myOptions); return result; diff --git a/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js b/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js index 3e89bd528..4a79b589e 100644 --- a/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js +++ b/modules/route/back/methods/roadmapStop/specs/getPalletMatchState.spec.js @@ -3,9 +3,9 @@ const {models} = require('vn-loopback/server/server'); describe('roadMapStop getPalletMatchState()', () => { it('should return list of pallet with true or false if state is matched', async() => { - const roadmapStopFk = 1; + const truckFk = 1; const state = 'ON DELIVERY'; - const result = await models.RoadmapStop.getPalletMatchState(roadmapStopFk, state); + const result = await models.RoadmapStop.getPalletMatchState(truckFk, state); expect(result[0].hasMatchStateCode).toBe(1); }); From 9708e79e5518addc77a0e447c65744d96a48a149 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 2 Jul 2024 12:41:51 +0200 Subject: [PATCH 061/173] build: increase version 2430 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 95d696fc3..ea126bce3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "24.28.0", + "version": "24.30.0", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From 0bb4439f85d07c6765d2873c0ca82f1b42a25358 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 2 Jul 2024 14:37:22 +0200 Subject: [PATCH 062/173] refs #7443 Deleted ekt barcode --- db/routines/edi/procedures/ekt_refresh.sql | 19 +++---------------- db/routines/edi/views/ektRecent.sql | 1 - db/routines/vn2008/views/buy_edi.sql | 1 - 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/db/routines/edi/procedures/ekt_refresh.sql b/db/routines/edi/procedures/ekt_refresh.sql index 0e9ed7d3c..8ba438c0a 100644 --- a/db/routines/edi/procedures/ekt_refresh.sql +++ b/db/routines/edi/procedures/ekt_refresh.sql @@ -7,7 +7,6 @@ BEGIN */ DECLARE vRewriteKop INT DEFAULT NULL; DECLARE vTruncatePutOrder INT DEFAULT NULL; - DECLARE vBarcode CHAR(15) DEFAULT NULL; DECLARE vKop INT; DECLARE vPutOrderFk BIGINT; @@ -16,17 +15,6 @@ BEGIN FROM ekt WHERE id = vSelf; - -- Generates the barcode - - SELECT CONCAT( - LPAD(IFNULL(auction,0), 3, 0), - LPAD(IFNULL(klo, 99), 2, 0), - LPAD(DAYOFYEAR(fec), 3, 0), - COALESCE(agj, RIGHT(batchNumber,7), id)) - INTO vBarcode - FROM ekt - WHERE id = vSelf; - -- Rewrites the kop parameter IF vKop IS NULL THEN @@ -46,10 +34,9 @@ BEGIN -- Refresh EKT - UPDATE ekt SET - barcode = vBarcode - ,kop = vKop - ,putOrderFk = vTruncatePutOrder + UPDATE ekt + SET kop = vKop, + putOrderFk = vTruncatePutOrder WHERE id = vSelf; END$$ DELIMITER ; diff --git a/db/routines/edi/views/ektRecent.sql b/db/routines/edi/views/ektRecent.sql index 3e41490ab..66ff7875e 100644 --- a/db/routines/edi/views/ektRecent.sql +++ b/db/routines/edi/views/ektRecent.sql @@ -2,7 +2,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `edi`.`ektRecent` AS SELECT `e`.`id` AS `id`, - `e`.`barcode` AS `barcode`, `e`.`entryYear` AS `entryYear`, `e`.`batchNumber` AS `batchNumber`, `e`.`deliveryNumber` AS `deliveryNumber`, diff --git a/db/routines/vn2008/views/buy_edi.sql b/db/routines/vn2008/views/buy_edi.sql index 0d194c89e..d00196e95 100644 --- a/db/routines/vn2008/views/buy_edi.sql +++ b/db/routines/vn2008/views/buy_edi.sql @@ -2,7 +2,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vn2008`.`buy_edi` AS SELECT `t`.`id` AS `id`, - `t`.`barcode` AS `barcode`, `t`.`entryYear` AS `entry_year`, `t`.`deliveryNumber` AS `delivery_number`, `t`.`fec` AS `fec`, From 0d70cb892909348e98086e07d564ea3df8f5fa0c Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 2 Jul 2024 17:39:46 +0200 Subject: [PATCH 063/173] fix: informatica no necesita este correo --- db/routines/vn/procedures/XDiario_check.sql | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/db/routines/vn/procedures/XDiario_check.sql b/db/routines/vn/procedures/XDiario_check.sql index 0fb1c410d..ef969924b 100644 --- a/db/routines/vn/procedures/XDiario_check.sql +++ b/db/routines/vn/procedures/XDiario_check.sql @@ -6,19 +6,6 @@ BEGIN * identificando y notificando los asientos descuadrados * y ajustando los saldos en caso necesario. */ - INSERT INTO mail (receiver, subject, body) - SELECT 'cau@verdnatura.es', - 'Asientos descuadrados', - GROUP_CONCAT(CONCAT(' Asiento: ', ASIEN, ' - Importe:', recon) SEPARATOR ' | \n') - FROM ( - SELECT ASIEN, - SUM(IFNULL(ROUND(Eurodebe, 2), 0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0)) recon - FROM XDiario - WHERE NOT enlazado - GROUP BY ASIEN - HAVING ABS(SUM(IFNULL(ROUND(Eurodebe, 2), 0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0))) > 0.01 - ) sub - HAVING COUNT(*); UPDATE XDiario xd JOIN ( From cc004a864a58397e0e2701aa7f7bbac29ad02575 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 2 Jul 2024 20:41:53 +0200 Subject: [PATCH 064/173] feat(salix): refs #7648 #7648 rename some travel fields --- modules/entry/back/methods/entry/filter.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 700d251a2..c25a7527e 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -178,10 +178,10 @@ module.exports = Self => { s.nickname AS supplierAlias, co.code AS companyCode, cu.code AS currencyCode, - t.shipped AS shipped, - t.landed AS landed, - t.warehouseInFk AS warehouseId, - w.name AS warehouseName + t.shipped, + t.landed, + t.warehouseInFk, + w.name AS warehouseInName FROM vn.entry e JOIN vn.supplier s ON s.id = e.supplierFk JOIN vn.travel t ON t.id = e.travelFk From adbbe4aef9c57513be79fb8e4804d9bf40a8f9fe Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 3 Jul 2024 01:46:01 +0200 Subject: [PATCH 065/173] fix(salix): refs #7648 #7648 solve big bug --- modules/entry/back/methods/entry/getBuys.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/entry/back/methods/entry/getBuys.js b/modules/entry/back/methods/entry/getBuys.js index e392ba3ce..444e6cb14 100644 --- a/modules/entry/back/methods/entry/getBuys.js +++ b/modules/entry/back/methods/entry/getBuys.js @@ -1,4 +1,3 @@ -const ForbiddenError = require('vn-loopback/util/forbiddenError'); const UserError = require('vn-loopback/util/user-error'); const mergeFilters = require('vn-loopback/util/filter').mergeFilters; @@ -37,7 +36,7 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const isSupplier = await Self.app.models.Supplier.findById(userId, options); + const isSupplier = await Self.app.models.Supplier.findById(userId, myOptions); if (isSupplier) { const isEntryOwner = (await Self.findById(id)).supplierFk === userId; From 946d6f553af0be220e5b9d882397c6fda4252daf Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 3 Jul 2024 08:16:55 +0200 Subject: [PATCH 066/173] perf(salix): refs #7648 #7648 sql conventions --- modules/entry/back/methods/entry/filter.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index c25a7527e..9bbce1c95 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -162,7 +162,7 @@ module.exports = Self => { e.invoiceNumber, e.isBooked, e.isExcludedFromAvailable, - e.evaNotes AS observation, + e.evaNotes observation, e.isConfirmed, e.isOrdered, e.isRaid, @@ -174,14 +174,14 @@ module.exports = Self => { e.gestDocFk, e.invoiceInFk, t.landed, - s.name AS supplierName, - s.nickname AS supplierAlias, - co.code AS companyCode, - cu.code AS currencyCode, + s.name supplierName, + s.nickname supplierAlias, + co.code companyCode, + cu.code currencyCode, t.shipped, t.landed, t.warehouseInFk, - w.name AS warehouseInName + w.name warehouseInName FROM vn.entry e JOIN vn.supplier s ON s.id = e.supplierFk JOIN vn.travel t ON t.id = e.travelFk From 19c378d6bd675b7e2079a6785477fd4b78ab66b0 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 3 Jul 2024 08:48:24 +0200 Subject: [PATCH 067/173] =?UTF-8?q?feat:=20refs=20#7116=20a=C3=B1adir=20co?= =?UTF-8?q?mentario?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/versions/10960-silverRoebelini/00-firstScript.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/10960-silverRoebelini/00-firstScript.sql b/db/versions/10960-silverRoebelini/00-firstScript.sql index 75fc5277f..228e0b014 100644 --- a/db/versions/10960-silverRoebelini/00-firstScript.sql +++ b/db/versions/10960-silverRoebelini/00-firstScript.sql @@ -5,4 +5,4 @@ CREATE TABLE IF NOT EXISTS `vn`.`agencyIncoming` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 -COLLATE=utf8mb3_unicode_ci; \ No newline at end of file +COLLATE=utf8mb3_unicode_ci COMMENT='Agencias de entrada de mercancias';; \ No newline at end of file From beff905e02bfb6b2d074eb122d0e01f8c9668ec8 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 3 Jul 2024 08:54:58 +0200 Subject: [PATCH 068/173] perf(salix): refs #7648 #7648 remove change role for user 2 --- db/dump/fixtures.before.sql | 4 ---- 1 file changed, 4 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index b27bc8ef6..359410564 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3912,7 +3912,3 @@ VALUES(1, ''); INSERT INTO dipole.expedition_PrintOut (expeditionFk, ticketFk, addressFk, street, postalCode, city, shopName, isPrinted, created, printerFk, routeFk, parkingCode, truckName, clientFk, phone, province, agency, m3, workerCode, itemFk, quantity, longName, shelvingFk, comments) VALUES(1, 1, 0, ' ', ' ', ' ', ' ', 0, '2001-01-01 00:00:00', 1, 0, ' ', ' ', 0, NULL, '', NULL, 0.000, NULL, 10, NULL, NULL, 'NCC', NULL); - -UPDATE account.`user` - SET `role`=131 - WHERE id=2; From d1ef1c80f8271026905e45fd2790160984ae5de1 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 3 Jul 2024 09:36:20 +0200 Subject: [PATCH 069/173] feat: refs #7382 Added unique key --- db/versions/11127-silverMoss/00-firstScript.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 db/versions/11127-silverMoss/00-firstScript.sql diff --git a/db/versions/11127-silverMoss/00-firstScript.sql b/db/versions/11127-silverMoss/00-firstScript.sql new file mode 100644 index 000000000..aae2e857e --- /dev/null +++ b/db/versions/11127-silverMoss/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.invoiceInTax ADD CONSTRAINT invoiceInTax_unique UNIQUE KEY (invoiceInFk,expenseFk); From 77d86c9fd979fe92aaa4b416c73c07a25f392f3d Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 3 Jul 2024 09:55:14 +0200 Subject: [PATCH 070/173] feat: refs #7664 Added created in calendar table --- db/versions/11128-turquoiseCymbidium/00-firstScript.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 db/versions/11128-turquoiseCymbidium/00-firstScript.sql diff --git a/db/versions/11128-turquoiseCymbidium/00-firstScript.sql b/db/versions/11128-turquoiseCymbidium/00-firstScript.sql new file mode 100644 index 000000000..4f6cafcf8 --- /dev/null +++ b/db/versions/11128-turquoiseCymbidium/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.calendar ADD created timestamp DEFAULT current_timestamp() NOT NULL AFTER dated; From aaca2d12c5e2eda72d92a0fc109806b6ae4e3336 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 3 Jul 2024 10:20:20 +0200 Subject: [PATCH 071/173] refactor: refs #7504 Rename id greuge --- db/versions/11129-limeHydrangea/00-firstScript.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 db/versions/11129-limeHydrangea/00-firstScript.sql diff --git a/db/versions/11129-limeHydrangea/00-firstScript.sql b/db/versions/11129-limeHydrangea/00-firstScript.sql new file mode 100644 index 000000000..eb2320ee1 --- /dev/null +++ b/db/versions/11129-limeHydrangea/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.greuge CHANGE Id id int(10) unsigned auto_increment NOT NULL; From a8d663bee46d62da682a56f5fed24bce5714c029 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 3 Jul 2024 10:49:51 +0200 Subject: [PATCH 072/173] feat: refs #7348 hasDailyInvoice field --- db/routines/vn/procedures/client_create.sql | 24 ++++++++++++------- .../11126-blueCamellia/00-firstScript.sql | 2 ++ 2 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 db/versions/11126-blueCamellia/00-firstScript.sql diff --git a/db/routines/vn/procedures/client_create.sql b/db/routines/vn/procedures/client_create.sql index d5d7258a1..f2321e129 100644 --- a/db/routines/vn/procedures/client_create.sql +++ b/db/routines/vn/procedures/client_create.sql @@ -34,20 +34,25 @@ BEGIN DECLARE vIsTaxDataChecked TINYINT(1); DECLARE vHasCoreVnl BOOLEAN; DECLARE vMandateTypeFk INT; + DECLARE vHasDailyInvoice BOOLEAN; - SELECT defaultPayMethodFk, - defaultDueDay, - defaultCredit, - defaultIsTaxDataChecked, - defaultHasCoreVnl, - defaultMandateTypeFk + SELECT cc.defaultPayMethodFk, + cc.defaultDueDay, + cc.defaultCredit, + cc.defaultIsTaxDataChecked, + cc.defaultHasCoreVnl, + cc.defaultMandateTypeFk, + c.hasDailyInvoice INTO vPayMethodFk, vDueDay, vDefaultCredit, vIsTaxDataChecked, vHasCoreVnl, - vMandateTypeFk - FROM clientConfig; + vMandateTypeFk, + vHasDailyInvoice + FROM clientConfig cc + LEFT JOIN province p ON p.id = vProvinceFk + LEFT JOIN country c ON c.id = p.countryFk; INSERT INTO `client` SET id = vUserFk, @@ -65,7 +70,8 @@ BEGIN credit = vDefaultCredit, isTaxDataChecked = vIsTaxDataChecked, hasCoreVnl = vHasCoreVnl, - isEqualizated = FALSE + isEqualizated = FALSE, + hasDailyInvoice = vHasDailyInvoice ON duplicate KEY UPDATE payMethodFk = vPayMethodFk, dueDay = vDueDay, diff --git a/db/versions/11126-blueCamellia/00-firstScript.sql b/db/versions/11126-blueCamellia/00-firstScript.sql new file mode 100644 index 000000000..45c2ed2dc --- /dev/null +++ b/db/versions/11126-blueCamellia/00-firstScript.sql @@ -0,0 +1,2 @@ +ALTER TABLE `client` +ADD COLUMN `hasDailyInvoice` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Indica si el cliente requiere facturación diaria por defecto se copiará lo que tenga country.hasDailyInvoice'; From cf63d6e71c2d86bdb44f40f227da3ae49e02ce3e Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 3 Jul 2024 11:17:33 +0200 Subject: [PATCH 073/173] feat: refs #7378 Added productionConfigLog --- .../triggers/productionConfig_afterDelete.sql | 12 ++++++++++ .../productionConfig_beforeInsert.sql | 8 +++++++ .../productionConfig_beforeUpdate.sql | 8 +++++++ .../11130-crimsonIvy/00-firstScript.sql | 23 +++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 db/routines/vn/triggers/productionConfig_afterDelete.sql create mode 100644 db/routines/vn/triggers/productionConfig_beforeInsert.sql create mode 100644 db/routines/vn/triggers/productionConfig_beforeUpdate.sql create mode 100644 db/versions/11130-crimsonIvy/00-firstScript.sql diff --git a/db/routines/vn/triggers/productionConfig_afterDelete.sql b/db/routines/vn/triggers/productionConfig_afterDelete.sql new file mode 100644 index 000000000..384bf681e --- /dev/null +++ b/db/routines/vn/triggers/productionConfig_afterDelete.sql @@ -0,0 +1,12 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`productionConfig_afterDelete` + AFTER DELETE ON `productionConfig` + FOR EACH ROW +BEGIN + INSERT INTO productionConfig + SET `action` = 'delete', + `changedModel` = 'ProductionConfig', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/productionConfig_beforeInsert.sql b/db/routines/vn/triggers/productionConfig_beforeInsert.sql new file mode 100644 index 000000000..99b217be4 --- /dev/null +++ b/db/routines/vn/triggers/productionConfig_beforeInsert.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`productionConfig_beforeInsert` + BEFORE INSERT ON `productionConfig` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/productionConfig_beforeUpdate.sql b/db/routines/vn/triggers/productionConfig_beforeUpdate.sql new file mode 100644 index 000000000..f1ceaa471 --- /dev/null +++ b/db/routines/vn/triggers/productionConfig_beforeUpdate.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`productionConfig_beforeUpdate` + BEFORE UPDATE ON `productionConfig` + FOR EACH ROW +BEGIN + SET NEW.editorFk = account.myUser_getId(); +END$$ +DELIMITER ; diff --git a/db/versions/11130-crimsonIvy/00-firstScript.sql b/db/versions/11130-crimsonIvy/00-firstScript.sql new file mode 100644 index 000000000..3bde55f55 --- /dev/null +++ b/db/versions/11130-crimsonIvy/00-firstScript.sql @@ -0,0 +1,23 @@ +ALTER TABLE vn.productionConfig + ADD editorFk int(10) unsigned DEFAULT NULL NULL; +ALTER TABLE vn.productionConfig + ADD CONSTRAINT productionConfig_user_FK FOREIGN KEY (editorFk) REFERENCES account.`user`(id); + +CREATE OR REPLACE TABLE `vn`.`productionConfigLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `originFk` int(11) DEFAULT NULL, + `userFk` int(10) unsigned DEFAULT NULL, + `action` set('insert','update','delete','select') NOT NULL, + `creationDate` timestamp NULL DEFAULT current_timestamp(), + `description` text CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL, + `changedModel` enum('ProductionConfig') NOT NULL DEFAULT 'ProductionConfig', + `oldInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`oldInstance`)), + `newInstance` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`newInstance`)), + `changedModelId` int(11) NOT NULL, + `changedModelValue` varchar(45) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `logRateuserFk` (`userFk`), + KEY `productionConfigLog_changedModel` (`changedModel`,`changedModelId`,`creationDate`), + KEY `productionConfigLog_originFk` (`originFk`,`creationDate`), + CONSTRAINT `productionConfigUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; From fafebb4339c76ea80d4d29ccc34165a66e244db6 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 3 Jul 2024 12:13:40 +0200 Subject: [PATCH 074/173] refs #6897 fix filter --- modules/entry/back/methods/entry/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index df5fef1bc..69bcb46da 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -180,7 +180,7 @@ module.exports = Self => { cu.code currencyCode, t.shipped, t.landed, - t.ref AS travelRef + t.ref AS travelRef, t.warehouseInFk, w.name warehouseInName FROM vn.entry e From 900fa2de5ed71fb921517578787e930a35e889c7 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 3 Jul 2024 13:03:19 +0200 Subject: [PATCH 075/173] fix: refs #7648 add myOpts --- modules/entry/back/methods/entry/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 69bcb46da..5989494a4 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -146,7 +146,7 @@ module.exports = Self => { }); filter = mergeFilters(ctx.args.filter, {where}); const userId = ctx.req.accessToken.userId; - const isSupplier = await Self.app.models.Supplier.findById(userId, options); + const isSupplier = await Self.app.models.Supplier.findById(userId, myOptions); if (isSupplier) { if (!filter.where) filter.where = {}; filter.where[`e.supplierFk`] = ctx.req.accessToken.userId; From 4f9552379ed043f5d334e588fc9678085e7a9929 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 3 Jul 2024 13:46:19 +0200 Subject: [PATCH 076/173] feat: refs #7654 entry_splitByShelving --- .../vn/procedures/entry_splitByShelving.sql | 170 ++++++++---------- .../11131-brownPhormium/00-firstScript.sql | 1 + 2 files changed, 80 insertions(+), 91 deletions(-) create mode 100644 db/versions/11131-brownPhormium/00-firstScript.sql diff --git a/db/routines/vn/procedures/entry_splitByShelving.sql b/db/routines/vn/procedures/entry_splitByShelving.sql index 2898141ea..839bf02d1 100644 --- a/db/routines/vn/procedures/entry_splitByShelving.sql +++ b/db/routines/vn/procedures/entry_splitByShelving.sql @@ -9,70 +9,81 @@ BEGIN * @param vToEntryFk Entrada destino */ DECLARE vBuyFk INT; - DECLARE vIshStickers INT; - DECLARE vBuyStickers INT; - DECLARE vDone BOOLEAN DEFAULT FALSE; - - DECLARE cur CURSOR FOR - SELECT bb.id buyFk, - FLOOR(ish.visible / ish.packing) ishStickers, - bb.stickers buyStickers - FROM vn.itemShelving ish - JOIN (SELECT b.id, b.itemFk, b.stickers - FROM vn.buy b - WHERE b.entryFk = vFromEntryFk - ORDER BY b.stickers DESC - LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk - AND bb.stickers >= FLOOR(ish.visible / ish.packing) - WHERE shelvingFk = vShelvingFk COLLATE utf8_general_ci - GROUP BY ish.id; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE vIshStickers INT; + DECLARE vBuyStickers INT; + DECLARE vDone BOOLEAN DEFAULT FALSE; - -- Cantidades de la matrícula que exceden la de las entradas - SELECT ish.itemFk, - i.longName, - FLOOR(ish.visible / ish.packing) AS etiEnMatricula, - bb.stickers etiEnEntrada - FROM vn.itemShelving ish - JOIN vn.item i ON i.id = ish.itemFk - LEFT JOIN (SELECT b.id, b.itemFk, b.stickers - FROM vn.buy b - WHERE b.entryFk = vFromEntryFk - ORDER BY b.stickers DESC - LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk - WHERE shelvingFk = vShelvingFk COLLATE utf8_general_ci - AND IFNULL(bb.stickers,0) < FLOOR(ish.visible / ish.packing) - GROUP BY ish.id; - - OPEN cur; - - read_loop: LOOP - SET vDone = FALSE; + DECLARE cur CURSOR FOR + SELECT bb.id buyFk, + FLOOR(ish.visible / ish.packing) ishStickers, + bb.stickers buyStickers + FROM itemShelving ish + JOIN (SELECT b.id, b.itemFk, b.stickers + FROM buy b + WHERE b.entryFk = vFromEntryFk + ORDER BY b.stickers DESC + LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk + AND bb.stickers >= FLOOR(ish.visible / ish.packing) + WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_general_ci + AND NOT ish.isSplit + GROUP BY ish.id; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - FETCH cur INTO vBuyFk, vIshStickers, vBuyStickers; + OPEN cur; - IF vDone THEN - LEAVE read_loop; - END IF; + read_loop: LOOP + SET vDone = FALSE; - IF vIshStickers = vBuyStickers THEN - UPDATE vn.buy - SET entryFk = vToEntryFk - WHERE id = vBuyFk; - ELSE - UPDATE vn.buy - SET stickers = stickers - vIshStickers, - quantity = stickers * packing - WHERE id = vBuyFk; - - INSERT INTO vn.buy(entryFk, + FETCH cur INTO vBuyFk, vIshStickers, vBuyStickers; + + IF vDone THEN + LEAVE read_loop; + END IF; + + IF vIshStickers = vBuyStickers THEN + UPDATE buy + SET entryFk = vToEntryFk + WHERE id = vBuyFk; + ELSE + UPDATE buy + SET stickers = stickers - vIshStickers, + quantity = stickers * packing + WHERE id = vBuyFk; + + INSERT INTO buy(entryFk, + itemFk, + quantity, + buyingValue, + freightValue, + isIgnored, + stickers, + packing, + `grouping`, + groupingMode, + comissionValue, + packageValue, + location, + packagingFk, + price1, + price2, + price3, + minPrice, + workerFk, + isChecked, + isPickedOff, + ektFk, + weight, + deliveryFk, + itemOriginalFk) + SELECT + vToEntryFk, itemFk, - quantity, + vIshStickers * packing, buyingValue, freightValue, isIgnored, - stickers, + vIshStickers, packing, `grouping`, groupingMode, @@ -90,40 +101,17 @@ BEGIN ektFk, weight, deliveryFk, - itemOriginalFk) - SELECT - vToEntryFk, - itemFk, - vIshStickers * packing, - buyingValue, - freightValue, - isIgnored, - vIshStickers, - packing, - `grouping`, - groupingMode, - comissionValue, - packageValue, - location, - packagingFk, - price1, - price2, - price3, - minPrice, - workerFk, - isChecked, - isPickedOff, - ektFk, - weight, - deliveryFk, - itemOriginalFk - FROM vn.buy - WHERE id = vBuyFk; - - UPDATE buy SET printedStickers = vIshStickers WHERE id = LAST_INSERT_ID(); - END IF; - END LOOP; - - CLOSE cur; + itemOriginalFk + FROM buy + WHERE id = vBuyFk; + + UPDATE buy SET printedStickers = vIshStickers WHERE id = LAST_INSERT_ID(); + END IF; + + UPDATE itemShelving + SET isSplit = TRUE + WHERE shelvingFk = vShelvingFk; + END LOOP; + CLOSE cur; END$$ DELIMITER ; diff --git a/db/versions/11131-brownPhormium/00-firstScript.sql b/db/versions/11131-brownPhormium/00-firstScript.sql new file mode 100644 index 000000000..341c9f1a3 --- /dev/null +++ b/db/versions/11131-brownPhormium/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.itemShelving ADD isSplit tinyint(1) NULL COMMENT 'Este valor cambia al splitar un carro que se ha quedado en holanda'; \ No newline at end of file From 2278b9a05aa25835ded18b6f2ff784ba5d88ff3f Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 3 Jul 2024 14:20:43 +0200 Subject: [PATCH 077/173] feat: refs #7382 Changes --- .../vn/procedures/invoiceIn_booking.sql | 25 +++++++++++++------ .../11127-silverMoss/00-firstScript.sql | 1 - 2 files changed, 18 insertions(+), 8 deletions(-) delete mode 100644 db/versions/11127-silverMoss/00-firstScript.sql diff --git a/db/routines/vn/procedures/invoiceIn_booking.sql b/db/routines/vn/procedures/invoiceIn_booking.sql index cd838861a..decbb7b1a 100644 --- a/db/routines/vn/procedures/invoiceIn_booking.sql +++ b/db/routines/vn/procedures/invoiceIn_booking.sql @@ -13,20 +13,31 @@ BEGIN * @param vBookEntry Id de asiento, si es NULL se genera uno nuevo */ DECLARE vFiscalYear INT; - DECLARE vHasDistinctTransactions INT; + DECLARE vDistinctTransactions INT; + DECLARE vHasRepeatedTransactions BOOL; - SELECT COUNT(DISTINCT transactionTypeSageFk) INTO vHasDistinctTransactions - FROM invoiceIn ii - JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id + SELECT COUNT(DISTINCT iit.transactionTypeSageFk) INTO vDistinctTransactions + FROM invoiceInTax iit JOIN invoiceInSerial iis ON iis.code = ii.serial - WHERE ii.id = vSelf + WHERE iit.invoiceInFk = vSelf AND iis.taxAreaFk = 'CEE' - AND transactionTypeSageFk; + AND iit.transactionTypeSageFk; - IF vHasDistinctTransactions > 1 THEN + IF vDistinctTransactions > 1 THEN CALL util.throw ('This invoice does not allow different types of transactions'); END IF; + SELECT TRUE INTO vHasRepeatedTransactions + FROM invoiceInTax + WHERE invoiceInFk = vSelf + GROUP BY transactionTypeSageFk + HAVING COUNT(transactionTypeSageFk) > 1 + LIMIT 1; + + IF vHasRepeatedTransactions THEN + CALL util.throw ('This invoice contains repeated types of transactions'); + END IF; + CREATE OR REPLACE TEMPORARY TABLE tInvoiceIn ENGINE = MEMORY SELECT ii.bookEntried, diff --git a/db/versions/11127-silverMoss/00-firstScript.sql b/db/versions/11127-silverMoss/00-firstScript.sql deleted file mode 100644 index aae2e857e..000000000 --- a/db/versions/11127-silverMoss/00-firstScript.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE vn.invoiceInTax ADD CONSTRAINT invoiceInTax_unique UNIQUE KEY (invoiceInFk,expenseFk); From 246b34571d786f8fbf635038304135629ab16077 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 3 Jul 2024 14:24:26 +0200 Subject: [PATCH 078/173] feat: refs #7382 Fix --- db/routines/vn/procedures/invoiceIn_booking.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/invoiceIn_booking.sql b/db/routines/vn/procedures/invoiceIn_booking.sql index decbb7b1a..c194a774d 100644 --- a/db/routines/vn/procedures/invoiceIn_booking.sql +++ b/db/routines/vn/procedures/invoiceIn_booking.sql @@ -17,7 +17,8 @@ BEGIN DECLARE vHasRepeatedTransactions BOOL; SELECT COUNT(DISTINCT iit.transactionTypeSageFk) INTO vDistinctTransactions - FROM invoiceInTax iit + FROM invoiceIn ii + JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id JOIN invoiceInSerial iis ON iis.code = ii.serial WHERE iit.invoiceInFk = vSelf AND iis.taxAreaFk = 'CEE' From d65af6aaaac6c5cb85856d2f44f97bf327b26a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 3 Jul 2024 18:00:28 +0200 Subject: [PATCH 079/173] feat: Avisar cuando no hay posibilidad de fichar refs #7669 --- .../vn/procedures/workerTimeControl_direction.sql | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/db/routines/vn/procedures/workerTimeControl_direction.sql b/db/routines/vn/procedures/workerTimeControl_direction.sql index f7a68e1e4..807dc46c6 100644 --- a/db/routines/vn/procedures/workerTimeControl_direction.sql +++ b/db/routines/vn/procedures/workerTimeControl_direction.sql @@ -9,6 +9,8 @@ BEGIN */ DECLARE vLastIn DATETIME ; DECLARE vIsMiddleOdd BOOLEAN ; + DECLARE vMailTo VARCHAR(50) DEFAULT NULL; + DECLARE vUserName VARCHAR(50) DEFAULT NULL; IF (vTimed IS NULL) THEN SET vTimed = util.VN_NOW(); @@ -57,5 +59,18 @@ BEGIN VALUES('in', NULL); END IF; + IF (SELECT option1 IS NULL AND option2 IS NULL FROM tmp.workerTimeControlDirection) THEN + SELECT CONCAT(u.name, '@verdnatura.es'), CONCAT(w.firstName, ' ', w.lastName) + INTO vMailTo, vUserName + FROM account.user u + JOIN worker w ON w.bossFk = u.id + WHERE w.id = vWorkerFk; + + CALL mail_insert( + vMailTo, + vMailTo, + 'Error al fichar', + CONCAT(vUserName, ' tiene problemas para fichar'); + END IF; END$$ DELIMITER ; From 989fa5ac5a3f2b101a38b85413f1552be9c3111f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Wed, 3 Jul 2024 18:10:02 +0200 Subject: [PATCH 080/173] feat: Avisar cuando no hay posibilidad de fichar refs #7669 --- db/routines/vn/procedures/workerTimeControl_direction.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/workerTimeControl_direction.sql b/db/routines/vn/procedures/workerTimeControl_direction.sql index 807dc46c6..8e807084c 100644 --- a/db/routines/vn/procedures/workerTimeControl_direction.sql +++ b/db/routines/vn/procedures/workerTimeControl_direction.sql @@ -70,7 +70,7 @@ BEGIN vMailTo, vMailTo, 'Error al fichar', - CONCAT(vUserName, ' tiene problemas para fichar'); + CONCAT(vUserName, ' tiene problemas para fichar')); END IF; END$$ DELIMITER ; From d59cab13d8556a12135a8a0540ea4de5d3fdfa34 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 3 Jul 2024 23:02:28 +0200 Subject: [PATCH 081/173] feat(salix): refs #7380 #7380 client.substitutionAllowed new field --- db/versions/11132-aquaDracena/00-firstScript.sql | 1 + modules/client/back/models/client.json | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 db/versions/11132-aquaDracena/00-firstScript.sql diff --git a/db/versions/11132-aquaDracena/00-firstScript.sql b/db/versions/11132-aquaDracena/00-firstScript.sql new file mode 100644 index 000000000..d309098c5 --- /dev/null +++ b/db/versions/11132-aquaDracena/00-firstScript.sql @@ -0,0 +1 @@ +ALTER TABLE vn.client ADD substitutionAllowed BOOL DEFAULT false NULL; diff --git a/modules/client/back/models/client.json b/modules/client/back/models/client.json index f3eb9919b..97c2a3624 100644 --- a/modules/client/back/models/client.json +++ b/modules/client/back/models/client.json @@ -53,6 +53,9 @@ "isActive": { "type": "boolean" }, + "substitutionAllowed": { + "type": "boolean" + }, "credit": { "type": "number" }, From 17e7dc8c7ee35b0ae9f9a1914b7c9ad2b3f114b0 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 3 Jul 2024 23:02:47 +0200 Subject: [PATCH 082/173] feat(salix): refs #7380 #7380 new typeObservation --- db/versions/11132-aquaDracena/00-firstScript.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/db/versions/11132-aquaDracena/00-firstScript.sql b/db/versions/11132-aquaDracena/00-firstScript.sql index d309098c5..1b304c1d0 100644 --- a/db/versions/11132-aquaDracena/00-firstScript.sql +++ b/db/versions/11132-aquaDracena/00-firstScript.sql @@ -1 +1,4 @@ +INSERT IGNORE INTO vn.observationType (`description`,code,hasNewBornMessage) + VALUES ('Sustitución','substitution',0); + ALTER TABLE vn.client ADD substitutionAllowed BOOL DEFAULT false NULL; From 897da1e48a70570d6fc172f301b7ac347bc84622 Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 4 Jul 2024 08:59:22 +0200 Subject: [PATCH 083/173] feat: refs #7654 --- .../vn/procedures/entry_splitByShelving.sql | 164 +++++++++--------- 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/db/routines/vn/procedures/entry_splitByShelving.sql b/db/routines/vn/procedures/entry_splitByShelving.sql index 839bf02d1..eb07c12b7 100644 --- a/db/routines/vn/procedures/entry_splitByShelving.sql +++ b/db/routines/vn/procedures/entry_splitByShelving.sql @@ -9,81 +9,55 @@ BEGIN * @param vToEntryFk Entrada destino */ DECLARE vBuyFk INT; - DECLARE vIshStickers INT; - DECLARE vBuyStickers INT; - DECLARE vDone BOOLEAN DEFAULT FALSE; + DECLARE vIshStickers INT; + DECLARE vBuyStickers INT; + DECLARE vDone BOOLEAN DEFAULT FALSE; + + DECLARE cur CURSOR FOR + SELECT bb.id buyFk, + FLOOR(ish.visible / ish.packing) ishStickers, + bb.stickers buyStickers + FROM itemShelving ish + JOIN (SELECT b.id, b.itemFk, b.stickers + FROM buy b + WHERE b.entryFk = vFromEntryFk + ORDER BY b.stickers DESC + LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk + AND bb.stickers >= FLOOR(ish.visible / ish.packing) + WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_general_ci + AND NOT ish.isSplit + GROUP BY ish.id; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN cur; + + read_loop: LOOP + SET vDone = FALSE; - DECLARE cur CURSOR FOR - SELECT bb.id buyFk, - FLOOR(ish.visible / ish.packing) ishStickers, - bb.stickers buyStickers - FROM itemShelving ish - JOIN (SELECT b.id, b.itemFk, b.stickers - FROM buy b - WHERE b.entryFk = vFromEntryFk - ORDER BY b.stickers DESC - LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk - AND bb.stickers >= FLOOR(ish.visible / ish.packing) - WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_general_ci - AND NOT ish.isSplit - GROUP BY ish.id; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - OPEN cur; - - read_loop: LOOP - SET vDone = FALSE; - - FETCH cur INTO vBuyFk, vIshStickers, vBuyStickers; - - IF vDone THEN - LEAVE read_loop; - END IF; - - IF vIshStickers = vBuyStickers THEN - UPDATE buy - SET entryFk = vToEntryFk - WHERE id = vBuyFk; - ELSE - UPDATE buy - SET stickers = stickers - vIshStickers, - quantity = stickers * packing - WHERE id = vBuyFk; - - INSERT INTO buy(entryFk, - itemFk, - quantity, - buyingValue, - freightValue, - isIgnored, - stickers, - packing, - `grouping`, - groupingMode, - comissionValue, - packageValue, - location, - packagingFk, - price1, - price2, - price3, - minPrice, - workerFk, - isChecked, - isPickedOff, - ektFk, - weight, - deliveryFk, - itemOriginalFk) - SELECT - vToEntryFk, + FETCH cur INTO vBuyFk, vIshStickers, vBuyStickers; + + IF vDone THEN + LEAVE read_loop; + END IF; + + IF vIshStickers = vBuyStickers THEN + UPDATE buy + SET entryFk = vToEntryFk + WHERE id = vBuyFk; + ELSE + UPDATE buy + SET stickers = stickers - vIshStickers, + quantity = stickers * packing + WHERE id = vBuyFk; + + INSERT INTO buy(entryFk, itemFk, - vIshStickers * packing, + quantity, buyingValue, freightValue, isIgnored, - vIshStickers, + stickers, packing, `grouping`, groupingMode, @@ -101,17 +75,43 @@ BEGIN ektFk, weight, deliveryFk, - itemOriginalFk - FROM buy - WHERE id = vBuyFk; - - UPDATE buy SET printedStickers = vIshStickers WHERE id = LAST_INSERT_ID(); - END IF; - - UPDATE itemShelving - SET isSplit = TRUE - WHERE shelvingFk = vShelvingFk; - END LOOP; - CLOSE cur; + itemOriginalFk) + SELECT + vToEntryFk, + itemFk, + vIshStickers * packing, + buyingValue, + freightValue, + isIgnored, + vIshStickers, + packing, + `grouping`, + groupingMode, + comissionValue, + packageValue, + location, + packagingFk, + price1, + price2, + price3, + minPrice, + workerFk, + isChecked, + isPickedOff, + ektFk, + weight, + deliveryFk, + itemOriginalFk + FROM buy + WHERE id = vBuyFk; + + UPDATE buy SET printedStickers = vIshStickers WHERE id = LAST_INSERT_ID(); + END IF; + + UPDATE itemShelving + SET isSplit = TRUE + WHERE shelvingFk = vShelvingFk; + END LOOP; + CLOSE cur; END$$ DELIMITER ; From a7895ab0a45c56ce7a04e86258dd3ab2add482f6 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 4 Jul 2024 09:17:22 +0200 Subject: [PATCH 084/173] refs #6769 First commit --- db/routines/vn/procedures/item_getBalance.sql | 224 +++++++++++------- 1 file changed, 144 insertions(+), 80 deletions(-) diff --git a/db/routines/vn/procedures/item_getBalance.sql b/db/routines/vn/procedures/item_getBalance.sql index a4942af6f..561957452 100644 --- a/db/routines/vn/procedures/item_getBalance.sql +++ b/db/routines/vn/procedures/item_getBalance.sql @@ -2,25 +2,65 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getBalance`( vItemFk INT, vWarehouseFk INT, - vDate DATETIME + vDated DATETIME ) BEGIN /** - * @vItemFk item a buscar - * @vWarehouseFk almacen donde buscar - * @vDate Si la fecha es null, muestra el histórico desde el inventario. - * Si la fecha no es null, muestra histórico desde la fecha de vDate. + * Calcula el disponible. + * + * @vItemFk Id de artículo + * @vWarehouseFk Id de almacén + * @vDated Fecha + * Si la fecha es NULL, muestra el histórico desde el inventario. + * Si la fecha no es NULL, muestra histórico desde la fecha de vDated. */ DECLARE vDateInventory DATETIME; + DECLARE vLifeScope DATE; + DECLARE vWarehouseInventoryFk INT; + DECLARE vSupplierInventoryFk INT; - IF vDate IS NULL THEN - SELECT inventoried INTO vDateInventory - FROM config; - ELSE - SELECT mockUtcTime INTO vDateInventory - FROM util.config; + SELECT IF(vDated, uc.mockUtcTime, c.inventoried) INTO vDateInventory + FROM config c + JOIN util.config uc; + + SELECT COALESCE(vDated, vDateInventory) - INTERVAL MAX(life) DAY + INTO vLifeScope + FROM itemType; + + SELECT warehouseOutFk, supplierFk + INTO vWarehouseInventoryFk, vSupplierInventoryFk + FROM inventoryConfig; + + IF NOT vWarehouseInventoryFk OR NOT vSupplierInventoryFk THEN + CALL util.throw('Config variables are not set'); END IF; + -- Calcula el ultimo dia de vida para cada producto + CREATE OR REPLACE TEMPORARY TABLE tItemRange + (PRIMARY KEY (itemFk)) + ENGINE = MEMORY + SELECT i.id itemFk, + util.dayEnd(c.maxLanded + INTERVAL it.life DAY) ended, + it.life + FROM item i + LEFT JOIN ( + SELECT b.itemFk, MAX(t.landed) maxLanded + FROM buy b + JOIN entry e ON b.entryFk = e.id + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseInFk + JOIN item i ON i.id = b.itemFk + JOIN itemType it ON it.id = i.typeFk + WHERE t.landed BETWEEN vLifeScope AND COALESCE(vDated, vDateInventory) + AND t.warehouseInFk = vWarehouseFk + AND t.warehouseOutFk <> vWarehouseInventoryFk + AND it.life + AND NOT e.isExcludedFromAvailable + GROUP BY b.itemFk + ) c ON i.id = c.itemFk + JOIN itemType it ON it.id = i.typeFk + HAVING ended >= COALESCE(vDated, vDateInventory) OR life IS NULL; + CREATE OR REPLACE TEMPORARY TABLE tItemDiary( shipped DATE, `in` INT(11), @@ -37,8 +77,9 @@ BEGIN `order` TINYINT(3) UNSIGNED, clientType VARCHAR(20), claimFk INT(10) UNSIGNED, - inventorySupplierFk INT(10) - ); + inventorySupplierFk INT(10), + orderFk INT(10) UNSIGNED + ) ENGINE = MEMORY; INSERT INTO tItemDiary WITH entriesIn AS ( @@ -57,7 +98,8 @@ BEGIN NULL `order`, NULL clientType, NULL claimFk, - ec.inventorySupplierFk + vSupplierInventoryFk inventorySupplierFk, + NULL orderFk FROM vn.buy b JOIN vn.entry e ON e.id = b.entryFk JOIN vn.travel tr ON tr.id = e.travelFk @@ -66,20 +108,20 @@ BEGIN OR (util.VN_CURDATE() AND tr.isReceived), 'DELIVERED', 'FREE') - JOIN vn.entryConfig ec WHERE tr.landed >= vDateInventory - AND vWarehouseFk = tr.warehouseInFk - AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL) + AND tr.warehouseInFk = vWarehouseFk + AND (s.id <> vSupplierInventoryFk OR vDated IS NULL) AND b.itemFk = vItemFk AND NOT e.isExcludedFromAvailable AND NOT e.isRaid - ), entriesOut AS ( + ), + entriesOut AS ( SELECT tr.shipped, NULL, b.quantity, st.alertLevel, st.name stateName, - s.name , + s.name, e.invoiceNumber, e.id entryFk, s.id supplierFk, @@ -89,7 +131,8 @@ BEGIN NULL `order`, NULL clientType, NULL claimFk, - ec.inventorySupplierFk + vSupplierInventoryFk, + NULL orderFk FROM vn.buy b JOIN vn.entry e ON e.id = b.entryFk JOIN vn.travel tr ON tr.id = e.travelFk @@ -102,39 +145,41 @@ BEGIN JOIN vn.entryConfig ec WHERE tr.shipped >= vDateInventory AND vWarehouseFk = tr.warehouseOutFk - AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL) + AND (s.id <> vSupplierInventoryFk OR vDated IS NULL) AND b.itemFk = vItemFk AND NOT e.isExcludedFromAvailable AND NOT w.isFeedStock AND NOT e.isRaid - ), sales AS ( - SELECT DATE(t.shipped) shipped, - s.quantity, - st2.alertLevel, - st2.name, - t.nickname, - t.refFk, - t.id ticketFk, - t.clientFk, - s.id saleFk, - st.`order`, - c.typeFk, - cb.claimFk - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id - LEFT JOIN vn.state st ON st.`code` = ts.`code` - JOIN vn.client c ON c.id = t.clientFk - JOIN vn.state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(), - 'DELIVERED', - IF (t.shipped > util.dayEnd(util.VN_CURDATE()), - 'FREE', - IFNULL(ts.code, 'FREE'))) - LEFT JOIN vn.claimBeginning cb ON s.id = cb.saleFk - WHERE t.shipped >= vDateInventory - AND s.itemFk = vItemFk - AND vWarehouseFk = t.warehouseFk - ),sale AS ( + ), + sales AS ( + WITH itemSales AS ( + SELECT DATE(t.shipped) shipped, + s.quantity, + st2.alertLevel, + st2.name, + t.nickname, + t.refFk, + t.id ticketFk, + t.clientFk, + s.id saleFk, + st.`order`, + c.typeFk, + cb.claimFk + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id + LEFT JOIN vn.state st ON st.`code` = ts.`code` + JOIN vn.client c ON c.id = t.clientFk + JOIN vn.state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(), + 'DELIVERED', + IF (t.shipped > util.dayEnd(util.VN_CURDATE()), + 'FREE', + IFNULL(ts.code, 'FREE'))) + LEFT JOIN vn.claimBeginning cb ON s.id = cb.saleFk + WHERE t.shipped >= vDateInventory + AND s.itemFk = vItemFk + AND vWarehouseFk = t.warehouseFk + ) SELECT s.shipped, NULL `in`, s.quantity, @@ -144,39 +189,55 @@ BEGIN s.refFk, s.ticketFk, s.clientFk, - IF(stk.saleFk, TRUE, NULL), + IF(stk.saleFk, TRUE, FALSE), TRUE, s.saleFk, s.`order`, s.typeFk, s.claimFk, - NULL - FROM sales s + NULL, + NULL orderFk + FROM itemSales s LEFT JOIN vn.state stPrep ON stPrep.`code` = 'PREPARED' LEFT JOIN vn.saleTracking stk ON stk.saleFk = s.saleFk AND stk.stateFk = stPrep.id GROUP BY s.saleFk - ) SELECT shipped, - `in`, - `out`, - alertLevel, - stateName, - `name`, - reference, - origin, - clientFk, - isPicked, - isTicket, - lineFk, - `order`, - clientType, - claimFk, - inventorySupplierFk - FROM entriesIn + ), + orders AS ( + SELECT r.shipment, + NULL 'in', + r.amount, + NULL alertLevel, + NULL stateName, + NULL, + NULL invoiceNumber, + NULL entryFk, + NULL supplierFk, + FALSE, + FALSE isTicket, + NULL buyFk, + NULL 'order', + c.typeFk, + NULL claimFk, + NULL inventorySupplierFk, + o.id + FROM hedera.orderRow r + JOIN hedera.`order` o ON o.id = r.orderFk + JOIN tItemRange ir ON ir.itemFk = r.itemFk + JOIN vn.client c ON c.id = o.customer_id + WHERE r.shipment >= vDateInventory + AND (ir.ended IS NULL OR r.shipment <= ir.ended) + AND r.warehouseFk = vWarehouseFk + AND NOT o.confirmed + AND r.itemFk = vItemFk + ) + SELECT * FROM entriesIn UNION ALL SELECT * FROM entriesOut UNION ALL - SELECT * FROM sale + SELECT * FROM sales + UNION ALL + SELECT * FROM orders ORDER BY shipped, (inventorySupplierFk = clientFk) DESC, alertLevel DESC, @@ -186,8 +247,7 @@ BEGIN `in` DESC, `out` DESC; - IF vDate IS NULL THEN - + IF vDated IS NULL THEN SET @a := 0; SET @currentLineFk := 0; SET @shipped := ''; @@ -211,16 +271,16 @@ BEGIN t.isPicked, t.clientType, t.claimFk, - t.`order` + t.`order`, + t.orderFk FROM tItemDiary t LEFT JOIN alertLevel a ON a.id = t.alertLevel; - ELSE SELECT IFNULL(SUM(IFNULL(`in`, 0)) - SUM(IFNULL(`out`, 0)), 0) INTO @a FROM tItemDiary - WHERE shipped < vDate; + WHERE shipped < vDated; - SELECT vDate shipped, + SELECT vDated shipped, 0 alertLevel, 0 stateName, 0 origin, @@ -236,7 +296,8 @@ BEGIN 0 isPicked, 0 clientType, 0 claimFk, - NULL `order` + NULL `order`, + 0 orderFk UNION ALL SELECT shipped, alertlevel, @@ -253,11 +314,14 @@ BEGIN isPicked, clientType, claimFk, - `order` + `order`, + orderFk FROM tItemDiary - WHERE shipped >= vDate; + WHERE shipped >= vDated; END IF; - DROP TEMPORARY TABLE tItemDiary; + DROP TEMPORARY TABLE + tItemDiary, + tItemRange; END$$ DELIMITER ; From cf7de14de6e5c9babc89d70c20224aa96c665c3f Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 4 Jul 2024 11:34:55 +0200 Subject: [PATCH 085/173] refs #6769 Changes, with error no database selected --- db/routines/vn/procedures/item_getBalance.sql | 95 ++++++++----------- 1 file changed, 38 insertions(+), 57 deletions(-) diff --git a/db/routines/vn/procedures/item_getBalance.sql b/db/routines/vn/procedures/item_getBalance.sql index 561957452..dc4e16789 100644 --- a/db/routines/vn/procedures/item_getBalance.sql +++ b/db/routines/vn/procedures/item_getBalance.sql @@ -61,29 +61,11 @@ BEGIN JOIN itemType it ON it.id = i.typeFk HAVING ended >= COALESCE(vDated, vDateInventory) OR life IS NULL; - CREATE OR REPLACE TEMPORARY TABLE tItemDiary( - shipped DATE, - `in` INT(11), - `out` INT(11), - alertLevel INT(11), - stateName VARCHAR(20), - `name` VARCHAR(50), - reference VARCHAR(50), - origin INT(11), - clientFk INT(11), - isPicked INT(11), - isTicket TINYINT(1), - lineFk INT(11), - `order` TINYINT(3) UNSIGNED, - clientType VARCHAR(20), - claimFk INT(10) UNSIGNED, - inventorySupplierFk INT(10), - orderFk INT(10) UNSIGNED - ) ENGINE = MEMORY; - - INSERT INTO tItemDiary + CREATE OR REPLACE TEMPORARY TABLE tItemDiary + ENGINE = MEMORY WITH entriesIn AS ( - SELECT tr.landed shipped, + SELECT 'entry' `type`, + tr.landed shipped, b.quantity `in`, NULL `out`, st.alertLevel , @@ -98,13 +80,12 @@ BEGIN NULL `order`, NULL clientType, NULL claimFk, - vSupplierInventoryFk inventorySupplierFk, - NULL orderFk + vSupplierInventoryFk inventorySupplierFk FROM vn.buy b JOIN vn.entry e ON e.id = b.entryFk JOIN vn.travel tr ON tr.id = e.travelFk JOIN vn.supplier s ON s.id = e.supplierFk - JOIN vn.state st ON st.`code` = IF( tr.landed < util.VN_CURDATE() + JOIN vn.state st ON st.`code` = IF(tr.landed < util.VN_CURDATE() OR (util.VN_CURDATE() AND tr.isReceived), 'DELIVERED', 'FREE') @@ -116,7 +97,8 @@ BEGIN AND NOT e.isRaid ), entriesOut AS ( - SELECT tr.shipped, + SELECT 'entry', + tr.shipped, NULL, b.quantity, st.alertLevel, @@ -131,8 +113,7 @@ BEGIN NULL `order`, NULL clientType, NULL claimFk, - vSupplierInventoryFk, - NULL orderFk + vSupplierInventoryFk FROM vn.buy b JOIN vn.entry e ON e.id = b.entryFk JOIN vn.travel tr ON tr.id = e.travelFk @@ -180,7 +161,8 @@ BEGIN AND s.itemFk = vItemFk AND vWarehouseFk = t.warehouseFk ) - SELECT s.shipped, + SELECT 'ticket', + s.shipped, NULL `in`, s.quantity, s.alertLevel, @@ -195,8 +177,7 @@ BEGIN s.`order`, s.typeFk, s.claimFk, - NULL, - NULL orderFk + NULL FROM itemSales s LEFT JOIN vn.state stPrep ON stPrep.`code` = 'PREPARED' LEFT JOIN vn.saleTracking stk ON stk.saleFk = s.saleFk @@ -204,23 +185,23 @@ BEGIN GROUP BY s.saleFk ), orders AS ( - SELECT r.shipment, + SELECT 'order' `type`, + r.shipment, NULL 'in', r.amount, NULL alertLevel, NULL stateName, - NULL, + c.name, NULL invoiceNumber, - NULL entryFk, - NULL supplierFk, + o.id origin, + c.id, FALSE, FALSE isTicket, NULL buyFk, NULL 'order', c.typeFk, NULL claimFk, - NULL inventorySupplierFk, - o.id + NULL FROM hedera.orderRow r JOIN hedera.`order` o ON o.id = r.orderFk JOIN tItemRange ir ON ir.itemFk = r.itemFk @@ -252,7 +233,8 @@ BEGIN SET @currentLineFk := 0; SET @shipped := ''; - SELECT DATE(@shipped:= t.shipped) shipped, + SELECT t.type, + DATE(@shipped:= t.shipped) shipped, t.alertLevel, t.stateName, t.origin, @@ -271,8 +253,7 @@ BEGIN t.isPicked, t.clientType, t.claimFk, - t.`order`, - t.orderFk + t.`order` FROM tItemDiary t LEFT JOIN alertLevel a ON a.id = t.alertLevel; ELSE @@ -280,26 +261,27 @@ BEGIN FROM tItemDiary WHERE shipped < vDated; - SELECT vDated shipped, - 0 alertLevel, - 0 stateName, - 0 origin, - '' reference, - 0 clientFk, + SELECT NULL `type`, + vDated shipped, + NULL alertLevel, + NULL stateName, + NULL origin, + NULL reference, + NULL clientFk, 'Inventario calculado', @a invalue, NULL `out`, @a balance, - 0 lastPreparedLineFk, - 0 isTicket, - 0 lineFk, - 0 isPicked, - 0 clientType, - 0 claimFk, - NULL `order`, - 0 orderFk + NULL lastPreparedLineFk, + NULL isTicket, + NULL lineFk, + NULL isPicked, + NULL clientType, + NULL claimFk, + NULL `order` UNION ALL - SELECT shipped, + SELECT `type`, + shipped, alertlevel, stateName, origin, @@ -314,8 +296,7 @@ BEGIN isPicked, clientType, claimFk, - `order`, - orderFk + `order` FROM tItemDiary WHERE shipped >= vDated; END IF; From 1fff3aa681acf5789975d1fad1a4ec051c9baa47 Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 4 Jul 2024 12:34:56 +0200 Subject: [PATCH 086/173] feat: refs #7670 addSale --- modules/ticket/back/methods/ticket/addSale.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/addSale.js b/modules/ticket/back/methods/ticket/addSale.js index 8dc7a633c..ad393fc65 100644 --- a/modules/ticket/back/methods/ticket/addSale.js +++ b/modules/ticket/back/methods/ticket/addSale.js @@ -70,7 +70,7 @@ module.exports = Self => { quantity: quantity }, myOptions); - await Self.rawSql('CALL vn.sale_calculateComponent(?, NULL)', [newSale.id], myOptions); + await Self.rawSql('CALL vn.sale_calculateComponent(?, ?)', [newSale.id, 'renewPrices'], myOptions); await Self.rawSql('CALL vn.ticket_recalc(?, NULL)', [id], myOptions); const sale = await models.Sale.findById(newSale.id, { From 776fd0564869de1019dd70df6972585fc894ee66 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 4 Jul 2024 12:45:52 +0200 Subject: [PATCH 087/173] fix: send rocket after commit cau 199307 --- modules/ticket/back/methods/sale/deleteSales.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/ticket/back/methods/sale/deleteSales.js b/modules/ticket/back/methods/sale/deleteSales.js index 0207815a9..0290b2b9d 100644 --- a/modules/ticket/back/methods/sale/deleteSales.js +++ b/modules/ticket/back/methods/sale/deleteSales.js @@ -66,6 +66,10 @@ module.exports = Self => { promises.push(deletedSale); } + const deletedSales = await Promise.all(promises); + + if (tx) await tx.commit(); + const salesPerson = ticket.client().salesPersonUser(); if (salesPerson) { const url = await Self.app.models.Url.getUrl(); @@ -75,13 +79,9 @@ module.exports = Self => { ticketUrl: `${url}ticket/${ticketId}/sale`, deletions: deletions }); - await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message, myOptions); + await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message); } - const deletedSales = await Promise.all(promises); - - if (tx) await tx.commit(); - return deletedSales; } catch (e) { if (tx) await tx.rollback(); From 6f0196d656fb8ffcdcfb20bc4979f9a23bc8a963 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 5 Jul 2024 07:06:40 +0200 Subject: [PATCH 088/173] refs #6769 Changes --- db/routines/vn/procedures/item_getBalance.sql | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/db/routines/vn/procedures/item_getBalance.sql b/db/routines/vn/procedures/item_getBalance.sql index dc4e16789..c2e0bc0c1 100644 --- a/db/routines/vn/procedures/item_getBalance.sql +++ b/db/routines/vn/procedures/item_getBalance.sql @@ -6,13 +6,11 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getBalance`( ) BEGIN /** - * Calcula el disponible. + * Calcula el balance de un artículo. * * @vItemFk Id de artículo * @vWarehouseFk Id de almacén - * @vDated Fecha - * Si la fecha es NULL, muestra el histórico desde el inventario. - * Si la fecha no es NULL, muestra histórico desde la fecha de vDated. + * @vDated Fecha a calcular, si es NULL muestra el histórico desde el inventario */ DECLARE vDateInventory DATETIME; DECLARE vLifeScope DATE; @@ -64,7 +62,8 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tItemDiary ENGINE = MEMORY WITH entriesIn AS ( - SELECT 'entry' `type`, + SELECT 'entry' originType, + e.id origin, tr.landed shipped, b.quantity `in`, NULL `out`, @@ -72,8 +71,8 @@ BEGIN st.name stateName, s.name `name`, e.invoiceNumber reference, - e.id origin, - s.id clientFk, + 'supplier' entityType, + s.id entity, IF(st.`code` = 'DELIVERED', TRUE, FALSE) isPicked, FALSE isTicket, b.id lineFk, @@ -98,6 +97,7 @@ BEGIN ), entriesOut AS ( SELECT 'entry', + e.id originType, tr.shipped, NULL, b.quantity, @@ -105,8 +105,8 @@ BEGIN st.name stateName, s.name, e.invoiceNumber, - e.id entryFk, - s.id supplierFk, + 'supplier' entityType, + s.id entity, IF(st.`code` = 'DELIVERED' , TRUE, FALSE), FALSE isTicket, b.id, @@ -123,7 +123,6 @@ BEGIN OR (tr.shipped = util.VN_CURDATE() AND tr.isReceived), 'DELIVERED', 'FREE') - JOIN vn.entryConfig ec WHERE tr.shipped >= vDateInventory AND vWarehouseFk = tr.warehouseOutFk AND (s.id <> vSupplierInventoryFk OR vDated IS NULL) @@ -141,7 +140,8 @@ BEGIN t.nickname, t.refFk, t.id ticketFk, - t.clientFk, + 'client' entityType, + t.clientFk entity, s.id saleFk, st.`order`, c.typeFk, @@ -162,6 +162,7 @@ BEGIN AND vWarehouseFk = t.warehouseFk ) SELECT 'ticket', + s.ticketFk, s.shipped, NULL `in`, s.quantity, @@ -169,8 +170,8 @@ BEGIN s.name, s.nickname, s.refFk, - s.ticketFk, - s.clientFk, + s.entityType, + s.entity, IF(stk.saleFk, TRUE, FALSE), TRUE, s.saleFk, @@ -185,7 +186,8 @@ BEGIN GROUP BY s.saleFk ), orders AS ( - SELECT 'order' `type`, + SELECT 'order' originType, + o.id origin, r.shipment, NULL 'in', r.amount, @@ -193,7 +195,7 @@ BEGIN NULL stateName, c.name, NULL invoiceNumber, - o.id origin, + 'client' entityType, c.id, FALSE, FALSE isTicket, @@ -220,7 +222,7 @@ BEGIN UNION ALL SELECT * FROM orders ORDER BY shipped, - (inventorySupplierFk = clientFk) DESC, + (inventorySupplierFk = entity) DESC, alertLevel DESC, isTicket, `order` DESC, @@ -233,13 +235,14 @@ BEGIN SET @currentLineFk := 0; SET @shipped := ''; - SELECT t.type, + SELECT t.originType, + t.origin, DATE(@shipped:= t.shipped) shipped, t.alertLevel, t.stateName, - t.origin, t.reference, - t.clientFk, + t.entityType, + t.entity, t.name, t.`in` invalue, t.`out`, @@ -261,13 +264,14 @@ BEGIN FROM tItemDiary WHERE shipped < vDated; - SELECT NULL `type`, + SELECT NULL originType, + NULL origin, vDated shipped, NULL alertLevel, NULL stateName, - NULL origin, NULL reference, - NULL clientFk, + NULL entityType, + NULL entity, 'Inventario calculado', @a invalue, NULL `out`, @@ -280,13 +284,14 @@ BEGIN NULL claimFk, NULL `order` UNION ALL - SELECT `type`, + SELECT originType, + origin, shipped, alertlevel, stateName, - origin, - reference, - clientFk, + reference, + entityType, + entity, name, `in`, `out`, @a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0), From 50c9ded103a66f7b667f6ec0f4da4ccfe71e5a86 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 5 Jul 2024 08:38:40 +0200 Subject: [PATCH 089/173] refs #6769 Fix --- db/routines/vn/procedures/item_getBalance.sql | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/item_getBalance.sql b/db/routines/vn/procedures/item_getBalance.sql index c2e0bc0c1..a12397aa6 100644 --- a/db/routines/vn/procedures/item_getBalance.sql +++ b/db/routines/vn/procedures/item_getBalance.sql @@ -34,7 +34,8 @@ BEGIN END IF; -- Calcula el ultimo dia de vida para cada producto - CREATE OR REPLACE TEMPORARY TABLE tItemRange + -- Tiene tmp a propósito, porque si no falla al utilizarlo en el WITH + CREATE OR REPLACE TEMPORARY TABLE tmp.itemRange (PRIMARY KEY (itemFk)) ENGINE = MEMORY SELECT i.id itemFk, @@ -206,7 +207,7 @@ BEGIN NULL FROM hedera.orderRow r JOIN hedera.`order` o ON o.id = r.orderFk - JOIN tItemRange ir ON ir.itemFk = r.itemFk + JOIN tmp.itemRange ir ON ir.itemFk = r.itemFk JOIN vn.client c ON c.id = o.customer_id WHERE r.shipment >= vDateInventory AND (ir.ended IS NULL OR r.shipment <= ir.ended) @@ -308,6 +309,6 @@ BEGIN DROP TEMPORARY TABLE tItemDiary, - tItemRange; + tmp.itemRange; END$$ DELIMITER ; From e3db143b443c7ecdc1412b7627c120a05d534207 Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 5 Jul 2024 08:55:24 +0200 Subject: [PATCH 090/173] feat: refs #7348 campo en json --- modules/client/back/models/client.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/client/back/models/client.json b/modules/client/back/models/client.json index f3eb9919b..f24f69ae7 100644 --- a/modules/client/back/models/client.json +++ b/modules/client/back/models/client.json @@ -144,6 +144,9 @@ }, "recommendedCredit": { "type": "number" + }, + "hasDailyInvoice": { + "type": "boolean" } }, From d4b4c0fafe9397d8389586dbecebbae8d8d73ec2 Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 5 Jul 2024 09:04:38 +0200 Subject: [PATCH 091/173] feat: refs #7348 campos a modificar --- modules/client/back/methods/client/updateFiscalData.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/client/back/methods/client/updateFiscalData.js b/modules/client/back/methods/client/updateFiscalData.js index 851648658..8ed55b856 100644 --- a/modules/client/back/methods/client/updateFiscalData.js +++ b/modules/client/back/methods/client/updateFiscalData.js @@ -99,6 +99,10 @@ module.exports = Self => { { arg: 'hasElectronicInvoice', type: 'boolean' + }, + { + arg: 'hasDailyInvoice', + type: 'boolean' } ], returns: { @@ -117,8 +121,6 @@ module.exports = Self => { const myOptions = {}; const models = Self.app.models; const args = ctx.args; - const userId = ctx.req.accessToken.userId; - const $t = ctx.req.__; if (typeof options == 'object') Object.assign(myOptions, options); From aa46d7a53659188933d6cc4a1307f6961f74f168 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 5 Jul 2024 09:46:09 +0200 Subject: [PATCH 092/173] refs #6769 item_getBalance optimization --- db/routines/vn/procedures/item_getBalance.sql | 68 +++++++++++-------- .../11135-whiteErica/00-firstScript.sql | 1 + 2 files changed, 39 insertions(+), 30 deletions(-) create mode 100644 db/versions/11135-whiteErica/00-firstScript.sql diff --git a/db/routines/vn/procedures/item_getBalance.sql b/db/routines/vn/procedures/item_getBalance.sql index a12397aa6..15be8c926 100644 --- a/db/routines/vn/procedures/item_getBalance.sql +++ b/db/routines/vn/procedures/item_getBalance.sql @@ -21,14 +21,14 @@ BEGIN FROM config c JOIN util.config uc; - SELECT COALESCE(vDated, vDateInventory) - INTERVAL MAX(life) DAY + SELECT vDateInventory - INTERVAL MAX(life) DAY INTO vLifeScope FROM itemType; SELECT warehouseOutFk, supplierFk INTO vWarehouseInventoryFk, vSupplierInventoryFk FROM inventoryConfig; - + IF NOT vWarehouseInventoryFk OR NOT vSupplierInventoryFk THEN CALL util.throw('Config variables are not set'); END IF; @@ -50,30 +50,32 @@ BEGIN JOIN warehouse w ON w.id = t.warehouseInFk JOIN item i ON i.id = b.itemFk JOIN itemType it ON it.id = i.typeFk - WHERE t.landed BETWEEN vLifeScope AND COALESCE(vDated, vDateInventory) + WHERE t.landed BETWEEN vLifeScope AND vDateInventory AND t.warehouseInFk = vWarehouseFk AND t.warehouseOutFk <> vWarehouseInventoryFk AND it.life + AND i.id = vItemFk AND NOT e.isExcludedFromAvailable GROUP BY b.itemFk ) c ON i.id = c.itemFk JOIN itemType it ON it.id = i.typeFk - HAVING ended >= COALESCE(vDated, vDateInventory) OR life IS NULL; + WHERE i.id = vItemFk + HAVING ended >= vDateInventory OR life IS NULL; CREATE OR REPLACE TEMPORARY TABLE tItemDiary ENGINE = MEMORY WITH entriesIn AS ( SELECT 'entry' originType, - e.id origin, + e.id originId, tr.landed shipped, b.quantity `in`, NULL `out`, st.alertLevel , st.name stateName, - s.name `name`, e.invoiceNumber reference, 'supplier' entityType, - s.id entity, + s.id entityId, + s.name entityName, IF(st.`code` = 'DELIVERED', TRUE, FALSE) isPicked, FALSE isTicket, b.id lineFk, @@ -104,10 +106,10 @@ BEGIN b.quantity, st.alertLevel, st.name stateName, - s.name, e.invoiceNumber, 'supplier' entityType, - s.id entity, + s.id entityId, + s.name, IF(st.`code` = 'DELIVERED' , TRUE, FALSE), FALSE isTicket, b.id, @@ -125,7 +127,7 @@ BEGIN 'DELIVERED', 'FREE') WHERE tr.shipped >= vDateInventory - AND vWarehouseFk = tr.warehouseOutFk + AND tr.warehouseOutFk = vWarehouseFk AND (s.id <> vSupplierInventoryFk OR vDated IS NULL) AND b.itemFk = vItemFk AND NOT e.isExcludedFromAvailable @@ -138,29 +140,30 @@ BEGIN s.quantity, st2.alertLevel, st2.name, - t.nickname, t.refFk, t.id ticketFk, 'client' entityType, - t.clientFk entity, + t.clientFk entityId, + t.nickname, s.id saleFk, st.`order`, c.typeFk, cb.claimFk FROM vn.sale s JOIN vn.ticket t ON t.id = s.ticketFk - LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id - LEFT JOIN vn.state st ON st.`code` = ts.`code` + LEFT JOIN vn.ticketLastState tls ON tls.ticketFk = t.id + LEFT JOIN vn.ticketTracking tt ON tt.id = tls.ticketTrackingFk + LEFT JOIN vn.state st ON st.id = tt.stateFk JOIN vn.client c ON c.id = t.clientFk JOIN vn.state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(), 'DELIVERED', IF (t.shipped > util.dayEnd(util.VN_CURDATE()), 'FREE', - IFNULL(ts.code, 'FREE'))) - LEFT JOIN vn.claimBeginning cb ON s.id = cb.saleFk + IFNULL(st.code, 'FREE'))) + LEFT JOIN vn.claimBeginning cb ON cb.saleFk = s.id WHERE t.shipped >= vDateInventory AND s.itemFk = vItemFk - AND vWarehouseFk = t.warehouseFk + AND t.warehouseFk = vWarehouseFk ) SELECT 'ticket', s.ticketFk, @@ -169,10 +172,10 @@ BEGIN s.quantity, s.alertLevel, s.name, - s.nickname, s.refFk, s.entityType, - s.entity, + s.entityId, + s.nickname, IF(stk.saleFk, TRUE, FALSE), TRUE, s.saleFk, @@ -188,16 +191,16 @@ BEGIN ), orders AS ( SELECT 'order' originType, - o.id origin, + o.id originId, r.shipment, NULL 'in', r.amount, NULL alertLevel, NULL stateName, - c.name, NULL invoiceNumber, 'client' entityType, c.id, + c.name, FALSE, FALSE isTicket, NULL buyFk, @@ -212,6 +215,10 @@ BEGIN WHERE r.shipment >= vDateInventory AND (ir.ended IS NULL OR r.shipment <= ir.ended) AND r.warehouseFk = vWarehouseFk + AND r.created >= ( + SELECT SUBTIME(util.VN_NOW(), reserveTime) + FROM hedera.orderConfig + ) AND NOT o.confirmed AND r.itemFk = vItemFk ) @@ -223,7 +230,7 @@ BEGIN UNION ALL SELECT * FROM orders ORDER BY shipped, - (inventorySupplierFk = entity) DESC, + (inventorySupplierFk = entityId) DESC, alertLevel DESC, isTicket, `order` DESC, @@ -237,14 +244,14 @@ BEGIN SET @shipped := ''; SELECT t.originType, - t.origin, + t.originId, DATE(@shipped:= t.shipped) shipped, t.alertLevel, t.stateName, t.reference, t.entityType, - t.entity, - t.name, + t.entityId, + t.entityName, t.`in` invalue, t.`out`, @a := @a + IFNULL(t.`in`, 0) - IFNULL(t.`out`, 0) balance, @@ -266,13 +273,13 @@ BEGIN WHERE shipped < vDated; SELECT NULL originType, - NULL origin, + NULL originId, vDated shipped, NULL alertLevel, NULL stateName, NULL reference, NULL entityType, - NULL entity, + NULL entityId, 'Inventario calculado', @a invalue, NULL `out`, @@ -286,14 +293,15 @@ BEGIN NULL `order` UNION ALL SELECT originType, - origin, + originId, shipped, alertlevel, stateName, reference, entityType, - entity, - name, `in`, + entityId, + entityName, + `in`, `out`, @a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0), 0, diff --git a/db/versions/11135-whiteErica/00-firstScript.sql b/db/versions/11135-whiteErica/00-firstScript.sql new file mode 100644 index 000000000..902608a3e --- /dev/null +++ b/db/versions/11135-whiteErica/00-firstScript.sql @@ -0,0 +1 @@ +CREATE INDEX travel_landed_IDX USING BTREE ON vn.travel (landed DESC,warehouseInFk,warehouseOutFk); From 182273d3b387c35cd40d296eceee468381d4ca4a Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 5 Jul 2024 09:59:15 +0200 Subject: [PATCH 093/173] refs #7450 Modified msg throw --- db/routines/vn/procedures/entry_isEditable.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/entry_isEditable.sql b/db/routines/vn/procedures/entry_isEditable.sql index a05a1fd92..c279fac65 100644 --- a/db/routines/vn/procedures/entry_isEditable.sql +++ b/db/routines/vn/procedures/entry_isEditable.sql @@ -18,7 +18,7 @@ BEGIN AND e.id = vSelf; IF vIsEditable AND NOT IFNULL(@isModeInventory, FALSE) THEN - CALL util.throw('Entry is not editable'); + CALL util.throw(CONCAT('Entry ', vSelf, ' is not editable')); END IF; END$$ DELIMITER ; From 1799b52f8b8fc0ac5188c38876aacb3aeb2f5a8d Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 5 Jul 2024 12:37:59 +0200 Subject: [PATCH 094/173] feat: refs #7622 Added type column addressWaste --- db/routines/vn/procedures/item_setVisibleDiscard.sql | 3 ++- db/versions/11136-maroonMedeola/00-firstScript.sql | 6 ++++++ .../models/{addressShortage.json => address-waste.json} | 8 ++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 db/versions/11136-maroonMedeola/00-firstScript.sql rename modules/client/back/models/{addressShortage.json => address-waste.json} (70%) diff --git a/db/routines/vn/procedures/item_setVisibleDiscard.sql b/db/routines/vn/procedures/item_setVisibleDiscard.sql index 0a6c54971..a44d87333 100644 --- a/db/routines/vn/procedures/item_setVisibleDiscard.sql +++ b/db/routines/vn/procedures/item_setVisibleDiscard.sql @@ -6,7 +6,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_setVisibleDisc vAddressFk INT) BEGIN /** - * Procedimiento para dar dar de baja/alta un item, si vAddressFk es NULL se entiende que se da de alta y se toma el addressFk de la configuración + * Procedimiento para dar dar de baja/alta un item, si vAdressFk es NULL + * se entiende que se da de alta y se toma el addressFk de la configuración * * @param vItemFk Identificador del ítem * @param vWarehouseFk id del warehouse diff --git a/db/versions/11136-maroonMedeola/00-firstScript.sql b/db/versions/11136-maroonMedeola/00-firstScript.sql new file mode 100644 index 000000000..09abfe391 --- /dev/null +++ b/db/versions/11136-maroonMedeola/00-firstScript.sql @@ -0,0 +1,6 @@ +RENAME TABLE vn.addressShortage TO vn.addressWaste; +ALTER TABLE vn.addressWaste ADD `type` ENUM('internal', 'external') NOT NULL; +INSERT INTO IGNORE vn.addressWaste (addressFk,`type`) VALUES + (2230,'external'), + (5986,'external'), + (7475,'external'); diff --git a/modules/client/back/models/addressShortage.json b/modules/client/back/models/address-waste.json similarity index 70% rename from modules/client/back/models/addressShortage.json rename to modules/client/back/models/address-waste.json index 1ae8d986c..2d7126eae 100644 --- a/modules/client/back/models/addressShortage.json +++ b/modules/client/back/models/address-waste.json @@ -1,15 +1,19 @@ { - "name": "AddressShortage", + "name": "AddressWaste", "base": "VnModel", "options": { "mysql": { - "table": "addressShortage" + "table": "addressWaste" } }, "properties": { "addressFk": { "type": "number", "id": true + }, + "type": { + "type": "string", + "id": true } }, "relations": { From b9e986c9627c26921e880245e4b7c8c264e55a64 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 5 Jul 2024 12:39:54 +0200 Subject: [PATCH 095/173] feat: refs #7622 Fix --- db/versions/11136-maroonMedeola/00-firstScript.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/11136-maroonMedeola/00-firstScript.sql b/db/versions/11136-maroonMedeola/00-firstScript.sql index 09abfe391..b0b92c7e9 100644 --- a/db/versions/11136-maroonMedeola/00-firstScript.sql +++ b/db/versions/11136-maroonMedeola/00-firstScript.sql @@ -1,6 +1,6 @@ RENAME TABLE vn.addressShortage TO vn.addressWaste; ALTER TABLE vn.addressWaste ADD `type` ENUM('internal', 'external') NOT NULL; -INSERT INTO IGNORE vn.addressWaste (addressFk,`type`) VALUES +INSERT IGNORE INTO vn.addressWaste (addressFk,`type`) VALUES (2230,'external'), (5986,'external'), (7475,'external'); From 1d59883d19f96020ec7d377cc965c975821b60e0 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 5 Jul 2024 13:14:16 +0200 Subject: [PATCH 096/173] feat: refs #7644 Minor change --- print/templates/reports/buy-label/buy-label.html | 2 +- print/templates/reports/buy-label/sql/buys.sql | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/print/templates/reports/buy-label/buy-label.html b/print/templates/reports/buy-label/buy-label.html index 494cdcbc5..b14e54759 100644 --- a/print/templates/reports/buy-label/buy-label.html +++ b/print/templates/reports/buy-label/buy-label.html @@ -59,7 +59,7 @@
- {{buy.id}} + {{buy.itemFk}} diff --git a/print/templates/reports/buy-label/sql/buys.sql b/print/templates/reports/buy-label/sql/buys.sql index 50b34bd03..41fd3556b 100644 --- a/print/templates/reports/buy-label/sql/buys.sql +++ b/print/templates/reports/buy-label/sql/buys.sql @@ -8,6 +8,7 @@ SELECT ROW_NUMBER() OVER(ORDER BY b.id) labelNum, b.`grouping`, i.stems, b.id, + b.itemFk, p.name producer FROM buy b JOIN item i ON i.id = b.itemFk From 3508cf3a9eea30366065b002e4135fce13590a17 Mon Sep 17 00:00:00 2001 From: ivanm Date: Fri, 5 Jul 2024 14:01:09 +0200 Subject: [PATCH 097/173] refs #7561 add fk en userFk --- db/versions/11137-salmonRoebelini/00-firstScript.sql | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 db/versions/11137-salmonRoebelini/00-firstScript.sql diff --git a/db/versions/11137-salmonRoebelini/00-firstScript.sql b/db/versions/11137-salmonRoebelini/00-firstScript.sql new file mode 100644 index 000000000..69d20ac6d --- /dev/null +++ b/db/versions/11137-salmonRoebelini/00-firstScript.sql @@ -0,0 +1,4 @@ +ALTER TABLE vn.expeditionState + MODIFY COLUMN userFk INT(10) UNSIGNED, + ADD CONSTRAINT expeditionState_userFk FOREIGN KEY (userFk) + REFERENCES account.`user`(id); \ No newline at end of file From 5192bfd8ead52327c2b474465f231b8e596466c8 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 5 Jul 2024 14:58:34 +0200 Subject: [PATCH 098/173] fix(salix): refs #7648 #7648 entryFilter and getBuys by fi --- modules/entry/back/methods/entry/filter.js | 7 ++++--- modules/entry/back/methods/entry/getBuys.js | 7 ++++--- modules/entry/back/methods/entry/specs/filter.spec.js | 4 ++-- modules/entry/back/methods/entry/specs/getBuys.spec.js | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 5989494a4..f21d9dbc4 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -146,10 +146,11 @@ module.exports = Self => { }); filter = mergeFilters(ctx.args.filter, {where}); const userId = ctx.req.accessToken.userId; - const isSupplier = await Self.app.models.Supplier.findById(userId, myOptions); - if (isSupplier) { + const client = await Self.app.models.Client.findById(userId, myOptions); + const supplier = await Self.app.models.Supplier.findOne({where: {nif: client.fi}}, myOptions); + if (supplier) { if (!filter.where) filter.where = {}; - filter.where[`e.supplierFk`] = ctx.req.accessToken.userId; + filter.where[`e.supplierFk`] = supplier.id; } const stmts = []; let stmt; diff --git a/modules/entry/back/methods/entry/getBuys.js b/modules/entry/back/methods/entry/getBuys.js index 444e6cb14..0cb71653e 100644 --- a/modules/entry/back/methods/entry/getBuys.js +++ b/modules/entry/back/methods/entry/getBuys.js @@ -36,9 +36,10 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const isSupplier = await Self.app.models.Supplier.findById(userId, myOptions); - if (isSupplier) { - const isEntryOwner = (await Self.findById(id)).supplierFk === userId; + const client = await Self.app.models.Client.findById(userId, myOptions); + const supplier = await Self.app.models.Supplier.findOne({where: {nif: client.fi}}, myOptions); + if (supplier) { + const isEntryOwner = (await Self.findById(id)).supplierFk === supplier.id; if (!isEntryOwner) throw new UserError('Access Denied'); } diff --git a/modules/entry/back/methods/entry/specs/filter.spec.js b/modules/entry/back/methods/entry/specs/filter.spec.js index 9d954cdc4..c8a5bd94f 100644 --- a/modules/entry/back/methods/entry/specs/filter.spec.js +++ b/modules/entry/back/methods/entry/specs/filter.spec.js @@ -56,7 +56,7 @@ describe('Entry filter()', () => { try { const ctx = { args: {}, - req: {accessToken: {userId: 2}} + req: {accessToken: {userId: 1102}} }; const result = await models.Entry.filter(ctx, options); @@ -79,7 +79,7 @@ describe('Entry filter()', () => { args: { supplierFk: 1 }, - req: {accessToken: {userId: 2}} + req: {accessToken: {userId: 1102}} }; const result = await models.Entry.filter(ctx, options); diff --git a/modules/entry/back/methods/entry/specs/getBuys.spec.js b/modules/entry/back/methods/entry/specs/getBuys.spec.js index cb7f7cb80..2d3531249 100644 --- a/modules/entry/back/methods/entry/specs/getBuys.spec.js +++ b/modules/entry/back/methods/entry/specs/getBuys.spec.js @@ -40,7 +40,7 @@ describe('entry getBuys()', () => { args: { search: 1 }, - req: {accessToken: {userId: 2}} + req: {accessToken: {userId: 1102}} }; const result = await models.Entry.getBuys(ctx, entryId, options); From 2f10066290c1c064c49a68167dd775698b0fe908 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Sun, 7 Jul 2024 23:23:30 +0200 Subject: [PATCH 099/173] feat(salix): refs #7380 #7380 remove new field --- db/versions/11132-aquaDracena/00-firstScript.sql | 2 -- modules/client/back/models/client.json | 3 --- 2 files changed, 5 deletions(-) diff --git a/db/versions/11132-aquaDracena/00-firstScript.sql b/db/versions/11132-aquaDracena/00-firstScript.sql index 1b304c1d0..a8baa8051 100644 --- a/db/versions/11132-aquaDracena/00-firstScript.sql +++ b/db/versions/11132-aquaDracena/00-firstScript.sql @@ -1,4 +1,2 @@ INSERT IGNORE INTO vn.observationType (`description`,code,hasNewBornMessage) VALUES ('Sustitución','substitution',0); - -ALTER TABLE vn.client ADD substitutionAllowed BOOL DEFAULT false NULL; diff --git a/modules/client/back/models/client.json b/modules/client/back/models/client.json index 97c2a3624..f3eb9919b 100644 --- a/modules/client/back/models/client.json +++ b/modules/client/back/models/client.json @@ -53,9 +53,6 @@ "isActive": { "type": "boolean" }, - "substitutionAllowed": { - "type": "boolean" - }, "credit": { "type": "number" }, From 3c2a44eb53334a31de7646f93a7f68c4a2fa1cc6 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Sun, 7 Jul 2024 23:47:00 +0200 Subject: [PATCH 100/173] feat(salix): refs #7380 #7380 add value to fixtures --- db/dump/fixtures.before.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 783feaca0..ebf0c3401 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -528,7 +528,8 @@ INSERT INTO `vn`.`observationType`(`id`,`description`, `code`) (5, 'Administrative', 'administrative'), (6, 'Weight', 'weight'), (7, 'InvoiceOut', 'invoiceOut'), - (8, 'DropOff', 'dropOff'); + (8, 'DropOff', 'dropOff'), + (9, 'Sustitución', 'substitution',0); INSERT INTO `vn`.`addressObservation`(`id`,`addressFk`,`observationTypeFk`,`description`) VALUES From e9d2ff14764bfc5eddcc1e0121de93d183c71546 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 8 Jul 2024 09:43:59 +0200 Subject: [PATCH 101/173] feat: refs #7582 claimDestination addColumn code --- db/versions/11138-aquaGalax/00-firstScript.sql | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 db/versions/11138-aquaGalax/00-firstScript.sql diff --git a/db/versions/11138-aquaGalax/00-firstScript.sql b/db/versions/11138-aquaGalax/00-firstScript.sql new file mode 100644 index 000000000..44fdd468f --- /dev/null +++ b/db/versions/11138-aquaGalax/00-firstScript.sql @@ -0,0 +1,9 @@ +USE `vn`; +ALTER TABLE `vn`.`claimDestination` +ADD COLUMN `code` varchar(45) DEFAULT NULL; + +UPDATE vn.claimDestination SET code='Good' WHERE description= 'Bueno'; +UPDATE vn.claimDestination SET code='Garbage/Loss' WHERE description = 'Basura/Perd.'; +UPDATE vn.claimDestination SET code='Manufacturing'WHERE description = 'Confeccion'; +UPDATE vn.claimDestination SET code='Claim' WHERE description = 'Reclam.PRAG'; +UPDATE vn.claimDestination SET code='Corrected' WHERE description = 'Corregido'; \ No newline at end of file From 9f57e50f8964f7617dd0e4999050d0dd901dcf1a Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 8 Jul 2024 09:54:40 +0200 Subject: [PATCH 102/173] feat(salix): refs #7380 #7380 add value to fixtures --- db/dump/fixtures.before.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index ebf0c3401..8bc70fbba 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -529,7 +529,7 @@ INSERT INTO `vn`.`observationType`(`id`,`description`, `code`) (6, 'Weight', 'weight'), (7, 'InvoiceOut', 'invoiceOut'), (8, 'DropOff', 'dropOff'), - (9, 'Sustitución', 'substitution',0); + (9, 'Sustitución', 'substitution'); INSERT INTO `vn`.`addressObservation`(`id`,`addressFk`,`observationTypeFk`,`description`) VALUES From 9f4680325bfb580147fdb1d9ead048a62689851a Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 8 Jul 2024 09:54:52 +0200 Subject: [PATCH 103/173] feat(salix): refs #7380 #7380 rename extension file --- db/versions/11132-aquaDracena/00-firstScript.sql | 2 -- db/versions/11132-aquaDracena/00-firstScript.vn.sql | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 db/versions/11132-aquaDracena/00-firstScript.sql create mode 100644 db/versions/11132-aquaDracena/00-firstScript.vn.sql diff --git a/db/versions/11132-aquaDracena/00-firstScript.sql b/db/versions/11132-aquaDracena/00-firstScript.sql deleted file mode 100644 index a8baa8051..000000000 --- a/db/versions/11132-aquaDracena/00-firstScript.sql +++ /dev/null @@ -1,2 +0,0 @@ -INSERT IGNORE INTO vn.observationType (`description`,code,hasNewBornMessage) - VALUES ('Sustitución','substitution',0); diff --git a/db/versions/11132-aquaDracena/00-firstScript.vn.sql b/db/versions/11132-aquaDracena/00-firstScript.vn.sql new file mode 100644 index 000000000..64f8442b4 --- /dev/null +++ b/db/versions/11132-aquaDracena/00-firstScript.vn.sql @@ -0,0 +1,2 @@ +INSERT IGNORE INTO vn.observationType (`description`,code) + VALUES ('Sustitución','substitution'); From 4b0a08d9653f1383666e53eb1eb1b268baf33c0b Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 8 Jul 2024 10:57:46 +0200 Subject: [PATCH 104/173] refactor: refs #7684 vehicle warehouseFk fix --- db/versions/11140-azurePhormium/00-firstScript.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 db/versions/11140-azurePhormium/00-firstScript.sql diff --git a/db/versions/11140-azurePhormium/00-firstScript.sql b/db/versions/11140-azurePhormium/00-firstScript.sql new file mode 100644 index 000000000..7c89110bb --- /dev/null +++ b/db/versions/11140-azurePhormium/00-firstScript.sql @@ -0,0 +1,3 @@ +ALTER TABLE vn.vehicle DROP FOREIGN KEY provinceFk; +ALTER TABLE vn.vehicle + ADD CONSTRAINT vehicle_warehouse_FK FOREIGN KEY (warehouseFk) REFERENCES vn.warehouse(id) ON DELETE RESTRICT ON UPDATE CASCADE; From 3fa0823d931bc8a817772f0ed855172151e537c5 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 8 Jul 2024 11:01:35 +0200 Subject: [PATCH 105/173] feat: refs #7582 quitar vn --- db/versions/11138-aquaGalax/00-firstScript.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/db/versions/11138-aquaGalax/00-firstScript.sql b/db/versions/11138-aquaGalax/00-firstScript.sql index 44fdd468f..1e759db61 100644 --- a/db/versions/11138-aquaGalax/00-firstScript.sql +++ b/db/versions/11138-aquaGalax/00-firstScript.sql @@ -1,4 +1,3 @@ -USE `vn`; ALTER TABLE `vn`.`claimDestination` ADD COLUMN `code` varchar(45) DEFAULT NULL; From a796787cb5eb3da34a893f25c79c7d52ff939aa0 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 8 Jul 2024 11:04:35 +0200 Subject: [PATCH 106/173] feat: refs #7582 --- db/versions/11138-aquaGalax/00-firstScript.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/versions/11138-aquaGalax/00-firstScript.sql b/db/versions/11138-aquaGalax/00-firstScript.sql index 1e759db61..0c6547260 100644 --- a/db/versions/11138-aquaGalax/00-firstScript.sql +++ b/db/versions/11138-aquaGalax/00-firstScript.sql @@ -1,8 +1,8 @@ ALTER TABLE `vn`.`claimDestination` ADD COLUMN `code` varchar(45) DEFAULT NULL; -UPDATE vn.claimDestination SET code='Good' WHERE description= 'Bueno'; -UPDATE vn.claimDestination SET code='Garbage/Loss' WHERE description = 'Basura/Perd.'; -UPDATE vn.claimDestination SET code='Manufacturing'WHERE description = 'Confeccion'; -UPDATE vn.claimDestination SET code='Claim' WHERE description = 'Reclam.PRAG'; -UPDATE vn.claimDestination SET code='Corrected' WHERE description = 'Corregido'; \ No newline at end of file +UPDATE IGNORE vn.claimDestination SET code='Good' WHERE description= 'Bueno'; +UPDATE IGNORE vn.claimDestination SET code='Garbage/Loss' WHERE description = 'Basura/Perd.'; +UPDATE IGNORE vn.claimDestination SET code='Manufacturing'WHERE description = 'Confeccion'; +UPDATE IGNORE vn.claimDestination SET code='Claim' WHERE description = 'Reclam.PRAG'; +UPDATE IGNORE vn.claimDestination SET code='Corrected' WHERE description = 'Corregido'; \ No newline at end of file From d0e4decf1e5dcf28011adb313d96fb674fd3db6e Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 8 Jul 2024 11:05:11 +0200 Subject: [PATCH 107/173] refs #6952 add producer sql trad --- print/templates/reports/invoice/invoice.html | 2 +- print/templates/reports/invoice/locale/en.yml | 2 +- print/templates/reports/invoice/locale/es.yml | 3 ++- print/templates/reports/invoice/sql/sales.sql | 4 +++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/print/templates/reports/invoice/invoice.html b/print/templates/reports/invoice/invoice.html index af1aaa423..c4e0b818a 100644 --- a/print/templates/reports/invoice/invoice.html +++ b/print/templates/reports/invoice/invoice.html @@ -104,7 +104,7 @@ {{sale.itemFk}} {{sale.quantity}} - {{sale.concept}} + {{sale.concept}} {{sale.subName}} {{sale.price | currency('EUR', $i18n.locale)}} {{(sale.discount / 100) | percentage}} {{sale.vatType}} diff --git a/print/templates/reports/invoice/locale/en.yml b/print/templates/reports/invoice/locale/en.yml index 336592f0c..336384457 100644 --- a/print/templates/reports/invoice/locale/en.yml +++ b/print/templates/reports/invoice/locale/en.yml @@ -34,4 +34,4 @@ plantPassport: Plant passport observations: Observations wireTransfer: "Pay method: Transferencia" accountNumber: "Account number: {0}" -services: Services \ No newline at end of file +services: Services diff --git a/print/templates/reports/invoice/locale/es.yml b/print/templates/reports/invoice/locale/es.yml index 32f6fc708..879977e39 100644 --- a/print/templates/reports/invoice/locale/es.yml +++ b/print/templates/reports/invoice/locale/es.yml @@ -34,4 +34,5 @@ plantPassport: Pasaporte fitosanitario observations: Observaciones wireTransfer: "Forma de pago: Transferencia" accountNumber: "Número de cuenta: {0}" -services: Servicios \ No newline at end of file +services: Servicios + diff --git a/print/templates/reports/invoice/sql/sales.sql b/print/templates/reports/invoice/sql/sales.sql index 8e5ad1102..2d29cc520 100644 --- a/print/templates/reports/invoice/sql/sales.sql +++ b/print/templates/reports/invoice/sql/sales.sql @@ -8,7 +8,8 @@ SELECT s.itemFk, s.concept, tc.code vatType, - it.isPackaging + it.isPackaging, + i.subName FROM vn.invoiceOut io JOIN vn.ticket t ON t.refFk = io.ref JOIN vn.supplier su ON su.id = io.companyFk @@ -38,6 +39,7 @@ SELECT NULL, ts.description, tc.code, + NULL, NULL FROM vn.invoiceOut io JOIN vn.ticket t ON t.refFk = io.ref From 0722a97c6000bd9ebc36b9349589bd660ee5e31a Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 8 Jul 2024 11:28:33 +0200 Subject: [PATCH 108/173] feat: refs #7582 --- db/versions/11138-aquaGalax/00-firstScript.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/11138-aquaGalax/00-firstScript.sql b/db/versions/11138-aquaGalax/00-firstScript.sql index 0c6547260..d492e6470 100644 --- a/db/versions/11138-aquaGalax/00-firstScript.sql +++ b/db/versions/11138-aquaGalax/00-firstScript.sql @@ -3,6 +3,6 @@ ADD COLUMN `code` varchar(45) DEFAULT NULL; UPDATE IGNORE vn.claimDestination SET code='Good' WHERE description= 'Bueno'; UPDATE IGNORE vn.claimDestination SET code='Garbage/Loss' WHERE description = 'Basura/Perd.'; -UPDATE IGNORE vn.claimDestination SET code='Manufacturing'WHERE description = 'Confeccion'; +UPDATE IGNORE vn.claimDestination SET code='Manufacturing' WHERE description = 'Confeccion'; UPDATE IGNORE vn.claimDestination SET code='Claim' WHERE description = 'Reclam.PRAG'; UPDATE IGNORE vn.claimDestination SET code='Corrected' WHERE description = 'Corregido'; \ No newline at end of file From f57ab7248233b260fac97baaad5c18005ce5e340 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 8 Jul 2024 13:17:29 +0200 Subject: [PATCH 109/173] refactor: refs #7580 Fix and improvement --- .../vn/procedures/collection_setParking.sql | 17 +++-- .../vn/procedures/saleGroup_setParking.sql | 20 ++++-- db/routines/vn/procedures/setParking.sql | 65 ++++++++----------- .../vn/procedures/ticket_setNextState.sql | 17 ++++- .../vn/procedures/ticket_setParking.sql | 22 +++++-- 5 files changed, 79 insertions(+), 62 deletions(-) diff --git a/db/routines/vn/procedures/collection_setParking.sql b/db/routines/vn/procedures/collection_setParking.sql index 73aa87bfb..5f6ca75da 100644 --- a/db/routines/vn/procedures/collection_setParking.sql +++ b/db/routines/vn/procedures/collection_setParking.sql @@ -1,15 +1,18 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_setParking`(IN `vCollectionFk` VARCHAR(8), IN `vParkingFk` INT) -proc: BEGIN +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`collection_setParking`( + vSelf INT, + vParkingFk INT +) +BEGIN /** * Aparca una colección en un parking. * - * @param vCollectionFk Id de la colección - * @param vParkingFk Id del parking + * @param vSelf Id colección + * @param vParkingFk Id parking */ - REPLACE vn.ticketParking(ticketFk, parkingFk) + REPLACE ticketParking(ticketFk, parkingFk) SELECT tc.ticketFk, vParkingFk - FROM vn.ticketCollection tc - WHERE tc.collectionFk = vCollectionFk; + FROM ticketCollection tc + WHERE tc.collectionFk = vSelf; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/saleGroup_setParking.sql b/db/routines/vn/procedures/saleGroup_setParking.sql index 4872f74c6..551ca6386 100644 --- a/db/routines/vn/procedures/saleGroup_setParking.sql +++ b/db/routines/vn/procedures/saleGroup_setParking.sql @@ -1,17 +1,25 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleGroup_setParking`(IN `vSaleGroupFk` VARCHAR(8), IN `vParkingFk` INT) -proc: BEGIN +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleGroup_setParking`( + vSaleGroupFk VARCHAR(8), + vParkingFk INT +) +BEGIN /** - * Aparca una preparación previa en un parking + * Aparca una preparación previa en un parking. * * @param vSaleGroupFk id de la preparación previa * @param vParkingFk id del parking */ - UPDATE vn.saleGroup sg + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + RESIGNAL; + END; + + UPDATE saleGroup sg SET sg.parkingFk = vParkingFk WHERE sg.id = vSaleGroupFk - AND sg.created >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); + AND sg.created >= util.VN_CURDATE() - INTERVAL 1 WEEK; - CALL vn.ticket_setNextState(vn.ticket_get(vSaleGroupFk)); + CALL ticket_setNextState(ticket_get(vSaleGroupFk)); END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/setParking.sql b/db/routines/vn/procedures/setParking.sql index d6def07de..c4e1fd19f 100644 --- a/db/routines/vn/procedures/setParking.sql +++ b/db/routines/vn/procedures/setParking.sql @@ -1,6 +1,9 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`setParking`(IN `vParam` VARCHAR(8), IN `vParkingCode` VARCHAR(8)) -proc: BEGIN +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`setParking`( + vParam VARCHAR(8), + vParkingCode VARCHAR(8) +) +BEGIN /** * Aparca una colección, un ticket, un saleGroup o un shelving en un parking * @@ -8,56 +11,40 @@ proc: BEGIN * @param vParkingCode código del parking */ DECLARE vParkingFk INT; - DECLARE vIsSaleGroup BOOL; - DECLARE vIsTicket BOOL; - DECLARE vIsCollection BOOL; + DECLARE vLastWeek DATE; - SET vParkingCode = replace(vParkingCode,' ',''); + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + SET vParkingCode = REPLACE(vParkingCode, ' ', ''); SELECT id INTO vParkingFk - FROM vn.parking + FROM parking WHERE code = vParkingCode COLLATE utf8_unicode_ci; IF vParkingFk IS NULL THEN CALL util.throw('parkingNotExist'); - LEAVE proc; END IF; - IF vParam REGEXP '^[0-9]+$' THEN - -- Se comprueba si es una preparación previa - SELECT COUNT(*) INTO vIsSaleGroup - FROM vn.saleGroup sg - WHERE sg.id = vParam; + IF vParam REGEXP '^[0-9]+$' THEN + SET vLastWeek = util.VN_CURDATE() - INTERVAL 1 WEEK; - IF vIsSaleGroup THEN - CALL vn.saleGroup_setParking(vParam, vParkingFk); - LEAVE proc; - END IF; - - -- Se comprueba si es un ticket - SELECT COUNT(*) INTO vIsTicket - FROM vn.ticket t - WHERE t.id = vParam - AND t.shipped >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); - - IF vIsTicket THEN - CALL vn.ticket_setParking(vParam, vParkingFk); - LEAVE proc; - END IF; - - -- Se comprueba si es una coleccion de tickets - SELECT COUNT(*) INTO vIsCollection - FROM vn.collection c - WHERE c.id = vParam - AND c.created >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); - - IF vIsCollection THEN - CALL vn.collection_setParking(vParam, vParkingFk); - LEAVE proc; + -- Comprobamos si es una prep. previa, ticket o colección + IF (SELECT TRUE FROM saleGroup sg WHERE sg.id = vParam) THEN + CALL saleGroup_setParking(vParam, vParkingFk); + ELSEIF (SELECT TRUE FROM ticket WHERE id = vParam shipped >= vLastWeek) THEN + CALL ticket_setParking(vParam, vParkingFk); + ELSEIF (SELECT TRUE FROM `collection` WHERE id = vParam AND created >= vLastWeek) THEN + CALL collection_setParking(vParam, vParkingFk); END IF; ELSE -- Por descarte, se considera una matrícula - CALL vn.shelving_setParking(vParam, vParkingFk); + CALL shelving_setParking(vParam, vParkingFk); END IF; + + COMMIT; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_setNextState.sql b/db/routines/vn/procedures/ticket_setNextState.sql index d13cd53f0..b09309a47 100644 --- a/db/routines/vn/procedures/ticket_setNextState.sql +++ b/db/routines/vn/procedures/ticket_setNextState.sql @@ -1,14 +1,21 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setNextState`(vSelf INT) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setNextState`( + vSelf INT +) BEGIN /** - * Cambia el estado del ticket al siguiente estado según la tabla state + * Cambia el estado del ticket al siguiente estado según la tabla state. * - * @param vSelf id dle ticket + * @param vSelf Id ticket */ DECLARE vStateFk INT; DECLARE vNewStateFk INT; + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + RESIGNAL; + END; + SELECT stateFk INTO vStateFk FROM ticketState WHERE ticketFk = vSelf; @@ -17,6 +24,10 @@ BEGIN FROM state WHERE id = vStateFk; + IF vNewStateFk IS NULL THEN + CALL util.throw('The ticket not have next state'); + END IF; + INSERT INTO ticketTracking(stateFk, ticketFk, userFk) VALUES (vNewStateFk, vSelf, account.myUser_getId()); END$$ diff --git a/db/routines/vn/procedures/ticket_setParking.sql b/db/routines/vn/procedures/ticket_setParking.sql index 54c64daea..7935e0d60 100644 --- a/db/routines/vn/procedures/ticket_setParking.sql +++ b/db/routines/vn/procedures/ticket_setParking.sql @@ -1,11 +1,14 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setParking`(IN `vTicketFk` VARCHAR(8), IN `vParkingFk` INT) -proc: BEGIN +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setParking`( + vSelf INT, + vParkingFk INT +) +BEGIN /** - * Aparca un ticket en un parking + * Aparca un ticket en un parking. * - * @param vTicketFk id del ticket - * @param vParkingFk id del parking + * @param vSelf Id ticket + * @param vParkingFk Id parking */ DECLARE vDone INT DEFAULT FALSE; DECLARE vCollectionTicketFk INT; @@ -14,16 +17,21 @@ proc: BEGIN FROM ticket t LEFT JOIN ticketCollection tc1 ON tc1.ticketFk = t.id LEFT JOIN ticketCollection tc2 ON tc2.collectionFk = tc1.collectionFk - WHERE t.id = vTicketFk; + WHERE t.id = vSelf; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + RESIGNAL; + END; + INSERT INTO vn.ticketParking(ticketFk, parkingFk) SELECT IFNULL(tc2.ticketFk, t.id), vParkingFk FROM ticket t LEFT JOIN ticketCollection tc1 ON tc1.ticketFk = t.id LEFT JOIN ticketCollection tc2 ON tc2.collectionFk = tc1.collectionFk - WHERE t.id = vTicketFk + WHERE t.id = vSelf ON DUPLICATE KEY UPDATE parkingFk = vParkingFk; OPEN vCursor; From 73b43aa254f4896261c1cc692fb6fd2dc5f8629e Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 8 Jul 2024 13:22:10 +0200 Subject: [PATCH 110/173] refactor: refs #7580 Fixes --- db/routines/vn/procedures/setParking.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/setParking.sql b/db/routines/vn/procedures/setParking.sql index c4e1fd19f..107ef66f4 100644 --- a/db/routines/vn/procedures/setParking.sql +++ b/db/routines/vn/procedures/setParking.sql @@ -33,9 +33,9 @@ BEGIN SET vLastWeek = util.VN_CURDATE() - INTERVAL 1 WEEK; -- Comprobamos si es una prep. previa, ticket o colección - IF (SELECT TRUE FROM saleGroup sg WHERE sg.id = vParam) THEN + IF (SELECT TRUE FROM saleGroup WHERE id = vParam) THEN CALL saleGroup_setParking(vParam, vParkingFk); - ELSEIF (SELECT TRUE FROM ticket WHERE id = vParam shipped >= vLastWeek) THEN + ELSEIF (SELECT TRUE FROM ticket WHERE id = vParam AND shipped >= vLastWeek) THEN CALL ticket_setParking(vParam, vParkingFk); ELSEIF (SELECT TRUE FROM `collection` WHERE id = vParam AND created >= vLastWeek) THEN CALL collection_setParking(vParam, vParkingFk); From 86859c98e37d50bac8fb40f22d0fbba2a7861388 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 8 Jul 2024 13:57:17 +0200 Subject: [PATCH 111/173] refactor: refs #7662 Added transaction --- .../ticket_splitItemPackingType.sql | 97 +++++++++++-------- 1 file changed, 57 insertions(+), 40 deletions(-) diff --git a/db/routines/vn/procedures/ticket_splitItemPackingType.sql b/db/routines/vn/procedures/ticket_splitItemPackingType.sql index d6e8e8a53..bc4c94d46 100644 --- a/db/routines/vn/procedures/ticket_splitItemPackingType.sql +++ b/db/routines/vn/procedures/ticket_splitItemPackingType.sql @@ -1,59 +1,67 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_splitItemPackingType`( - vTicketFk INT, - vOriginalItemPackingTypeFk VARCHAR(1) + vSelf INT, + vItemPackingTypeFk VARCHAR(1) ) BEGIN /** * Clona y reparte las ventas de un ticket en funcion del tipo de empaquetado. * Respeta el id inicial para el tipo propuesto. * - * @param vTicketFk Identificador de vn.ticket - * @param vOriginalItemPackingTypeFk Tipo para el que se reserva el número de ticket original + * @param vSelf Id ticket + * @param vItemPackingTypeFk Tipo para el que se reserva el número de ticket original * @return table tmp.ticketIPT(ticketFk, itemPackingTypeFk) */ DECLARE vItemPackingTypeFk VARCHAR(1) DEFAULT 'H'; DECLARE vNewTicketFk INT; DECLARE vPackingTypesToSplit INT; DECLARE vDone INT DEFAULT FALSE; - - DECLARE cur1 CURSOR FOR + DECLARE vSaleGroup CURSOR FOR SELECT itemPackingTypeFk - FROM tmp.saleGroup + FROM tSaleGroup WHERE itemPackingTypeFk IS NOT NULL - ORDER BY (itemPackingTypeFk = vOriginalItemPackingTypeFk) DESC; + ORDER BY (itemPackingTypeFk = vItemPackingTypeFk) DESC; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN + ROLLBACK; RESIGNAL; END; - DELETE FROM vn.sale - WHERE quantity = 0 - AND ticketFk = vTicketFk; + START TRANSACTION; - CREATE OR REPLACE TEMPORARY TABLE tmp.sale + SELECT id + FROM sale + WHERE ticketFk = vSelf + AND NOT quantity + FOR UPDATE; + + DELETE FROM sale + WHERE NOT quantity + AND ticketFk = vSelf; + + CREATE OR REPLACE TEMPORARY TABLE tSale (PRIMARY KEY (id)) ENGINE = MEMORY - SELECT s.id, i.itemPackingTypeFk , IFNULL(sv.litros, 0) litros - FROM vn.sale s - JOIN vn.item i ON i.id = s.itemFk - LEFT JOIN vn.saleVolume sv ON sv.saleFk = s.id - WHERE s.ticketFk = vTicketFk; + SELECT s.id, i.itemPackingTypeFk, IFNULL(sv.litros, 0) litros + FROM sale s + JOIN item i ON i.id = s.itemFk + LEFT JOIN saleVolume sv ON sv.saleFk = s.id + WHERE s.ticketFk = vSelf; - CREATE OR REPLACE TEMPORARY TABLE tmp.saleGroup + CREATE OR REPLACE TEMPORARY TABLE tSaleGroup ENGINE = MEMORY SELECT itemPackingTypeFk, SUM(litros) totalLitros - FROM tmp.sale + FROM tSale GROUP BY itemPackingTypeFk; SELECT COUNT(*) INTO vPackingTypesToSplit - FROM tmp.saleGroup + FROM tSaleGroup WHERE itemPackingTypeFk IS NOT NULL; - CREATE OR REPLACE TEMPORARY TABLE tmp.ticketIPT ( + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketIPT( ticketFk INT, itemPackingTypeFk VARCHAR(1) ) ENGINE = MEMORY; @@ -61,55 +69,64 @@ BEGIN CASE vPackingTypesToSplit WHEN 0 THEN INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk) - VALUES(vTicketFk, vItemPackingTypeFk); + VALUES(vSelf, vItemPackingTypeFk); WHEN 1 THEN INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk) - SELECT vTicketFk, itemPackingTypeFk - FROM tmp.saleGroup + SELECT vSelf, itemPackingTypeFk + FROM tSaleGroup WHERE itemPackingTypeFk IS NOT NULL; ELSE - OPEN cur1; - - FETCH cur1 INTO vItemPackingTypeFk; + OPEN vSaleGroup; + FETCH vSaleGroup INTO vItemPackingTypeFk; INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk) - VALUES(vTicketFk, vItemPackingTypeFk); + VALUES(vSelf, vItemPackingTypeFk); - read_loop: LOOP - FETCH cur1 INTO vItemPackingTypeFk; + l: LOOP + SET vDone = FALSE; + FETCH vSaleGroup INTO vItemPackingTypeFk; IF vDone THEN - LEAVE read_loop; + LEAVE l; END IF; - CALL vn.ticket_Clone(vTicketFk, vNewTicketFk); + CALL ticket_Clone(vSelf, vNewTicketFk); INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk) VALUES(vNewTicketFk, vItemPackingTypeFk); END LOOP; - CLOSE cur1; + CLOSE vSaleGroup; - UPDATE vn.sale s - JOIN tmp.sale ts ON ts.id = s.id + SELECT s.id + FROM sale s + JOIN tSale ts ON ts.id = s.id + JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = ts.itemPackingTypeFk + WHERE s.ticketFk = vSelf + FOR UPDATE; + + UPDATE sale s + JOIN tSale ts ON ts.id = s.id JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = ts.itemPackingTypeFk SET s.ticketFk = t.ticketFk; SELECT itemPackingTypeFk INTO vItemPackingTypeFk - FROM tmp.saleGroup sg + FROM tSaleGroup sg WHERE sg.itemPackingTypeFk IS NOT NULL ORDER BY sg.itemPackingTypeFk LIMIT 1; - UPDATE vn.sale s - JOIN tmp.sale ts ON ts.id = s.id + UPDATE sale s + JOIN tSale ts ON ts.id = s.id JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = vItemPackingTypeFk SET s.ticketFk = t.ticketFk WHERE ts.itemPackingTypeFk IS NULL; END CASE; + COMMIT; + DROP TEMPORARY TABLE - tmp.sale, - tmp.saleGroup; + tSale, + tSaleGroup; END$$ DELIMITER ; From 32793990ec6d86b0ab24181db3416f305c5a3d90 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 8 Jul 2024 14:01:18 +0200 Subject: [PATCH 112/173] refactor: refs #7662 Minor change --- db/routines/vn/procedures/collection_new.sql | 1 - .../ticket_splitItemPackingType.sql | 20 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/db/routines/vn/procedures/collection_new.sql b/db/routines/vn/procedures/collection_new.sql index 029427306..cd4b1b47f 100644 --- a/db/routines/vn/procedures/collection_new.sql +++ b/db/routines/vn/procedures/collection_new.sql @@ -229,7 +229,6 @@ BEGIN AND ((vTicketVolume + @volume) <= vVolumeLimit OR vVolumeLimit IS NULL) THEN CALL ticket_splitItemPackingType(vTicketFk, vItemPackingTypeFk); - DROP TEMPORARY TABLE tmp.ticketIPT; UPDATE tmp.productionBuffer pb JOIN ( diff --git a/db/routines/vn/procedures/ticket_splitItemPackingType.sql b/db/routines/vn/procedures/ticket_splitItemPackingType.sql index bc4c94d46..2a84948c9 100644 --- a/db/routines/vn/procedures/ticket_splitItemPackingType.sql +++ b/db/routines/vn/procedures/ticket_splitItemPackingType.sql @@ -10,7 +10,6 @@ BEGIN * * @param vSelf Id ticket * @param vItemPackingTypeFk Tipo para el que se reserva el número de ticket original - * @return table tmp.ticketIPT(ticketFk, itemPackingTypeFk) */ DECLARE vItemPackingTypeFk VARCHAR(1) DEFAULT 'H'; DECLARE vNewTicketFk INT; @@ -61,17 +60,17 @@ BEGIN FROM tSaleGroup WHERE itemPackingTypeFk IS NOT NULL; - CREATE OR REPLACE TEMPORARY TABLE tmp.ticketIPT( + CREATE OR REPLACE TEMPORARY TABLE tTicketIPT( ticketFk INT, itemPackingTypeFk VARCHAR(1) ) ENGINE = MEMORY; CASE vPackingTypesToSplit WHEN 0 THEN - INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk) + INSERT INTO tTicketIPT(ticketFk, itemPackingTypeFk) VALUES(vSelf, vItemPackingTypeFk); WHEN 1 THEN - INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk) + INSERT INTO tTicketIPT(ticketFk, itemPackingTypeFk) SELECT vSelf, itemPackingTypeFk FROM tSaleGroup WHERE itemPackingTypeFk IS NOT NULL; @@ -79,7 +78,7 @@ BEGIN OPEN vSaleGroup; FETCH vSaleGroup INTO vItemPackingTypeFk; - INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk) + INSERT INTO tTicketIPT(ticketFk, itemPackingTypeFk) VALUES(vSelf, vItemPackingTypeFk); l: LOOP @@ -92,7 +91,7 @@ BEGIN CALL ticket_Clone(vSelf, vNewTicketFk); - INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk) + INSERT INTO tTicketIPT(ticketFk, itemPackingTypeFk) VALUES(vNewTicketFk, vItemPackingTypeFk); END LOOP; @@ -101,13 +100,13 @@ BEGIN SELECT s.id FROM sale s JOIN tSale ts ON ts.id = s.id - JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = ts.itemPackingTypeFk + JOIN tTicketIPT t ON t.itemPackingTypeFk = ts.itemPackingTypeFk WHERE s.ticketFk = vSelf FOR UPDATE; UPDATE sale s JOIN tSale ts ON ts.id = s.id - JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = ts.itemPackingTypeFk + JOIN tTicketIPT t ON t.itemPackingTypeFk = ts.itemPackingTypeFk SET s.ticketFk = t.ticketFk; SELECT itemPackingTypeFk INTO vItemPackingTypeFk @@ -118,7 +117,7 @@ BEGIN UPDATE sale s JOIN tSale ts ON ts.id = s.id - JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = vItemPackingTypeFk + JOIN tTicketIPT t ON t.itemPackingTypeFk = vItemPackingTypeFk SET s.ticketFk = t.ticketFk WHERE ts.itemPackingTypeFk IS NULL; END CASE; @@ -127,6 +126,7 @@ BEGIN DROP TEMPORARY TABLE tSale, - tSaleGroup; + tSaleGroup, + tTicketIPT; END$$ DELIMITER ; From eaca3427772d8c02d6ccc5ad600b2fb075d67dd4 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 8 Jul 2024 14:11:55 +0200 Subject: [PATCH 113/173] refactor: refs #7662 Minor change --- db/routines/vn/procedures/collection_new.sql | 1 + .../ticket_splitItemPackingType.sql | 19 +++++++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/db/routines/vn/procedures/collection_new.sql b/db/routines/vn/procedures/collection_new.sql index cd4b1b47f..029427306 100644 --- a/db/routines/vn/procedures/collection_new.sql +++ b/db/routines/vn/procedures/collection_new.sql @@ -229,6 +229,7 @@ BEGIN AND ((vTicketVolume + @volume) <= vVolumeLimit OR vVolumeLimit IS NULL) THEN CALL ticket_splitItemPackingType(vTicketFk, vItemPackingTypeFk); + DROP TEMPORARY TABLE tmp.ticketIPT; UPDATE tmp.productionBuffer pb JOIN ( diff --git a/db/routines/vn/procedures/ticket_splitItemPackingType.sql b/db/routines/vn/procedures/ticket_splitItemPackingType.sql index 2a84948c9..87fbafe13 100644 --- a/db/routines/vn/procedures/ticket_splitItemPackingType.sql +++ b/db/routines/vn/procedures/ticket_splitItemPackingType.sql @@ -60,17 +60,17 @@ BEGIN FROM tSaleGroup WHERE itemPackingTypeFk IS NOT NULL; - CREATE OR REPLACE TEMPORARY TABLE tTicketIPT( + CREATE OR REPLACE TEMPORARY TABLE tmp.ticketIPT( ticketFk INT, itemPackingTypeFk VARCHAR(1) ) ENGINE = MEMORY; CASE vPackingTypesToSplit WHEN 0 THEN - INSERT INTO tTicketIPT(ticketFk, itemPackingTypeFk) + INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk) VALUES(vSelf, vItemPackingTypeFk); WHEN 1 THEN - INSERT INTO tTicketIPT(ticketFk, itemPackingTypeFk) + INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk) SELECT vSelf, itemPackingTypeFk FROM tSaleGroup WHERE itemPackingTypeFk IS NOT NULL; @@ -78,7 +78,7 @@ BEGIN OPEN vSaleGroup; FETCH vSaleGroup INTO vItemPackingTypeFk; - INSERT INTO tTicketIPT(ticketFk, itemPackingTypeFk) + INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk) VALUES(vSelf, vItemPackingTypeFk); l: LOOP @@ -91,7 +91,7 @@ BEGIN CALL ticket_Clone(vSelf, vNewTicketFk); - INSERT INTO tTicketIPT(ticketFk, itemPackingTypeFk) + INSERT INTO tmp.ticketIPT(ticketFk, itemPackingTypeFk) VALUES(vNewTicketFk, vItemPackingTypeFk); END LOOP; @@ -100,13 +100,13 @@ BEGIN SELECT s.id FROM sale s JOIN tSale ts ON ts.id = s.id - JOIN tTicketIPT t ON t.itemPackingTypeFk = ts.itemPackingTypeFk + JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = ts.itemPackingTypeFk WHERE s.ticketFk = vSelf FOR UPDATE; UPDATE sale s JOIN tSale ts ON ts.id = s.id - JOIN tTicketIPT t ON t.itemPackingTypeFk = ts.itemPackingTypeFk + JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = ts.itemPackingTypeFk SET s.ticketFk = t.ticketFk; SELECT itemPackingTypeFk INTO vItemPackingTypeFk @@ -117,7 +117,7 @@ BEGIN UPDATE sale s JOIN tSale ts ON ts.id = s.id - JOIN tTicketIPT t ON t.itemPackingTypeFk = vItemPackingTypeFk + JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = vItemPackingTypeFk SET s.ticketFk = t.ticketFk WHERE ts.itemPackingTypeFk IS NULL; END CASE; @@ -126,7 +126,6 @@ BEGIN DROP TEMPORARY TABLE tSale, - tSaleGroup, - tTicketIPT; + tSaleGroup; END$$ DELIMITER ; From 3f0335cf37e4fe4a9f83d50c51683e269e9ec5f5 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 08:37:36 +0200 Subject: [PATCH 114/173] feat: refs #7644 Added with recursive buy-label --- print/templates/reports/buy-label/buy-label.js | 2 +- print/templates/reports/buy-label/sql/buys.sql | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/print/templates/reports/buy-label/buy-label.js b/print/templates/reports/buy-label/buy-label.js index b6e0a5031..7d626c052 100755 --- a/print/templates/reports/buy-label/buy-label.js +++ b/print/templates/reports/buy-label/buy-label.js @@ -7,7 +7,7 @@ module.exports = { name: 'buy-label', mixins: [vnReport], async serverPrefetch() { - this.buys = await this.rawSqlFromDef('buys', [this.id]); + this.buys = await this.rawSqlFromDef('buys', [this.id, this.id]); this.maxLabelNum = Math.max(...this.buys.map(buy => buy.labelNum)); const date = new Date(); this.weekNum = moment(date).isoWeek(); diff --git a/print/templates/reports/buy-label/sql/buys.sql b/print/templates/reports/buy-label/sql/buys.sql index 41fd3556b..e05ca2a66 100644 --- a/print/templates/reports/buy-label/sql/buys.sql +++ b/print/templates/reports/buy-label/sql/buys.sql @@ -1,4 +1,15 @@ -SELECT ROW_NUMBER() OVER(ORDER BY b.id) labelNum, +WITH RECURSIVE numbers AS ( + SELECT 1 n + UNION ALL + SELECT n + 1 + FROM numbers + WHERE n < ( + SELECT MAX(stickers) + FROM buy + WHERE entryFk = ? + ) +) +SELECT ROW_NUMBER() OVER(ORDER BY b.id, num.n) labelNum, i.name, i.`size`, i.category, @@ -15,4 +26,6 @@ SELECT ROW_NUMBER() OVER(ORDER BY b.id) labelNum, LEFT JOIN producer p ON p.id = i.producerFk LEFT JOIN ink ON ink.id = i.inkFk LEFT JOIN origin o ON o.id = i.originFk - WHERE b.entryFk = ? \ No newline at end of file + JOIN numbers num + WHERE b.entryFk = ? + AND num.n <= b.stickers \ No newline at end of file From 6430fb5b5178b1ce2046250d51d0d9a025cb0e30 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 08:43:02 +0200 Subject: [PATCH 115/173] refactor: refs #7662 Requested changes --- db/routines/vn/procedures/ticket_splitItemPackingType.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/ticket_splitItemPackingType.sql b/db/routines/vn/procedures/ticket_splitItemPackingType.sql index 87fbafe13..db2d1e4c1 100644 --- a/db/routines/vn/procedures/ticket_splitItemPackingType.sql +++ b/db/routines/vn/procedures/ticket_splitItemPackingType.sql @@ -10,6 +10,7 @@ BEGIN * * @param vSelf Id ticket * @param vItemPackingTypeFk Tipo para el que se reserva el número de ticket original + * @return table tmp.ticketIPT(ticketFk, itemPackingTypeFk) */ DECLARE vItemPackingTypeFk VARCHAR(1) DEFAULT 'H'; DECLARE vNewTicketFk INT; @@ -101,7 +102,6 @@ BEGIN FROM sale s JOIN tSale ts ON ts.id = s.id JOIN tmp.ticketIPT t ON t.itemPackingTypeFk = ts.itemPackingTypeFk - WHERE s.ticketFk = vSelf FOR UPDATE; UPDATE sale s From 7279feab12f6050cd4aa4840c370082db48304c6 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 09:33:31 +0200 Subject: [PATCH 116/173] feat: refs #7505 Changes --- .../cache/procedures/visible_refresh.sql | 2 +- .../vn/procedures/item_calcVisible.sql | 22 +++++++++---------- .../vn/procedures/multipleInventory.sql | 19 ++++++++-------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index b200e86f2..4feffde8e 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -25,7 +25,7 @@ proc: BEGIN WHERE warehouse_id = v_warehouse; -- Calculamos los movimientos confirmados de hoy - CALL vn.item_calcVisible(v_warehouse, util.VN_CURDATE(), NULL); + CALL vn.item_calcVisible(NULL, util.VN_CURDATE(), v_warehouse); DELETE FROM visible WHERE calc_id = v_calc; INSERT INTO visible (calc_id, item_id,visible) diff --git a/db/routines/vn/procedures/item_calcVisible.sql b/db/routines/vn/procedures/item_calcVisible.sql index f7eee661b..728c94276 100644 --- a/db/routines/vn/procedures/item_calcVisible.sql +++ b/db/routines/vn/procedures/item_calcVisible.sql @@ -1,8 +1,8 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_calcVisible`( - vWarehouseFk INT, - vDated INT, - vItemFk INT + vSelf INT, + vDated DATE, + vWarehouseFk INT ) BEGIN /** @@ -10,12 +10,12 @@ BEGIN * * @param vWarehouse Warehouse id * @param vDated Max date to filter - * @param vItemFk Item id + * @param vSelf Item id * @param tmp.itemVisible(item_id, stock, visible) */ DECLARE vTomorrow DATETIME DEFAULT vDated + INTERVAL 1 DAY; - INSERT INTO tmp.itemVisible (item_id, visible) + INSERT INTO tmp.itemVisible(item_id, visible) SELECT itemFk, SUM(quantity) FROM ( SELECT i.itemFk, i.quantity @@ -29,8 +29,8 @@ BEGIN WHERE st.created > vDated AND (s.isPicked OR st.isChecked) ) stPrevious ON `stPrevious`.`saleFk` = i.saleFk - WHERE i.warehouseFk = vWarehouseFk - AND (vItemFk IS NULL OR i.itemFk = vItemFk) + WHERE IFNULL(vWarehouseFk, i.warehouseFk) = i.warehouseFk + AND (vSelf IS NULL OR i.itemFk = vSelf) AND (s.isPicked OR i.reserved OR stPrevious.saleFk) AND i.shipped >= vDated AND i.shipped < vTomorrow UNION ALL @@ -38,8 +38,8 @@ BEGIN FROM itemEntryIn WHERE isReceived AND landed >= vDated AND landed < vTomorrow - AND warehouseInFk = vWarehouseFk - AND (vItemFk IS NULL OR itemFk = vItemFk) + AND IFNULL(vWarehouseFk, warehouseInFk) = warehouseInFk + AND (vSelf IS NULL OR itemFk = vSelf) AND NOT isVirtualStock UNION ALL SELECT itemFk, quantity @@ -47,8 +47,8 @@ BEGIN WHERE isDelivered AND shipped >= vDated AND shipped < vTomorrow - AND warehouseOutFk = vWarehouseFk - AND (vItemFk IS NULL OR itemFk = vItemFk) + AND IFNULL(vWarehouseFk, warehouseOutFk) = warehouseOutFk + AND (vSelf IS NULL OR itemFk = vSelf) ) t GROUP BY itemFk ON DUPLICATE KEY UPDATE diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index dd3bd6f17..3e0cf72c7 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -83,19 +83,19 @@ proc: BEGIN ai.sd = iic.quantity; -- Cálculo del visible - CALL cache.visible_refresh(vCalc, FALSE, vWarehouseFk); + CALL cache.stock_refresh(false); - CREATE OR REPLACE TEMPORARY TABLE tItemVisibleCalc + CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible (PRIMARY KEY (item_id)) ENGINE = MEMORY - SELECT item_id, visible - FROM cache.visible - WHERE calc_id = vCalc; + SELECT item_id, amount stock, amount visible + FROM cache.stock + WHERE warehouse_id = vWarehouseFk; - CALL item_calcVisible(vWarehouseFk, util.VN_CURDATE(), NULL); + CALL item_calcVisible(NULL, vWarehouseFk, util.VN_CURDATE()); UPDATE tmp.itemInventory it - JOIN tItemVisibleCalc ivc ON ivc.item_id = it.id - SET it.visible = it.visible + ivc.visible; + JOIN tmp.itemVisible iv ON iv.item_id = it.id + SET it.visible = it.visible + iv.visible; -- Calculo del disponible CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc @@ -168,7 +168,6 @@ proc: BEGIN tmp.itemCalc, tmp.itemAtp, tItemInventoryCalc, - tItemVisibleCalc, - tmp.itemAtp; + tmp.itemVisible; END$$ DELIMITER ; From 86acc644fea1069e7f94ec52b76ef7a4bafaa635 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 09:38:07 +0200 Subject: [PATCH 117/173] feat: refs #7505 Changes --- db/routines/vn/procedures/multipleInventory.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index 3e0cf72c7..33eb0b0ed 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -83,7 +83,7 @@ proc: BEGIN ai.sd = iic.quantity; -- Cálculo del visible - CALL cache.stock_refresh(false); + CALL cache.stock_refresh(false); CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible (PRIMARY KEY (item_id)) @@ -92,7 +92,7 @@ proc: BEGIN FROM cache.stock WHERE warehouse_id = vWarehouseFk; - CALL item_calcVisible(NULL, vWarehouseFk, util.VN_CURDATE()); + CALL item_calcVisible(NULL, vWarehouseFk, vDate); UPDATE tmp.itemInventory it JOIN tmp.itemVisible iv ON iv.item_id = it.id SET it.visible = it.visible + iv.visible; From 29f9fa0ce36d6c1b9eab9c220b48d9454451f953 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 09:45:55 +0200 Subject: [PATCH 118/173] feat: refs #7505 Optimization --- .../vn/procedures/multipleInventory.sql | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/db/routines/vn/procedures/multipleInventory.sql b/db/routines/vn/procedures/multipleInventory.sql index 33eb0b0ed..6cd584c6e 100644 --- a/db/routines/vn/procedures/multipleInventory.sql +++ b/db/routines/vn/procedures/multipleInventory.sql @@ -10,7 +10,7 @@ proc: BEGIN DECLARE vDateTo DATETIME; DECLARE vDateToTomorrow DATETIME; DECLARE vDefaultDayRange INT; - DECLARE vCalc INT; + DECLARE vCalcFk INT; IF vDate < util.VN_CURDATE() THEN LEAVE proc; @@ -83,19 +83,18 @@ proc: BEGIN ai.sd = iic.quantity; -- Cálculo del visible - CALL cache.stock_refresh(false); + CALL cache.visible_refresh(vCalcFk, FALSE, vWarehouseFk); - CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible + CREATE OR REPLACE TEMPORARY TABLE tItemVisibleCalc (PRIMARY KEY (item_id)) ENGINE = MEMORY - SELECT item_id, amount stock, amount visible - FROM cache.stock - WHERE warehouse_id = vWarehouseFk; + SELECT item_id, visible + FROM cache.visible + WHERE calc_id = vCalcFk; - CALL item_calcVisible(NULL, vWarehouseFk, vDate); UPDATE tmp.itemInventory it - JOIN tmp.itemVisible iv ON iv.item_id = it.id - SET it.visible = it.visible + iv.visible; + JOIN tItemVisibleCalc ivc ON ivc.item_id = it.id + SET it.visible = it.visible + ivc.visible; -- Calculo del disponible CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc @@ -168,6 +167,6 @@ proc: BEGIN tmp.itemCalc, tmp.itemAtp, tItemInventoryCalc, - tmp.itemVisible; + tItemVisibleCalc; END$$ DELIMITER ; From 4dcc8b02a597eb818d79029aa8a3ee6e6cbdc643 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 9 Jul 2024 10:01:32 +0200 Subject: [PATCH 119/173] feat: refs #7685 delivery coordinates --- .../procedures/address_updateCorordinates.sql | 30 +++++++++++++++++++ .../vn/triggers/delivery_beforeInsert.sql | 12 ++------ .../vn/triggers/delivery_beforeUpdate.sql | 12 ++------ 3 files changed, 34 insertions(+), 20 deletions(-) create mode 100644 db/routines/vn/procedures/address_updateCorordinates.sql diff --git a/db/routines/vn/procedures/address_updateCorordinates.sql b/db/routines/vn/procedures/address_updateCorordinates.sql new file mode 100644 index 000000000..2004cd180 --- /dev/null +++ b/db/routines/vn/procedures/address_updateCorordinates.sql @@ -0,0 +1,30 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`address_updateCorordinates`( + vTicketFk INT, + vLongitude INT, + vLatitude INT) +BEGIN +/** + * Actualiza las coordenadas de una direccion + * + * @param vTicketFk id del ticket + * @param vLongitude longitud de la direccion + * @param vLatitude latitud de la dirrecion + */ + DECLARE vAddressFK INT; + + START TRANSACTION; + + SELECT addressFK INTO vAddressFK + FROM ticket + WHERE id = vTicketFk + FOR UPDATE; + + UPDATE address + SET longitude = vLongitude, + latitude = vLatitude + WHERE id = vAddressFK; + + COMMIT; +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/delivery_beforeInsert.sql b/db/routines/vn/triggers/delivery_beforeInsert.sql index 89431c30f..c9679ed13 100644 --- a/db/routines/vn/triggers/delivery_beforeInsert.sql +++ b/db/routines/vn/triggers/delivery_beforeInsert.sql @@ -4,16 +4,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`delivery_beforeInsert FOR EACH ROW BEGIN - IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL) - THEN - UPDATE address - SET longitude = NEW.longitude, - latitude = NEW.latitude - WHERE id IN ( - SELECT addressFK - FROM ticket - WHERE id = NEW.ticketFk - ); + IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL) THEN + CALL address_updateCorordinates(NEW.ticketFk,NEW.longitude,NEW.latitude); END IF; END$$ diff --git a/db/routines/vn/triggers/delivery_beforeUpdate.sql b/db/routines/vn/triggers/delivery_beforeUpdate.sql index 7e6aa7d4c..dda0e9dd2 100644 --- a/db/routines/vn/triggers/delivery_beforeUpdate.sql +++ b/db/routines/vn/triggers/delivery_beforeUpdate.sql @@ -4,16 +4,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`delivery_beforeUpdate FOR EACH ROW BEGIN -IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL) - THEN - UPDATE address - SET longitude = NEW.longitude, - latitude = NEW.latitude - WHERE id IN ( - SELECT addressFK - FROM ticket - WHERE id = NEW.ticketFk - ); + IF (NEW.longitude IS NOT NULL AND NEW.latitude IS NOT NULL AND NEW.ticketFK IS NOT NULL) THEN + CALL address_updateCorordinates(NEW.ticketFk,NEW.longitude,NEW.latitude); END IF; END$$ From be83fa672957c57014cce14e8d20ef497e706985 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 11:13:55 +0200 Subject: [PATCH 120/173] fix: refs #7622 Fix --- modules/client/back/model-config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/client/back/model-config.json b/modules/client/back/model-config.json index fc1254dd8..e6690ee5f 100644 --- a/modules/client/back/model-config.json +++ b/modules/client/back/model-config.json @@ -5,7 +5,7 @@ "AddressObservation": { "dataSource": "vn" }, - "AddressShortage": { + "AddressWaste": { "dataSource": "vn" }, "BankEntity": { From f8169b3034e24ebc217c9bce76f9ce54975afbab Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 9 Jul 2024 12:46:50 +0200 Subject: [PATCH 121/173] feat: refs #7544 chages required --- db/routines/vn/events/claim_changeState.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/events/claim_changeState.sql b/db/routines/vn/events/claim_changeState.sql index 790ef0c34..5d94170a0 100644 --- a/db/routines/vn/events/claim_changeState.sql +++ b/db/routines/vn/events/claim_changeState.sql @@ -6,15 +6,15 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`claim_changeState` ENABLE DO BEGIN - DECLARE vClaimStete INT; + DECLARE vClaimState INT; - SELECT id INTO vClaimStete + SELECT id INTO vClaimState FROM claimState cs WHERE cs.code = 'canceled'; UPDATE claim c JOIN claimState cs ON cs.id = c.claimStateFk - SET c.claimStateFk = vClaimStete + SET c.claimStateFk = vClaimState WHERE c.created < util.VN_CURDATE() - INTERVAL 2 MONTH AND cs.code IN('incomplete','coming','waiting','out'); From c2e9095ccdae2ac6d7b0940916c186259dc43abe Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 14:22:32 +0200 Subject: [PATCH 122/173] feat: refs #7505 Requested changes --- db/routines/cache/procedures/visible_refresh.sql | 2 +- db/routines/vn/procedures/item_calcVisible.sql | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index 4feffde8e..a59669ff6 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -25,7 +25,7 @@ proc: BEGIN WHERE warehouse_id = v_warehouse; -- Calculamos los movimientos confirmados de hoy - CALL vn.item_calcVisible(NULL, util.VN_CURDATE(), v_warehouse); + CALL vn.item_calcVisible(NULL, v_warehouse); DELETE FROM visible WHERE calc_id = v_calc; INSERT INTO visible (calc_id, item_id,visible) diff --git a/db/routines/vn/procedures/item_calcVisible.sql b/db/routines/vn/procedures/item_calcVisible.sql index 728c94276..820e73a7e 100644 --- a/db/routines/vn/procedures/item_calcVisible.sql +++ b/db/routines/vn/procedures/item_calcVisible.sql @@ -1,7 +1,6 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_calcVisible`( vSelf INT, - vDated DATE, vWarehouseFk INT ) BEGIN @@ -9,11 +8,11 @@ BEGIN * Calcula el visible de un artículo o de todos. * * @param vWarehouse Warehouse id - * @param vDated Max date to filter * @param vSelf Item id * @param tmp.itemVisible(item_id, stock, visible) */ - DECLARE vTomorrow DATETIME DEFAULT vDated + INTERVAL 1 DAY; + DECLARE vDated DATE DEFAULT util.VN_CURDATE(); + DECLARE vTomorrow DATETIME DEFAULT util.tomorrow(); INSERT INTO tmp.itemVisible(item_id, visible) SELECT itemFk, SUM(quantity) From 470c9bc8720dc1db1a84c47acabe00da23cb29d3 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 14:24:17 +0200 Subject: [PATCH 123/173] feat: refs #7505 Minor changes --- db/routines/cache/procedures/visible_refresh.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index a59669ff6..d7e02ad96 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -1,13 +1,13 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`visible_refresh`(OUT v_calc INT, v_refresh BOOL, v_warehouse INT) -proc: BEGIN +BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN CALL cache_calc_unlock (v_calc); RESIGNAL; END; - CALL cache_calc_start (v_calc, v_refresh, 'visible', v_warehouse); + CALL cache_calc_start (v_calc, v_refresh, 'visible', v_warehouse); IF !v_refresh THEN LEAVE proc; @@ -15,13 +15,13 @@ proc: BEGIN -- Calculamos el stock hasta ayer - CALL `cache`.stock_refresh(false); + CALL cache.stock_refresh(false); CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible (PRIMARY KEY (item_id)) ENGINE = MEMORY SELECT item_id, amount stock, amount visible - FROM `cache`.stock + FROM cache.stock WHERE warehouse_id = v_warehouse; -- Calculamos los movimientos confirmados de hoy @@ -31,7 +31,7 @@ proc: BEGIN INSERT INTO visible (calc_id, item_id,visible) SELECT v_calc, item_id, visible FROM tmp.itemVisible; - CALL cache_calc_end (v_calc); + CALL cache_calc_end (v_calc); DROP TEMPORARY TABLE tmp.itemVisible; END$$ From e2b6473831e2211406e8f5c35fbecb9c9c271bbb Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 14:24:35 +0200 Subject: [PATCH 124/173] feat: refs #7505 Minor changes --- db/routines/cache/procedures/visible_refresh.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/cache/procedures/visible_refresh.sql b/db/routines/cache/procedures/visible_refresh.sql index d7e02ad96..78d23dbfb 100644 --- a/db/routines/cache/procedures/visible_refresh.sql +++ b/db/routines/cache/procedures/visible_refresh.sql @@ -1,6 +1,6 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`visible_refresh`(OUT v_calc INT, v_refresh BOOL, v_warehouse INT) -BEGIN +proc:BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN CALL cache_calc_unlock (v_calc); From 1ca95678dfdc3eb08816c5f949e89da3146c95ae Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 9 Jul 2024 14:53:09 +0200 Subject: [PATCH 125/173] Fix --- db/routines/vn/procedures/ticket_splitItemPackingType.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/ticket_splitItemPackingType.sql b/db/routines/vn/procedures/ticket_splitItemPackingType.sql index 8eeec551a..c2ec50fd9 100644 --- a/db/routines/vn/procedures/ticket_splitItemPackingType.sql +++ b/db/routines/vn/procedures/ticket_splitItemPackingType.sql @@ -36,7 +36,7 @@ BEGIN CALL util.debugAdd('ticket_splitItemPackingType', JSON_OBJECT( 'errorNumber', vErrorNumber, 'errorMsg', vErrorMsg, - 'ticketFk', vTicketFk + 'ticketFk', vSelf )); -- Tmp ROLLBACK; RESIGNAL; From 004dcb67ff3a5486cb2ae89d1d910faae5d5a862 Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 10 Jul 2024 07:13:57 +0200 Subject: [PATCH 126/173] feat: refs #7116 insert into agencyIncoming --- db/routines/vn/events/claim_changeState.sql | 22 +++++++++++++++++++ .../10960-silverRoebelini/00-firstScript.sql | 17 +++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 db/routines/vn/events/claim_changeState.sql diff --git a/db/routines/vn/events/claim_changeState.sql b/db/routines/vn/events/claim_changeState.sql new file mode 100644 index 000000000..9197f2a56 --- /dev/null +++ b/db/routines/vn/events/claim_changeState.sql @@ -0,0 +1,22 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`claim_changeState` + ON SCHEDULE EVERY 1 DAY + STARTS '2024-06-06 07:52:46.000' + ON COMPLETION PRESERVE + ENABLE +DO BEGIN + + DECLARE vClaimState INT; + + SELECT id INTO vClaimState + FROM claimState cs + WHERE cs.code = 'canceled'; + + UPDATE claim c + JOIN claimState cs ON cs.id = c.claimStateFk + SET c.claimStateFk = vClaimState + WHERE c.created < util.VN_CURDATE() - INTERVAL 2 MONTH + AND cs.code IN('incomplete','coming','waiting','out'); + +END$$ +DELIMITER ; diff --git a/db/versions/10960-silverRoebelini/00-firstScript.sql b/db/versions/10960-silverRoebelini/00-firstScript.sql index 228e0b014..c53a09549 100644 --- a/db/versions/10960-silverRoebelini/00-firstScript.sql +++ b/db/versions/10960-silverRoebelini/00-firstScript.sql @@ -5,4 +5,19 @@ CREATE TABLE IF NOT EXISTS `vn`.`agencyIncoming` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 -COLLATE=utf8mb3_unicode_ci COMMENT='Agencias de entrada de mercancias';; \ No newline at end of file +COLLATE=utf8mb3_unicode_ci COMMENT='Agencias de entrada de mercancias'; + +INSERT IGNORE INTO vn.agencyIncoming (agencyModeFk) VALUES +(1343), (1002), (1282), (841), (1303), (714), (556), (1786), (1785), (1784), +(1780), (1783), (1758), (1782), (1772), (1789), (1776), (1791), (1778), (1792), +(1779), (1362), (681), (1765), (15), (1594), (1706), (1707), (907), (1260), +(1715), (1371), (1372), (53), (689), (1375), (738), (742), (1307), (1700), (608), +(1311), (1315), (1339), (1433), (1338), (1332), (1844), (842), (1382), (1466), +(1719), (1723), (1725), (1720), (1732), (1736), (1728), (1724), (1726), (1727), +(1767), (1734), (1730), (1845), (1729), (1746), (1699), (2), (671), (1379), (614), +(1718), (1697), (62), (1529), (1392), (1378), (1438), (1796), (1688), (686), +(1326), (1691), (1), (1560), (1695), (1696), (1558), (1648), (1649), (1598), +(1680), (1694), (1600), (1601), (1602), (1712), (1603), (1604), (1641), (1692), +(1693), (1650), (1683), (1682), (1681), (1713), (1826), (1768), (1769), (1770), +(1593), (1443), (1244), (1679), (1006), (1361), (1102), (1655), (1744), (1225), +(1007); From 3c975aa9c47bc0e6c83b3704d6af981c24bd61fb Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 10 Jul 2024 11:32:41 +0200 Subject: [PATCH 127/173] refactor: refs #7580 Requested changes --- db/routines/vn/procedures/setParking.sql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/setParking.sql b/db/routines/vn/procedures/setParking.sql index 107ef66f4..087fb4c07 100644 --- a/db/routines/vn/procedures/setParking.sql +++ b/db/routines/vn/procedures/setParking.sql @@ -28,7 +28,9 @@ BEGIN IF vParkingFk IS NULL THEN CALL util.throw('parkingNotExist'); END IF; - + + START TRANSACTION; + IF vParam REGEXP '^[0-9]+$' THEN SET vLastWeek = util.VN_CURDATE() - INTERVAL 1 WEEK; From 27f9001e344ca45654aa762c32564bbf44417c0f Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 10 Jul 2024 11:35:05 +0200 Subject: [PATCH 128/173] refactor: refs #7378 Requested changes --- db/versions/11130-crimsonIvy/00-firstScript.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/11130-crimsonIvy/00-firstScript.sql b/db/versions/11130-crimsonIvy/00-firstScript.sql index 3bde55f55..c93f2f6b7 100644 --- a/db/versions/11130-crimsonIvy/00-firstScript.sql +++ b/db/versions/11130-crimsonIvy/00-firstScript.sql @@ -16,7 +16,7 @@ CREATE OR REPLACE TABLE `vn`.`productionConfigLog` ( `changedModelId` int(11) NOT NULL, `changedModelValue` varchar(45) DEFAULT NULL, PRIMARY KEY (`id`), - KEY `logRateuserFk` (`userFk`), + KEY `productionConfigLog_userFk` (`userFk`), KEY `productionConfigLog_changedModel` (`changedModel`,`changedModelId`,`creationDate`), KEY `productionConfigLog_originFk` (`originFk`,`creationDate`), CONSTRAINT `productionConfigUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE From 203db3ec3a34921a533a8e8a0dc61be49603899f Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 10 Jul 2024 12:47:09 +0200 Subject: [PATCH 129/173] feat solvePrintLabel refs #7269 --- print/templates/reports/collection-label/collection-label.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/print/templates/reports/collection-label/collection-label.html b/print/templates/reports/collection-label/collection-label.html index 752a31185..143efc525 100644 --- a/print/templates/reports/collection-label/collection-label.html +++ b/print/templates/reports/collection-label/collection-label.html @@ -19,7 +19,7 @@ {{dashIfEmpty(labelData.workerCode)}} - {{labelData.labelCount || 0}} + {{this.labelCount || labelData.labelCount || 0}} {{labelData.code == 'V' ? (labelData.size || 0) + 'cm' : (labelData.volume || 0) + 'm³'}} From 5304929f57593a9d477bf5238172f54aff8b11a3 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 11 Jul 2024 08:52:07 +0200 Subject: [PATCH 130/173] feat: #refs 7348 schema --- db/versions/11126-blueCamellia/00-firstScript.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/11126-blueCamellia/00-firstScript.sql b/db/versions/11126-blueCamellia/00-firstScript.sql index 45c2ed2dc..40c5e2b37 100644 --- a/db/versions/11126-blueCamellia/00-firstScript.sql +++ b/db/versions/11126-blueCamellia/00-firstScript.sql @@ -1,2 +1,2 @@ -ALTER TABLE `client` +ALTER TABLE `vn`.`client` ADD COLUMN `hasDailyInvoice` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Indica si el cliente requiere facturación diaria por defecto se copiará lo que tenga country.hasDailyInvoice'; From 02bcfd9be38d21199ee12defadffda57efd3d035 Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 11 Jul 2024 08:57:45 +0200 Subject: [PATCH 131/173] feat: refs #7704 Major changes --- .../hedera/procedures/order_addItem.sql | 15 +++-- db/routines/vn/procedures/item_getSimilar.sql | 2 +- db/routines/vn2008/views/buySource.sql | 3 +- .../11149-silverSalal/00-firstScript.sql | 20 +++++++ modules/item/back/model-config.json | 3 + .../back/models/item-minimum-quantity.json | 57 +++++++++++++++++++ modules/item/back/models/item.json | 4 -- modules/item/front/summary/index.html | 3 - .../order/back/methods/order/catalogFilter.js | 19 +++++-- modules/order/front/catalog-view/index.html | 12 ---- .../order/front/catalog-view/locale/es.yml | 3 +- modules/ticket/back/models/sale.js | 28 ++++++++- 12 files changed, 134 insertions(+), 35 deletions(-) create mode 100644 db/versions/11149-silverSalal/00-firstScript.sql create mode 100644 modules/item/back/models/item-minimum-quantity.json diff --git a/db/routines/hedera/procedures/order_addItem.sql b/db/routines/hedera/procedures/order_addItem.sql index d9c15c0eb..d47d8b870 100644 --- a/db/routines/hedera/procedures/order_addItem.sql +++ b/db/routines/hedera/procedures/order_addItem.sql @@ -56,11 +56,18 @@ BEGIN CALL util.throw ('ORDER_ROW_UNAVAILABLE'); END IF; - SELECT IFNULL(minQuantity, 0) INTO vMinQuantity - FROM vn.item - WHERE id = vItem; + SELECT quantity + FROM vn.itemMinimalQuantity + WHERE itemFk = vItem + AND ( + util.VN_CURDATE() BETWEEN `started` AND `ended` + OR + (util.VN_CURDATE() >= `started` AND `ended` IS NULL) + ) + AND (warehouseFk = vWarehouse OR warehouseFk IS NULL) + LIMIT 1; - IF vAmount < LEAST(vMinQuantity, vAvailable) THEN + IF vAmount < LEAST(IFNULL(vMinQuantity, 0), vAvailable) THEN CALL util.throw ('quantityLessThanMin'); END IF; diff --git a/db/routines/vn/procedures/item_getSimilar.sql b/db/routines/vn/procedures/item_getSimilar.sql index 557d77bdf..72c543b40 100644 --- a/db/routines/vn/procedures/item_getSimilar.sql +++ b/db/routines/vn/procedures/item_getSimilar.sql @@ -63,7 +63,7 @@ BEGIN WHEN b.groupingMode = 'grouping' THEN b.grouping WHEN b.groupingMode = 'packing' THEN b.packing ELSE 1 - END AS minQuantity, + END minQuantity, v.visible located, b.price2 FROM vn.item i diff --git a/db/routines/vn2008/views/buySource.sql b/db/routines/vn2008/views/buySource.sql index 33226a1dc..850483833 100644 --- a/db/routines/vn2008/views/buySource.sql +++ b/db/routines/vn2008/views/buySource.sql @@ -54,8 +54,7 @@ AS SELECT `b`.`entryFk` AS `Id_Entrada`, `i`.`packingOut` AS `packingOut`, `b`.`itemOriginalFk` AS `itemOriginalFk`, `io`.`longName` AS `itemOriginalName`, - `it`.`gramsMax` AS `gramsMax`, - `i`.`minQuantity` AS `minQuantity` + `it`.`gramsMax` AS `gramsMax` FROM ( ( ( diff --git a/db/versions/11149-silverSalal/00-firstScript.sql b/db/versions/11149-silverSalal/00-firstScript.sql new file mode 100644 index 000000000..3225f137f --- /dev/null +++ b/db/versions/11149-silverSalal/00-firstScript.sql @@ -0,0 +1,20 @@ +ALTER TABLE vn.item CHANGE minQuantity minQuantity__ int(10) unsigned DEFAULT + NULL NULL COMMENT '@deprecated 2024-07-11 refs #7704 Cantidad mínima para una línea de venta'; + +CREATE TABLE `vn`.`itemMinimumQuantity` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `itemFk` int(10) NOT NULL, + `quantity` int(10) NOT NULL, + `started` date NOT NULL, + `ended` date DEFAULT NULL, + `warehouseFk` smallint(5) unsigned DEFAULT NULL, + `created` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`id`), + UNIQUE KEY `itemMinimumQuantity_UNIQUE` (`itemFk`, `started`, `ended`, `warehouseFk`), + KEY `itemFk` (`itemFk`), + KEY `started` (`started`), + KEY `ended` (`ended`), + KEY `warehouseFk` (`warehouseFk`), + CONSTRAINT `itemMinimumQuantity_ibfk_1` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `itemMinimumQuantity_ibfk_2` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; diff --git a/modules/item/back/model-config.json b/modules/item/back/model-config.json index 2d06e1ada..5dbe4d62a 100644 --- a/modules/item/back/model-config.json +++ b/modules/item/back/model-config.json @@ -32,6 +32,9 @@ "ItemLog": { "dataSource": "vn" }, + "ItemMinimumQuantity": { + "dataSource": "vn" + }, "ItemPackingType": { "dataSource": "vn" }, diff --git a/modules/item/back/models/item-minimum-quantity.json b/modules/item/back/models/item-minimum-quantity.json new file mode 100644 index 000000000..848b42a3f --- /dev/null +++ b/modules/item/back/models/item-minimum-quantity.json @@ -0,0 +1,57 @@ +{ + "name": "ItemMinimumQuantity", + "base": "VnModel", + "options": { + "mysql": { + "table": "itemMinimumQuantity" + } + }, + "properties": { + "id": { + "type": "number", + "id": true, + "description": "Id" + }, + "itemFk": { + "type": "number", + "required": true + }, + "quantity": { + "type": "number", + "required": true + }, + "started": { + "type": "date", + "required": true + }, + "ended": { + "type": "date" + }, + "warehouseFk": { + "type": "number" + }, + "created": { + "type": "date" + } + }, + "relations": { + "item": { + "type": "belongsTo", + "model": "Item", + "foreignKey": "itemFk" + }, + "warehouse": { + "type": "belongsTo", + "model": "Warehouse", + "foreignKey": "warehouseFk" + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "buyer", + "permission": "ALLOW" + } + ] +} \ No newline at end of file diff --git a/modules/item/back/models/item.json b/modules/item/back/models/item.json index 10cff3e04..eda56e938 100644 --- a/modules/item/back/models/item.json +++ b/modules/item/back/models/item.json @@ -152,10 +152,6 @@ "columnName": "doPhoto" } }, - "minQuantity": { - "type": "number", - "description": "Min quantity" - }, "photoMotivation": { "type": "string" } diff --git a/modules/item/front/summary/index.html b/modules/item/front/summary/index.html index 13c671d29..0e4cfc955 100644 --- a/modules/item/front/summary/index.html +++ b/modules/item/front/summary/index.html @@ -128,9 +128,6 @@ - -

diff --git a/modules/order/back/methods/order/catalogFilter.js b/modules/order/back/methods/order/catalogFilter.js index ab1d7784e..3d67e080c 100644 --- a/modules/order/back/methods/order/catalogFilter.js +++ b/modules/order/back/methods/order/catalogFilter.js @@ -101,6 +101,14 @@ module.exports = Self => { )); stmt = new ParameterizedSQL(` + WITH minQuantity AS ( + SELECT itemFk, quantity, warehouseFk + FROM vn.itemMinimalQuantity + WHERE (util.VN_CURDATE() BETWEEN started AND ended + OR (util.VN_CURDATE() >= started AND ended IS NULL)) + GROUP BY itemFk, warehouseFk + ORDER BY warehouseFk DESC + ) SELECT i.id, i.name, i.subName, @@ -125,6 +133,9 @@ module.exports = Self => { JOIN vn.itemType it ON it.id = i.typeFk JOIN vn.worker w on w.id = it.workerFk LEFT JOIN vn.ink ON ink.id = i.inkFk + LEFT JOIN tmp.ticketComponentPrice tcp ON tcp.itemFk = i.id + LEFT JOIN minQuantity mq ON mq.itemFk = i.id + AND (mq.warehouseFk = tpc.warehouseFk OR mq.warehouseFk IS NULL) `); // Apply order by tag @@ -158,21 +169,19 @@ module.exports = Self => { // Apply item prices const pricesIndex = stmts.push( - `SELECT - tcp.itemFk, + `SELECT tcp.itemFk, tcp.grouping, tcp.price, tcp.rate, tcp.warehouseFk, tcp.priceKg, - w.name AS warehouse + w.name warehouse FROM tmp.ticketComponentPrice tcp JOIN vn.warehouse w ON w.id = tcp.warehouseFk`) - 1; // Get tags from all items const itemTagsIndex = stmts.push( - `SELECT - t.id, + `SELECT t.id, t.name, t.isFree, t.sourceTable, diff --git a/modules/order/front/catalog-view/index.html b/modules/order/front/catalog-view/index.html index 081ce05a0..562723cf7 100644 --- a/modules/order/front/catalog-view/index.html +++ b/modules/order/front/catalog-view/index.html @@ -37,18 +37,6 @@ value="{{::item.value7}}"> - - - - - - {{::item.minQuantity}} -