From 64bddd4f63273063b7d35f63c993a0c491f62836 Mon Sep 17 00:00:00 2001 From: pablone Date: Wed, 10 Jul 2024 10:41:52 +0200 Subject: [PATCH 01/20] feat: refs #6403 add dynamic clientType --- back/methods/mrw-config/cancelShipment.ejs | 2 +- back/methods/mrw-config/cancelShipment.js | 4 +-- back/methods/mrw-config/createShipment.ejs | 2 +- back/methods/mrw-config/createShipment.js | 11 +++---- back/methods/mrw-config/getLabel.ejs | 2 +- back/methods/mrw-config/getLabel.js | 16 +++++++-- .../mrw-config/specs/createShipment.spec.js | 18 +++++----- back/methods/viaexpress-config/renderer.js | 4 +-- back/model-config.json | 3 ++ back/models/mrw-config.js | 25 ++++++++++++++ back/models/mrw-config.json | 3 ++ back/models/mrw-service.json | 33 +++++++++++++++++++ modules/zone/back/models/agency-mode.json | 5 +++ 13 files changed, 101 insertions(+), 27 deletions(-) create mode 100644 back/models/mrw-service.json diff --git a/back/methods/mrw-config/cancelShipment.ejs b/back/methods/mrw-config/cancelShipment.ejs index 9ef401bc8..bc0662981 100644 --- a/back/methods/mrw-config/cancelShipment.ejs +++ b/back/methods/mrw-config/cancelShipment.ejs @@ -2,7 +2,7 @@ <%= mrw.franchiseCode %> - <%= mrw.subscriberCode %> + <%= clientType %> <%= mrw.user %> <%= mrw.password %> diff --git a/back/methods/mrw-config/cancelShipment.js b/back/methods/mrw-config/cancelShipment.js index 86bbb7410..10d556575 100644 --- a/back/methods/mrw-config/cancelShipment.js +++ b/back/methods/mrw-config/cancelShipment.js @@ -27,9 +27,9 @@ module.exports = Self => { const mrw = await models.MrwConfig.findOne(); const {externalId} = await models.Expedition.findById(expeditionFk); - + const clientType = await models.MrwConfig.getClientType(expeditionFk); const template = fs.readFileSync(__dirname + '/cancelShipment.ejs', 'utf-8'); - const renderedXml = ejs.render(template, {mrw, externalId}); + const renderedXml = ejs.render(template, {mrw, externalId, clientType}); const response = await axios.post(mrw.url, renderedXml, { headers: { 'Content-Type': 'application/soap+xml; charset=utf-8' diff --git a/back/methods/mrw-config/createShipment.ejs b/back/methods/mrw-config/createShipment.ejs index 8e123ddd9..65326112b 100644 --- a/back/methods/mrw-config/createShipment.ejs +++ b/back/methods/mrw-config/createShipment.ejs @@ -3,7 +3,7 @@ <%= mrw.franchiseCode %> - <%= expeditionData.clientType %> + <%= clientType %> <%= mrw.user %> <%= mrw.password %> diff --git a/back/methods/mrw-config/createShipment.js b/back/methods/mrw-config/createShipment.js index 9b23cc370..ab25113dc 100644 --- a/back/methods/mrw-config/createShipment.js +++ b/back/methods/mrw-config/createShipment.js @@ -22,6 +22,7 @@ module.exports = Self => { Self.createShipment = async expeditionFk => { const models = Self.app.models; const mrw = await Self.getConfig(); + const clientType = await models.MrwConfig.getClientType(expeditionFk); const today = Date.vnNew(); const [hours, minutes] = mrw?.expeditionDeadLine ? mrw.expeditionDeadLine.split(':').map(Number) : [0, 0]; @@ -52,8 +53,7 @@ module.exports = Self => { CONCAT( e.ticketFk, LPAD(e.counter, mc.counterWidth, '0')) reference, LPAD(IF(mw.serviceType IS NULL, ms.serviceType, mw.serviceType), mc.serviceTypeWidth, '0') serviceType, IF(mw.weekdays, 'S', 'N') weekDays, - oa.description deliveryObservation, - LPAD(ms.clientType, mc.clientTypeWidth, '0') clientType + oa.description deliveryObservation FROM expedition e JOIN ticket t ON e.ticketFk = t.id JOIN agencyMode am ON am.id = t.agencyModeFk @@ -73,22 +73,19 @@ module.exports = Self => { const [expeditionData] = await Self.rawSql(query, [expeditionFk]); - if (!expeditionData) - throw new UserError(`This expedition is not a MRW shipment`); - if (expeditionData?.shipped.setHours(0, 0, 0, 0) < today.setHours(0, 0, 0, 0)) throw new UserError(`This ticket has a shipped date earlier than today`); const shipmentResponse = await Self.sendXmlDoc( __dirname + `/createShipment.ejs`, - {mrw, expeditionData}, + {mrw, expeditionData, clientType}, 'application/soap+xml' ); const shipmentId = Self.getTextByTag(shipmentResponse, 'NumeroEnvio'); if (!shipmentId) throw new UserError(Self.getTextByTag(shipmentResponse, 'Mensaje')); - const file = await models.MrwConfig.getLabel(shipmentId); + const file = await models.MrwConfig.getLabel(shipmentId, clientType); return {shipmentId, file}; }; diff --git a/back/methods/mrw-config/getLabel.ejs b/back/methods/mrw-config/getLabel.ejs index 09bdb3f6c..b0dae17c8 100644 --- a/back/methods/mrw-config/getLabel.ejs +++ b/back/methods/mrw-config/getLabel.ejs @@ -2,7 +2,7 @@ <%= mrw.franchiseCode %> - <%= mrw.subscriberCode %> + <%= clientType %> <%= mrw.user %> <%= mrw.password %> diff --git a/back/methods/mrw-config/getLabel.js b/back/methods/mrw-config/getLabel.js index aa9b87af1..4af3276bb 100644 --- a/back/methods/mrw-config/getLabel.js +++ b/back/methods/mrw-config/getLabel.js @@ -6,7 +6,13 @@ module.exports = Self => { arg: 'shipmentId', type: 'string', required: true - }], + }, + { + arg: 'clientType', + type: 'string', + required: true + }, + ], returns: { type: 'string', root: true @@ -17,10 +23,14 @@ module.exports = Self => { } }); - Self.getLabel = async shipmentId => { + Self.getLabel = async(shipmentId, clientType) => { const mrw = await Self.getConfig(); - const getLabelResponse = await Self.sendXmlDoc(__dirname + `/getLabel.ejs`, {mrw, shipmentId}, 'text/xml'); + const getLabelResponse = await Self.sendXmlDoc( + __dirname + `/getLabel.ejs`, + {mrw, shipmentId, clientType}, + 'text/xml' + ); return Self.getTextByTag(getLabelResponse, 'EtiquetaFile'); }; diff --git a/back/methods/mrw-config/specs/createShipment.spec.js b/back/methods/mrw-config/specs/createShipment.spec.js index 883dd8f6f..1ab77f608 100644 --- a/back/methods/mrw-config/specs/createShipment.spec.js +++ b/back/methods/mrw-config/specs/createShipment.spec.js @@ -40,15 +40,12 @@ describe('MRWConfig createShipment()', () => { ); + await models.MrwService.create( + {'agencyModeCodeFk': 'mrw', 'clientType': '000001', 'serviceType': 105, 'kg': 10} + ); + await createMrwConfig(); - await models.Application.rawSql( - `INSERT INTO vn.mrwService - SET agencyModeCodeFk = 'mrw', - clientType = 1, - serviceType = 1, - kg = 1`, null - ); await models.Ticket.create(ticket1); await models.Expedition.create(expedition1); }); @@ -82,7 +79,8 @@ describe('MRWConfig createShipment()', () => { 'user': 'user', 'password': 'password', 'franchiseCode': 'franchiseCode', - 'subscriberCode': 'subscriberCode' + 'subscriberCode': 'subscriberCode', + 'clientTypeWidth': 6 } ); } @@ -115,10 +113,10 @@ describe('MRWConfig createShipment()', () => { it('should fail if expeditionFk is not a MrwExpedition', async() => { let error; - await models.MrwConfig.createShipment(undefined).catch(e => { + await models.MrwConfig.createShipment(15).catch(e => { error = e; }).finally(async() => { - expect(error.message).toEqual(`This expedition is not a MRW shipment`); + expect(error.message).toEqual(`ClientType not available`); }); }); diff --git a/back/methods/viaexpress-config/renderer.js b/back/methods/viaexpress-config/renderer.js index c8533ea6b..5d83b5870 100644 --- a/back/methods/viaexpress-config/renderer.js +++ b/back/methods/viaexpress-config/renderer.js @@ -20,7 +20,7 @@ module.exports = Self => { } }); - Self.renderer = async (expeditionFk) => { + Self.renderer = async expeditionFk => { const models = Self.app.models; const viaexpressConfig = await models.ViaexpressConfig.findOne({ @@ -109,7 +109,7 @@ module.exports = Self => { const ticket = expedition.ticket(); const sender = ticket.company().client(); const shipped = ticket.shipped.toISOString(); - const isInterdia = (ticket.agencyModeFk === viaexpressConfig.agencyModeFk) + const isInterdia = (ticket.agencyModeFk === viaexpressConfig.agencyModeFk); const data = { viaexpressConfig, sender, diff --git a/back/model-config.json b/back/model-config.json index 58fa86797..a16fe4e8a 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -192,5 +192,8 @@ }, "RouteConfig": { "dataSource": "vn" + }, + "MrwService": { + "dataSource": "vn" } } \ No newline at end of file diff --git a/back/models/mrw-config.js b/back/models/mrw-config.js index c738c9c0e..8bb24dbe5 100644 --- a/back/models/mrw-config.js +++ b/back/models/mrw-config.js @@ -31,5 +31,30 @@ module.exports = Self => { }); return parser.parseFromString(data.data, 'text/xml'); }; + + Self.getClientType = async function(expeditionFk) { + if (!expeditionFk) throw new UserError(`No expeditionFk defined`); + + const {clientTypeWidth} = await Self.getConfig(); + const result = await Self.app.models.Expedition.findById(expeditionFk, + {include: [{ + relation: 'ticket', + scope: { + include: { + relation: 'agencyMode', + scope: { + include: { + relation: 'mrwService', + } + } + } + } + }]} + ); + const clientType = result?.ticket()?.agencyMode()?.mrwService()?.clientType; + if (!clientType || !clientTypeWidth) throw new UserError(`ClientType not available`); + + return clientType.toString().padStart(clientTypeWidth, '0'); + }; }; diff --git a/back/models/mrw-config.json b/back/models/mrw-config.json index c96b68cf3..60c0ca2a2 100644 --- a/back/models/mrw-config.json +++ b/back/models/mrw-config.json @@ -45,6 +45,9 @@ }, "notified":{ "type": "date" + }, + "clientTypeWidth": { + "type": "number" } } } diff --git a/back/models/mrw-service.json b/back/models/mrw-service.json new file mode 100644 index 000000000..1ad72d060 --- /dev/null +++ b/back/models/mrw-service.json @@ -0,0 +1,33 @@ +{ + "name": "MrwService", + "base": "VnModel", + "options": { + "mysql": { + "table": "mrwService" + } + }, + "properties": { + "agencyModeCodeFk": { + "id": true, + "type": "string", + "required": true + }, + "clientType": { + "type": "number", + "required": true + }, + "serviceType": { + "type": "number" + }, + "kg": { + "type": "number" + } + }, + "relations": { + "agency": { + "type": "hasOne", + "model": "AgencyMode", + "foreignKey": "code" + } + } +} diff --git a/modules/zone/back/models/agency-mode.json b/modules/zone/back/models/agency-mode.json index 99ed43b97..6033e26c6 100644 --- a/modules/zone/back/models/agency-mode.json +++ b/modules/zone/back/models/agency-mode.json @@ -60,6 +60,11 @@ "type": "hasMany", "model": "Zone", "foreignKey": "agencyModeFk" + }, + "mrwService": { + "type": "belongsTo", + "model": "MrwService", + "foreignKey": "code" } }, "acls": [ -- 2.40.1 From 8c8ec6192a739b0d42e6d56f2a1f6c759e861bba Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 10 Jul 2024 13:53:38 +0200 Subject: [PATCH 02/20] feat newState refs #7642 --- db/versions/11147-brownBamboo/00-firstScript.vn.sql | 5 +++++ modules/ticket/back/methods/ticket/saveSign.js | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 db/versions/11147-brownBamboo/00-firstScript.vn.sql diff --git a/db/versions/11147-brownBamboo/00-firstScript.vn.sql b/db/versions/11147-brownBamboo/00-firstScript.vn.sql new file mode 100644 index 000000000..aaf1fd34a --- /dev/null +++ b/db/versions/11147-brownBamboo/00-firstScript.vn.sql @@ -0,0 +1,5 @@ +-- Place your SQL code here + + +INSERT INTO vn.state ( name, `order`, alertLevel, code, sectorProdPriority, nextStateFk, isPreviousPreparable, isPicked, isPreparable, semaphore, isPrintable, isOK, graphCategory, isNotValidated, classColor) VALUES('Entregado en parte', 13, 3, 'PARTIALLYDELIVERED', NULL, 16, 0, 1, 0, 0, 0, 0, 0, 0, NULL); + diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index ed54a5074..f90cc72c2 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -140,7 +140,16 @@ module.exports = Self => { await models.TicketDms.create({ticketFk: ticket.id, dmsFk: dms[0].id}, myOptions); await ticket.updateAttribute('isSigned', true, myOptions); - await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, 'DELIVERED'], myOptions); + const [{stateForTicket}] = await Self.rawSql(` + SELECT + IF((SUM(CASE WHEN est.code = 'DELIVERED' THEN 1 ELSE 0 END) = COUNT(*)), + 'DELIVERED','PARTIALLYDELIVERED') stateForTicket + FROM vn.expedition e + JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk + WHERE e.ticketFk = ?; + `, [ticketId], myOptions); + + await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, stateForTicket], myOptions); if (ticket?.address()?.province()?.country()?.code != 'ES' && ticket.cmrFk) { await models.Ticket.saveCmr(ctx, [ticketId], myOptions); -- 2.40.1 From 0579e7dbbff60c8e3e1c7410b17e184b7329683c Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 11 Jul 2024 09:14:14 +0200 Subject: [PATCH 03/20] hotfix routeSummary --- modules/route/front/summary/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/route/front/summary/index.html b/modules/route/front/summary/index.html index 8269bf118..764312d16 100644 --- a/modules/route/front/summary/index.html +++ b/modules/route/front/summary/index.html @@ -35,10 +35,10 @@ + value="{{$ctrl.summary.route.started | date: 'HH:mm'}}"> + value="{{$ctrl.summary.route.finished | date: 'HH:mm'}}"> -- 2.40.1 From 97fe9debf6f6d8fe0d33b39e0d9f2b9813c34d63 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 11 Jul 2024 12:57:15 +0200 Subject: [PATCH 04/20] feat newState refs #7642 --- .../11147-brownBamboo/00-firstScript.vn.sql | 2 +- .../methods/ticket/specs/saveSign.spec.js | 30 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/db/versions/11147-brownBamboo/00-firstScript.vn.sql b/db/versions/11147-brownBamboo/00-firstScript.vn.sql index aaf1fd34a..eb62b98b0 100644 --- a/db/versions/11147-brownBamboo/00-firstScript.vn.sql +++ b/db/versions/11147-brownBamboo/00-firstScript.vn.sql @@ -1,5 +1,5 @@ -- Place your SQL code here -INSERT INTO vn.state ( name, `order`, alertLevel, code, sectorProdPriority, nextStateFk, isPreviousPreparable, isPicked, isPreparable, semaphore, isPrintable, isOK, graphCategory, isNotValidated, classColor) VALUES('Entregado en parte', 13, 3, 'PARTIALLYDELIVERED', NULL, 16, 0, 1, 0, 0, 0, 0, 0, 0, NULL); +INSERT INTO vn.state ( name, `order`, alertLevel, code, sectorProdPriority, nextStateFk, isPreviousPreparable, isPicked, isPreparable, semaphore, isPrintable, isOK, graphCategory, isNotValidated, classColor) VALUES('Entregado en parte', 13, 3, 'PARTIALLY_DELIVERED', NULL, 16, 0, 1, 0, 0, 0, 0, 0, 0, NULL); diff --git a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js index 792e9e824..df7c13aad 100644 --- a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js +++ b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js @@ -8,7 +8,7 @@ describe('Ticket saveSign()', () => { accessToken: {userId: 9} }}; - it(`should throw error if the ticket's alert level is lower than 2`, async() => { + fit(`should throw error if the ticket's alert level is lower than 2`, async() => { const tx = await models.TicketDms.beginTransaction({}); const ticketWithOkState = 12; let error; @@ -26,4 +26,32 @@ describe('Ticket saveSign()', () => { expect(error).toBeDefined(); }); + + fit('should change state for ticket', async() => { + const tx = await models.TicketDms.beginTransaction({}); + const ticketWithOkState = 12; + const ticketStateId = 16; + const ticketCode = 'PARTIALLY_DELIVERED'; + + try { + const options = {transaction: tx}; + const tickets = [ticketWithOkState]; + const state = await models.State.findById(ticketStateId); + await state.updateAttributes({ + code: ticketCode + }, options); + const ticketState = await models.TicketTracking.findById(ticketStateId); + await ticketState.updateAttributes({ + code: ticketCode + }, options); + + await models.Ticket.saveSign(ctx, tickets, options); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + + expect(ticket.toEqual('DELIVERED')); + }); }); -- 2.40.1 From 69bcad9ce006687604c8ecfdbebcc543e31cfcc0 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 11 Jul 2024 18:09:00 +0200 Subject: [PATCH 05/20] feat itemShelvingSale refs #6861 --- .../vn/procedures/itemShelvingSale_setQuantity.sql | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql index 42f915ead..93927d417 100644 --- a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql +++ b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql @@ -21,6 +21,7 @@ BEGIN DECLARE vRemainingQuantity INT; DECLARE vItemFk INT; DECLARE vTotalQuantity INT; + DECLARE vStateCode VARCHAR(45); DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN @@ -32,10 +33,11 @@ BEGIN CALL util.throw('Reservation completed'); END IF; - SELECT s.itemFk, iss.saleFk, iss.itemShelvingFk, SUM(IFNULL(iss.quantity,0)) - INTO vItemFk, vSaleFk, vItemShelvingFk, vReservedQuantity + SELECT s.itemFk, iss.saleFk, iss.itemShelvingFk, SUM(IFNULL(iss.quantity,0)), IF(sgd.id, 'PREVIOUS_PREPARATION', 'PREPARED') vStateCode + INTO vItemFk, vSaleFk, vItemShelvingFk, vReservedQuantity, vStateCode FROM itemShelvingSale iss JOIN sale s ON s.id = iss.saleFk + LEFT JOIN vn.saleGroupDetail sgd ON sgd.saleFk = iss.saleFk WHERE iss.id = vItemShelvingSaleFk AND NOT iss.isPicked; @@ -74,7 +76,7 @@ BEGIN vTotalQuantity, `account`.`myUser_getId`(), NULL, - 'PREPARED', + vStateCode, TRUE); UPDATE sale s -- 2.40.1 From 21987011b6392f4277c4ba1da3719e1533dfee38 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 12 Jul 2024 09:06:05 +0200 Subject: [PATCH 06/20] feat itemShelvingSale refs #6861 --- .../vn/procedures/itemShelvingSale_setQuantity.sql | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql index 93927d417..85f56ee68 100644 --- a/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql +++ b/db/routines/vn/procedures/itemShelvingSale_setQuantity.sql @@ -33,8 +33,16 @@ BEGIN CALL util.throw('Reservation completed'); END IF; - SELECT s.itemFk, iss.saleFk, iss.itemShelvingFk, SUM(IFNULL(iss.quantity,0)), IF(sgd.id, 'PREVIOUS_PREPARATION', 'PREPARED') vStateCode - INTO vItemFk, vSaleFk, vItemShelvingFk, vReservedQuantity, vStateCode + SELECT s.itemFk, + iss.saleFk, + iss.itemShelvingFk, + SUM(IFNULL(iss.quantity,0)), + IF(sgd.id, 'PREVIOUS_PREPARATION', 'PREPARED') + INTO vItemFk, + vSaleFk, + vItemShelvingFk, + vReservedQuantity, + vStateCode FROM itemShelvingSale iss JOIN sale s ON s.id = iss.saleFk LEFT JOIN vn.saleGroupDetail sgd ON sgd.saleFk = iss.saleFk -- 2.40.1 From b93601d6d868e042ec739725a5b832383e94d83a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 12 Jul 2024 08:27:24 +0000 Subject: [PATCH 07/20] Actualizar db/routines/vn/procedures/itemShelvingSale_addBySale.sql --- .../procedures/itemShelvingSale_addBySale.sql | 214 +++++++++--------- 1 file changed, 113 insertions(+), 101 deletions(-) diff --git a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql index 7e836859a..2aae37353 100644 --- a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql +++ b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql @@ -1,102 +1,114 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_addBySale`( - vSaleFk INT -) -proc: BEGIN -/** - * Reserva una línea de venta en la ubicación más óptima - * - * @param vSaleFk Id de sale - * @param vItemShelvingSaleFk Id de reserva - */ - DECLARE vLastPickingOrder INT; - DECLARE vDone INT DEFAULT FALSE; - DECLARE vItemShelvingFk INT; - DECLARE vAvailable INT; - DECLARE vReservedQuantity INT; - DECLARE vOutStanding INT; - DECLARE vUserFk INT; - - DECLARE vItemShelvingAvailable CURSOR FOR - SELECT ish.id itemShelvingFk, - ish.available - FROM sale s - JOIN itemShelving ish ON ish.itemFk = s.itemFk - 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 - WHERE s.id = vSaleFk - AND NOT sc.isHideForPickers - ORDER BY s.id, - p.pickingOrder >= vLastPickingOrder, - sh.priority DESC, - ish.available >= s.quantity DESC, - s.quantity MOD ish.grouping = 0 DESC, - ish.grouping DESC, - IF(pc.orderMode = 'Location', p.pickingOrder, ish.created); - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - SELECT MAX(p.pickingOrder), s.quantity - SUM(IFNULL(iss.quantity, 0)) - INTO vLastPickingOrder, vOutStanding - FROM sale s - LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id - LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk - LEFT JOIN shelving sh ON sh.code = ish.shelvingFk - LEFT JOIN parking p ON p.id = sh.parkingFk - WHERE s.id = vSaleFk; - - IF vOutStanding <= 0 THEN - LEAVE proc; - END IF; - - SELECT getUser() INTO vUserFk; - - OPEN vItemShelvingAvailable; - l: LOOP - SET vDone = FALSE; - FETCH vItemShelvingAvailable INTO vItemShelvingFk, vAvailable; - - IF vOutStanding <= 0 OR vDone THEN - LEAVE l; - END IF; - - START TRANSACTION; - - SELECT id INTO vItemShelvingFk - FROM itemShelving - WHERE id = vItemShelvingFk - FOR UPDATE; - - SELECT LEAST(vOutStanding, vAvailable) INTO vReservedQuantity; - SET vOutStanding = vOutStanding - vReservedQuantity; - - IF vReservedQuantity > 0 THEN - - INSERT INTO itemShelvingSale( - itemShelvingFk, - saleFk, - quantity, - userFk) - SELECT vItemShelvingFk, - vSaleFk, - vReservedQuantity, - vUserFk; - - UPDATE itemShelving - SET available = available - vReservedQuantity - WHERE id = vItemShelvingFk; - - END IF; - - COMMIT; - END LOOP; - CLOSE vItemShelvingAvailable; -END$$ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingSale_addBySale`( + vSaleFk INT +) +proc: BEGIN +/** + * Reserva una línea de venta en la ubicación más óptima + * + * @param vSaleFk Id de sale + * @param vItemShelvingSaleFk Id de reserva + */ + DECLARE vLastPickingOrder INT; + DECLARE vDone INT DEFAULT FALSE; + DECLARE vItemShelvingFk INT; + DECLARE vAvailable INT; + DECLARE vReservedQuantity INT; + DECLARE vOutStanding INT; + DECLARE vUserFk INT; + DECLARE vTotalReservedQuantity INT; + DECLARE vSaleQuantity INT; + + DECLARE vItemShelvingAvailable CURSOR FOR + SELECT ish.id itemShelvingFk, + ish.available + FROM sale s + JOIN itemShelving ish ON ish.itemFk = s.itemFk + 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 + WHERE s.id = vSaleFk + AND NOT sc.isHideForPickers + ORDER BY s.id, + p.pickingOrder >= vLastPickingOrder, + sh.priority DESC, + ish.available >= s.quantity DESC, + s.quantity MOD ish.grouping = 0 DESC, + ish.grouping DESC, + IF(pc.orderMode = 'Location', p.pickingOrder, ish.created); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + SELECT MAX(p.pickingOrder), s.quantity - SUM(IFNULL(iss.quantity, 0)), s.quantity + INTO vLastPickingOrder, vOutStanding, vSaleQuantity + FROM sale s + LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id + LEFT JOIN itemShelving ish ON ish.id = iss.itemShelvingFk + LEFT JOIN shelving sh ON sh.code = ish.shelvingFk + LEFT JOIN parking p ON p.id = sh.parkingFk + WHERE s.id = vSaleFk; + + IF vOutStanding <= 0 THEN + LEAVE proc; + END IF; + + SELECT getUser() INTO vUserFk; + + OPEN vItemShelvingAvailable; + l: LOOP + SET vDone = FALSE; + FETCH vItemShelvingAvailable INTO vItemShelvingFk, vAvailable; + + IF vOutStanding <= 0 OR vDone THEN + SELECT SUM(IFNULL(quantity, 0)) + INTO vTotalReservedQuantity + FROM itemShelvingSale + WHERE saleFk = vSaleFk; + + IF vTotalReservedQuantity <> vSaleQuantity THEN + UPDATE sale + SET quantity = vTotalReservedQuantity + WHERE id = vSaleFk; + END IF + LEAVE l; + END IF; + + START TRANSACTION; + + SELECT id INTO vItemShelvingFk + FROM itemShelving + WHERE id = vItemShelvingFk + FOR UPDATE; + + SELECT LEAST(vOutStanding, vAvailable) INTO vReservedQuantity; + SET vOutStanding = vOutStanding - vReservedQuantity; + + IF vReservedQuantity > 0 THEN + + INSERT INTO itemShelvingSale( + itemShelvingFk, + saleFk, + quantity, + userFk) + SELECT vItemShelvingFk, + vSaleFk, + vReservedQuantity, + vUserFk; + + UPDATE itemShelving + SET available = available - vReservedQuantity + WHERE id = vItemShelvingFk; + + END IF; + + COMMIT; + END LOOP; + CLOSE vItemShelvingAvailable; +END$$ DELIMITER ; \ No newline at end of file -- 2.40.1 From 323d26f226482a72cb34f7c8c05d9ef773368862 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 12 Jul 2024 10:37:39 +0200 Subject: [PATCH 08/20] Fix --- db/routines/vn/procedures/itemShelvingSale_addBySale.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql index 2aae37353..909ce5155 100644 --- a/db/routines/vn/procedures/itemShelvingSale_addBySale.sql +++ b/db/routines/vn/procedures/itemShelvingSale_addBySale.sql @@ -75,7 +75,7 @@ proc: BEGIN UPDATE sale SET quantity = vTotalReservedQuantity WHERE id = vSaleFk; - END IF + END IF; LEAVE l; END IF; -- 2.40.1 From 896d273da81d0eb99331f759d5f26f72c24accd6 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 12 Jul 2024 12:06:37 +0200 Subject: [PATCH 09/20] fix(worker_new): fix countryFk --- modules/client/front/postcode/index.html | 2 +- modules/worker/back/methods/worker/new.js | 12 ++++++------ modules/worker/back/models/worker.js | 7 +++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/modules/client/front/postcode/index.html b/modules/client/front/postcode/index.html index b3dbb74d8..fa0b7870f 100644 --- a/modules/client/front/postcode/index.html +++ b/modules/client/front/postcode/index.html @@ -53,7 +53,7 @@ diff --git a/modules/worker/back/methods/worker/new.js b/modules/worker/back/methods/worker/new.js index ba9dc3853..fad464ae1 100644 --- a/modules/worker/back/methods/worker/new.js +++ b/modules/worker/back/methods/worker/new.js @@ -171,8 +171,8 @@ module.exports = Self => { const address = await models.Address.create({ clientFk: user.id, street: street, - city: city, - provinceFk: provinceFk, + city, + provinceFk, postalCode: postcode, mobile: phone, nickname: nickname, @@ -193,7 +193,9 @@ module.exports = Self => { } await user.updateAttribute('email', email, myOptions); - + const {countryFk} = await Self.app.models.Province.findById(provinceFk, { + fields: ['countryFk'] + }); await models.Worker.create({ id: user.id, firstName, @@ -202,6 +204,7 @@ module.exports = Self => { bossFk, fi, birth, + originCountryFk: countryFk }, myOptions); @@ -212,11 +215,8 @@ module.exports = Self => { const message = e.sqlMessage; if (e.message && e.message.includes(`Email already exists`)) throw new UserError(`This personal mail already exists`); - if (code === 'ER_DUP_ENTRY' && message.includes(`CodigoTrabajador_UNIQUE`)) throw new UserError(`This worker code already exists`); - if (code === 'ER_DUP_ENTRY' && message.includes(`PRIMARY`)) throw new UserError(`This worker already exists`); - throw e; } diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index 0b0e043f2..3351c348c 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -27,11 +27,10 @@ module.exports = Self => { }); async function tinIsValid(err, done) { - const filter = { + const country = await Self.app.models.Country.findOne({ fields: ['code'], - where: {id: this.countryFk} - }; - const country = await Self.app.models.Country.findOne(filter); + where: {id: this.originCountryFk} + }); const code = country ? country.code.toLowerCase() : null; if (!this.fi || !validateTin(this.fi, code)) -- 2.40.1 From 66959dd3885bf94372139d0818c05161273bb4a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 12 Jul 2024 12:10:43 +0200 Subject: [PATCH 10/20] hotfix: packaging ticket 199070 --- .../vn/procedures/sale_getBoxPickingList.sql | 25 ++++++++++--------- db/routines/vn/procedures/ticket_close.sql | 8 ++++-- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/db/routines/vn/procedures/sale_getBoxPickingList.sql b/db/routines/vn/procedures/sale_getBoxPickingList.sql index 7466eb9be..8d16d556b 100644 --- a/db/routines/vn/procedures/sale_getBoxPickingList.sql +++ b/db/routines/vn/procedures/sale_getBoxPickingList.sql @@ -19,21 +19,20 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.sale (saleFk INT PRIMARY KEY) - SELECT - s.ticketFk, - s.id saleFk, - s.itemFk, - s.concept, - s.quantity, - MAKETIME(pb.HH,pb.mm,0) etd, - pb.routeFk, - FLOOR(s.quantity / IF(i.isBoxPickingMode, ish.packing, i.packingOut)) stickers, - IF(i.isBoxPickingMode, ish.packing, i.packingOut) packing, - b.packagingFk + SELECT s.ticketFk, + s.id saleFk, + s.itemFk, + s.concept, + s.quantity, + MAKETIME(pb.HH,pb.mm,0) etd, + pb.routeFk, + FLOOR(s.quantity / IF(i.isBoxPickingMode, ish.packing, i.packingOut)) stickers, + IF(i.isBoxPickingMode, ish.packing, i.packingOut) packing, + IF(pa.isPackageReturnable, pc.defaultBigPackageFk, b.packagingFk) FROM sale s JOIN item i ON i.id = s.itemFk JOIN itemShelving ish ON ish.itemFk = s.itemFk - LEFT JOIN ( SELECT iss.itemShelvingFk, + LEFT JOIN ( SELECT iss.itemShelvingFk, s.itemFk, SUM(iss.quantity) reserve FROM itemShelvingSale iss @@ -52,6 +51,8 @@ BEGIN LEFT JOIN ticketState ts ON ts.ticketFk = s.ticketFk LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = vWarehouseFk LEFT JOIN buy b ON b.id = lb.buy_id + LEFT JOIN packaging pa ON pa.id = b.packagingFk + JOIN packagingConfig pc WHERE IF(i.isBoxPickingMode, ish.packing, i.packingOut) <= LEAST(s.quantity, ish.visible - IFNULL(tISS.reserve,0)) AND NOT pb.problem diff --git a/db/routines/vn/procedures/ticket_close.sql b/db/routines/vn/procedures/ticket_close.sql index 47d748ddf..16173719a 100644 --- a/db/routines/vn/procedures/ticket_close.sql +++ b/db/routines/vn/procedures/ticket_close.sql @@ -44,14 +44,14 @@ BEGIN t.shipped, IFNULL(a.hasDailyInvoice, co.hasDailyInvoice), w.isManaged, - c.hasToInvoice + c.hasToInvoice INTO vClientFk, vIsTaxDataChecked, vCompanyFk, vShipped, vHasDailyInvoice, vWithPackage, - vHasToInvoice + vHasToInvoice FROM ticket t JOIN `client` c ON c.id = t.clientFk JOIN province p ON p.id = c.provinceFk @@ -64,8 +64,12 @@ BEGIN (SELECT vCurTicketFk, p.id, COUNT(*) FROM expedition e JOIN packaging p ON p.id = e.packagingFk + JOIN ticket t ON t.id = e.ticketFk + JOIN agencyMode am ON am.id = t.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk WHERE e.ticketFk = vCurTicketFk AND p.isPackageReturnable AND vWithPackage + AND NOT dm.`code`= 'PICKUP' GROUP BY p.itemFk); -- No retornables o no catalogados -- 2.40.1 From d2e482d7cd01d29b39035f7fc5f14fc7dbe6508c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Fri, 12 Jul 2024 12:13:21 +0200 Subject: [PATCH 11/20] hotfix: packaging ticket 199070 --- db/routines/vn/procedures/ticket_close.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/ticket_close.sql b/db/routines/vn/procedures/ticket_close.sql index 16173719a..7f52e81a7 100644 --- a/db/routines/vn/procedures/ticket_close.sql +++ b/db/routines/vn/procedures/ticket_close.sql @@ -65,8 +65,8 @@ BEGIN FROM expedition e JOIN packaging p ON p.id = e.packagingFk JOIN ticket t ON t.id = e.ticketFk - JOIN agencyMode am ON am.id = t.agencyModeFk - JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + LEFT JOIN agencyMode am ON am.id = t.agencyModeFk + LEFT JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk WHERE e.ticketFk = vCurTicketFk AND p.isPackageReturnable AND vWithPackage AND NOT dm.`code`= 'PICKUP' -- 2.40.1 From cb107215b609ef12822d00263f9135e3c7652234 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 12 Jul 2024 13:14:00 +0200 Subject: [PATCH 12/20] feat itemShelvingSale refs #6861 --- back/methods/collection/getTickets.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/back/methods/collection/getTickets.js b/back/methods/collection/getTickets.js index 663b70e94..b79dbc93a 100644 --- a/back/methods/collection/getTickets.js +++ b/back/methods/collection/getTickets.js @@ -63,8 +63,7 @@ module.exports = Self => { iss.isPicked FROM ticketCollection tc LEFT JOIN collection c ON c.id = tc.collectionFk - JOIN ticket t ON t.id = tc.ticketFk - JOIN sale s ON s.ticketFk = t.id + JOIN sale s ON s.ticketFk = tc.ticketFk LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id LEFT JOIN saleGroup sg ON sg.id = sgd.saleGroupFk LEFT JOIN parking p2 ON p2.id = sg.parkingFk @@ -103,9 +102,8 @@ module.exports = Self => { FROM sectorCollection sc JOIN sectorCollectionSaleGroup ss ON ss.sectorCollectionFk = sc.id JOIN saleGroup sg ON sg.id = ss.saleGroupFk - JOIN ticket t ON t.id = sg.ticketFk - JOIN sale s ON s.ticketFk = t.id - LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id + LEFT JOIN saleGroupDetail sgd ON sgd.saleGroupFk = sg.id + JOIN sale s ON s.id = sgd.saleFk LEFT JOIN parking p2 ON p2.id = sg.parkingFk JOIN item i ON i.id = s.itemFk JOIN itemShelvingSale iss ON iss.saleFk = s.id -- 2.40.1 From 67b19ee4ca10e99e68c1937bb0f1eca3daa92e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Sun, 14 Jul 2024 09:08:14 +0200 Subject: [PATCH 13/20] hotfix: packaging ticket 199070 --- db/routines/vn/procedures/sale_getBoxPickingList.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/sale_getBoxPickingList.sql b/db/routines/vn/procedures/sale_getBoxPickingList.sql index 8d16d556b..a95ed5b0c 100644 --- a/db/routines/vn/procedures/sale_getBoxPickingList.sql +++ b/db/routines/vn/procedures/sale_getBoxPickingList.sql @@ -28,7 +28,7 @@ BEGIN pb.routeFk, FLOOR(s.quantity / IF(i.isBoxPickingMode, ish.packing, i.packingOut)) stickers, IF(i.isBoxPickingMode, ish.packing, i.packingOut) packing, - IF(pa.isPackageReturnable, pc.defaultBigPackageFk, b.packagingFk) + IF(pa.isPackageReturnable, pc.defaultBigPackageFk, b.packagingFk) packagingFk FROM sale s JOIN item i ON i.id = s.itemFk JOIN itemShelving ish ON ish.itemFk = s.itemFk -- 2.40.1 From 573f5c8d28d1151ca6952edd6fb1c58af6b1992a Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 15 Jul 2024 12:28:30 +0200 Subject: [PATCH 14/20] feat newState refs #7642 --- .../11147-brownBamboo/00-firstScript.sql | 2 ++ .../11147-brownBamboo/00-firstScript.vn.sql | 2 +- .../ticket/back/methods/ticket/saveSign.js | 2 +- .../methods/ticket/specs/saveSign.spec.js | 30 +++++++++++-------- 4 files changed, 21 insertions(+), 15 deletions(-) create mode 100644 db/versions/11147-brownBamboo/00-firstScript.sql diff --git a/db/versions/11147-brownBamboo/00-firstScript.sql b/db/versions/11147-brownBamboo/00-firstScript.sql new file mode 100644 index 000000000..5a9098583 --- /dev/null +++ b/db/versions/11147-brownBamboo/00-firstScript.sql @@ -0,0 +1,2 @@ + +ALTER TABLE vn.ticketLastState MODIFY COLUMN name varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL; diff --git a/db/versions/11147-brownBamboo/00-firstScript.vn.sql b/db/versions/11147-brownBamboo/00-firstScript.vn.sql index eb62b98b0..53737fa30 100644 --- a/db/versions/11147-brownBamboo/00-firstScript.vn.sql +++ b/db/versions/11147-brownBamboo/00-firstScript.vn.sql @@ -1,5 +1,5 @@ -- Place your SQL code here -INSERT INTO vn.state ( name, `order`, alertLevel, code, sectorProdPriority, nextStateFk, isPreviousPreparable, isPicked, isPreparable, semaphore, isPrintable, isOK, graphCategory, isNotValidated, classColor) VALUES('Entregado en parte', 13, 3, 'PARTIALLY_DELIVERED', NULL, 16, 0, 1, 0, 0, 0, 0, 0, 0, NULL); +INSERT INTO vn.state ( name, `order`, alertLevel, code, sectorProdPriority, nextStateFk, isPreviousPreparable, isPicked, isPreparable, semaphore, isPrintable, isOK, graphCategory, isNotValidated, classColor) VALUES('Entregado en parte', 13, 3, 'PARTIAL_DELIVERED', NULL, 16, 0, 1, 0, 0, 0, 0, 0, 0, NULL); diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index f90cc72c2..a76395c77 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -143,7 +143,7 @@ module.exports = Self => { const [{stateForTicket}] = await Self.rawSql(` SELECT IF((SUM(CASE WHEN est.code = 'DELIVERED' THEN 1 ELSE 0 END) = COUNT(*)), - 'DELIVERED','PARTIALLYDELIVERED') stateForTicket + 'DELIVERED','PARTIAL_DELIVERED') stateForTicket FROM vn.expedition e JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk WHERE e.ticketFk = ?; diff --git a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js index df7c13aad..23c09c184 100644 --- a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js +++ b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js @@ -8,7 +8,7 @@ describe('Ticket saveSign()', () => { accessToken: {userId: 9} }}; - fit(`should throw error if the ticket's alert level is lower than 2`, async() => { + it(`should throw error if the ticket's alert level is lower than 2`, async() => { const tx = await models.TicketDms.beginTransaction({}); const ticketWithOkState = 12; let error; @@ -27,31 +27,35 @@ describe('Ticket saveSign()', () => { expect(error).toBeDefined(); }); - fit('should change state for ticket', async() => { - const tx = await models.TicketDms.beginTransaction({}); - const ticketWithOkState = 12; + it('should change state for ticket', async() => { + const tx = await models.State.beginTransaction({}); + const ticketWithOkState = 7; const ticketStateId = 16; - const ticketCode = 'PARTIALLY_DELIVERED'; + const ticketCode = 'PARTIAL_DELIVERED'; + spyOn(models.Dms, 'uploadFile').and.returnValue([{id: 1}]); + let ticketTrackingAfter; try { const options = {transaction: tx}; const tickets = [ticketWithOkState]; - const state = await models.State.findById(ticketStateId); + + const state = await models.State.findById(ticketStateId, null, options); await state.updateAttributes({ - code: ticketCode - }, options); - const ticketState = await models.TicketTracking.findById(ticketStateId); - await ticketState.updateAttributes({ - code: ticketCode + code: ticketCode, + name: ticketCode + }, options); + + await models.Ticket.saveSign(ctx, tickets, null, null, options); + ticketTrackingAfter = await models.TicketLastState.findOne({ + where: {ticketFk: ticketWithOkState} }, options); - await models.Ticket.saveSign(ctx, tickets, options); await tx.rollback(); } catch (e) { await tx.rollback(); throw e; } - expect(ticket.toEqual('DELIVERED')); + expect(ticketTrackingAfter.name).toBe('PARTIAL_DELIVERED'); }); }); -- 2.40.1 From 8dbdbdf23bea35d2837f9ebd5a9e06443f51fc57 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 15 Jul 2024 12:30:09 +0200 Subject: [PATCH 15/20] feat newState refs #7642 --- modules/ticket/back/methods/ticket/saveSign.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index a76395c77..ae06d84ba 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -140,7 +140,7 @@ module.exports = Self => { await models.TicketDms.create({ticketFk: ticket.id, dmsFk: dms[0].id}, myOptions); await ticket.updateAttribute('isSigned', true, myOptions); - const [{stateForTicket}] = await Self.rawSql(` + const [{stateCode}] = await Self.rawSql(` SELECT IF((SUM(CASE WHEN est.code = 'DELIVERED' THEN 1 ELSE 0 END) = COUNT(*)), 'DELIVERED','PARTIAL_DELIVERED') stateForTicket @@ -149,7 +149,7 @@ module.exports = Self => { WHERE e.ticketFk = ?; `, [ticketId], myOptions); - await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, stateForTicket], myOptions); + await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketId, stateCode], myOptions); if (ticket?.address()?.province()?.country()?.code != 'ES' && ticket.cmrFk) { await models.Ticket.saveCmr(ctx, [ticketId], myOptions); -- 2.40.1 From 8df64013eee4072f5cc0770ee08fa3b8a5d43647 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 15 Jul 2024 13:00:16 +0200 Subject: [PATCH 16/20] Merge branch 'master' of https://gitea.verdnatura.es/verdnatura/salix into 6861_reservas_retro --- modules/ticket/back/methods/ticket/saveSign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index ae06d84ba..a751bd93a 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -143,7 +143,7 @@ module.exports = Self => { const [{stateCode}] = await Self.rawSql(` SELECT IF((SUM(CASE WHEN est.code = 'DELIVERED' THEN 1 ELSE 0 END) = COUNT(*)), - 'DELIVERED','PARTIAL_DELIVERED') stateForTicket + 'DELIVERED','PARTIAL_DELIVERED') stateCode FROM vn.expedition e JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk WHERE e.ticketFk = ?; -- 2.40.1 From a821aa317a69ad607fd0a3e84468686b8733c580 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 15 Jul 2024 16:03:28 +0200 Subject: [PATCH 17/20] feat newState refs #7642 --- .../11153-purpleMedeola/00-firstScript.sql | 3 +++ .../11153-purpleMedeola/00-firstScript.vn.sql | 3 +++ .../back/methods/ticket/specs/saveSign.spec.js | 16 ++++++++-------- 3 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 db/versions/11153-purpleMedeola/00-firstScript.sql create mode 100644 db/versions/11153-purpleMedeola/00-firstScript.vn.sql diff --git a/db/versions/11153-purpleMedeola/00-firstScript.sql b/db/versions/11153-purpleMedeola/00-firstScript.sql new file mode 100644 index 000000000..f9399cb05 --- /dev/null +++ b/db/versions/11153-purpleMedeola/00-firstScript.sql @@ -0,0 +1,3 @@ + + +ALTER TABLE vn.ticketLastState MODIFY COLUMN name varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL; \ No newline at end of file diff --git a/db/versions/11153-purpleMedeola/00-firstScript.vn.sql b/db/versions/11153-purpleMedeola/00-firstScript.vn.sql new file mode 100644 index 000000000..95160a847 --- /dev/null +++ b/db/versions/11153-purpleMedeola/00-firstScript.vn.sql @@ -0,0 +1,3 @@ + + +INSERT INTO vn.state ( name, `order`, alertLevel, code, sectorProdPriority, nextStateFk, isPreviousPreparable, isPicked, isPreparable, semaphore, isPrintable, isOK, graphCategory, isNotValidated, classColor) VALUES('Entregado en parte', 13, 3, 'PARTIAL_DELIVERED', NULL, 16, 0, 1, 0, 0, 0, 0, 0, 0, NULL); \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js index 23c09c184..c46c9a53c 100644 --- a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js +++ b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js @@ -27,17 +27,17 @@ describe('Ticket saveSign()', () => { expect(error).toBeDefined(); }); - it('should change state for ticket', async() => { - const tx = await models.State.beginTransaction({}); - const ticketWithOkState = 7; + fit('should change state for ticket', async() => { + const tx = await models.Ticket.beginTransaction({}); + const ticketWithPackedState = 7; const ticketStateId = 16; const ticketCode = 'PARTIAL_DELIVERED'; spyOn(models.Dms, 'uploadFile').and.returnValue([{id: 1}]); - let ticketTrackingAfter; + let ticketLastState; try { const options = {transaction: tx}; - const tickets = [ticketWithOkState]; + const tickets = [ticketWithPackedState]; const state = await models.State.findById(ticketStateId, null, options); await state.updateAttributes({ @@ -46,8 +46,8 @@ describe('Ticket saveSign()', () => { }, options); await models.Ticket.saveSign(ctx, tickets, null, null, options); - ticketTrackingAfter = await models.TicketLastState.findOne({ - where: {ticketFk: ticketWithOkState} + ticketLastState = await models.TicketLastState.findOne({ + where: {ticketFk: ticketWithPackedState} }, options); await tx.rollback(); @@ -56,6 +56,6 @@ describe('Ticket saveSign()', () => { throw e; } - expect(ticketTrackingAfter.name).toBe('PARTIAL_DELIVERED'); + expect(ticketLastState.name).toBe('PARTIAL_DELIVERED'); }); }); -- 2.40.1 From 1d66a2e752c1e2b72e118f1fae3b2c949ef33d6a Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 15 Jul 2024 16:07:59 +0200 Subject: [PATCH 18/20] Revert "feat newState refs #7642" This reverts commit a821aa317a69ad607fd0a3e84468686b8733c580. --- .../11153-purpleMedeola/00-firstScript.sql | 3 --- .../11153-purpleMedeola/00-firstScript.vn.sql | 3 --- .../back/methods/ticket/specs/saveSign.spec.js | 16 ++++++++-------- 3 files changed, 8 insertions(+), 14 deletions(-) delete mode 100644 db/versions/11153-purpleMedeola/00-firstScript.sql delete mode 100644 db/versions/11153-purpleMedeola/00-firstScript.vn.sql diff --git a/db/versions/11153-purpleMedeola/00-firstScript.sql b/db/versions/11153-purpleMedeola/00-firstScript.sql deleted file mode 100644 index f9399cb05..000000000 --- a/db/versions/11153-purpleMedeola/00-firstScript.sql +++ /dev/null @@ -1,3 +0,0 @@ - - -ALTER TABLE vn.ticketLastState MODIFY COLUMN name varchar(20) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL; \ No newline at end of file diff --git a/db/versions/11153-purpleMedeola/00-firstScript.vn.sql b/db/versions/11153-purpleMedeola/00-firstScript.vn.sql deleted file mode 100644 index 95160a847..000000000 --- a/db/versions/11153-purpleMedeola/00-firstScript.vn.sql +++ /dev/null @@ -1,3 +0,0 @@ - - -INSERT INTO vn.state ( name, `order`, alertLevel, code, sectorProdPriority, nextStateFk, isPreviousPreparable, isPicked, isPreparable, semaphore, isPrintable, isOK, graphCategory, isNotValidated, classColor) VALUES('Entregado en parte', 13, 3, 'PARTIAL_DELIVERED', NULL, 16, 0, 1, 0, 0, 0, 0, 0, 0, NULL); \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js index c46c9a53c..23c09c184 100644 --- a/modules/ticket/back/methods/ticket/specs/saveSign.spec.js +++ b/modules/ticket/back/methods/ticket/specs/saveSign.spec.js @@ -27,17 +27,17 @@ describe('Ticket saveSign()', () => { expect(error).toBeDefined(); }); - fit('should change state for ticket', async() => { - const tx = await models.Ticket.beginTransaction({}); - const ticketWithPackedState = 7; + it('should change state for ticket', async() => { + const tx = await models.State.beginTransaction({}); + const ticketWithOkState = 7; const ticketStateId = 16; const ticketCode = 'PARTIAL_DELIVERED'; spyOn(models.Dms, 'uploadFile').and.returnValue([{id: 1}]); - let ticketLastState; + let ticketTrackingAfter; try { const options = {transaction: tx}; - const tickets = [ticketWithPackedState]; + const tickets = [ticketWithOkState]; const state = await models.State.findById(ticketStateId, null, options); await state.updateAttributes({ @@ -46,8 +46,8 @@ describe('Ticket saveSign()', () => { }, options); await models.Ticket.saveSign(ctx, tickets, null, null, options); - ticketLastState = await models.TicketLastState.findOne({ - where: {ticketFk: ticketWithPackedState} + ticketTrackingAfter = await models.TicketLastState.findOne({ + where: {ticketFk: ticketWithOkState} }, options); await tx.rollback(); @@ -56,6 +56,6 @@ describe('Ticket saveSign()', () => { throw e; } - expect(ticketLastState.name).toBe('PARTIAL_DELIVERED'); + expect(ticketTrackingAfter.name).toBe('PARTIAL_DELIVERED'); }); }); -- 2.40.1 From fb9bf4126e20aa722554db7377bb64af05d6a876 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 15 Jul 2024 16:08:11 +0200 Subject: [PATCH 19/20] Revert "Merge branch 'master' of https://gitea.verdnatura.es/verdnatura/salix into 6861_reservas_retro" This reverts commit 8df64013eee4072f5cc0770ee08fa3b8a5d43647. --- modules/ticket/back/methods/ticket/saveSign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index a751bd93a..ae06d84ba 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -143,7 +143,7 @@ module.exports = Self => { const [{stateCode}] = await Self.rawSql(` SELECT IF((SUM(CASE WHEN est.code = 'DELIVERED' THEN 1 ELSE 0 END) = COUNT(*)), - 'DELIVERED','PARTIAL_DELIVERED') stateCode + 'DELIVERED','PARTIAL_DELIVERED') stateForTicket FROM vn.expedition e JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk WHERE e.ticketFk = ?; -- 2.40.1 From bc86bde5a4964e28bf57371e74ce1b0a082d4530 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 15 Jul 2024 16:09:13 +0200 Subject: [PATCH 20/20] Revert "Revert "Merge branch 'master' of https://gitea.verdnatura.es/verdnatura/salix into 6861_reservas_retro"" This reverts commit fb9bf4126e20aa722554db7377bb64af05d6a876. --- modules/ticket/back/methods/ticket/saveSign.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index ae06d84ba..a751bd93a 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -143,7 +143,7 @@ module.exports = Self => { const [{stateCode}] = await Self.rawSql(` SELECT IF((SUM(CASE WHEN est.code = 'DELIVERED' THEN 1 ELSE 0 END) = COUNT(*)), - 'DELIVERED','PARTIAL_DELIVERED') stateForTicket + 'DELIVERED','PARTIAL_DELIVERED') stateCode FROM vn.expedition e JOIN vn.expeditionStateType est ON est.id = e.stateTypeFk WHERE e.ticketFk = ?; -- 2.40.1