From 288dc1c598b7cc4ff2457c9bfc9bc683ffce5086 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 21 Oct 2024 10:05:58 +0200 Subject: [PATCH 1/6] feat: refs #7524 myteam filter wip --- .../back/methods/ticket/getTicketsAdvance.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/modules/ticket/back/methods/ticket/getTicketsAdvance.js b/modules/ticket/back/methods/ticket/getTicketsAdvance.js index 1bd5f83de..4585c5d61 100644 --- a/modules/ticket/back/methods/ticket/getTicketsAdvance.js +++ b/modules/ticket/back/methods/ticket/getTicketsAdvance.js @@ -50,6 +50,11 @@ module.exports = Self => { type: 'boolean', description: 'True when lines and stock of origin are equal' }, + { + arg: 'myTeam', + type: 'boolean', + description: `Whether to show only tickets for the current logged user team (currently user tickets)` + }, { arg: 'filter', type: 'object', @@ -69,11 +74,27 @@ module.exports = Self => { Self.getTicketsAdvance = async(ctx, options) => { const args = ctx.args; const conn = Self.dataSource.connector; + const userId = ctx.req.accessToken.userId; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); + const teamMembersId = []; + if (args.myTeam != null) { + const worker = await models.Worker.findById(userId, { + include: { + relation: 'collegues' + } + }, myOptions); + const collegues = worker.collegues() || []; + for (let collegue of collegues) + teamMembersId.push(collegue.collegueFk); + + if (teamMembersId.length == 0) + teamMembersId.push(userId); + } + const where = buildFilter(ctx.args, (param, value) => { switch (param) { case 'id': @@ -96,6 +117,11 @@ module.exports = Self => { }; case 'isFullMovable': return {'f.isFullMovable': value}; + case 'myTeam': + if (value) + return {'c.salesPersonFk': {inq: teamMembersId}}; + else + return {'c.salesPersonFk': {nin: teamMembersId}}; } }); From cb4e8355ba3f21d05c202ded792f3588d1f5bf65 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 21 Oct 2024 10:58:36 +0200 Subject: [PATCH 2/6] feat: refs #7524 myteam filter --- modules/ticket/back/methods/ticket/getTicketsAdvance.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/ticket/back/methods/ticket/getTicketsAdvance.js b/modules/ticket/back/methods/ticket/getTicketsAdvance.js index 4585c5d61..1088d357c 100644 --- a/modules/ticket/back/methods/ticket/getTicketsAdvance.js +++ b/modules/ticket/back/methods/ticket/getTicketsAdvance.js @@ -82,7 +82,7 @@ module.exports = Self => { const teamMembersId = []; if (args.myTeam != null) { - const worker = await models.Worker.findById(userId, { + const worker = await Self.app.models.Worker.findById(userId, { include: { relation: 'collegues' } @@ -119,9 +119,9 @@ module.exports = Self => { return {'f.isFullMovable': value}; case 'myTeam': if (value) - return {'c.salesPersonFk': {inq: teamMembersId}}; + return {'workerFk': {inq: teamMembersId}}; else - return {'c.salesPersonFk': {nin: teamMembersId}}; + return {'workerFk': {nin: teamMembersId}}; } }); From 1efe258ea0b14c26a9035dc946d23ca394c182f6 Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 21 Oct 2024 14:30:45 +0200 Subject: [PATCH 3/6] fix: refs #7524 filter by department --- .../vn/procedures/ticket_canAdvance.sql | 7 +++-- .../back/methods/ticket/getTicketsAdvance.js | 29 ++++--------------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/db/routines/vn/procedures/ticket_canAdvance.sql b/db/routines/vn/procedures/ticket_canAdvance.sql index 57c3f4235..e8fc70bba 100644 --- a/db/routines/vn/procedures/ticket_canAdvance.sql +++ b/db/routines/vn/procedures/ticket_canAdvance.sql @@ -51,7 +51,8 @@ BEGIN origin.companyFk futureCompanyFk, IFNULL(dest.nickname, origin.nickname) nickname, dest.landed, - dest.preparation + dest.preparation, + origin.departmentFk FROM ( SELECT s.ticketFk, c.salesPersonFk workerFk, @@ -71,9 +72,11 @@ BEGIN t.addressFk, t.warehouseFk, t.companyFk, - t.agencyModeFk + t.agencyModeFk, + wd.departmentFk FROM ticket t JOIN client c ON c.id = t.clientFk + JOIN workerDepartment wd ON wd.workerFk = c.salesPersonFk JOIN sale s ON s.ticketFk = t.id JOIN saleVolume sv ON sv.saleFk = s.id JOIN item i ON i.id = s.itemFk diff --git a/modules/ticket/back/methods/ticket/getTicketsAdvance.js b/modules/ticket/back/methods/ticket/getTicketsAdvance.js index 1088d357c..41f3ee79a 100644 --- a/modules/ticket/back/methods/ticket/getTicketsAdvance.js +++ b/modules/ticket/back/methods/ticket/getTicketsAdvance.js @@ -51,9 +51,9 @@ module.exports = Self => { description: 'True when lines and stock of origin are equal' }, { - arg: 'myTeam', - type: 'boolean', - description: `Whether to show only tickets for the current logged user team (currently user tickets)` + arg: 'departmentFk', + type: 'number', + description: 'Department identifier' }, { arg: 'filter', @@ -74,27 +74,11 @@ module.exports = Self => { Self.getTicketsAdvance = async(ctx, options) => { const args = ctx.args; const conn = Self.dataSource.connector; - const userId = ctx.req.accessToken.userId; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); - const teamMembersId = []; - if (args.myTeam != null) { - const worker = await Self.app.models.Worker.findById(userId, { - include: { - relation: 'collegues' - } - }, myOptions); - const collegues = worker.collegues() || []; - for (let collegue of collegues) - teamMembersId.push(collegue.collegueFk); - - if (teamMembersId.length == 0) - teamMembersId.push(userId); - } - const where = buildFilter(ctx.args, (param, value) => { switch (param) { case 'id': @@ -117,11 +101,8 @@ module.exports = Self => { }; case 'isFullMovable': return {'f.isFullMovable': value}; - case 'myTeam': - if (value) - return {'workerFk': {inq: teamMembersId}}; - else - return {'workerFk': {nin: teamMembersId}}; + case 'departmentFk': + return {'f.departmentFk': value}; } }); From 6ef77604985c3ea38d9e3de0843b57ce28b5cb7e Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 22 Oct 2024 10:06:59 +0200 Subject: [PATCH 4/6] fix: refs #6861 fixTransactionCommit --- .../collection_addWithReservation.sql | 18 +++---- .../procedures/itemShelvingSale_addBySale.sql | 49 ++++++++++--------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/db/routines/vn/procedures/collection_addWithReservation.sql b/db/routines/vn/procedures/collection_addWithReservation.sql index cc0b7fd9b..bb6e94a63 100644 --- a/db/routines/vn/procedures/collection_addWithReservation.sql +++ b/db/routines/vn/procedures/collection_addWithReservation.sql @@ -37,23 +37,23 @@ BEGIN WHERE t.id = vTicketFk; CALL cache.available_refresh( - vCacheAvailableFk, + vCacheAvailableFk, FALSE, - vWarehouseFk, + vWarehouseFk, util.VN_CURDATE()); SELECT available INTO vAvailable FROM cache.available - WHERE calc_id = vCacheAvailableFk + WHERE calc_id = vCacheAvailableFk AND item_id = vItemFk; - + IF vAvailable < vQuantity THEN SET vHasThrow = TRUE; ELSE SELECT `name`, - CONCAT(getUser(), ' ', DATE_FORMAT(util.VN_NOW(), '%H:%i'), ' ', name) + CONCAT(getUser(), ' ', DATE_FORMAT(util.VN_NOW(), '%H:%i'), ' ', name) INTO vItemName, vConcept - FROM item + FROM item WHERE id = vItemFk; START TRANSACTION; @@ -69,7 +69,7 @@ BEGIN CALL sale_calculateComponent(vSaleFk, NULL); CALL itemShelvingSale_addBySale(vSaleFk, vSectorFk); - + IF NOT EXISTS (SELECT TRUE FROM itemShelvingSale WHERE saleFk = vSaleFk LIMIT 1) THEN SET vHasThrow = TRUE; END IF; @@ -78,13 +78,13 @@ BEGIN IF vHasThrow THEN CALL util.throw("There is no available for the selected item"); END IF; - + IF vSaleGroupFk THEN INSERT INTO saleGroupDetail SET saleFk = vSaleFk, saleGroupFk = vSaleGroupFk; END IF; - + COMMIT; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql index 6625e89b8..06736732a 100644 --- a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql +++ b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql @@ -18,8 +18,9 @@ proc: BEGIN DECLARE vReservedQuantity INT; DECLARE vOutStanding INT; DECLARE vUserFk INT; - DECLARE vTotalReservedQuantity INT; + DECLARE vTotalReservedQuantity INT; DECLARE vSaleQuantity INT; + DECLARE vIsRequiredTx BOOL DEFAULT NOT @@in_transaction; DECLARE vItemShelvingAvailable CURSOR FOR SELECT ish.id itemShelvingFk, @@ -29,7 +30,7 @@ proc: BEGIN JOIN shelving sh ON sh.code = ish.shelvingFk JOIN parking p ON p.id = sh.parkingFk JOIN sector sc ON sc.id = p.sectorFk - JOIN productionConfig pc + JOIN productionConfig pc WHERE s.id = vSaleFk AND NOT sc.isHideForPickers AND (sc.id = vSectorFk OR vSectorFk IS NULL) @@ -44,15 +45,15 @@ proc: BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - ROLLBACK; + CALL util.tx_rollback(vIsRequiredTx); RESIGNAL; END; - - START TRANSACTION; - + + CALL util.tx_start(vIsRequiredTx); + SELECT id INTO vSaleFk FROM sale - WHERE id = vSaleFk + WHERE id = vSaleFk FOR UPDATE; SELECT MAX(p.pickingOrder), s.quantity - SUM(IFNULL(iss.quantity, 0)), s.quantity @@ -65,7 +66,7 @@ proc: BEGIN WHERE s.id = vSaleFk; IF vOutStanding <= 0 THEN - COMMIT; + CALL util.tx_commit(vIsRequiredTx); LEAVE proc; END IF; @@ -85,7 +86,7 @@ proc: BEGIN IF vTotalReservedQuantity <> vSaleQuantity THEN CALL util.debugAdd('itemShelvingSale_addBySale', CONCAT(vSaleFk, ' - ', vSaleQuantity,' - ', vTotalReservedQuantity,'-', vOutStanding,'-', account.myUser_getId())); - + UPDATE sale SET quantity = vTotalReservedQuantity WHERE id = vSaleFk; @@ -93,7 +94,7 @@ proc: BEGIN LEAVE l; END IF; - SELECT id INTO vItemShelvingFk + SELECT id INTO vItemShelvingFk FROM itemShelving WHERE id = vItemShelvingFk FOR UPDATE; @@ -102,19 +103,19 @@ proc: BEGIN SET vOutStanding = vOutStanding - vReservedQuantity; IF vReservedQuantity > 0 THEN - CALL util.debugAdd('itemShelvingSale_addBySale_reservedQuantity', - CONCAT(vSaleFk, ' - ', vReservedQuantity, ' - ', vOutStanding, account.myUser_getId())); - INSERT INTO itemShelvingSale( - itemShelvingFk, - saleFk, - quantity, - userFk, - isPicked) - SELECT vItemShelvingFk, - vSaleFk, - vReservedQuantity, - vUserFk, - FALSE; + CALL util.debugAdd('itemShelvingSale_addBySale_reservedQuantity', + CONCAT(vSaleFk, ' - ', vReservedQuantity, ' - ', vOutStanding, account.myUser_getId())); + INSERT INTO itemShelvingSale( + itemShelvingFk, + saleFk, + quantity, + userFk, + isPicked) + SELECT vItemShelvingFk, + vSaleFk, + vReservedQuantity, + vUserFk, + FALSE; UPDATE itemShelving SET available = available - vReservedQuantity @@ -123,6 +124,6 @@ proc: BEGIN END IF; END LOOP; CLOSE vItemShelvingAvailable; - COMMIT; + CALL util.tx_commit(vIsRequiredTx); END$$ DELIMITER ; \ No newline at end of file From ee0c0996f6e00507519e35368f279bee4b6b8e95 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 22 Oct 2024 12:16:26 +0200 Subject: [PATCH 5/6] feat: refs #7524 add e2e --- db/dump/fixtures.before.sql | 2 +- .../ticket/specs/getTicketsAdvance.spec.js | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 5076f9330..a667b6d27 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -403,7 +403,7 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city (1112, 'Trash', NULL, 'GARBAGE MAN', 'Unknown name', 'NEW YORK CITY, UNDERGROUND', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 0, 1, 0, NULL, 1, 0, NULL, 0, 'others','loses'); INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`) - SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), UPPER(CONCAT(name, 'Social')), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1 + SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), UPPER(CONCAT(name, 'Social')), CONCAT(name, 'Contact'), UPPER(CONCAT(name, 'Street')), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1 FROM `account`.`role` `r` WHERE `r`.`hasLogin` = 1; diff --git a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js index 488cd1fc2..a941013cd 100644 --- a/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js +++ b/modules/ticket/back/methods/ticket/specs/getTicketsAdvance.spec.js @@ -6,6 +6,9 @@ describe('TicketFuture getTicketsAdvance()', () => { today.setHours(0, 0, 0, 0); let tomorrow = Date.vnNew(); tomorrow.setDate(today.getDate() + 1); + const salesDeptId = 43; + const spain1DeptId = 95; + beforeAll.mockLoopBackContext(); it('should return the tickets passing the required data', async() => { const tx = await models.Ticket.beginTransaction({}); @@ -129,4 +132,39 @@ describe('TicketFuture getTicketsAdvance()', () => { throw e; } }); + + it('should return the tickets matching the right department', async() => { + const tx = await models.Ticket.beginTransaction({}); + + try { + const options = {transaction: tx}; + ctx.args = { + dateFuture: tomorrow, + dateToAdvance: today, + warehouseFk: 1, + }; + + await models.Ticket.updateAll({id: {inq: [12, 31]}}, {clientFk: 1}, options); + const client = await models.Client.findById(1, null, options); + await client.updateAttribute('salesPersonFk', 1, options); + const business = await models.Business.findById(1, null, options); + await business.updateAttributes({departmentFk: spain1DeptId}, options); + + const saleTickets = await models.Ticket.getTicketsAdvance(ctx, options); + const filteredSaleTickets = await models.Ticket.getTicketsAdvance( + {args: {...ctx.args, departmentFk: spain1DeptId}}, + options); + + expect(saleTickets.length).toBeGreaterThan(filteredSaleTickets.length); + expect(saleTickets.some(ticket => ticket.departmentFk === salesDeptId)).toBeTrue(); + expect(saleTickets.some(ticket => ticket.departmentFk === spain1DeptId)).toBeTrue(); + + expect(filteredSaleTickets.some(ticket => ticket.departmentFk === salesDeptId)).toBeFalse(); + expect(filteredSaleTickets.some(ticket => ticket.departmentFk === spain1DeptId)).toBeTrue(); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); From 1c5e4f40cec2c18cbf28e266bc37cd2e50fdf225 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 22 Oct 2024 12:39:51 +0200 Subject: [PATCH 6/6] feat: refs #8083 add prop --- modules/ticket/back/models/expedition.json | 117 +++++++++++---------- 1 file changed, 60 insertions(+), 57 deletions(-) diff --git a/modules/ticket/back/models/expedition.json b/modules/ticket/back/models/expedition.json index 2dcca1e87..f3f912ec3 100644 --- a/modules/ticket/back/models/expedition.json +++ b/modules/ticket/back/models/expedition.json @@ -1,63 +1,66 @@ { - "name": "Expedition", - "base": "VnModel", - "mixins": { - "Loggable": true + "name": "Expedition", + "base": "VnModel", + "mixins": { + "Loggable": true + }, + "options": { + "mysql": { + "table": "expedition" + } + }, + "properties": { + "id": { + "id": true, + "type": "number", + "description": "Identifier" }, - "options": { - "mysql": { - "table": "expedition" - } + "freightItemFk": { + "type": "number" }, - "properties": { - "id": { - "id": true, - "type": "number", - "description": "Identifier" - }, - "freightItemFk": { - "type": "number" - }, - "created": { - "type": "date" - }, - "counter": { - "type": "number" - }, - "externalId": { - "type": "string" - } + "created": { + "type": "date" }, - "relations": { - "ticket": { - "type": "belongsTo", - "model": "Ticket", - "foreignKey": "ticketFk" - }, - "agencyMode": { - "type": "belongsTo", - "model": "AgencyMode", - "foreignKey": "agencyModeFk" - }, - "worker": { - "type": "belongsTo", - "model": "Worker", - "foreignKey": "workerFk" - }, - "packages": { - "type": "hasMany", - "model": "TicketPackaging", - "foreignKey": "ticketFk" - }, - "freightItem": { - "type": "belongsTo", - "model": "Item", - "foreignKey": "freightItemFk" - }, - "packaging": { - "type": "belongsTo", - "model": "Package", - "foreignKey": "packagingFk" - } + "counter": { + "type": "number" + }, + "externalId": { + "type": "string" + }, + "stateTypeFk": { + "type": "number" + } + }, + "relations": { + "ticket": { + "type": "belongsTo", + "model": "Ticket", + "foreignKey": "ticketFk" + }, + "agencyMode": { + "type": "belongsTo", + "model": "AgencyMode", + "foreignKey": "agencyModeFk" + }, + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + }, + "packages": { + "type": "hasMany", + "model": "TicketPackaging", + "foreignKey": "ticketFk" + }, + "freightItem": { + "type": "belongsTo", + "model": "Item", + "foreignKey": "freightItemFk" + }, + "packaging": { + "type": "belongsTo", + "model": "Package", + "foreignKey": "packagingFk" } } +} \ No newline at end of file