From 961fafb33e4c3e204e8e5a43ceebf8a0ccf41ec8 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 5 Aug 2024 15:32:36 +0200 Subject: [PATCH 01/18] feat: refs #7404 stockBought add and calculate --- back/models/buyer.json | 3 + db/dump/fixtures.before.sql | 17 ++++++ .../vn/procedures/stockBought_calculate.sql | 54 ++++++++++++++++++ db/routines/vn/views/buyer.sql | 4 +- .../11115-turquoiseRose/00-firstScript.sql | 30 ++++++++++ loopback/locale/en.json | 8 ++- loopback/locale/es.json | 5 +- .../account/back/models/mail-alias-account.js | 1 + modules/entry/back/methods/entry/filter.js | 1 - .../methods/stock-bought/getStockBought.js | 52 +++++++++++++++++ .../stock-bought/getStockBoughtDetail.js | 56 +++++++++++++++++++ modules/entry/back/model-config.json | 3 + modules/entry/back/models/stock-bought.js | 10 ++++ modules/entry/back/models/stock-bought.json | 34 +++++++++++ 14 files changed, 272 insertions(+), 6 deletions(-) create mode 100644 db/routines/vn/procedures/stockBought_calculate.sql create mode 100644 db/versions/11115-turquoiseRose/00-firstScript.sql create mode 100644 modules/entry/back/methods/stock-bought/getStockBought.js create mode 100644 modules/entry/back/methods/stock-bought/getStockBoughtDetail.js create mode 100644 modules/entry/back/models/stock-bought.js create mode 100644 modules/entry/back/models/stock-bought.json diff --git a/back/models/buyer.json b/back/models/buyer.json index a17d3b538..a1297eda3 100644 --- a/back/models/buyer.json +++ b/back/models/buyer.json @@ -15,6 +15,9 @@ "nickname": { "type": "string", "required": true + }, + "display": { + "type": "boolean" } }, "acls": [ diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index f800a1da1..7f3ede501 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3882,3 +3882,20 @@ INSERT INTO `vn`.`calendarHolidays` (calendarHolidaysTypeFk, dated, calendarHoli (1, '2001-05-17', 1, 5), (1, '2001-05-18', 1, 5); +INSERT INTO vn.stockBought (workerFk, bought, reserve, dated) + VALUES(35, 1.00, 1.00, '2001-01-01'); + +INSERT INTO vn.auctionConfig (id,conversionCoefficient,warehouseFk) + VALUES (1,0.6,6); + +INSERT INTO vn.warehouse (id,name,isFeedStock,delay,hasAvailable,isForTicket,countryFk,labelZone,hasComission,isInventory,isComparative,valuatedInventory,isManaged,hasConfectionTeam,hasStowaway,hasDms,isBuyerToBeEmailed,hasUbications,hasProduction,hasMachine,isLogiflora,isBionic,isHalt,isOrigin,isDestiny) + VALUES (6,'Warehouse six',0,0.004,1,0,1,0,0,1,1,0,1,0,0,0,0,1,1,0,0,1,0,0,0); + +INSERT INTO vn.travel (id,shipped,landed,warehouseInFk,warehouseOutFk,agencyFk__,`ref`,isDelivered,isReceived,m3,kg,cargoSupplierFk,totalEntries,agencyModeFk,editorFk,awbFk) + VALUES (11,'2001-01-01','2001-01-02',6,3,0,'eleventh travel',0,0,50.00,500,2,0,1,100,4); + +INSERT INTO vn.entry (id,supplierFk,invoiceNumber,isBooked,isExcludedFromAvailable,isConfirmed,isOrdered,isRaid,commission,created,evaNotes,travelFk,currencyFk,companyFk,isBlocked__,reference,editorFk,locked) + VALUES (9,69,'IN2009',0,1,0,0,1,0.0,'2000-12-01 00:00:00.000','',11,1,442,0,'Movement 9',100,'2024-07-30 08:13:49.000'); + +INSERT INTO vn.buy (entryFk,itemFk,quantity,dispatched,buyingValue,freightValue,isIgnored,stickers,packing,`grouping`,groupingMode,comissionValue,packageValue,packagingFk,price1,price2,price3,minPrice,printedStickers,workerFk,isChecked,isPickedOff,created,`__cm2`,weight,itemOriginalFk,editorFk,buyerFk) + VALUES (9,1,5000,0,50.0000,1.500,0,1,1,1,'packing',0.000,1.500,'4',0.00,99.60,99.40,0.00,0,0,1,0,'2024-07-30 08:13:51.000',0,1.00,1,100,35); diff --git a/db/routines/vn/procedures/stockBought_calculate.sql b/db/routines/vn/procedures/stockBought_calculate.sql new file mode 100644 index 000000000..54ac78d8e --- /dev/null +++ b/db/routines/vn/procedures/stockBought_calculate.sql @@ -0,0 +1,54 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`stockBought_calculate`() +BEGIN +/** + * Inserts the purchase volume per buyer + * into stockBought according to the date. + * + * @param vDated Purchase date + */ + DECLARE vDated DATE; + SET vDated = util.VN_CURDATE(); + + CREATE OR REPLACE TEMPORARY TABLE tStockBought + SELECT workerFk, reserve + FROM stockBought + WHERE dated = vDated + AND reserve; + + DELETE FROM stockBought WHERE dated = vDated; + + INSERT INTO stockBought (workerFk, bought, dated) + SELECT it.workerFk, + ROUND(SUM( + (ac.conversionCoefficient * + (b.quantity / b.packing) * + buy_getVolume(b.id) + ) / (vc.trolleyM3 * 1000000) + ), 1), + vDated + FROM entry e + JOIN travel t ON t.id = e.travelFk + JOIN warehouse w ON w.id = t.warehouseInFk + JOIN buy b ON b.entryFk = e.id + JOIN item i ON i.id = b.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN auctionConfig ac + JOIN volumeConfig vc + WHERE t.shipped = vDated + AND t.warehouseInFk = ac.warehouseFk + GROUP BY it.workerFk; + + UPDATE stockBought s + JOIN tStockBought ts ON ts.workerFk = s.workerFk + SET s.reserve = ts.reserve + WHERE s.dated = vDated; + + INSERT INTO stockBought (workerFk, reserve, dated) + SELECT ts.workerFk, ts.reserve, vDated + FROM tStockBought ts + WHERE ts.workerFk NOT IN (SELECT workerFk FROM stockBought WHERE dated = vDated); + + DROP TEMPORARY TABLE tStockBought; +END$$ +DELIMITER ; diff --git a/db/routines/vn/views/buyer.sql b/db/routines/vn/views/buyer.sql index 7114c50bc..455c68770 100644 --- a/db/routines/vn/views/buyer.sql +++ b/db/routines/vn/views/buyer.sql @@ -2,10 +2,12 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vn`.`buyer` AS SELECT DISTINCT `u`.`id` AS `userFk`, - `u`.`nickname` AS `nickname` + `u`.`nickname` AS `nickname`, + `ic`.`display` AS `display` FROM ( `account`.`user` `u` JOIN `vn`.`itemType` `it` ON(`it`.`workerFk` = `u`.`id`) + JOIN `vn`.`itemCategory` `ic` ON(`ic`.`id` = `it`.`categoryFk`) ) WHERE `u`.`active` <> 0 ORDER BY `u`.`nickname` diff --git a/db/versions/11115-turquoiseRose/00-firstScript.sql b/db/versions/11115-turquoiseRose/00-firstScript.sql new file mode 100644 index 000000000..3982936fc --- /dev/null +++ b/db/versions/11115-turquoiseRose/00-firstScript.sql @@ -0,0 +1,30 @@ +-- Place your SQL code here +-- vn.stockBought definition + +CREATE TABLE IF NOT EXISTS vn.stockBought ( + id INT UNSIGNED auto_increment NOT NULL, + workerFk int(10) unsigned NOT NULL, + bought decimal(10,2) NOT NULL COMMENT 'purchase volume in m3 for the day', + reserve decimal(10,2) NULL COMMENT 'reserved volume in m3 for the day', + dated DATE NOT NULL DEFAULT current_timestamp(), + CONSTRAINT stockBought_pk PRIMARY KEY (id), + CONSTRAINT stockBought_unique UNIQUE KEY (workerFk,dated), + CONSTRAINT stockBought_worker_FK FOREIGN KEY (workerFk) REFERENCES vn.worker(id) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; + + +INSERT IGNORE vn.stockBought (workerFk, bought, reserve, dated) + SELECT userFk, SUM(buyed), SUM(IFNULL(reserved,0)), dated + FROM vn.stockBuyed + WHERE userFk IS NOT NULL + AND buyed IS NOT NULL + GROUP BY userFk, dated; + +INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId) + VALUES ('StockBought','*','READ','ALLOW','ROLE','buyer'), + ('StockBought','*','WRITE','ALLOW','ROLE','buyer'), + ('Buyer','*','READ','ALLOW','ROLE','buyer'); + diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 1e5733442..79f7eecc5 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -233,5 +233,9 @@ "It has been invoiced but the PDF could not be generated": "It has been invoiced but the PDF could not be generated", "It has been invoiced but the PDF of refund not be generated": "It has been invoiced but the PDF of refund not be generated", "Cannot add holidays on this day": "Cannot add holidays on this day", - "Cannot send mail": "Cannot send mail" -} + "Cannot send mail": "Cannot send mail", + "Payment method is required": "Payment method is required", + "This worker already exists": "This worker already exists", + "This personal mail already exists": "This personal mail already exists", + "This buyer has already made a reservation for this date": "This buyer has already made a reservation for this date" +} \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 5b5928993..a11fb6f7c 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -366,5 +366,6 @@ "It has been invoiced but the PDF could not be generated": "Se ha facturado pero no se ha podido generar el PDF", "It has been invoiced but the PDF of refund not be generated": "Se ha facturado pero no se ha podido generar el PDF del abono", "Payment method is required": "El método de pago es obligatorio", - "Cannot send mail": "Não é possível enviar o email" -} + "Cannot send mail": "Não é possível enviar o email", + "This buyer has already made a reservation for this date": "This buyer has already made a reservation for this date" +} \ No newline at end of file diff --git a/modules/account/back/models/mail-alias-account.js b/modules/account/back/models/mail-alias-account.js index 61ca344e9..0eee6a123 100644 --- a/modules/account/back/models/mail-alias-account.js +++ b/modules/account/back/models/mail-alias-account.js @@ -1,5 +1,6 @@ const ForbiddenError = require('vn-loopback/util/forbiddenError'); +const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.rewriteDbError(function(err) { diff --git a/modules/entry/back/methods/entry/filter.js b/modules/entry/back/methods/entry/filter.js index 1cd12b737..a8a9d4de1 100644 --- a/modules/entry/back/methods/entry/filter.js +++ b/modules/entry/back/methods/entry/filter.js @@ -1,4 +1,3 @@ - const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; const buildFilter = require('vn-loopback/util/filter').buildFilter; const mergeFilters = require('vn-loopback/util/filter').mergeFilters; diff --git a/modules/entry/back/methods/stock-bought/getStockBought.js b/modules/entry/back/methods/stock-bought/getStockBought.js new file mode 100644 index 000000000..da194ed80 --- /dev/null +++ b/modules/entry/back/methods/stock-bought/getStockBought.js @@ -0,0 +1,52 @@ +module.exports = Self => { + Self.remoteMethod('getStockBought', { + description: 'Returns the stock bought for a given date', + accessType: 'READ', + accepts: [{ + arg: 'dated', + type: 'date', + description: 'The date to filter', + } + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/getStockBought`, + verb: 'GET' + } + }); + + Self.getStockBought = async(dated = Date.vnNew()) => { + const models = Self.app.models; + const today = Date.vnNew(); + dated.setHours(0, 0, 0, 0); + today.setHours(0, 0, 0, 0); + + if (dated.getTime() === today.getTime()) + await models.StockBought.rawSql(`CALL vn.stockBought_calculate()`); + + return models.StockBought.find( + { + where: { + dated: dated + }, + include: [ + { + relation: 'worker', + scope: { + include: [ + { + relation: 'user', + scope: { + fields: ['id', 'name'] + } + } + ] + } + } + ] + }); + }; +}; diff --git a/modules/entry/back/methods/stock-bought/getStockBoughtDetail.js b/modules/entry/back/methods/stock-bought/getStockBoughtDetail.js new file mode 100644 index 000000000..471d5c9c4 --- /dev/null +++ b/modules/entry/back/methods/stock-bought/getStockBoughtDetail.js @@ -0,0 +1,56 @@ +module.exports = Self => { + Self.remoteMethod('getStockBoughtDetail', { + description: 'Returns the detail of stock bought for a given date and a worker', + accessType: 'READ', + accepts: [{ + arg: 'workerFk', + type: 'number', + description: 'The worker to filter', + required: true, + }, { + arg: 'dated', + type: 'string', + description: 'The date to filter', + } + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/getStockBoughtDetail`, + verb: 'GET' + } + }); + + Self.getStockBoughtDetail = async(workerFk, dated = Date.vnNew()) => { + console.log('dated: ', new Date(dated)); + console.log('new Date(dated).setHours(0, 0, 0, 0): ', new Date(dated).setHours(0, 0, 0, 0)); + return Self.rawSql( + `SELECT e.id entryFk, + i.id itemFk, + i.longName itemName, + b.quantity, + ROUND((ac.conversionCoefficient * + (b.quantity / b.packing) * + buy_getVolume(b.id) + ) / (vc.trolleyM3 * 1000000), + 2 + ) volume, + b.packagingFk, + b.packing + FROM entry e + JOIN travel t ON t.id = e.travelFk + JOIN buy b ON b.entryFk = e.id + JOIN item i ON i.id = b.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN worker w ON w.id = it.workerFk + JOIN auctionConfig ac + JOIN volumeConfig vc + WHERE t.warehouseInFk = ac.warehouseFk + AND it.workerFk = ? + AND t.shipped = ?`, + [workerFk, new Date(dated)] + ); + }; +}; diff --git a/modules/entry/back/model-config.json b/modules/entry/back/model-config.json index dc7fd86be..85f5e8285 100644 --- a/modules/entry/back/model-config.json +++ b/modules/entry/back/model-config.json @@ -25,5 +25,8 @@ }, "EntryType": { "dataSource": "vn" + }, + "StockBought": { + "dataSource": "vn" } } \ No newline at end of file diff --git a/modules/entry/back/models/stock-bought.js b/modules/entry/back/models/stock-bought.js new file mode 100644 index 000000000..ae52e7654 --- /dev/null +++ b/modules/entry/back/models/stock-bought.js @@ -0,0 +1,10 @@ +const UserError = require('vn-loopback/util/user-error'); +module.exports = Self => { + require('../methods/stock-bought/getStockBought')(Self); + require('../methods/stock-bought/getStockBoughtDetail')(Self); + Self.rewriteDbError(function(err) { + if (err.code === 'ER_DUP_ENTRY') + return new UserError(`This buyer has already made a reservation for this date`); + return err; + }); +}; diff --git a/modules/entry/back/models/stock-bought.json b/modules/entry/back/models/stock-bought.json new file mode 100644 index 000000000..18c9f0347 --- /dev/null +++ b/modules/entry/back/models/stock-bought.json @@ -0,0 +1,34 @@ +{ + "name": "StockBought", + "base": "VnModel", + "options": { + "mysql": { + "table": "stockBought" + } + }, + "properties": { + "id": { + "type": "number", + "id": true + }, + "workerFk": { + "type": "number" + }, + "bought": { + "type": "number" + }, + "reserve": { + "type": "number" + }, + "dated": { + "type": "date" + } + }, + "relations": { + "worker": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "workerFk" + } + } +} From 47543d5760cdfcb848eaaacb5b4f094b687d8c2e Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 5 Aug 2024 15:34:01 +0200 Subject: [PATCH 02/18] refactor: refs #7404 remove console.log --- modules/entry/back/methods/stock-bought/getStockBoughtDetail.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/entry/back/methods/stock-bought/getStockBoughtDetail.js b/modules/entry/back/methods/stock-bought/getStockBoughtDetail.js index 471d5c9c4..0657fcb9a 100644 --- a/modules/entry/back/methods/stock-bought/getStockBoughtDetail.js +++ b/modules/entry/back/methods/stock-bought/getStockBoughtDetail.js @@ -24,8 +24,6 @@ module.exports = Self => { }); Self.getStockBoughtDetail = async(workerFk, dated = Date.vnNew()) => { - console.log('dated: ', new Date(dated)); - console.log('new Date(dated).setHours(0, 0, 0, 0): ', new Date(dated).setHours(0, 0, 0, 0)); return Self.rawSql( `SELECT e.id entryFk, i.id itemFk, From 6d25cb3c8c1e4a89ecbe133759519f67578cdda7 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 5 Aug 2024 15:35:48 +0200 Subject: [PATCH 03/18] fix: refs #7404 fix translation --- loopback/locale/es.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index a11fb6f7c..4c7df3e0c 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -366,6 +366,6 @@ "It has been invoiced but the PDF could not be generated": "Se ha facturado pero no se ha podido generar el PDF", "It has been invoiced but the PDF of refund not be generated": "Se ha facturado pero no se ha podido generar el PDF del abono", "Payment method is required": "El método de pago es obligatorio", - "Cannot send mail": "Não é possível enviar o email", + "Cannot send mail": "No se ha podido enviar el correo", "This buyer has already made a reservation for this date": "This buyer has already made a reservation for this date" } \ No newline at end of file From 0e7272f911d2c2214ae16e0a8d852f95092eb336 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 5 Aug 2024 15:42:21 +0200 Subject: [PATCH 04/18] fix: refs #7404 fix error message --- modules/entry/back/methods/entry/print.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/entry/back/methods/entry/print.js b/modules/entry/back/methods/entry/print.js index c155c3d8b..626e212b7 100644 --- a/modules/entry/back/methods/entry/print.js +++ b/modules/entry/back/methods/entry/print.js @@ -52,7 +52,7 @@ module.exports = Self => { await merger.add(new Uint8Array(pdfBuffer[0])); } - if (!merger._doc) throw new UserError('The entry not have stickers'); + if (!merger._doc) throw new UserError('The entry does not have stickers'); return [await merger.saveAsBuffer(), 'application/pdf', `filename="entry-${id}.pdf"`]; }; }; From 323ab638d79abbc5228d9c152305bf8fe6043af8 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 5 Aug 2024 15:55:44 +0200 Subject: [PATCH 05/18] fix: refs #7404 fix fixtures and back test --- db/dump/fixtures.before.sql | 51 ++++++++----------- .../back/methods/entry/specs/filter.spec.js | 4 +- .../travel/specs/extraCommunityFilter.spec.js | 4 +- .../back/methods/travel/specs/filter.spec.js | 4 +- 4 files changed, 26 insertions(+), 37 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index a0f2537d1..69d838998 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3929,44 +3929,33 @@ INSERT INTO vn.travel (id,shipped,landed,warehouseInFk,warehouseOutFk,agencyFk__ VALUES (11,'2001-01-01','2001-01-02',6,3,0,'eleventh travel',0,0,50.00,500,2,0,1,100,4); INSERT INTO vn.entry (id,supplierFk,invoiceNumber,isBooked,isExcludedFromAvailable,isConfirmed,isOrdered,isRaid,commission,created,evaNotes,travelFk,currencyFk,companyFk,isBlocked__,reference,editorFk,locked) - VALUES (9,69,'IN2009',0,1,0,0,1,0.0,'2000-12-01 00:00:00.000','',11,1,442,0,'Movement 9',100,'2024-07-30 08:13:49.000'); + VALUES (99,69,'IN2009',0,1,0,0,1,0.0,'2000-12-01 00:00:00.000','',11,1,442,0,'Movement 9',100,'2024-07-30 08:13:49.000'); INSERT INTO vn.buy (entryFk,itemFk,quantity,dispatched,buyingValue,freightValue,isIgnored,stickers,packing,`grouping`,groupingMode,comissionValue,packageValue,packagingFk,price1,price2,price3,minPrice,printedStickers,workerFk,isChecked,isPickedOff,created,`__cm2`,weight,itemOriginalFk,editorFk,buyerFk) - VALUES (9,1,5000,0,50.0000,1.500,0,1,1,1,'packing',0.000,1.500,'4',0.00,99.60,99.40,0.00,0,0,1,0,'2024-07-30 08:13:51.000',0,1.00,1,100,35); -INSERT INTO vn.payrollComponent -(id, name, isSalaryAgreed, isVariable, isException) - VALUES - (1, 'Salario1', 1, 0, 0), + VALUES (99,1,5000,0,50.0000,1.500,0,1,1,1,'packing',0.000,1.500,'4',0.00,99.60,99.40,0.00,0,0,1,0,'2024-07-30 08:13:51.000',0,1.00,1,100,35); + +INSERT INTO vn.payrollComponent (id, name, isSalaryAgreed, isVariable, isException) + VALUES (1, 'Salario1', 1, 0, 0), (2, 'Salario2', 1, 1, 0), (3, 'Salario3', 1, 0, 1); - -INSERT INTO vn.workerIncome -(debit, credit, incomeTypeFk, paymentDate, workerFk, concept) - VALUES - (1000.00, 900.00, 2, '2000-01-01', 1106, NULL), +INSERT INTO vn.workerIncome (debit, credit, incomeTypeFk, paymentDate, workerFk, concept) + VALUES (1000.00, 900.00, 2, '2000-01-01', 1106, NULL), (1001.00, 800.00, 2, '2000-01-01', 1106, NULL); +INSERT INTO dipole.printer (id, description) VALUES(1, ''); -INSERT INTO dipole.printer (id, description) -VALUES(1, ''); +INSERT INTO dipole.expedition_PrintOut (expeditionFk, ticketFk, addressFk, street, postalCode, city, shopName, isPrinted, created, printerFk, routeFk, parkingCode, truckName, clientFk, phone, province, agency, m3, workerCode, itemFk, quantity, longName, shelvingFk, comments) + VALUES(1, 1, 0, ' ', ' ', ' ', ' ', 0, '2001-01-01 00:00:00', 1, 0, ' ', ' ', 0, NULL, '', NULL, 0.000, NULL, 10, NULL, NULL, 'NCC', NULL); -INSERT INTO dipole.expedition_PrintOut (expeditionFk, ticketFk, addressFk, street, postalCode, city, shopName, isPrinted, created, printerFk, routeFk, parkingCode, -truckName, clientFk, phone, province, agency, m3, workerCode, itemFk, quantity, longName, shelvingFk, comments) -VALUES(1, 1, 0, ' ', ' ', ' ', ' ', 0, '2001-01-01 00:00:00', 1, 0, ' ', ' ', 0, NULL, '', NULL, 0.000, NULL, 10, NULL, NULL, 'NCC', NULL); +INSERT INTO vn.accountDetail (id, value, accountDetailTypeFk, supplierAccountFk) + VALUES (21, 'ES12345B12345678', 3, 241), + (35, 'ES12346B12345679', 3, 241); -INSERT INTO vn.accountDetail -(id, value, accountDetailTypeFk, supplierAccountFk) -VALUES - (21, 'ES12345B12345678', 3, 241), - (35, 'ES12346B12345679', 3, 241); - -INSERT INTO vn.accountDetailType -(id, description) -VALUES - (1, 'IBAN'), - (2, 'SWIFT'), - (3, 'Referencia Remesas'), - (4, 'Referencia Transferencias'), - (5, 'Referencia Nominas'), - (6, 'ABA'); +INSERT INTO vn.accountDetailType (id, description) + VALUES (1, 'IBAN'), + (2, 'SWIFT'), + (3, 'Referencia Remesas'), + (4, 'Referencia Transferencias'), + (5, 'Referencia Nominas'), + (6, 'ABA'); diff --git a/modules/entry/back/methods/entry/specs/filter.spec.js b/modules/entry/back/methods/entry/specs/filter.spec.js index c7156062a..145da170a 100644 --- a/modules/entry/back/methods/entry/specs/filter.spec.js +++ b/modules/entry/back/methods/entry/specs/filter.spec.js @@ -39,7 +39,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(11); + expect(result.length).toEqual(12); await tx.rollback(); } catch (e) { @@ -131,7 +131,7 @@ describe('Entry filter()', () => { const result = await models.Entry.filter(ctx, options); - expect(result.length).toEqual(10); + expect(result.length).toEqual(11); await tx.rollback(); } catch (e) { diff --git a/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js b/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js index 7e90c7681..97e1e5e77 100644 --- a/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js +++ b/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js @@ -79,7 +79,7 @@ describe('Travel extraCommunityFilter()', () => { const result = await app.models.Travel.extraCommunityFilter(ctx, filter); - expect(result.length).toEqual(9); + expect(result.length).toEqual(10); }); it('should return the travel matching "cargoSupplierFk"', async() => { @@ -110,6 +110,6 @@ describe('Travel extraCommunityFilter()', () => { const result = await app.models.Travel.extraCommunityFilter(ctx, filter); - expect(result.length).toEqual(2); + expect(result.length).toEqual(3); }); }); diff --git a/modules/travel/back/methods/travel/specs/filter.spec.js b/modules/travel/back/methods/travel/specs/filter.spec.js index a608a980e..2b6885cae 100644 --- a/modules/travel/back/methods/travel/specs/filter.spec.js +++ b/modules/travel/back/methods/travel/specs/filter.spec.js @@ -68,7 +68,7 @@ describe('Travel filter()', () => { const result = await app.models.Travel.filter(ctx); - expect(result.length).toEqual(1); + expect(result.length).toEqual(2); }); it('should return the travel matching "continent"', async() => { @@ -80,6 +80,6 @@ describe('Travel filter()', () => { const result = await app.models.Travel.filter(ctx); - expect(result.length).toEqual(6); + expect(result.length).toEqual(7); }); }); From b636b5429aa0d892c73cffa88551d1fb29b9982a Mon Sep 17 00:00:00 2001 From: pablone Date: Fri, 9 Aug 2024 08:20:42 +0200 Subject: [PATCH 06/18] fix: refs #7404 refactor fixtures --- db/dump/fixtures.before.sql | 44 ++++++++++++++----------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 69d838998..63be254d3 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -178,12 +178,12 @@ INSERT INTO `vn`.`country`(`id`, `name`, `isUeeMember`, `code`, `currencyFk`, `i (30,'Canarias', 1, 'IC', 1, 24, 4, 1, 2); INSERT INTO `vn`.`warehouse`(`id`, `name`, `code`, `isComparative`, `isInventory`, `hasAvailable`, `isManaged`, `hasDms`, `hasComission`, `countryFk`, `hasProduction`, `isOrigin`, `isDestiny`) - VALUES - (1, 'Warehouse One', 'ALG', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), + VALUES (1, 'Warehouse One', 'ALG', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), (2, 'Warehouse Two', NULL, 1, 1, 1, 1, 0, 1, 13, 1, 1, 0), (3, 'Warehouse Three', NULL, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0), (4, 'Warehouse Four', NULL, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1), (5, 'Warehouse Five', NULL, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0), + (6, 'Warehouse six', NULL, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0), (13, 'Inventory', 'inv', 1, 1, 1, 0, 0, 0, 1, 0, 0, 0), (60, 'Algemesi', NULL, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0); @@ -1492,16 +1492,16 @@ INSERT INTO `vn`.`awb` (id, code, package, weight, created, amount, transitoryFk (10, '07546500856', 185, 2364, util.VN_CURDATE(), 5321, 442, 1); INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseOutFk`, `agencyModeFk`, `m3`, `kg`,`ref`, `totalEntries`, `cargoSupplierFk`, `awbFK`) - VALUES - (1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 2, 1, 100.00, 1000, 'first travel', 1, 1, 1), - (2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 2, 1, 150, 2000, 'second travel', 2, 2, 2), - (3, util.VN_CURDATE(), util.VN_CURDATE(), 1, 2, 1, 0.00, 0.00, 'third travel', 1, 1, 3), - (4, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 3, 1, 50.00, 500, 'fourth travel', 0, 2, 4), - (5, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 3, 1, 50.00, 500, 'fifth travel', 1, 1, 5), - (6, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 4, 1, 50.00, 500, 'sixth travel', 1, 2, 6), - (7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1, 7), - (8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2, 10), - (10, DATE_ADD(util.VN_CURDATE(), INTERVAL + 5 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL + 5 DAY), 5, 1, 1, 50.00, 500, 'nineth travel', 1, 2, 10); + VALUES (1, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 2, 1, 100.00, 1000, 'first travel', 1, 1, 1), + (2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 2, 1, 150.00, 2000, 'second travel', 2, 2, 2), + (3, util.VN_CURDATE(), util.VN_CURDATE(), 1, 2, 1, 0.00, 0.00, 'third travel', 1, 1, 3), + (4, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 3, 1, 50.00, 500, 'fourth travel', 0, 2, 4), + (5, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 3, 1, 50.00, 500, 'fifth travel', 1, 1, 5), + (6, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 4, 1, 50.00, 500, 'sixth travel', 1, 2, 6), + (7, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 4, 1, 50.00, 500, 'seventh travel', 2, 1, 7), + (8, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 5, 1, 1, 50.00, 500, 'eight travel', 1, 2, 10), + (10, DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL +5 DAY), 5, 1, 1, 50.00, 500, 'nineth travel', 1, 2, 10), + (11, util.VN_CURDATE() , util.VN_CURDATE() + INTERVAL 1 DAY, 6, 3, 0, 50.00, 500, 'eleventh travel', 1, 2, 4); INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `invoiceNumber`, `reference`, `isExcludedFromAvailable`, `isRaid`, `evaNotes`) VALUES @@ -1514,7 +1514,8 @@ INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed (7, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2007', 'Movement 7', 0, 0, 'observation seven'), (8, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'IN2008', 'Movement 8', 1, 1, ''), (9, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 9', 1, 1, ''), - (10, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 9', 1, 1, ''); + (10, 2, DATE_ADD(util.VN_CURDATE(), INTERVAL +2 DAY), 10, 0, 442, 'IN2009', 'Movement 10', 1, 1, ''), + (99, 69, '2000-12-01 00:00:00.000', 11, 0, 442, 'IN2009', 'Movement 99', 1, 1, ''); INSERT INTO `bs`.`waste`(`buyerFk`, `year`, `week`, `itemFk`, `itemTypeFk`, `saleTotal`, `saleQuantity`, `saleInternalWaste`, `saleExternalWaste`) VALUES @@ -1534,7 +1535,7 @@ INSERT INTO `bs`.`waste`(`buyerFk`, `year`, `week`, `itemFk`, `itemTypeFk`, `sal ('103', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 6, 1, '186', '0', '51', '53.12'), ('103', YEAR(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK)), WEEK(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 WEEK), 1), 7, 1, '277', '0', '53.12', '56.20'); -INSERT INTO `vn`.`buy`(`id`,`entryFk`,`itemFk`,`buyingValue`,`quantity`,`packagingFk`,`stickers`,`freightValue`,`packageValue`,`comissionValue`,`packing`,`grouping`,`groupingMode`,`location`,`price1`,`price2`,`price3`, `printedStickers`,`isChecked`,`isIgnored`,`weight`, `created`) +INSERT INTO vn.buy(id,entryFk,itemFk,buyingValue,quantity,packagingFk,stickers,freightValue,packageValue,comissionValue,packing,grouping,groupingMode,location,price1,price2,price3,printedStickers,isChecked,isIgnored,weight,created) VALUES (1, 1, 1, 50, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, util.VN_CURDATE() - INTERVAL 2 MONTH), (2, 2, 1, 50, 100, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.6, 99.4, 0, 1, 0, 1, util.VN_CURDATE() - INTERVAL 1 MONTH), @@ -1550,7 +1551,8 @@ INSERT INTO `vn`.`buy`(`id`,`entryFk`,`itemFk`,`buyingValue`,`quantity`,`packagi (12, 6, 4, 1.25, 0, 3, 1, 2.500, 2.500, 0.000, 10, 10, 'grouping', NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()), (13, 7, 1, 50, 0, 3, 1, 2.000, 2.000, 0.000, 1, 1, 'packing', NULL, 0.00, 99.6, 99.4, 0, 1, 0, 4, util.VN_CURDATE()), (14, 7, 2, 5, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 'grouping', NULL, 0.00, 7.30, 7.00, 0, 1, 0, 4, util.VN_CURDATE()), - (15, 7, 4, 1.25, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 'grouping', NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()); + (15, 7, 4, 1.25, 0, 3, 1, 2.000, 2.000, 0.000, 10, 10, 'grouping', NULL, 0.00, 1.75, 1.67, 0, 1, 0, 4, util.VN_CURDATE()), + (16, 99,1,50.0000, 5000, 4, 1, 1.500, 1.500, 0.000, 1, 1, 'packing', NULL, 0.00, 99.60, 99.40, 0, 1, 0, 1.00, '2024-07-30 08:13:51.000'); INSERT INTO `hedera`.`order`(`id`, `date_send`, `customer_id`, `delivery_method_id`, `agency_id`, `address_id`, `company_id`, `note`, `source_app`, `confirmed`,`total`, `date_make`, `first_row_stamp`, `confirm_date`) VALUES @@ -3922,18 +3924,6 @@ INSERT INTO vn.stockBought (workerFk, bought, reserve, dated) INSERT INTO vn.auctionConfig (id,conversionCoefficient,warehouseFk) VALUES (1,0.6,6); -INSERT INTO vn.warehouse (id,name,isFeedStock,delay,hasAvailable,isForTicket,countryFk,labelZone,hasComission,isInventory,isComparative,valuatedInventory,isManaged,hasConfectionTeam,hasStowaway,hasDms,isBuyerToBeEmailed,hasUbications,hasProduction,hasMachine,isLogiflora,isBionic,isHalt,isOrigin,isDestiny) - VALUES (6,'Warehouse six',0,0.004,1,0,1,0,0,1,1,0,1,0,0,0,0,1,1,0,0,1,0,0,0); - -INSERT INTO vn.travel (id,shipped,landed,warehouseInFk,warehouseOutFk,agencyFk__,`ref`,isDelivered,isReceived,m3,kg,cargoSupplierFk,totalEntries,agencyModeFk,editorFk,awbFk) - VALUES (11,'2001-01-01','2001-01-02',6,3,0,'eleventh travel',0,0,50.00,500,2,0,1,100,4); - -INSERT INTO vn.entry (id,supplierFk,invoiceNumber,isBooked,isExcludedFromAvailable,isConfirmed,isOrdered,isRaid,commission,created,evaNotes,travelFk,currencyFk,companyFk,isBlocked__,reference,editorFk,locked) - VALUES (99,69,'IN2009',0,1,0,0,1,0.0,'2000-12-01 00:00:00.000','',11,1,442,0,'Movement 9',100,'2024-07-30 08:13:49.000'); - -INSERT INTO vn.buy (entryFk,itemFk,quantity,dispatched,buyingValue,freightValue,isIgnored,stickers,packing,`grouping`,groupingMode,comissionValue,packageValue,packagingFk,price1,price2,price3,minPrice,printedStickers,workerFk,isChecked,isPickedOff,created,`__cm2`,weight,itemOriginalFk,editorFk,buyerFk) - VALUES (99,1,5000,0,50.0000,1.500,0,1,1,1,'packing',0.000,1.500,'4',0.00,99.60,99.40,0.00,0,0,1,0,'2024-07-30 08:13:51.000',0,1.00,1,100,35); - INSERT INTO vn.payrollComponent (id, name, isSalaryAgreed, isVariable, isException) VALUES (1, 'Salario1', 1, 0, 0), (2, 'Salario2', 1, 1, 0), From 8607a60ca7c57267ef3a86f3002fbf997a7a82af Mon Sep 17 00:00:00 2001 From: pablone Date: Wed, 11 Sep 2024 07:56:08 +0200 Subject: [PATCH 07/18] feat: refs #7404 format date before select --- db/routines/vn/procedures/stockBought_calculate.sql | 4 +--- .../back/methods/stock-bought/getStockBoughtDetail.js | 10 +++++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/db/routines/vn/procedures/stockBought_calculate.sql b/db/routines/vn/procedures/stockBought_calculate.sql index 54ac78d8e..6eabe015c 100644 --- a/db/routines/vn/procedures/stockBought_calculate.sql +++ b/db/routines/vn/procedures/stockBought_calculate.sql @@ -3,9 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`stockBought_calcula BEGIN /** * Inserts the purchase volume per buyer - * into stockBought according to the date. - * - * @param vDated Purchase date + * into stockBought according to the current date. */ DECLARE vDated DATE; SET vDated = util.VN_CURDATE(); diff --git a/modules/entry/back/methods/stock-bought/getStockBoughtDetail.js b/modules/entry/back/methods/stock-bought/getStockBoughtDetail.js index 0657fcb9a..6f09f1f67 100644 --- a/modules/entry/back/methods/stock-bought/getStockBoughtDetail.js +++ b/modules/entry/back/methods/stock-bought/getStockBoughtDetail.js @@ -23,7 +23,11 @@ module.exports = Self => { } }); - Self.getStockBoughtDetail = async(workerFk, dated = Date.vnNew()) => { + Self.getStockBoughtDetail = async(workerFk, dated) => { + if (!dated) { + dated = Date.vnNew(); + dated.setHours(0, 0, 0, 0); + } return Self.rawSql( `SELECT e.id entryFk, i.id itemFk, @@ -47,8 +51,8 @@ module.exports = Self => { JOIN volumeConfig vc WHERE t.warehouseInFk = ac.warehouseFk AND it.workerFk = ? - AND t.shipped = ?`, - [workerFk, new Date(dated)] + AND t.shipped = util.VN_CURDATE()`, + [workerFk] ); }; }; From cc1cd0563fe1b8cee7bbedf3b827fe881d908d54 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 16 Sep 2024 09:00:46 +0200 Subject: [PATCH 08/18] feat: refs #7404 fixtures and translates --- db/dump/fixtures.before.sql | 2 +- loopback/locale/en.json | 3 +- .../methods/stock-bought/getStockBought.js | 49 +++++++++++-------- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index ce33b4e48..cd1a470ff 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -183,7 +183,7 @@ INSERT INTO `vn`.`warehouse`(`id`, `name`, `code`, `isComparative`, `isInventory (3, 'Warehouse Three', NULL, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0), (4, 'Warehouse Four', NULL, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1), (5, 'Warehouse Five', NULL, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0), - (6, 'Warehouse six', NULL, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0), + (6, 'Warehouse six', 'VNH', 1, 1, 1, 1, 0, 0, 1, 1, 0, 0), (13, 'Inventory', 'inv', 1, 1, 1, 0, 0, 0, 1, 0, 0, 0), (60, 'Algemesi', NULL, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0); diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 06538a524..b8835f5f3 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -235,5 +235,6 @@ "Cannot add holidays on this day": "Cannot add holidays on this day", "Cannot send mail": "Cannot send mail", "CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`": "CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`", - "This postcode already exists": "This postcode already exists" + "This postcode already exists": "This postcode already exists", + "This buyer has already made a reservation for this date": "This buyer has already made a reservation for this date" } \ No newline at end of file diff --git a/modules/entry/back/methods/stock-bought/getStockBought.js b/modules/entry/back/methods/stock-bought/getStockBought.js index da194ed80..0f67d878d 100644 --- a/modules/entry/back/methods/stock-bought/getStockBought.js +++ b/modules/entry/back/methods/stock-bought/getStockBought.js @@ -3,6 +3,11 @@ module.exports = Self => { description: 'Returns the stock bought for a given date', accessType: 'READ', accepts: [{ + arg: 'workerFk', + type: 'number', + description: 'The id for a buyer', + }, + { arg: 'dated', type: 'date', description: 'The date to filter', @@ -18,7 +23,7 @@ module.exports = Self => { } }); - Self.getStockBought = async(dated = Date.vnNew()) => { + Self.getStockBought = async(workerFk, dated = Date.vnNew()) => { const models = Self.app.models; const today = Date.vnNew(); dated.setHours(0, 0, 0, 0); @@ -27,26 +32,30 @@ module.exports = Self => { if (dated.getTime() === today.getTime()) await models.StockBought.rawSql(`CALL vn.stockBought_calculate()`); - return models.StockBought.find( - { - where: { - dated: dated - }, - include: [ - { - relation: 'worker', - scope: { - include: [ - { - relation: 'user', - scope: { - fields: ['id', 'name'] - } + const filter = { + where: { + dated: dated + }, + include: [ + { + relation: 'worker', + scope: { + include: [ + { + relation: 'user', + scope: { + fields: ['id', 'name'] } - ] - } + } + ] } - ] - }); + } + ] + }; + + if (workerFk) filter.where.workerFk = workerFk; + console.log('workerFk: ', workerFk); + + return models.StockBought.find(filter); }; }; From 138640f9910cfc63efd08db06f0a8650207a6d36 Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 16 Sep 2024 12:05:36 +0200 Subject: [PATCH 09/18] fix: refs #7404 update test to match new fixtures for travel by continent --- .../back/methods/travel/specs/extraCommunityFilter.spec.js | 4 ++-- modules/travel/back/methods/travel/specs/filter.spec.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js b/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js index 97e1e5e77..7e90c7681 100644 --- a/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js +++ b/modules/travel/back/methods/travel/specs/extraCommunityFilter.spec.js @@ -79,7 +79,7 @@ describe('Travel extraCommunityFilter()', () => { const result = await app.models.Travel.extraCommunityFilter(ctx, filter); - expect(result.length).toEqual(10); + expect(result.length).toEqual(9); }); it('should return the travel matching "cargoSupplierFk"', async() => { @@ -110,6 +110,6 @@ describe('Travel extraCommunityFilter()', () => { const result = await app.models.Travel.extraCommunityFilter(ctx, filter); - expect(result.length).toEqual(3); + expect(result.length).toEqual(2); }); }); diff --git a/modules/travel/back/methods/travel/specs/filter.spec.js b/modules/travel/back/methods/travel/specs/filter.spec.js index 2b6885cae..a608a980e 100644 --- a/modules/travel/back/methods/travel/specs/filter.spec.js +++ b/modules/travel/back/methods/travel/specs/filter.spec.js @@ -68,7 +68,7 @@ describe('Travel filter()', () => { const result = await app.models.Travel.filter(ctx); - expect(result.length).toEqual(2); + expect(result.length).toEqual(1); }); it('should return the travel matching "continent"', async() => { @@ -80,6 +80,6 @@ describe('Travel filter()', () => { const result = await app.models.Travel.filter(ctx); - expect(result.length).toEqual(7); + expect(result.length).toEqual(6); }); }); From 1f1da689d4bcec0072e2281d9ed564af610b6c8c Mon Sep 17 00:00:00 2001 From: pablone Date: Mon, 16 Sep 2024 12:17:51 +0200 Subject: [PATCH 10/18] fix: refs #7404 remove console log --- modules/entry/back/methods/stock-bought/getStockBought.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/entry/back/methods/stock-bought/getStockBought.js b/modules/entry/back/methods/stock-bought/getStockBought.js index 0f67d878d..94e206ece 100644 --- a/modules/entry/back/methods/stock-bought/getStockBought.js +++ b/modules/entry/back/methods/stock-bought/getStockBought.js @@ -54,7 +54,6 @@ module.exports = Self => { }; if (workerFk) filter.where.workerFk = workerFk; - console.log('workerFk: ', workerFk); return models.StockBought.find(filter); }; From 7540526b9b0e1cc57247dd9e49ca4063a5f74894 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 16 Sep 2024 12:26:29 +0200 Subject: [PATCH 11/18] feat: refs #7964 entry_beforeUpdate --- db/routines/vn/triggers/entry_beforeUpdate.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/triggers/entry_beforeUpdate.sql b/db/routines/vn/triggers/entry_beforeUpdate.sql index ee2178024..e57ba08a9 100644 --- a/db/routines/vn/triggers/entry_beforeUpdate.sql +++ b/db/routines/vn/triggers/entry_beforeUpdate.sql @@ -71,7 +71,10 @@ BEGIN SET NEW.currencyFk = entry_getCurrency(NEW.currencyFk, NEW.supplierFk); END IF; - IF NOT (NEW.travelFk <=> OLD.travelFk) OR NOT (NEW.currencyFk <=> OLD.currencyFk) THEN + IF NOT (NEW.travelFk <=> OLD.travelFk) + OR NOT (NEW.currencyFk <=> OLD.currencyFk) + OR (NEW.supplierFk <=> OLD.supplierFk) THEN + SET NEW.commission = entry_getCommission(NEW.travelFk, NEW.currencyFk, NEW.supplierFk); END IF; END$$ From e4a74ba0e9ea9632bc0c6ecf9b0f44de613f07b6 Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 16 Sep 2024 13:24:33 +0200 Subject: [PATCH 12/18] feat: refs #3505 testBack closure --- .../mrw-config/specs/createShipment.spec.js | 17 ++- db/dump/fixtures.before.sql | 68 +++++----- modules/invoiceOut/back/models/invoice-out.js | 6 +- .../sales-monitor/specs/salesFilter.spec.js | 15 ++- .../back/methods/ticket-weekly/filter.js | 17 +-- .../ticket-weekly/specs/filter.spec.js | 4 +- .../back/methods/ticket/closeByAgency.js | 79 ------------ .../back/methods/ticket/closeByRoute.js | 75 ----------- .../back/methods/ticket/closeByTicket.js | 30 ++++- modules/ticket/back/methods/ticket/closure.js | 41 ++++-- modules/ticket/back/methods/ticket/saveCmr.js | 2 +- .../back/methods/ticket/specs/closure.spec.js | 119 ++++++++++++++++++ .../back/methods/ticket/specs/filter.spec.js | 20 ++- .../ticket/specs/isEditableOrThrow.spec.js | 2 +- modules/ticket/back/models/ticket-methods.js | 2 - print/core/email.js | 2 +- 16 files changed, 262 insertions(+), 237 deletions(-) delete mode 100644 modules/ticket/back/methods/ticket/closeByAgency.js delete mode 100644 modules/ticket/back/methods/ticket/closeByRoute.js create mode 100644 modules/ticket/back/methods/ticket/specs/closure.spec.js diff --git a/back/methods/mrw-config/specs/createShipment.spec.js b/back/methods/mrw-config/specs/createShipment.spec.js index 1ab77f608..c8a5295f7 100644 --- a/back/methods/mrw-config/specs/createShipment.spec.js +++ b/back/methods/mrw-config/specs/createShipment.spec.js @@ -12,9 +12,8 @@ const ticket1 = { 'addressFk': 1, 'agencyModeFk': 999 }; - +let expedition; const expedition1 = { - 'id': 17, 'agencyModeFk': 999, 'ticketFk': 44, 'freightItemFk': 71, @@ -47,7 +46,7 @@ describe('MRWConfig createShipment()', () => { await createMrwConfig(); await models.Ticket.create(ticket1); - await models.Expedition.create(expedition1); + expedition = await models.Expedition.create(expedition1); }); afterAll(async() => { @@ -93,7 +92,7 @@ describe('MRWConfig createShipment()', () => { } it('should create a shipment and return a base64Binary label', async() => { - const {file} = await models.MrwConfig.createShipment(expedition1.id); + const {file} = await models.MrwConfig.createShipment(expedition.id); expect(file).toEqual(mockBase64Binary); }); @@ -101,7 +100,7 @@ describe('MRWConfig createShipment()', () => { it('should fail if mrwConfig has no data', async() => { let error; await models.MrwConfig.destroyAll(); - await models.MrwConfig.createShipment(expedition1.id).catch(e => { + await models.MrwConfig.createShipment(expedition.id).catch(e => { error = e; }).finally(async() => { expect(error.message).toEqual(`MRW service is not configured`); @@ -126,7 +125,7 @@ describe('MRWConfig createShipment()', () => { yesterday.setDate(yesterday.getDate() - 1); await models.Ticket.updateAll({id: ticket1.id}, {shipped: yesterday}); - await models.MrwConfig.createShipment(expedition1.id).catch(e => { + await models.MrwConfig.createShipment(expedition.id).catch(e => { error = e; }).finally(async() => { expect(error.message).toEqual(`This ticket has a shipped date earlier than today`); @@ -136,7 +135,7 @@ describe('MRWConfig createShipment()', () => { it('should send mail if you are past the dead line and is not notified today', async() => { await models.MrwConfig.updateAll({id: 1}, {expeditionDeadLine: '10:00:00', notified: null}); - await models.MrwConfig.createShipment(expedition1.id); + await models.MrwConfig.createShipment(expedition.id); const notification = await getLastNotification(); expect(notification.notificationFk).toEqual(filter.notificationFk); @@ -144,7 +143,7 @@ describe('MRWConfig createShipment()', () => { it('should send mail if you are past the dead line and it is notified from another day', async() => { await models.MrwConfig.updateAll({id: 1}, {expeditionDeadLine: '10:00:00', notified: new Date()}); - await models.MrwConfig.createShipment(expedition1.id); + await models.MrwConfig.createShipment(expedition.id); const notification = await getLastNotification(); expect(notification.notificationFk).toEqual(filter.notificationFk); @@ -152,7 +151,7 @@ describe('MRWConfig createShipment()', () => { it('should not send mail if you are past the dead line and it is notified', async() => { await models.MrwConfig.updateAll({id: 1}, {expeditionDeadLine: '10:00:00', notified: Date.vnNew()}); - await models.MrwConfig.createShipment(expedition1.id); + await models.MrwConfig.createShipment(expedition.id); const notification = await getLastNotification(); expect(notification).toEqual(null); diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index fdd6d6d65..a28212270 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -335,21 +335,21 @@ INSERT INTO `vn`.`payDem`(`id`, `payDem`) (2, 20), (7, 0); -INSERT INTO `vn`.`autonomy`(`id`, `name`, `countryFk`) +INSERT INTO `vn`.`autonomy`(`id`, `name`, `countryFk`, `hasDailyInvoice`) VALUES - (1, 'Autonomy one', 1), - (2, 'Autonomy two', 1), - (3, 'Autonomy three', 2), - (4, 'Autonomy four', 13); + (1, 'Autonomy one', 1, 1), + (2, 'Autonomy two', 1, 0), + (3, 'Autonomy three', 2, 0), + (4, 'Autonomy four', 13, 0); INSERT INTO `vn`.`province`(`id`, `name`, `countryFk`, `autonomyFk`, `warehouseFk`) VALUES - (1, 'Province one', 1, 1, NULL), - (2, 'Province two', 1, 1, NULL), - (3, 'Province three', 30, 2, NULL), - (4, 'Province four', 2, 3, NULL), - (5, 'Province five', 13, 4, NULL); + (1, 'Province one', 1, 1, NULL), + (2, 'Province two', 1, 1, NULL), + (3, 'Province three', 30, 2, NULL), + (4, 'Province four', 2, 3, NULL), + (5, 'Province five', 13, 4, NULL); INSERT INTO `vn`.`town`(`id`, `name`, `provinceFk`) VALUES @@ -361,11 +361,11 @@ INSERT INTO `vn`.`town`(`id`, `name`, `provinceFk`) INSERT INTO `vn`.`postCode`(`code`, `townFk`, `geoFk`) VALUES - ('46000', 1, 6), - ('46460', 2, 6), - ('46680', 3, 6), - ('46600', 4, 7), - ('EC170150', 5, 8); + ('46000', 1, 6), + ('46460', 2, 6), + ('46680', 3, 6), + ('46600', 4, 7), + ('EC170150', 5, 8); INSERT INTO `vn`.`clientType`(`code`, `type`) VALUES @@ -397,7 +397,7 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city (1107, 'Hank Pym', '09854837G', 'ANT MAN', 'Hawk', 'ANTHILL, SAN FRANCISCO, CALIFORNIA', 'Gotham', 46460, 1111111111, 222222222, 1, 'HankPym@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 0, 0, NULL, 0, 0, 19, 0, 'florist','normal'), (1108, 'Charles Xavier', '22641921P', 'PROFESSOR X', 'Beast', '3800 VICTORY PKWY, CINCINNATI, OH 45207, USA', 'Gotham', 46460, 1111111111, 222222222, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 5, 1, 300, 13, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, NULL, 0, 0, 19, 0, 'florist','normal'), (1109, 'Bruce Banner', '16104829E', 'HULK', 'Black widow', 'SOMEWHERE IN NEW YORK', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 0, 0, NULL, 0, 0, 9, 0, 'florist','normal'), - (1110, 'Jessica Jones', '58282869H', 'JESSICA JONES', 'Luke Cage', 'NYCC 2015 POSTER', 'Gotham', 46460, 1111111111, 222222222, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 0, 0, NULL, 0, 0, NULL, 0, 'florist','normal'), + (1110, 'Jessica Jones', '58282869H', 'JESSICA JONES', 'Luke Cage', 'NYCC 2015 POSTER', 'Gotham', 46460, 1111111111, 222222222, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 0, NULL, 0, 0, NULL, 1, 'florist','normal'), (1111, 'Missing', NULL, 'MISSING MAN', 'Anton', 'THE SPACE, UNIVERSE FAR AWAY', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 0, 1, 0, NULL, 1, 0, NULL, 0, 'others','loses'), (1112, 'Trash', NULL, 'GARBAGE MAN', 'Unknown name', 'NEW YORK CITY, UNDERGROUND', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 0, 1, 0, NULL, 1, 0, NULL, 0, 'others','loses'); @@ -821,10 +821,10 @@ INSERT INTO `vn`.`ticketTracking`(`ticketFk`, `stateFk`, `userFk`, `created`) (12, 3, 19, util.VN_NOW()), (13, 3, 19, util.VN_NOW()), (14, 3, 19, util.VN_NOW()), - (15, 2, 19, util.VN_NOW()), + (15, 10, 19, util.VN_NOW()), (16, 3, 19, util.VN_NOW()), (17, 2, 19, util.VN_NOW()), - (18, 2, 19, util.VN_NOW()), + (37, 10, 19, util.VN_NOW()), (19, 2, 19, util.VN_NOW()), (20, 1, 19, DATE_ADD(util.VN_NOW(), INTERVAL +1 MONTH)), (21, 1, 19, DATE_ADD(util.VN_NOW(), INTERVAL +1 MONTH)), @@ -1031,19 +1031,20 @@ INSERT INTO `vn`.`expeditionStateType`(`id`, `description`, `code`) INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `freightItemFk`, `created`, `counter`, `workerFk`, `externalId`, `packagingFk`, `stateTypeFk`, `hostFk`) VALUES - (1, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 18, 'UR9000006041', 94, 1, 'pc1'), - (2, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 18, 'UR9000006041', 94, 1, NULL), - (3, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 18, 'UR9000006041', 94, 2, NULL), - (4, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 18, 'UR9000006041', 94, 2, NULL), - (5, 1, 2, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 18, NULL, 94, 3, NULL), - (6, 7, 3, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 18, NULL, 94, 3, NULL), - (7, 2, 4, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), 1, 18, NULL, 94, NULL,NULL), - (8, 3, 5, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), 1, 18, NULL, 94, 1, NULL), - (9, 3, 6, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 18, NULL, 94, 2, NULL), - (10, 7, 7, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), - (11, 7, 8, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), - (12, 7, 9, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), - (13, 1, 10,71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL); + (1, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 18, 'UR9000006041', 94, 1, 'pc1'), + (2, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 2, 18, 'UR9000006041', 94, 1, NULL), + (3, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 3, 18, 'UR9000006041', 94, 2, NULL), + (4, 1, 1, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 4, 18, 'UR9000006041', 94, 2, NULL), + (5, 1, 2, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 18, NULL, 94, 3, NULL), + (6, 7, 3, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -2 MONTH), 1, 18, NULL, 94, 3, NULL), + (7, 2, 4, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -3 MONTH), 1, 18, NULL, 94, NULL,NULL), + (8, 3, 5, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -4 MONTH), 1, 18, NULL, 94, 1, NULL), + (9, 3, 6, 71, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1, 18, NULL, 94, 2, NULL), + (10, 7, 7, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), + (11, 7, 8, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), + (12, 7, 9, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), + (13, 1, 10, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL), + (14, 1, 37, 71, util.VN_NOW(), 1, 18, NULL, 94, 3, NULL); INSERT INTO `vn`.`expeditionState`(`id`, `created`, `expeditionFk`, `typeFk`, `userFk`) @@ -1478,7 +1479,8 @@ INSERT INTO `vn`.`ticketWeekly`(`ticketFk`, `weekDay`) (2, 1), (3, 2), (5, 6), - (15, 6); + (15, 6), + (17, 6); INSERT INTO `vn`.`awb` (id, code, package, weight, created, amount, transitoryFk, taxFk) VALUES @@ -3970,6 +3972,6 @@ VALUES (5, 'Referencia Nominas', 'payRef'), (6, 'ABA', 'aba'); -INSERT IGNORE INTO ormConfig +INSERT IGNORE INTO ormConfig SET id =1, selectLimit = 1000; diff --git a/modules/invoiceOut/back/models/invoice-out.js b/modules/invoiceOut/back/models/invoice-out.js index 47dbcbea4..bab1fa375 100644 --- a/modules/invoiceOut/back/models/invoice-out.js +++ b/modules/invoiceOut/back/models/invoice-out.js @@ -83,8 +83,10 @@ module.exports = Self => { const invoiceOutSerial = await Self.app.models.InvoiceOutSerial.findById(serial); if (invoiceOutSerial?.taxAreaFk == 'WORLD') { const address = await Self.app.models.Address.findById(addressId); - if (!address || !address.customsAgentFk || !address.incotermsFk) - throw new UserError('The address of the customer must have information about Incoterms and Customs Agent'); + if (!address?.customsAgentFk || !address.incotermsFk) { + throw new UserError( + 'The address of the customer must have information about Incoterms and Customs Agent'); + } } return serial; diff --git a/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js b/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js index 9460addfa..738af5219 100644 --- a/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js +++ b/modules/monitor/back/methods/sales-monitor/specs/salesFilter.spec.js @@ -39,7 +39,7 @@ describe('SalesMonitor salesFilter()', () => { const filter = {}; const result = await models.SalesMonitor.salesFilter(ctx, filter, options); - expect(result.length).toBeGreaterThan(10); + expect(result.length).toBeGreaterThan(9); await tx.rollback(); } catch (e) { @@ -146,13 +146,20 @@ describe('SalesMonitor salesFilter()', () => { try { const options = {transaction: tx}; + const alertLevel = await models.AlertLevel.findOne({ + where: {code: 'FREE'}, + options + }); + + const alertLevelFree = alertLevel.id; + const ctx = {req: {accessToken: {userId: 9}}, args: {pending: false}}; const filter = {order: 'alertLevel ASC'}; const result = await models.SalesMonitor.salesFilter(ctx, filter, options); - const firstRow = result[0]; - expect(result.length).toEqual(15); - expect(firstRow.alertLevel).not.toEqual(0); + result.forEach(row => { + expect(row.alertLevel).toBeGreaterThan(alertLevelFree); + }); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/back/methods/ticket-weekly/filter.js b/modules/ticket/back/methods/ticket-weekly/filter.js index a43b5e270..21f31518e 100644 --- a/modules/ticket/back/methods/ticket-weekly/filter.js +++ b/modules/ticket/back/methods/ticket-weekly/filter.js @@ -38,14 +38,17 @@ module.exports = Self => { Object.assign(myOptions, options); const where = buildFilter(ctx.args, (param, value) => { - switch (param) { - case 'search': - return {or: [ - {'t.id': value}, - {'c.id': value}, - {'c.name': {like: `%${value}%`}} - ]}; + if (param === 'search') { + return { + or: [ + {'t.id': value}, + {'c.id': value}, + {'c.name': {like: `%${value}%`}} + ] + }; } + + return {}; }); filter = mergeFilters(ctx.args.filter, {where}); diff --git a/modules/ticket/back/methods/ticket-weekly/specs/filter.spec.js b/modules/ticket/back/methods/ticket-weekly/specs/filter.spec.js index 453b7924f..9b1ad5209 100644 --- a/modules/ticket/back/methods/ticket-weekly/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket-weekly/specs/filter.spec.js @@ -13,11 +13,11 @@ describe('ticket-weekly filter()', () => { const ctx = {req: {accessToken: {userId: authUserId}}, args: {filter: filter}}; const result = await models.TicketWeekly.filter(ctx, null, options); - + const totalRecords = await models.TicketWeekly.count(); const firstRow = result[0]; expect(firstRow.ticketFk).toEqual(2); - expect(result.length).toEqual(4); + expect(result.length).toEqual(totalRecords); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/back/methods/ticket/closeByAgency.js b/modules/ticket/back/methods/ticket/closeByAgency.js deleted file mode 100644 index eb1aee349..000000000 --- a/modules/ticket/back/methods/ticket/closeByAgency.js +++ /dev/null @@ -1,79 +0,0 @@ -const closure = require('./closure'); - -module.exports = Self => { - Self.remoteMethodCtx('closeByAgency', { - description: 'Makes the closure process by agency mode', - accessType: 'WRITE', - accepts: [ - { - arg: 'agencyModeFk', - type: ['number'], - required: true, - description: 'The agencies mode ids', - }, - { - arg: 'warehouseFk', - type: 'number', - description: 'The ticket warehouse id', - required: true - }, - { - arg: 'to', - type: 'date', - description: 'Max closure date', - required: true - } - ], - returns: { - type: 'object', - root: true - }, - http: { - path: `/close-by-agency`, - verb: 'POST' - } - }); - - Self.closeByAgency = async ctx => { - const args = ctx.args; - - const tickets = await Self.rawSql(` - SELECT - t.id, - t.clientFk, - t.companyFk, - c.name clientName, - c.email recipient, - c.salesPersonFk, - c.isToBeMailed, - c.hasToInvoice, - co.hasDailyInvoice, - eu.email salesPersonEmail - FROM expedition e - JOIN ticket t ON t.id = e.ticketFk - 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.agencyModeFk IN(?) - AND t.warehouseFk = ? - AND DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY) - AND util.dayEnd(?) - AND t.refFk IS NULL - GROUP BY e.ticketFk`, [ - args.agencyModeFk, - args.warehouseFk, - args.to, - args.to - ]); - - await closure(Self, tickets); - - return { - message: 'Success' - }; - }; -}; diff --git a/modules/ticket/back/methods/ticket/closeByRoute.js b/modules/ticket/back/methods/ticket/closeByRoute.js deleted file mode 100644 index 58e130b8e..000000000 --- a/modules/ticket/back/methods/ticket/closeByRoute.js +++ /dev/null @@ -1,75 +0,0 @@ -const closure = require('./closure'); -const {Email} = require('vn-print'); - -module.exports = Self => { - Self.remoteMethodCtx('closeByRoute', { - description: 'Makes the closure process by route', - accessType: 'WRITE', - accepts: [ - { - arg: 'routeFk', - type: 'number', - required: true, - description: 'The routes ids', - }, - ], - returns: { - type: 'object', - root: true - }, - http: { - path: `/close-by-route`, - verb: 'POST' - } - }); - - Self.closeByRoute = async ctx => { - const args = ctx.args; - - const tickets = await Self.rawSql(` - SELECT - t.id, - t.clientFk, - t.companyFk, - c.name clientName, - c.email recipient, - c.salesPersonFk, - c.isToBeMailed, - c.hasToInvoice, - co.hasDailyInvoice, - eu.email salesPersonEmail - FROM expedition e - JOIN ticket t ON t.id = e.ticketFk - 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.routeFk = ? - AND t.refFk IS NULL - GROUP BY e.ticketFk`, [args.routeFk]); - - await closure(Self, tickets); - - // Send route report to the agency - const [agencyMail] = await Self.rawSql(` - SELECT am.reportMail - FROM route r - JOIN agencyMode am ON am.id = r.agencyModeFk - WHERE r.id = ?`, [args.routeFk]); - - if (agencyMail) { - const email = new Email('driver-route', { - id: args.routeFk, - recipient: agencyMail - }); - await email.send(); - } - - return { - message: 'Success' - }; - }; -}; diff --git a/modules/ticket/back/methods/ticket/closeByTicket.js b/modules/ticket/back/methods/ticket/closeByTicket.js index 8884897c2..40fe048a5 100644 --- a/modules/ticket/back/methods/ticket/closeByTicket.js +++ b/modules/ticket/back/methods/ticket/closeByTicket.js @@ -23,11 +23,25 @@ module.exports = Self => { } }); - Self.closeByTicket = async ctx => { + Self.closeByTicket = async(ctx, options) => { + let tx; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + const userId = ctx.req.accessToken.userId; + myOptions.userId = userId; + const args = ctx.args; const tickets = await Self.rawSql(` - SELECT + SELECT t.id, t.clientFk, t.companyFk, @@ -37,7 +51,8 @@ module.exports = Self => { c.isToBeMailed, c.hasToInvoice, co.hasDailyInvoice, - eu.email salesPersonEmail + eu.email salesPersonEmail, + t.addressFk FROM expedition e JOIN ticket t ON t.id = e.ticketFk JOIN ticketState ts ON ts.ticketFk = t.id @@ -49,9 +64,14 @@ module.exports = Self => { WHERE al.code = 'PACKED' AND t.id = ? AND t.refFk IS NULL - GROUP BY e.ticketFk`, [args.id]); + GROUP BY e.ticketFk`, + [args.id], + myOptions); - await closure(Self, tickets); + await closure(ctx, Self, tickets, 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 4622ba271..a75596bac 100644 --- a/modules/ticket/back/methods/ticket/closure.js +++ b/modules/ticket/back/methods/ticket/closure.js @@ -1,13 +1,22 @@ -/* eslint max-len: ["error", { "code": 150 }]*/ - const Report = require('vn-print/core/report'); const Email = require('vn-print/core/email'); const smtp = require('vn-print/core/smtp'); const config = require('vn-print/core/config'); const storage = require('vn-print/core/storage'); -module.exports = async function(ctx, Self, tickets, reqArgs = {}) { +module.exports = async function(ctx, Self, tickets, options) { const userId = ctx.req.accessToken.userId; + const myOptions = {userId}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + let tx; + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + if (tickets.length == 0) return; const failedtickets = []; @@ -17,7 +26,7 @@ module.exports = async function(ctx, Self, tickets, reqArgs = {}) { await Self.rawSql( `CALL vn.ticket_closeByTicket(?)`, [ticket.id], - {userId} + myOptions ); const [invoiceOut] = await Self.rawSql(` @@ -26,7 +35,7 @@ module.exports = async function(ctx, Self, tickets, reqArgs = {}) { JOIN invoiceOut io ON io.ref = t.refFk JOIN company cny ON cny.id = io.companyFk WHERE t.id = ? - `, [ticket.id]); + `, [ticket.id], myOptions); const mailOptions = { overrideAttachments: true, @@ -63,7 +72,7 @@ module.exports = async function(ctx, Self, tickets, reqArgs = {}) { await Self.rawSql( 'UPDATE invoiceOut SET hasPdf = true WHERE id = ?', [invoiceOut.id], - {userId}, + myOptions ); if (isToBeMailed) { @@ -108,7 +117,9 @@ module.exports = async function(ctx, Self, tickets, reqArgs = {}) { WHERE t.clientFk = ? AND NOT t.isDeleted AND c.isVies - `, [ticket.clientFk]); + `, + [ticket.clientFk], + myOptions); if (firstOrder == 1) { const args = { @@ -127,20 +138,22 @@ module.exports = async function(ctx, Self, tickets, reqArgs = {}) { SELECT id FROM sample WHERE code = 'incoterms-authorization' - `); + `, + null, + myOptions); await Self.rawSql(` INSERT INTO clientSample (clientFk, typeFk, companyFk) VALUES(?, ?, ?) - `, [ticket.clientFk, sample.id, ticket.companyFk], {userId}); + `, + [ticket.clientFk, sample.id, ticket.companyFk], + myOptions); } } catch (error) { - // Domain not found if (error.responseCode == 450) { await invalidEmail(ticket); continue; } - // Save tickets on a list of failed ids failedtickets.push({ id: ticket.id, stacktrace: error, @@ -148,7 +161,6 @@ module.exports = async function(ctx, Self, tickets, reqArgs = {}) { } } - // Send email with failed tickets if (failedtickets.length > 0) { let body = 'This following tickets have failed:

'; @@ -164,11 +176,14 @@ module.exports = async function(ctx, Self, tickets, reqArgs = {}) { }).catch(err => console.error(err)); } + if (tx) + await tx.commit(); + async function invalidEmail(ticket) { await Self.rawSql( `UPDATE client SET email = NULL WHERE id = ?`, [ticket.clientFk], - {userId}, + myOptions ); const body = `No se ha podido enviar el albarán ${ticket.id} diff --git a/modules/ticket/back/methods/ticket/saveCmr.js b/modules/ticket/back/methods/ticket/saveCmr.js index f8d0af8ef..339ac1e38 100644 --- a/modules/ticket/back/methods/ticket/saveCmr.js +++ b/modules/ticket/back/methods/ticket/saveCmr.js @@ -39,7 +39,7 @@ module.exports = Self => { }, myOptions); for (const ticketId of tickets) { - const ticket = await models.Ticket.findById(ticketId, myOptions); + const ticket = await models.Ticket.findById(ticketId, null, myOptions); if (ticket.cmrFk) { const hasDmsCmr = await Self.rawSql(` diff --git a/modules/ticket/back/methods/ticket/specs/closure.spec.js b/modules/ticket/back/methods/ticket/specs/closure.spec.js new file mode 100644 index 000000000..a184bb7af --- /dev/null +++ b/modules/ticket/back/methods/ticket/specs/closure.spec.js @@ -0,0 +1,119 @@ +const models = require('vn-loopback/server/server').models; +const LoopBackContext = require('loopback-context'); +const smtp = require('vn-print/core/smtp'); +const Email = require('vn-print/core/email'); +const config = require('vn-print/core/config'); +const closure = require('../closure'); + +fdescribe('Ticket closure functionality', () => { + const userId = 19; + const companyFk = 442; + const activeCtx = { + getLocale: () => 'es', + accessToken: {userId: userId}, + headers: {origin: 'http://localhost:5000'}, + }; + let ctx = {req: activeCtx}; + let tx; + let options; + + beforeEach(async() => { + LoopBackContext.getCurrentContext = () => ({ + active: activeCtx, + }); + + tx = await models.Sale.beginTransaction({}); + options = {transaction: tx}; + }); + + afterEach(async() => { + await tx.rollback(); + }); + + it('should successfully close a ticket and not invoiced', async() => { + const ticketId = 15; + const tickets = [{ + id: ticketId, + clientFk: 1101, + companyFk, + addressFk: 1, + isToBeMailed: true, + recipient: 'some@email.com', + salesPersonFk: userId + }]; + + const ticketStateBefore = await models.TicketState.findById(ticketId, null, options); + + await closure(ctx, models.Ticket, tickets, options); + + const ticketStateAfter = await models.TicketState.findById(ticketId, null, options); + + expect(ticketStateBefore.code).not.toBe(ticketStateAfter.code); + + const ticketAfter = await models.TicketState.findById(ticketId, null, options); + + expect(ticketAfter.refFk).toBeUndefined(); + }); + + fit('should send Incoterms authorization email on first order', async() => { + const ticketId = 37; + ctx.args = { + id: ticketId, + }; + + const ticket = await models.Ticket.findById(ticketId, null, options); + spyOn(Email.prototype, 'send').and.returnValue(Promise.resolve()); + + await models.Ticket.closeByTicket(ctx, options); + + const sample = await models.Sample.findOne({ + where: {code: 'incoterms-authorization'}, + fields: ['id'] + }, + options); + + const insertedSample = await models.ClientSample.findOne({ + where: { + clientFk: ticket.clientFk, + typeFk: sample.id, + companyFk: companyFk + } + }, options); + + expect(insertedSample.clientFk).toEqual(ticket.clientFk); + }); + + it('should report failed tickets and set client email to null', async() => { + const ticketId = 37; + const clientId = 1110; + const tickets = [{ + id: ticketId, + clientFk: clientId, + companyFk, + addressFk: 1, + isToBeMailed: true, + recipient: 'invalid@example.com', + salesPersonFk: userId + }]; + + spyOn(Email.prototype, 'send').and.callFake(() => { + const error = new Error('Invalid email'); + error.responseCode = 450; + return Promise.reject(error); + }); + + await closure(ctx, models.Ticket, tickets, options); + + const client = await models.Client.findById(clientId, null, options); + + expect(client.email).toBeNull(); + + const reportEmail = await smtp.send({ + to: config.app.reportEmail, + subject: '[API] Nightly ticket closure report', + html: `This following tickets have failed:` + }); + + expect(reportEmail).not.toBeNull(); + }); +}); diff --git a/modules/ticket/back/methods/ticket/specs/filter.spec.js b/modules/ticket/back/methods/ticket/specs/filter.spec.js index 72249fe5d..d0edb24e3 100644 --- a/modules/ticket/back/methods/ticket/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket/specs/filter.spec.js @@ -21,7 +21,7 @@ describe('ticket filter()', () => { } }); - it('should return the tickets matching the problems on true', async() => { + it('should return at least one ticket matching the problems on true', async() => { const tx = await models.Ticket.beginTransaction({}); try { @@ -41,7 +41,15 @@ describe('ticket filter()', () => { const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); - expect(result.length).toBeGreaterThan(3); + const hasProblemTicket = result.some(ticket => + ticket.isFreezed === true || + ticket.hasRisk === true || + ticket.hasTicketRequest === true || + (typeof ticket.hasRounding === 'string' && ticket.hasRounding.trim().length > 0) || + (typeof ticket.itemShortage === 'string' && ticket.itemShortage.trim().length > 0) + ); + + expect(hasProblemTicket).toBe(true); await tx.rollback(); } catch (e) { @@ -71,7 +79,13 @@ describe('ticket filter()', () => { const filter = {}; const result = await models.Ticket.filter(ctx, filter, options); - expect(result.length).toEqual(11); + result.forEach(ticket => { + expect(ticket.isFreezed).toEqual(null); + expect(ticket.hasRisk).toEqual(null); + expect(ticket.hasTicketRequest).toEqual(null); + expect(ticket.itemShortage).toEqual(null); + expect(ticket.hasRounding).toEqual(null); + }); await tx.rollback(); } catch (e) { diff --git a/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js b/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js index 883b0de2e..1a8025f09 100644 --- a/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js +++ b/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js @@ -65,7 +65,7 @@ describe('ticket isEditableOrThrow()', () => { const options = {transaction: tx}; const ctx = {req: {accessToken: {userId: 1}}}; - await models.Ticket.isEditableOrThrow(ctx, 15, options); + await models.Ticket.isEditableOrThrow(ctx, 17, options); await tx.rollback(); } catch (e) { error = e; diff --git a/modules/ticket/back/models/ticket-methods.js b/modules/ticket/back/models/ticket-methods.js index 12161d5f5..7fe968b26 100644 --- a/modules/ticket/back/models/ticket-methods.js +++ b/modules/ticket/back/models/ticket-methods.js @@ -33,8 +33,6 @@ module.exports = function(Self) { require('../methods/ticket/deliveryNoteCsvEmail')(Self); require('../methods/ticket/closeAll')(Self); require('../methods/ticket/closeByTicket')(Self); - require('../methods/ticket/closeByAgency')(Self); - require('../methods/ticket/closeByRoute')(Self); require('../methods/ticket/getTicketsFuture')(Self); require('../methods/ticket/merge')(Self); require('../methods/ticket/getTicketsAdvance')(Self); diff --git a/print/core/email.js b/print/core/email.js index a0bcf9122..a673685bb 100644 --- a/print/core/email.js +++ b/print/core/email.js @@ -33,7 +33,7 @@ class Email extends Component { const attachments = []; const getAttachments = async(componentPath, files) => { for (const file of files) { - const fileCopy = Object.assign({}, file); + const fileCopy = {...file}; const fileName = fileCopy.filename; if (options.overrideAttachments && !fileName.includes('.png')) continue; From f43fa32d364d1beb8f6d1c6520dff70e77594851 Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 16 Sep 2024 13:26:53 +0200 Subject: [PATCH 13/18] feat: refs #3505 fdescribe --- modules/ticket/back/methods/ticket/specs/closure.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket/specs/closure.spec.js b/modules/ticket/back/methods/ticket/specs/closure.spec.js index a184bb7af..303c38233 100644 --- a/modules/ticket/back/methods/ticket/specs/closure.spec.js +++ b/modules/ticket/back/methods/ticket/specs/closure.spec.js @@ -5,7 +5,7 @@ const Email = require('vn-print/core/email'); const config = require('vn-print/core/config'); const closure = require('../closure'); -fdescribe('Ticket closure functionality', () => { +describe('Ticket closure functionality', () => { const userId = 19; const companyFk = 442; const activeCtx = { @@ -55,7 +55,7 @@ fdescribe('Ticket closure functionality', () => { expect(ticketAfter.refFk).toBeUndefined(); }); - fit('should send Incoterms authorization email on first order', async() => { + it('should send Incoterms authorization email on first order', async() => { const ticketId = 37; ctx.args = { id: ticketId, From 51da7ae063385148090226a8e5ffbbd30ee8316c Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 16 Sep 2024 13:33:53 +0200 Subject: [PATCH 14/18] feat: refs #7893 Created waste_addSalesLauncher --- db/routines/bs/procedures/waste_addSales.sql | 16 ++++++++++++---- .../bs/procedures/waste_addSalesLauncher.sql | 6 ++++++ .../11237-goldenBamboo/00-firstScript.sql | 3 +++ 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 db/routines/bs/procedures/waste_addSalesLauncher.sql create mode 100644 db/versions/11237-goldenBamboo/00-firstScript.sql diff --git a/db/routines/bs/procedures/waste_addSales.sql b/db/routines/bs/procedures/waste_addSales.sql index f23c1b360..128c4f2db 100644 --- a/db/routines/bs/procedures/waste_addSales.sql +++ b/db/routines/bs/procedures/waste_addSales.sql @@ -1,8 +1,16 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`waste_addSales`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`waste_addSales`( + vDateFrom DATE, + vDateTo DATE +) BEGIN - DECLARE vDateFrom DATE DEFAULT util.VN_CURDATE() - INTERVAL WEEKDAY(util.VN_CURDATE()) DAY; - DECLARE vDateTo DATE DEFAULT vDateFrom + INTERVAL 6 DAY; + IF vDateFrom IS NULL THEN + SET vDateFrom = util.VN_CURDATE() - INTERVAL WEEKDAY(util.VN_CURDATE()) DAY; + END IF; + + IF vDateTo IS NULL THEN + SET vDateTo = vDateFrom + INTERVAL 6 DAY; + END IF; CALL cache.last_buy_refresh(FALSE); @@ -56,6 +64,6 @@ BEGIN JOIN vn.buy b ON b.id = lb.buy_id WHERE t.shipped BETWEEN vDateFrom AND vDateTo AND w.isManaged - GROUP BY i.id; + GROUP BY YEAR(t.shipped), WEEK(t.shipped, 4), i.id; END$$ DELIMITER ; diff --git a/db/routines/bs/procedures/waste_addSalesLauncher.sql b/db/routines/bs/procedures/waste_addSalesLauncher.sql new file mode 100644 index 000000000..5eaea9be4 --- /dev/null +++ b/db/routines/bs/procedures/waste_addSalesLauncher.sql @@ -0,0 +1,6 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`waste_addSalesLauncher`() +BEGIN + CALL waste_addSales(NULL, NULL); +END$$ +DELIMITER ; diff --git a/db/versions/11237-goldenBamboo/00-firstScript.sql b/db/versions/11237-goldenBamboo/00-firstScript.sql new file mode 100644 index 000000000..3e387eba8 --- /dev/null +++ b/db/versions/11237-goldenBamboo/00-firstScript.sql @@ -0,0 +1,3 @@ +UPDATE bs.nightTask + SET `procedure` = 'waste_addSalesLauncher' + WHERE `procedure` = 'waste_addSales'; From 10fcbffd376d81e55b4622f8543fc0334f129f58 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 16 Sep 2024 13:37:35 +0200 Subject: [PATCH 15/18] feat: refs #7964 entry_beforeUpdate not --- db/routines/vn/triggers/entry_beforeUpdate.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/triggers/entry_beforeUpdate.sql b/db/routines/vn/triggers/entry_beforeUpdate.sql index e57ba08a9..8e5a326a0 100644 --- a/db/routines/vn/triggers/entry_beforeUpdate.sql +++ b/db/routines/vn/triggers/entry_beforeUpdate.sql @@ -73,7 +73,7 @@ BEGIN IF NOT (NEW.travelFk <=> OLD.travelFk) OR NOT (NEW.currencyFk <=> OLD.currencyFk) - OR (NEW.supplierFk <=> OLD.supplierFk) THEN + OR NOT (NEW.supplierFk <=> OLD.supplierFk) THEN SET NEW.commission = entry_getCommission(NEW.travelFk, NEW.currencyFk, NEW.supplierFk); END IF; From e5e14878b874faf8b7e9b1f6b097092c94b919b8 Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 17 Sep 2024 07:57:00 +0200 Subject: [PATCH 16/18] feat: refs #3505 remove return --- e2e/paths/05-ticket/09_weekly.spec.js | 4 ++-- modules/ticket/back/methods/ticket-weekly/filter.js | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/e2e/paths/05-ticket/09_weekly.spec.js b/e2e/paths/05-ticket/09_weekly.spec.js index 1caf91f9c..370d422e6 100644 --- a/e2e/paths/05-ticket/09_weekly.spec.js +++ b/e2e/paths/05-ticket/09_weekly.spec.js @@ -19,7 +19,7 @@ describe('Ticket descriptor path', () => { it('should count the amount of tickets in the turns section', async() => { const result = await page.countElement(selectors.ticketsIndex.weeklyTicket); - expect(result).toEqual(5); + expect(result).toEqual(6); }); it('should go back to the ticket index then search and access a ticket summary', async() => { @@ -106,7 +106,7 @@ describe('Ticket descriptor path', () => { await page.doSearch(); const nResults = await page.countElement(selectors.ticketsIndex.searchWeeklyResult); - expect(nResults).toEqual(5); + expect(nResults).toEqual(6); }); it('should update the agency then remove it afterwards', async() => { diff --git a/modules/ticket/back/methods/ticket-weekly/filter.js b/modules/ticket/back/methods/ticket-weekly/filter.js index 21f31518e..6c9ed4f8b 100644 --- a/modules/ticket/back/methods/ticket-weekly/filter.js +++ b/modules/ticket/back/methods/ticket-weekly/filter.js @@ -47,8 +47,6 @@ module.exports = Self => { ] }; } - - return {}; }); filter = mergeFilters(ctx.args.filter, {where}); From 0c259b7a81f7e0d90ceca94d99ed1737548e1fc1 Mon Sep 17 00:00:00 2001 From: pablone Date: Tue, 17 Sep 2024 10:32:26 +0200 Subject: [PATCH 17/18] fix: refs #7404 remove duplicate translate --- loopback/locale/en.json | 1 - 1 file changed, 1 deletion(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 875f06e3b..352e08826 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -235,7 +235,6 @@ "Cannot add holidays on this day": "Cannot add holidays on this day", "Cannot send mail": "Cannot send mail", "CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`": "CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`", - "This postcode already exists": "This postcode already exists", "Original invoice not found": "Original invoice not found", "There is already a tray with the same height": "There is already a tray with the same height", "The height must be greater than 50cm": "The height must be greater than 50cm", From fa5ace677cec91a359bfb875370139505efdea10 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 17 Sep 2024 12:35:08 +0200 Subject: [PATCH 18/18] refactor: refs #7893 Requested changes --- db/routines/bs/procedures/waste_addSales.sql | 6 ++++++ db/versions/11240-aquaCyca/00-firstScript.sql | 1 + 2 files changed, 7 insertions(+) create mode 100644 db/versions/11240-aquaCyca/00-firstScript.sql diff --git a/db/routines/bs/procedures/waste_addSales.sql b/db/routines/bs/procedures/waste_addSales.sql index 128c4f2db..ea4adbc27 100644 --- a/db/routines/bs/procedures/waste_addSales.sql +++ b/db/routines/bs/procedures/waste_addSales.sql @@ -4,6 +4,12 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `bs`.`waste_addSales`( vDateTo DATE ) BEGIN +/** + * Recalcula las mermas de un periodo. + * + * @param vDateFrom Fecha desde + * @param vDateTo Fecha hasta + */ IF vDateFrom IS NULL THEN SET vDateFrom = util.VN_CURDATE() - INTERVAL WEEKDAY(util.VN_CURDATE()) DAY; END IF; diff --git a/db/versions/11240-aquaCyca/00-firstScript.sql b/db/versions/11240-aquaCyca/00-firstScript.sql new file mode 100644 index 000000000..97ad39ef1 --- /dev/null +++ b/db/versions/11240-aquaCyca/00-firstScript.sql @@ -0,0 +1 @@ +GRANT EXECUTE ON PROCEDURE bs.waste_addSales TO buyerBoss;