From 4ee6a46bd567cfbc7660d78daae1b88af76fce6a Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 14 Oct 2024 11:29:49 +0200 Subject: [PATCH 01/12] feat: added new filter param --- .../back/methods/ticket-request/filter.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/modules/ticket/back/methods/ticket-request/filter.js b/modules/ticket/back/methods/ticket-request/filter.js index 5364cef9a..ad000036b 100644 --- a/modules/ticket/back/methods/ticket-request/filter.js +++ b/modules/ticket/back/methods/ticket-request/filter.js @@ -59,6 +59,11 @@ module.exports = Self => { arg: 'state', type: 'string', description: `Search request by request state` + }, + { + arg: 'myTeam', + type: 'boolean', + description: `Team partners` } ], returns: { @@ -75,6 +80,24 @@ module.exports = Self => { const conn = Self.dataSource.connector; const userId = ctx.req.accessToken.userId; const myOptions = {}; + const models = Self.app.models; + const args = ctx.args; + + // Apply filter by team + 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); + } if (typeof options == 'object') Object.assign(myOptions, options); @@ -113,6 +136,11 @@ module.exports = Self => { return {'w.id': value}; case 'salesPersonFk': return {'c.salesPersonFk': value}; + case 'myTeam': + if (value) + return {'c.salesPersonFk': {inq: teamMembersId}}; + else + return {'c.salesPersonFk': {nin: teamMembersId}}; } }); From 07849ebeb8234172072b027317ad8517dc34cfe4 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 14 Oct 2024 13:25:09 +0200 Subject: [PATCH 02/12] fix: myTeam param --- modules/ticket/back/methods/ticket-request/filter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket-request/filter.js b/modules/ticket/back/methods/ticket-request/filter.js index ad000036b..2e1d2fbae 100644 --- a/modules/ticket/back/methods/ticket-request/filter.js +++ b/modules/ticket/back/methods/ticket-request/filter.js @@ -138,9 +138,9 @@ module.exports = Self => { return {'c.salesPersonFk': value}; case 'myTeam': if (value) - return {'c.salesPersonFk': {inq: teamMembersId}}; + return {'tr.requesterFk': {inq: teamMembersId}}; else - return {'c.salesPersonFk': {nin: teamMembersId}}; + return {'tr.requesterFk': {nin: teamMembersId}}; } }); From 52e573501ad4d5fa120291b24f1ba9cf53dfaea0 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 15 Oct 2024 08:46:43 +0200 Subject: [PATCH 03/12] feat: refs #8108 create tables itemTag --- .../11300-limeMedeola/00-firstScript.sql | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 db/versions/11300-limeMedeola/00-firstScript.sql diff --git a/db/versions/11300-limeMedeola/00-firstScript.sql b/db/versions/11300-limeMedeola/00-firstScript.sql new file mode 100644 index 000000000..21920b692 --- /dev/null +++ b/db/versions/11300-limeMedeola/00-firstScript.sql @@ -0,0 +1,85 @@ +CREATE TABLE IF NOT EXISTS `vn`.`itemFarmingTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemFarmingTag` (`name`) VALUES ('Enraizado'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemFarmingTag' + WHERE name= 'cultivo'; + + + +CREATE TABLE IF NOT EXISTS `vn`.`itemWrappingTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Bolsa'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Caja cartón'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Caja decorativa'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Celofán'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Papel kraft'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Plástico'); +INSERT IGNORE INTO `vn`.`itemWrappingTag` (`name`) VALUES ('Variable'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemWrappingTag' + WHERE name= 'Envoltorio'; + + + +CREATE TABLE IF NOT EXISTS `vn`.`itemLanguageTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Castellano'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Catalán'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Euskera'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Francés'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Gallego'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Inglés'); +INSERT IGNORE INTO `vn`.`itemLanguageTag` (`name`) VALUES ('Portugués'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemLanguageTag' + WHERE name= 'Idioma'; + + + +CREATE TABLE IF NOT EXISTS `vn`.`itemStemTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemStemTag` (`name`) VALUES ('Natural'); +INSERT IGNORE INTO `vn`.`itemStemTag` (`name`) VALUES ('Seminatural'); +INSERT IGNORE INTO `vn`.`itemStemTag` (`name`) VALUES ('Sintético'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemStemTag' + WHERE name= 'Tronco'; + + +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemFarmingTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemLanguageTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemStemTag TO logisticAssist; \ No newline at end of file From e334152acc901fb1357a59d9da85c317b9b29548 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 15 Oct 2024 09:03:15 +0200 Subject: [PATCH 04/12] refactor: deleted comment --- .../ticket/back/methods/ticket-request/filter.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/modules/ticket/back/methods/ticket-request/filter.js b/modules/ticket/back/methods/ticket-request/filter.js index 2e1d2fbae..53f90b98f 100644 --- a/modules/ticket/back/methods/ticket-request/filter.js +++ b/modules/ticket/back/methods/ticket-request/filter.js @@ -83,7 +83,12 @@ module.exports = Self => { const models = Self.app.models; const args = ctx.args; - // Apply filter by team + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (ctx.args.mine) + ctx.args.attenderFk = userId; + const teamMembersId = []; if (args.myTeam != null) { const worker = await models.Worker.findById(userId, { @@ -99,12 +104,6 @@ module.exports = Self => { teamMembersId.push(userId); } - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (ctx.args.mine) - ctx.args.attenderFk = userId; - let where = buildFilter(ctx.args, (param, value) => { switch (param) { case 'search': From da55fffef02385c03945fb5ca30b0f42a8961161 Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 15 Oct 2024 11:18:04 +0200 Subject: [PATCH 05/12] feat: refs #8108 addMoreTablesTag --- db/routines/vn/procedures/entry_transfer.sql | 121 ++++++++++++++++++ .../11300-limeMedeola/00-firstScript.sql | 72 ++++++++++- 2 files changed, 189 insertions(+), 4 deletions(-) create mode 100644 db/routines/vn/procedures/entry_transfer.sql diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql new file mode 100644 index 000000000..6d7da2b37 --- /dev/null +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -0,0 +1,121 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`(vOriginalEntry INT, OUT vNewEntry INT) +BEGIN +/** +* Adelanta a mañana la mercancia de una entrada a partir de lo que hay ubicado en el almacén +* +* @param vOriginalEntry entrada que se quiera adelantar +*/ + + DECLARE vNewEntryFk INT; + DECLARE vTravelFk INT; + DECLARE vWarehouseFk INT; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + -- Clonar la entrada + CALL entry_clone(vOriginalEntry,vNewEntryFk); + + START TRANSACTION; + + -- Hay que crear un nuevo travel, con salida hoy y llegada mañana y asignar la entrada nueva al nuevo travel. + INSERT INTO travel( + shipped, + landed, + warehouseInFk, + warehouseOutFk, + `ref`, + isReceived, + agencyModeFk) + SELECT util.VN_CURDATE(), + util.VN_CURDATE() + INTERVAL 1 DAY, + t.warehouseInFk, + t.warehouseInFk, + t.`ref`, + t.isReceived, + t.agencyModeFk + FROM travel t + JOIN entry e ON e.travelFk = t.id + WHERE e.id = vOriginalEntry; + + SET vTravelFk = LAST_INSERT_ID(); + + UPDATE entry + SET travelFk = vTravelFk + WHERE id = vNewEntryFk; + + -- Poner a 0 las cantidades + UPDATE buy b + SET b.quantity = 0, b.stickers = 0 + WHERE b.entryFk = vNewEntryFk; + + -- Eliminar duplicados + DELETE b.* + FROM buy b + LEFT JOIN (SELECT b.id, b.itemFk + FROM buy b + WHERE b.entryFk = vNewEntryFk + GROUP BY b.itemFk) tBuy ON tBuy.id = b.id + WHERE b.entryFk = vNewEntryFk + AND tBuy.id IS NULL; + + SELECT t.warehouseInFk INTO vWarehouseFk + FROM travel t + JOIN entry e ON e.travelFk = t.id + WHERE e.id = vOriginalEntry; + + -- Actualizar la nueva entrada con lo que no está ubicado HOY, descontando lo vendido HOY de esas ubicaciones + CREATE OR REPLACE TEMPORARY TABLE tBuy + ENGINE = MEMORY + SELECT tBuy.itemFk, IFNULL(iss.visible,0) visible, tBuy.totalQuantity, IFNULL(sales.sold,0) sold + FROM (SELECT b.itemFk, SUM(b.quantity) totalQuantity + FROM buy b + WHERE b.entryFk = vOriginalEntry + GROUP BY b.itemFk + ) tBuy + LEFT JOIN ( + SELECT ish.itemFk, SUM(visible) visible + FROM itemShelving ish + JOIN shelving sh ON sh.code = ish.shelvingFk + JOIN parking p ON p.id = sh.parkingFk + JOIN sector s ON s.id = p.sectorFk + WHERE s.warehouseFk = vWarehouseFk + AND sh.parked = util.VN_CURDATE() + GROUP BY ish.itemFk) iss ON tBuy.itemFk = iss.itemFk + LEFT JOIN ( + SELECT s.itemFk, SUM(s.quantity) sold + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN itemShelvingSale iss ON iss.saleFk = s.id + JOIN itemShelving is2 ON is2.id = iss.itemShelvingFk + JOIN shelving s2 ON s2.code = is2.shelvingFk + WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + AND s2.parked = util.VN_CURDATE() + GROUP BY s.itemFk) sales ON sales.itemFk = tBuy.itemFk + WHERE visible = tBuy.totalQuantity + OR iss.itemFk IS NULL; + + UPDATE buy b + JOIN (SELECT * FROM tBuy) sub ON sub.itemFk = b.itemFk + SET b.quantity = sub.totalQuantity - sub.visible - sub.sold + WHERE b.entryFk = vNewEntryFk; + + -- Limpia la nueva entrada + DELETE b.* + FROM buy b + WHERE b.entryFk = vNewEntryFk + AND b.quantity = 0; + + COMMIT; + + SET vNewEntry = vNewEntryFk; + + CALL cache.visible_refresh(@c,TRUE,7); + CALL cache.available_refresh(@c, TRUE, 7, util.VN_CURDATE()); + +END$$ +DELIMITER ; diff --git a/db/versions/11300-limeMedeola/00-firstScript.sql b/db/versions/11300-limeMedeola/00-firstScript.sql index 21920b692..313a65e81 100644 --- a/db/versions/11300-limeMedeola/00-firstScript.sql +++ b/db/versions/11300-limeMedeola/00-firstScript.sql @@ -79,7 +79,71 @@ UPDATE vn.tag WHERE name= 'Tronco'; -GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemFarmingTag TO logisticAssist; -GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist; -GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemLanguageTag TO logisticAssist; -GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemStemTag TO logisticAssist; \ No newline at end of file +CREATE TABLE IF NOT EXISTS `vn`.`itemBreederTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemBreederTag` (`name`) VALUES ('David Austin'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemBreederTag' + WHERE name= 'Obtentor'; + + + +CREATE TABLE IF NOT EXISTS `vn`.`itemBaseTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Biodegradable'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Caballete'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Cerámica'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Cristal'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Plástico por inyección'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Madera'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Plástico'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Rígido'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Ruedas'); +INSERT IGNORE INTO `vn`.`itemBaseTag` (`name`) VALUES ('Sin soporte rígido'); + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemBaseTag' + WHERE name= 'Soporte'; + + + +CREATE TABLE IF NOT EXISTS `vn`.`itemVatRateTag` ( + `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_UNIQUE` (`name`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT + CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; + +INSERT IGNORE INTO `vn`.`itemVatRateTag` (`name`) VALUES ('General'); +INSERT IGNORE INTO `vn`.`itemVatRateTag` (`name`) VALUES ('Reducido'); + + +UPDATE vn.tag + SET isFree=0, + sourceTable='itemVatRateTag' + WHERE name= 'Tipo de IVA'; + + +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemFarmingTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemLanguageTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemStemTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemBaseTag TO logisticAssist; +GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemBreederTag TO logisticAssist; \ No newline at end of file From 8da005f08ab1c0775c1cfee83bbdbadff3ca0cfa Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 15 Oct 2024 11:19:08 +0200 Subject: [PATCH 06/12] feat: refs #8108 refs #9108 --- db/routines/vn/procedures/entry_transfer.sql | 121 ------------------- 1 file changed, 121 deletions(-) delete mode 100644 db/routines/vn/procedures/entry_transfer.sql diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql deleted file mode 100644 index 6d7da2b37..000000000 --- a/db/routines/vn/procedures/entry_transfer.sql +++ /dev/null @@ -1,121 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`(vOriginalEntry INT, OUT vNewEntry INT) -BEGIN -/** -* Adelanta a mañana la mercancia de una entrada a partir de lo que hay ubicado en el almacén -* -* @param vOriginalEntry entrada que se quiera adelantar -*/ - - DECLARE vNewEntryFk INT; - DECLARE vTravelFk INT; - DECLARE vWarehouseFk INT; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - -- Clonar la entrada - CALL entry_clone(vOriginalEntry,vNewEntryFk); - - START TRANSACTION; - - -- Hay que crear un nuevo travel, con salida hoy y llegada mañana y asignar la entrada nueva al nuevo travel. - INSERT INTO travel( - shipped, - landed, - warehouseInFk, - warehouseOutFk, - `ref`, - isReceived, - agencyModeFk) - SELECT util.VN_CURDATE(), - util.VN_CURDATE() + INTERVAL 1 DAY, - t.warehouseInFk, - t.warehouseInFk, - t.`ref`, - t.isReceived, - t.agencyModeFk - FROM travel t - JOIN entry e ON e.travelFk = t.id - WHERE e.id = vOriginalEntry; - - SET vTravelFk = LAST_INSERT_ID(); - - UPDATE entry - SET travelFk = vTravelFk - WHERE id = vNewEntryFk; - - -- Poner a 0 las cantidades - UPDATE buy b - SET b.quantity = 0, b.stickers = 0 - WHERE b.entryFk = vNewEntryFk; - - -- Eliminar duplicados - DELETE b.* - FROM buy b - LEFT JOIN (SELECT b.id, b.itemFk - FROM buy b - WHERE b.entryFk = vNewEntryFk - GROUP BY b.itemFk) tBuy ON tBuy.id = b.id - WHERE b.entryFk = vNewEntryFk - AND tBuy.id IS NULL; - - SELECT t.warehouseInFk INTO vWarehouseFk - FROM travel t - JOIN entry e ON e.travelFk = t.id - WHERE e.id = vOriginalEntry; - - -- Actualizar la nueva entrada con lo que no está ubicado HOY, descontando lo vendido HOY de esas ubicaciones - CREATE OR REPLACE TEMPORARY TABLE tBuy - ENGINE = MEMORY - SELECT tBuy.itemFk, IFNULL(iss.visible,0) visible, tBuy.totalQuantity, IFNULL(sales.sold,0) sold - FROM (SELECT b.itemFk, SUM(b.quantity) totalQuantity - FROM buy b - WHERE b.entryFk = vOriginalEntry - GROUP BY b.itemFk - ) tBuy - LEFT JOIN ( - SELECT ish.itemFk, SUM(visible) visible - FROM itemShelving ish - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON p.id = sh.parkingFk - JOIN sector s ON s.id = p.sectorFk - WHERE s.warehouseFk = vWarehouseFk - AND sh.parked = util.VN_CURDATE() - GROUP BY ish.itemFk) iss ON tBuy.itemFk = iss.itemFk - LEFT JOIN ( - SELECT s.itemFk, SUM(s.quantity) sold - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN itemShelvingSale iss ON iss.saleFk = s.id - JOIN itemShelving is2 ON is2.id = iss.itemShelvingFk - JOIN shelving s2 ON s2.code = is2.shelvingFk - WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) - AND s2.parked = util.VN_CURDATE() - GROUP BY s.itemFk) sales ON sales.itemFk = tBuy.itemFk - WHERE visible = tBuy.totalQuantity - OR iss.itemFk IS NULL; - - UPDATE buy b - JOIN (SELECT * FROM tBuy) sub ON sub.itemFk = b.itemFk - SET b.quantity = sub.totalQuantity - sub.visible - sub.sold - WHERE b.entryFk = vNewEntryFk; - - -- Limpia la nueva entrada - DELETE b.* - FROM buy b - WHERE b.entryFk = vNewEntryFk - AND b.quantity = 0; - - COMMIT; - - SET vNewEntry = vNewEntryFk; - - CALL cache.visible_refresh(@c,TRUE,7); - CALL cache.available_refresh(@c, TRUE, 7, util.VN_CURDATE()); - -END$$ -DELIMITER ; From 4a88ba5078132adee8e7f24657ee29da0445f873 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 15 Oct 2024 15:43:12 +0200 Subject: [PATCH 07/12] feat: refs #7744 closeAll Test --- db/dump/fixtures.before.sql | 24 ++++-- loopback/locale/es.json | 1 + loopback/locale/fr.json | 1 + loopback/locale/pt.json | 1 + modules/invoiceOut/back/models/invoice-out.js | 2 + modules/ticket/back/methods/sale/usesMana.js | 2 +- .../ticket/back/methods/ticket/closeAll.js | 44 +++++----- modules/ticket/back/methods/ticket/closure.js | 10 ++- .../methods/ticket/specs/closeAll.spec.js | 80 +++++++++++++++++++ 9 files changed, 136 insertions(+), 29 deletions(-) create mode 100644 modules/ticket/back/methods/ticket/specs/closeAll.spec.js diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 7f7e50dd3..6007b73e0 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -632,14 +632,21 @@ INSERT INTO vn.invoiceOutConfig SET id = 1, parallelism = 8; -INSERT INTO `vn`.`invoiceOutSerial` (`code`, `description`, `isTaxed`, `taxAreaFk`, `isCEE`, `type`) +INSERT INTO `vn`.`invoiceOutSerial` + (`code`,`description`, `isTaxed`, `taxAreaFk`, `isCEE`, `type`) VALUES - ('A', 'Global nacional', 1, 'NATIONAL', 0, 'global'), - ('T', 'Española rapida', 1, 'NATIONAL', 0, 'quick'), - ('V', 'Intracomunitaria global', 0, 'CEE', 1, 'global'), - ('M', 'Múltiple nacional', 1, 'NATIONAL', 0, 'multiple'), - ('R', 'Rectificativa', 1, 'NATIONAL', 0, NULL), - ('E', 'Exportación rápida', 0, 'WORLD', 0, 'quick'); + ('A', 'Global nacional', 1, 'NATIONAL', 0, 'global'), + ('T', 'Española rapida', 1, 'NATIONAL', 0, 'quick'), + ('V', 'Intracomunitaria global', 0, 'CEE', 1, 'global'), + ('M', 'Múltiple nacional', 1, 'NATIONAL', 0, 'multiple'), + ('R', 'Rectificativa', 1, 'NATIONAL', 0, NULL), + ('E', 'Exportación rápida', 0, 'WORLD', 0, 'quick'), + ('H', 'Intracomunitaria rápida', 0, 'CEE', 1, 'quick'), + ('P', 'Factura simplificada', 1, 'NATIONAL', 0, NULL), + ('PE', 'COOPERATIE FLORAHOLLAND UA', 0, 'CEE', 1, NULL), + ('S', 'Simplificada', 1, 'NATIONAL', 0, NULL), + ('X', 'Exportación global', 0, 'WORLD', 0, 'global'), + ('N', 'Múltiple Intracomunitaria', 0, 'CEE', 1, 'multiple'); INSERT INTO `vn`.`invoiceOut`(`id`, `serial`, `amount`, `issued`,`clientFk`, `created`, `companyFk`, `dued`, `booked`, `bankFk`, `hasPdf`) VALUES @@ -2911,7 +2918,8 @@ INSERT INTO `util`.`notification` (`id`, `name`, `description`) (6, 'book-entry-deleted', 'accounting entries deleted'), (7, 'zone-included','An email to notify zoneCollisions'), (8, 'backup-printer-selected','A backup printer has been selected'), - (9, 'mrw-deadline','The MRW deadline has passed'); + (9, 'mrw-deadline','The MRW deadline has passed'), + (10,'invoice-ticket-closure','Tickets not invoiced during the nightly closure ticket process'); TRUNCATE `util`.`notificationAcl`; INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 9308fd4ec..0349fa8fb 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -350,6 +350,7 @@ "Cmr file does not exist": "El archivo del cmr no existe", "You are not allowed to modify the alias": "No estás autorizado a modificar el alias", "The address of the customer must have information about Incoterms and Customs Agent": "El consignatario del cliente debe tener informado Incoterms y Agente de aduanas", + "No invoice series found for these parameters": "No se encontró una serie para estos parámetros", "The line could not be marked": "La linea no puede ser marcada", "Through this procedure, it is not possible to modify the password of users with verified email": "Mediante este procedimiento, no es posible modificar la contraseña de usuarios con correo verificado", "They're not your subordinate": "No es tu subordinado/a.", diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index a6648b186..23bd5cc04 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -350,6 +350,7 @@ "Cmr file does not exist": "Le fichier cmr n'existe pas", "You are not allowed to modify the alias": "Vous n'êtes pas autorisé à modifier l'alias", "The address of the customer must have information about Incoterms and Customs Agent": "L'adresse du client doit contenir des informations sur les Incoterms et l'agent des douanes", + "No invoice series found for these parameters": "Aucune série de facture trouvée pour ces paramètres", "The line could not be marked": "La ligne ne peut pas être marquée", "This password can only be changed by the user themselves": "Ce mot de passe ne peut être modifié que par l'utilisateur lui-même", "They're not your subordinate": "Ce n'est pas votre subordonné.", diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index a43f0e780..f85afd607 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -350,6 +350,7 @@ "Cmr file does not exist": "O arquivo CMR não existe", "You are not allowed to modify the alias": "Você não tem permissão para modificar o alias", "The address of the customer must have information about Incoterms and Customs Agent": "O endereço do cliente deve ter informações sobre Incoterms e Agente Aduaneiro", + "No invoice series found for these parameters": "Nenhuma série de fatura encontrada para esses parâmetros", "The line could not be marked": "A linha não pôde ser marcada", "This password can only be changed by the user themselves": "Esta senha só pode ser alterada pelo próprio usuário", "They're not your subordinate": "Eles não são seus subordinados.", diff --git a/modules/invoiceOut/back/models/invoice-out.js b/modules/invoiceOut/back/models/invoice-out.js index bab1fa375..f8fc8cdbf 100644 --- a/modules/invoiceOut/back/models/invoice-out.js +++ b/modules/invoiceOut/back/models/invoice-out.js @@ -79,6 +79,8 @@ module.exports = Self => { type ], myOptions); + if (!serial) + throw new UserError('No invoice series found for these parameters'); const invoiceOutSerial = await Self.app.models.InvoiceOutSerial.findById(serial); if (invoiceOutSerial?.taxAreaFk == 'WORLD') { diff --git a/modules/ticket/back/methods/sale/usesMana.js b/modules/ticket/back/methods/sale/usesMana.js index 31beb3a4c..b4768d80a 100644 --- a/modules/ticket/back/methods/sale/usesMana.js +++ b/modules/ticket/back/methods/sale/usesMana.js @@ -31,6 +31,6 @@ module.exports = Self => { const usesMana = departments.find(department => department.id == workerDepartment.departmentFk); - return usesMana ? true : false; + return !!usesMana; }; }; diff --git a/modules/ticket/back/methods/ticket/closeAll.js b/modules/ticket/back/methods/ticket/closeAll.js index 4fd72d454..1b3f84295 100644 --- a/modules/ticket/back/methods/ticket/closeAll.js +++ b/modules/ticket/back/methods/ticket/closeAll.js @@ -1,11 +1,17 @@ -const UserError = require('vn-loopback/util/user-error'); const closure = require('./closure'); module.exports = Self => { Self.remoteMethodCtx('closeAll', { description: 'Makes the closure process from all warehouses', accessType: 'WRITE', - accepts: [], + accepts: [ + { + arg: 'options', + type: 'object', + http: {source: 'body'}, + description: 'Optional parameters, including transaction.' + } + ], returns: { type: 'object', root: true @@ -16,21 +22,20 @@ module.exports = Self => { } }); - Self.closeAll = async ctx => { + Self.closeAll = async(ctx, options) => { + const userId = ctx.req.accessToken.userId; + const myOptions = {userId}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + let tx; + // IMPORTANT: Due to its high cost in production, wrapping this process in a transaction may cause timeouts. + const toDate = Date.vnNew(); toDate.setHours(0, 0, 0, 0); toDate.setDate(toDate.getDate() - 1); - const todayMinDate = Date.vnNew(); - todayMinDate.setHours(0, 0, 0, 0); - - const todayMaxDate = Date.vnNew(); - todayMaxDate.setHours(23, 59, 59, 59); - - // Prevent closure for current day - if (toDate >= todayMinDate && toDate <= todayMaxDate) - throw new UserError('You cannot close tickets for today'); - const tickets = await Self.rawSql(` SELECT t.id, t.clientFk, @@ -58,12 +63,12 @@ module.exports = Self => { AND t.shipped BETWEEN ? - INTERVAL tc.closureDaysAgo DAY AND util.dayEnd(?) AND t.refFk IS NULL GROUP BY t.id - `, [toDate, toDate]); + `, [toDate, toDate], myOptions); const ticketIds = tickets.map(ticket => ticket.id); await Self.rawSql(` INSERT INTO util.debug (variable, value) VALUES ('nightInvoicing', ?) - `, [ticketIds.join(',')]); + `, [ticketIds.join(',')], myOptions); await Self.rawSql(` WITH ticketNotInvoiceable AS( @@ -133,9 +138,9 @@ module.exports = Self => { ) SELECT IF(errors = '{"tickets": null}', 'No errors', util.notification_send('invoice-ticket-closure', errors, NULL)) - FROM ticketNotInvoiceable`, [toDate, toDate]); + FROM ticketNotInvoiceable`, [toDate, toDate], myOptions); - await closure(ctx, Self, tickets); + await closure(ctx, Self, tickets, myOptions); await Self.rawSql(` UPDATE ticket t @@ -150,7 +155,10 @@ module.exports = Self => { AND al.code NOT IN ('DELIVERED', 'PACKED') AND NOT t.packages AND tob.id IS NULL - AND t.routeFk`, [toDate, toDate], {userId: ctx.req.accessToken.userId}); + AND t.routeFk`, [toDate, toDate], myOptions); + + if (tx) + await tx.commit(); return { message: 'Success' diff --git a/modules/ticket/back/methods/ticket/closure.js b/modules/ticket/back/methods/ticket/closure.js index 56bd6eccd..64f198834 100644 --- a/modules/ticket/back/methods/ticket/closure.js +++ b/modules/ticket/back/methods/ticket/closure.js @@ -19,9 +19,15 @@ module.exports = async function(ctx, Self, tickets, options) { const failedtickets = []; for (const ticket of tickets) { try { - await Self.rawSql(`CALL util.debugAdd('invoicingTicket', ?)`, [ticket.id], {userId}); + await Self.rawSql(`CALL util.debugAdd('invoicingTicket', ?)`, [ticket.id], {userId}, + myOptions); - await Self.app.models.InvoiceOut.getSerial(ticket.clientFk, ticket.companyFk, ticket.addressFk, 'quick'); + await Self.app.models.InvoiceOut.getSerial( + ticket.clientFk, + ticket.companyFk, + ticket.addressFk, + 'quick', + myOptions); await Self.rawSql( `CALL vn.ticket_closeByTicket(?)`, [ticket.id], diff --git a/modules/ticket/back/methods/ticket/specs/closeAll.spec.js b/modules/ticket/back/methods/ticket/specs/closeAll.spec.js new file mode 100644 index 000000000..4b067ce7e --- /dev/null +++ b/modules/ticket/back/methods/ticket/specs/closeAll.spec.js @@ -0,0 +1,80 @@ +const models = require('vn-loopback/server/server').models; +const LoopBackContext = require('loopback-context'); + +fdescribe('Ticket Closure - closeAll function', () => { + let ctx = { + req: { + getLocale: () => 'es', + accessToken: {userId: 1106}, + headers: {origin: 'http://localhost'}, + __: value => value, + }, + args: {} + }; + let options; + let tx; + let originalVnNew; + + beforeEach(async() => { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: ctx.req}); + tx = await models.Ticket.beginTransaction({}); + options = {transaction: tx}; + originalVnNew = Date.vnNew; + spyOn(Date, 'vnNew').and.callFake(() => { + const mockDate = originalVnNew(); + mockDate.setDate(mockDate.getDate() + 1); + return mockDate; + }); + }); + + afterEach(async() => { + if (tx) + await tx.rollback(); + }); + + xit('should successfully close all tickets when conditions are met', async() => { + const ticketsBefore = await models.Ticket.find({ + where: { + packages: {neq: 0} + } + }, options); + const packedTicketsIds = ticketsBefore.map(ticket => ticket.id); + + const packedTicketsBefore = await models.TicketLastState.find({ + where: { + ticketFk: {inq: packedTicketsIds}, + lastState: 'Encajado' + } + }, options); + + await models.Ticket.closeAll(ctx, options); + + const packedTicketsAfter = await models.TicketLastState.find({ + where: { + ticketFk: {inq: packedTicketsIds}, + lastState: 'Encajado' + } + }, options); + + expect(packedTicketsBefore.length).toBeGreaterThan(packedTicketsAfter.length); + }); + + fit('should set routeFk to NULL when conditions are met', async() => { + const ticketsBefore = await models.Ticket.find({ + where: { + routeFk: {neq: null} + } + }, options); + + await models.Ticket.closeAll(ctx, options); + + const ticketsAfter = await models.Ticket.find({ + where: { + id: {inq: ticketsBefore.map(ticket => ticket.id)}, + routeFk: {neq: null} + } + }, options); + + expect(ticketsBefore.length).toBeGreaterThan(ticketsAfter.length); + }); +}); From c6e764b478b9481376f187c32c9c73b5b26cb23d Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 16 Oct 2024 08:32:10 +0200 Subject: [PATCH 08/12] feat: refs #7348 hasDailyInvoice from client --- back/models/autonomy.json | 6 +- back/models/country.json | 4 + back/models/province.json | 5 +- db/routines/vn/procedures/client_create.sql | 10 +- db/routines/vn/procedures/ticket_close.sql | 7 +- .../11302-limeTulip/00-firstScript.sql | 13 ++ .../back/methods/client/createWithUser.js | 20 ++- .../client/specs/createWithUser.spec.js | 143 +++++++++++------- .../ticket/back/methods/ticket/closeAll.js | 4 +- .../back/methods/ticket/closeByTicket.js | 4 +- 10 files changed, 145 insertions(+), 71 deletions(-) create mode 100644 db/versions/11302-limeTulip/00-firstScript.sql diff --git a/back/models/autonomy.json b/back/models/autonomy.json index 8c9d82936..214061cf5 100644 --- a/back/models/autonomy.json +++ b/back/models/autonomy.json @@ -16,6 +16,10 @@ "name": { "type": "string", "required": true + }, + "hasDailyInvoice": { + "type": "boolean", + "description": "Indicates if the autonomy has daily invoice enabled" } }, "relations": { @@ -40,4 +44,4 @@ "permission": "ALLOW" } ] -} \ No newline at end of file +} diff --git a/back/models/country.json b/back/models/country.json index 5b9d842a8..80d456702 100644 --- a/back/models/country.json +++ b/back/models/country.json @@ -28,6 +28,10 @@ }, "continentFk": { "type": "number" + }, + "hasDailyInvoice": { + "type": "boolean", + "description": "Indicates if the autonomy has daily invoice enabled" } }, "relations": { diff --git a/back/models/province.json b/back/models/province.json index 77e0b24a6..61a1574d7 100644 --- a/back/models/province.json +++ b/back/models/province.json @@ -16,6 +16,9 @@ "name": { "type": "string", "required": true + }, + "autonomyFk": { + "type": "number" } }, "relations": { @@ -55,4 +58,4 @@ "permission": "ALLOW" } ] -} \ No newline at end of file +} diff --git a/db/routines/vn/procedures/client_create.sql b/db/routines/vn/procedures/client_create.sql index 3df3df905..fad01c107 100644 --- a/db/routines/vn/procedures/client_create.sql +++ b/db/routines/vn/procedures/client_create.sql @@ -34,22 +34,19 @@ BEGIN DECLARE vIsTaxDataChecked TINYINT(1); DECLARE vHasCoreVnl BOOLEAN; DECLARE vMandateTypeFk INT; - DECLARE vHasDailyInvoice BOOLEAN; SELECT cc.defaultPayMethodFk, cc.defaultDueDay, cc.defaultCredit, cc.defaultIsTaxDataChecked, cc.defaultHasCoreVnl, - cc.defaultMandateTypeFk, - c.hasDailyInvoice + cc.defaultMandateTypeFk INTO vPayMethodFk, vDueDay, vDefaultCredit, vIsTaxDataChecked, vHasCoreVnl, - vMandateTypeFk, - vHasDailyInvoice + vMandateTypeFk FROM clientConfig cc LEFT JOIN province p ON p.id = vProvinceFk LEFT JOIN country c ON c.id = p.countryFk; @@ -70,8 +67,7 @@ BEGIN credit = vDefaultCredit, isTaxDataChecked = vIsTaxDataChecked, hasCoreVnl = vHasCoreVnl, - isEqualizated = FALSE, - hasDailyInvoice = vHasDailyInvoice + isEqualizated = FALSE ON duplicate KEY UPDATE payMethodFk = vPayMethodFk, dueDay = vDueDay, diff --git a/db/routines/vn/procedures/ticket_close.sql b/db/routines/vn/procedures/ticket_close.sql index 0da001ffa..e2dcef9a5 100644 --- a/db/routines/vn/procedures/ticket_close.sql +++ b/db/routines/vn/procedures/ticket_close.sql @@ -43,7 +43,7 @@ BEGIN c.isTaxDataChecked, t.companyFk, t.shipped, - IFNULL(a.hasDailyInvoice, co.hasDailyInvoice), + c.hasDailyInvoice, w.isManaged, c.hasToInvoice INTO vClientFk, @@ -55,9 +55,6 @@ BEGIN vHasToInvoice FROM ticket t JOIN `client` c ON c.id = t.clientFk - JOIN province p ON p.id = c.provinceFk - LEFT JOIN autonomy a ON a.id = p.autonomyFk - JOIN country co ON co.id = p.countryFk JOIN warehouse w ON w.id = t.warehouseFk WHERE t.id = vCurTicketFk; @@ -85,7 +82,7 @@ BEGIN IF(vHasDailyInvoice) AND vHasToInvoice THEN SELECT invoiceSerial(vClientFk, vCompanyFk, 'quick') INTO vSerial; - IF vSerial IS NULL THEN + IF vSerial IS NULL THEN CALL util.throw('Cannot booking without a serial'); END IF; diff --git a/db/versions/11302-limeTulip/00-firstScript.sql b/db/versions/11302-limeTulip/00-firstScript.sql new file mode 100644 index 000000000..7bda31b64 --- /dev/null +++ b/db/versions/11302-limeTulip/00-firstScript.sql @@ -0,0 +1,13 @@ + +UPDATE `vn`.`client` c + JOIN `vn`.`country` co ON co.id=c.countryFk +SET c.hasDailyInvoice = co.hasDailyInvoice +WHERE co.hasDailyInvoice IS NOT NULL + AND c.hasDailyInvoice = FALSE; + +UPDATE `vn`.`client` c + JOIN `vn`.`province` p ON p.id=c.provinceFk + JOIN `vn`.`autonomy` a ON a.id = p.autonomyFk +SET c.hasDailyInvoice = a.hasDailyInvoice +WHERE a.hasDailyInvoice IS NOT NULL + AND c.hasDailyInvoice = FALSE; diff --git a/modules/client/back/methods/client/createWithUser.js b/modules/client/back/methods/client/createWithUser.js index 06b885ab8..c8cd282e1 100644 --- a/modules/client/back/methods/client/createWithUser.js +++ b/modules/client/back/methods/client/createWithUser.js @@ -43,6 +43,23 @@ module.exports = function(Self) { }; try { + const province = await models.Province.findOne({ + where: {id: data.provinceFk}, + fields: ['autonomyFk'] + }); + + const autonomy = province ? await models.Autonomy.findOne({ + where: {id: province.autonomyFk}, + fields: ['hasDailyInvoice'] + }) : null; + + const country = await models.Country.findOne({ + where: {id: data.countryFk}, + fields: ['hasDailyInvoice'] + }); + + const hasDailyInvoice = (autonomy?.hasDailyInvoice ?? country?.hasDailyInvoice) || false; + const account = await models.VnUser.create(user, myOptions); const client = await Self.create({ id: account.id, @@ -57,7 +74,8 @@ module.exports = function(Self) { provinceFk: data.provinceFk, countryFk: data.countryFk, isEqualizated: data.isEqualizated, - businessTypeFk: data.businessTypeFk + businessTypeFk: data.businessTypeFk, + hasDailyInvoice: hasDailyInvoice }, myOptions); const address = await models.Address.create({ diff --git a/modules/client/back/methods/client/specs/createWithUser.spec.js b/modules/client/back/methods/client/specs/createWithUser.spec.js index 5b1ff5da9..f47c24087 100644 --- a/modules/client/back/methods/client/specs/createWithUser.spec.js +++ b/modules/client/back/methods/client/specs/createWithUser.spec.js @@ -1,67 +1,79 @@ const models = require('vn-loopback/server/server').models; + describe('Client Create', () => { - const newAccount = { - userName: 'deadpool', - email: 'deadpool@marvel.com', - fi: '16195279J', - name: 'Wade', - socialName: 'DEADPOOL MARVEL', - street: 'WALL STREET', - city: 'New York', - businessTypeFk: 'florist', - provinceFk: 1 - }; - const newAccountWithoutEmail = JSON.parse(JSON.stringify(newAccount)); - delete newAccountWithoutEmail.email; + let options; + let tx; beforeAll.mockLoopBackContext(); - it(`should not find deadpool as he's not created yet`, async() => { - const tx = await models.Client.beginTransaction({}); + beforeEach(async() => { + tx = await models.Client.beginTransaction({}); + options = {transaction: tx}; + }); + afterEach(async() => await tx.rollback()); + + it('should not find deadpool as he is not created yet', async() => { try { - const options = {transaction: tx}; + const account = await models.VnUser.findOne({where: {name: 'deadpool'}}, options); + const client = await models.Client.findOne({where: {name: 'Wade'}}, options); - const account = await models.VnUser.findOne({where: {name: newAccount.userName}}, options); - const client = await models.Client.findOne({where: {name: newAccount.name}}, options); - - expect(account).toEqual(null); - expect(client).toEqual(null); - - await tx.rollback(); + expect(account).toBeNull(); + expect(client).toBeNull(); } catch (e) { await tx.rollback(); throw e; } }); - it('should not create a new account', async() => { - const tx = await models.Client.beginTransaction({}); - + it('should throw an error when creating a new account without email', async() => { let error; + const newAccountWithoutEmail = { + userName: 'deadpool', + fi: '16195279J', + name: 'Wade', + socialName: 'DEADPOOL MARVEL', + street: 'WALL STREET', + city: 'New York', + businessTypeFk: 'florist', + provinceFk: 1 + }; + try { - const options = {transaction: tx}; await models.Client.createWithUser(newAccountWithoutEmail, options); - - await tx.rollback(); + fail('shapoifaspodifa spdofij'); } catch (e) { - error = e.message; - - await tx.rollback(); + error = e; } - expect(error).toEqual(`An email is necessary`); + expect(error.message).toEqual('An email is necessary'); }); - it('should create a new account', async() => { - const tx = await models.Client.beginTransaction({}); + it('should create a new account with dailyInvoice', async() => { + const newAccount = { + userName: 'deadpool', + email: 'deadpool@marvel.com', + fi: '16195279J', + name: 'Wade', + socialName: 'DEADPOOL MARVEL', + street: 'WALL STREET', + city: 'New York', + businessTypeFk: 'florist', + provinceFk: 1 + }; try { - const options = {transaction: tx}; + const province = await models.Province.findById(newAccount.provinceFk, { + fields: ['id', 'name', 'autonomyFk'], + include: { + relation: 'autonomy' + } + }, options); const client = await models.Client.createWithUser(newAccount, options); const account = await models.VnUser.findOne({where: {name: newAccount.userName}}, options); + expect(province.autonomy().hasDailyInvoice).toBeTruthy(); expect(account.name).toEqual(newAccount.userName); expect(client.id).toEqual(account.id); expect(client.name).toEqual(newAccount.name); @@ -69,8 +81,38 @@ describe('Client Create', () => { expect(client.fi).toEqual(newAccount.fi); expect(client.socialName).toEqual(newAccount.socialName); expect(client.businessTypeFk).toEqual(newAccount.businessTypeFk); - + expect(client.hasDailyInvoice).toBeTruthy(); + } catch (e) { await tx.rollback(); + throw e; + } + }); + + it('should create a new account without dailyInvoice', async() => { + const newAccount = { + userName: 'deadpool', + email: 'deadpool@marvel.com', + fi: '16195279J', + name: 'Wade', + socialName: 'DEADPOOL MARVEL', + street: 'WALL STREET', + city: 'New York', + businessTypeFk: 'florist', + provinceFk: 3 + }; + + try { + const province = await models.Province.findById(newAccount.provinceFk, { + fields: ['id', 'name', 'autonomyFk'], + include: { + relation: 'autonomy' + } + }, options); + + const client = await models.Client.createWithUser(newAccount, options); + + expect(province.autonomy.hasDailyInvoice).toBeFalsy(); + expect(client.hasDailyInvoice).toBeFalsy(); } catch (e) { await tx.rollback(); throw e; @@ -78,26 +120,25 @@ describe('Client Create', () => { }); it('should not be able to create a user if exists', async() => { - const tx = await models.Client.beginTransaction({}); - let error; - + const newAccount = { + userName: 'deadpool', + email: 'deadpool@marvel.com', + fi: '16195279J', + name: 'Wade', + socialName: 'DEADPOOL MARVEL', + street: 'WALL STREET', + city: 'New York', + businessTypeFk: 'florist', + provinceFk: 1 + }; try { - const options = {transaction: tx}; - await models.Client.createWithUser(newAccount, options); - const client = await models.Client.createWithUser(newAccount, options); - - expect(client).toBeNull(); - - await tx.rollback(); + await models.Client.createWithUser(newAccount, options); } catch (e) { - await tx.rollback(); error = e; } - const errorName = error.details.codes.name[0]; - - expect(errorName).toEqual('uniqueness'); + expect(error.message).toContain('already exists'); }); }); diff --git a/modules/ticket/back/methods/ticket/closeAll.js b/modules/ticket/back/methods/ticket/closeAll.js index 4fd72d454..b9060d2f2 100644 --- a/modules/ticket/back/methods/ticket/closeAll.js +++ b/modules/ticket/back/methods/ticket/closeAll.js @@ -41,7 +41,7 @@ module.exports = Self => { c.salesPersonFk, c.isToBeMailed, c.hasToInvoice, - co.hasDailyInvoice, + c.hasDailyInvoice, eu.email salesPersonEmail, t.addressFk FROM ticket t @@ -120,7 +120,7 @@ module.exports = Self => { WHERE (al.code = 'PACKED' OR (am.code = 'refund' AND al.code <> 'delivered')) AND t.shipped BETWEEN ? - INTERVAL tc.closureDaysAgo DAY AND util.dayEnd(?) AND t.refFk IS NULL - AND IFNULL(a.hasDailyInvoice, co.hasDailyInvoice) + AND c.hasDailyInvoice GROUP BY ticketFk HAVING hasErrorToInvoice OR hasErrorTaxDataChecked diff --git a/modules/ticket/back/methods/ticket/closeByTicket.js b/modules/ticket/back/methods/ticket/closeByTicket.js index 40fe048a5..8a21267b6 100644 --- a/modules/ticket/back/methods/ticket/closeByTicket.js +++ b/modules/ticket/back/methods/ticket/closeByTicket.js @@ -50,7 +50,7 @@ module.exports = Self => { c.salesPersonFk, c.isToBeMailed, c.hasToInvoice, - co.hasDailyInvoice, + c.hasDailyInvoice, eu.email salesPersonEmail, t.addressFk FROM expedition e @@ -58,8 +58,6 @@ module.exports = Self => { JOIN ticketState ts ON ts.ticketFk = t.id JOIN alertLevel al ON al.id = ts.alertLevel JOIN client c ON c.id = t.clientFk - JOIN province p ON p.id = c.provinceFk - JOIN country co ON co.id = p.countryFk LEFT JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk WHERE al.code = 'PACKED' AND t.id = ? From aac4dd0a6d1719ccc9937faa67871b5dd205bc78 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 16 Oct 2024 08:52:27 +0200 Subject: [PATCH 09/12] feat: refs #7348 minor bug --- modules/client/back/methods/client/specs/createWithUser.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/client/back/methods/client/specs/createWithUser.spec.js b/modules/client/back/methods/client/specs/createWithUser.spec.js index f47c24087..8cff96ac5 100644 --- a/modules/client/back/methods/client/specs/createWithUser.spec.js +++ b/modules/client/back/methods/client/specs/createWithUser.spec.js @@ -41,7 +41,6 @@ describe('Client Create', () => { try { await models.Client.createWithUser(newAccountWithoutEmail, options); - fail('shapoifaspodifa spdofij'); } catch (e) { error = e; } From 681f82a3ae934f7834d1122ef2821241242f1771 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 16 Oct 2024 16:09:53 +0200 Subject: [PATCH 10/12] feat: refs #7744 test back ok --- .../back/methods/invoiceOut/delete.js | 8 ++--- modules/ticket/back/methods/ticket/closure.js | 3 +- .../methods/ticket/specs/closeAll.spec.js | 32 ++----------------- 3 files changed, 8 insertions(+), 35 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/delete.js b/modules/invoiceOut/back/methods/invoiceOut/delete.js index d6efd9961..1ab9a582b 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/delete.js +++ b/modules/invoiceOut/back/methods/invoiceOut/delete.js @@ -37,7 +37,7 @@ module.exports = Self => { const tickets = await models.Ticket.find({ where: {refFk: invoiceOut.ref} }, myOptions); - + const [bookEntry] = await models.Xdiario.find({ where: { SERIE: invoiceOut.ref[0], @@ -55,13 +55,13 @@ module.exports = Self => { if (bookEntry) { if (bookEntry.enlazadoSage) { const params = { - bookEntry: bookEntry.ASIEN, + bookEntry: bookEntry.ASIEN, invoiceOutRef: invoiceOut.ref - } + }; await Self.rawSql(`SELECT util.notification_send('book-entry-deleted', ?, NULL)`, [JSON.stringify(params)], myOptions); - }; + } await models.Xdiario.destroyAll({ ASIEN: bookEntry.ASIEN diff --git a/modules/ticket/back/methods/ticket/closure.js b/modules/ticket/back/methods/ticket/closure.js index 64f198834..e4cb49007 100644 --- a/modules/ticket/back/methods/ticket/closure.js +++ b/modules/ticket/back/methods/ticket/closure.js @@ -19,8 +19,7 @@ module.exports = async function(ctx, Self, tickets, options) { const failedtickets = []; for (const ticket of tickets) { try { - await Self.rawSql(`CALL util.debugAdd('invoicingTicket', ?)`, [ticket.id], {userId}, - myOptions); + await Self.rawSql(`CALL util.debugAdd('invoicingTicket', ?)`, [ticket.id], myOptions); await Self.app.models.InvoiceOut.getSerial( ticket.clientFk, diff --git a/modules/ticket/back/methods/ticket/specs/closeAll.spec.js b/modules/ticket/back/methods/ticket/specs/closeAll.spec.js index 4b067ce7e..f01541eec 100644 --- a/modules/ticket/back/methods/ticket/specs/closeAll.spec.js +++ b/modules/ticket/back/methods/ticket/specs/closeAll.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); -fdescribe('Ticket Closure - closeAll function', () => { +describe('Ticket Closure - closeAll function', () => { let ctx = { req: { getLocale: () => 'es', @@ -17,6 +17,7 @@ fdescribe('Ticket Closure - closeAll function', () => { beforeEach(async() => { spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({active: ctx.req}); + tx = await models.Ticket.beginTransaction({}); options = {transaction: tx}; originalVnNew = Date.vnNew; @@ -32,34 +33,7 @@ fdescribe('Ticket Closure - closeAll function', () => { await tx.rollback(); }); - xit('should successfully close all tickets when conditions are met', async() => { - const ticketsBefore = await models.Ticket.find({ - where: { - packages: {neq: 0} - } - }, options); - const packedTicketsIds = ticketsBefore.map(ticket => ticket.id); - - const packedTicketsBefore = await models.TicketLastState.find({ - where: { - ticketFk: {inq: packedTicketsIds}, - lastState: 'Encajado' - } - }, options); - - await models.Ticket.closeAll(ctx, options); - - const packedTicketsAfter = await models.TicketLastState.find({ - where: { - ticketFk: {inq: packedTicketsIds}, - lastState: 'Encajado' - } - }, options); - - expect(packedTicketsBefore.length).toBeGreaterThan(packedTicketsAfter.length); - }); - - fit('should set routeFk to NULL when conditions are met', async() => { + it('should set routeFk to NULL when conditions are met', async() => { const ticketsBefore = await models.Ticket.find({ where: { routeFk: {neq: null} From faecbbb3735034876e7544891fc63702e089b0ad Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 17 Oct 2024 13:08:58 +0200 Subject: [PATCH 11/12] feat: refs #8108 saltos de linea --- db/versions/11300-limeMedeola/00-firstScript.sql | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/db/versions/11300-limeMedeola/00-firstScript.sql b/db/versions/11300-limeMedeola/00-firstScript.sql index 313a65e81..28b033b4a 100644 --- a/db/versions/11300-limeMedeola/00-firstScript.sql +++ b/db/versions/11300-limeMedeola/00-firstScript.sql @@ -13,8 +13,6 @@ UPDATE vn.tag sourceTable='itemFarmingTag' WHERE name= 'cultivo'; - - CREATE TABLE IF NOT EXISTS `vn`.`itemWrappingTag` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, @@ -36,8 +34,6 @@ UPDATE vn.tag sourceTable='itemWrappingTag' WHERE name= 'Envoltorio'; - - CREATE TABLE IF NOT EXISTS `vn`.`itemLanguageTag` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, @@ -59,8 +55,6 @@ UPDATE vn.tag sourceTable='itemLanguageTag' WHERE name= 'Idioma'; - - CREATE TABLE IF NOT EXISTS `vn`.`itemStemTag` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, @@ -94,8 +88,6 @@ UPDATE vn.tag sourceTable='itemBreederTag' WHERE name= 'Obtentor'; - - CREATE TABLE IF NOT EXISTS `vn`.`itemBaseTag` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, @@ -120,8 +112,6 @@ UPDATE vn.tag sourceTable='itemBaseTag' WHERE name= 'Soporte'; - - CREATE TABLE IF NOT EXISTS `vn`.`itemVatRateTag` ( `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, @@ -133,13 +123,11 @@ CREATE TABLE IF NOT EXISTS `vn`.`itemVatRateTag` ( INSERT IGNORE INTO `vn`.`itemVatRateTag` (`name`) VALUES ('General'); INSERT IGNORE INTO `vn`.`itemVatRateTag` (`name`) VALUES ('Reducido'); - UPDATE vn.tag SET isFree=0, sourceTable='itemVatRateTag' WHERE name= 'Tipo de IVA'; - GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemFarmingTag TO logisticAssist; GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemWrappingTag TO logisticAssist; GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE vn.itemLanguageTag TO logisticAssist; From bbc17d1ff886898b90cb2a75d33d8598665fcb27 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 21 Oct 2024 08:33:16 +0200 Subject: [PATCH 12/12] fix: refs #230926 item_getSimilar --- db/routines/vn/procedures/item_getSimilar.sql | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/item_getSimilar.sql b/db/routines/vn/procedures/item_getSimilar.sql index 537f53848..336f3521e 100644 --- a/db/routines/vn/procedures/item_getSimilar.sql +++ b/db/routines/vn/procedures/item_getSimilar.sql @@ -24,6 +24,7 @@ BEGIN CALL cache.available_refresh(vAvailableCalcFk, FALSE, vWarehouseFk, vDated); CALL cache.visible_refresh(vVisibleCalcFk, FALSE, vWarehouseFk); + CALL buy_getUltimate(NULL, vWarehouseFk, vDated); WITH itemTags AS ( SELECT i.id, @@ -74,14 +75,13 @@ BEGIN AND a.calc_id = vAvailableCalcFk LEFT JOIN cache.visible v ON v.item_id = i.id AND v.calc_id = vVisibleCalcFk - LEFT JOIN cache.last_buy lb ON lb.item_id = i.id - AND lb.warehouse_id = vWarehouseFk + LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = i.id LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vSelf LEFT JOIN vn.itemTag it ON it.itemFk = i.id AND it.priority = vPriority LEFT JOIN vn.tag t ON t.id = it.tagFk - LEFT JOIN vn.buy b ON b.id = lb.buy_id + LEFT JOIN vn.buy b ON b.id = bu.buyFk JOIN itemTags its WHERE a.available > 0 AND (i.typeFk = its.typeFk OR NOT vShowType) @@ -98,5 +98,7 @@ BEGIN (i.tag8 = its.tag8) DESC, match8 DESC LIMIT 100; + + DROP TEMPORARY TABLE tmp.buyUltimate; END$$ DELIMITER ;