From 517aeebe8bc4783df346c35851f5ba106d4c0439 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 18 Mar 2024 14:20:05 +0100 Subject: [PATCH 01/29] refs #7019 fix(createManualInvoice): add throw error --- loopback/locale/es.json | 3 +- .../methods/invoiceOut/createManualInvoice.js | 55 +++++++++---------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 7730d4a8c..a390707ad 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -348,5 +348,6 @@ "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", "This password can only be changed by the user themselves": "Esta contraseña solo puede ser modificada por el propio usuario", - "They're not your subordinate": "No es tu subordinado/a." + "They're not your subordinate": "No es tu subordinado/a.", + "Select ticket or client": "Elija un ticket o un client" } diff --git a/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js index 043dfbead..9803f20f7 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js @@ -46,12 +46,11 @@ module.exports = Self => { } }); - Self.createManualInvoice = async(ctx, options) => { + Self.createManualInvoice = async(ctx, clientFk, ticketFk, maxShipped, serial, taxArea, reference, options) => { + if (!clientFk && !ticketFk) throw new UserError(`Select ticket or client`); const models = Self.app.models; - const args = ctx.args; - - let tx; const myOptions = {userId: ctx.req.accessToken.userId}; + let tx; if (typeof options == 'object') Object.assign(myOptions, options); @@ -61,18 +60,15 @@ module.exports = Self => { myOptions.transaction = tx; } - const ticketId = args.ticketFk; - let clientId = args.clientFk; - let maxShipped = args.maxShipped; let companyId; let newInvoice; let query; try { - if (ticketId) { - const ticket = await models.Ticket.findById(ticketId, null, myOptions); + if (ticketFk) { + const ticket = await models.Ticket.findById(ticketFk, null, myOptions); const company = await models.Company.findById(ticket.companyFk, null, myOptions); - clientId = ticket.clientFk; + clientFk = ticket.clientFk; maxShipped = ticket.shipped; companyId = ticket.companyFk; @@ -85,7 +81,7 @@ module.exports = Self => { throw new UserError(`A ticket with an amount of zero can't be invoiced`); // Validates ticket nagative base - const hasNegativeBase = await getNegativeBase(maxShipped, clientId, companyId, myOptions); + const hasNegativeBase = await getNegativeBase(maxShipped, clientFk, companyId, myOptions); if (hasNegativeBase && company.code == 'VNL') throw new UserError(`A ticket with a negative base can't be invoiced`); } else { @@ -95,7 +91,7 @@ module.exports = Self => { const company = await models.Ticket.findOne({ fields: ['companyFk'], where: { - clientFk: clientId, + clientFk: clientFk, shipped: {lte: maxShipped} } }, myOptions); @@ -103,7 +99,7 @@ module.exports = Self => { } // Validate invoiceable client - const isClientInvoiceable = await isInvoiceable(clientId, myOptions); + const isClientInvoiceable = await isInvoiceable(clientFk, myOptions); if (!isClientInvoiceable) throw new UserError(`This client is not invoiceable`); @@ -114,27 +110,27 @@ module.exports = Self => { if (maxShipped >= tomorrow) throw new UserError(`Can't invoice to future`); - const maxInvoiceDate = await getMaxIssued(args.serial, companyId, myOptions); + const maxInvoiceDate = await getMaxIssued(serial, companyId, myOptions); if (Date.vnNew() < maxInvoiceDate) throw new UserError(`Can't invoice to past`); - if (ticketId) { + if (ticketFk) { query = `CALL invoiceOut_newFromTicket(?, ?, ?, ?, @newInvoiceId)`; await Self.rawSql(query, [ - ticketId, - args.serial, - args.taxArea, - args.reference + ticketFk, + serial, + taxArea, + reference ], myOptions); } else { query = `CALL invoiceOut_newFromClient(?, ?, ?, ?, ?, ?, @newInvoiceId)`; await Self.rawSql(query, [ - clientId, - args.serial, + clientFk, + serial, maxShipped, companyId, - args.taxArea, - args.reference + taxArea, + reference ], myOptions); } @@ -146,26 +142,27 @@ module.exports = Self => { throw e; } - if (newInvoice.id) - await Self.createPdf(ctx, newInvoice.id); + if (!newInvoice.id) throw new UserError(`...`); + + await Self.createPdf(ctx, newInvoice.id); return newInvoice; }; - async function isInvoiceable(clientId, options) { + async function isInvoiceable(clientFk, options) { const models = Self.app.models; const query = `SELECT (hasToInvoice AND isTaxDataChecked) AS invoiceable FROM client WHERE id = ?`; - const [result] = await models.InvoiceOut.rawSql(query, [clientId], options); + const [result] = await models.InvoiceOut.rawSql(query, [clientFk], options); return result.invoiceable; } - async function getNegativeBase(maxShipped, clientId, companyId, options) { + async function getNegativeBase(maxShipped, clientFk, companyId, options) { const models = Self.app.models; await models.InvoiceOut.rawSql('CALL invoiceOut_exportationFromClient(?,?,?)', - [maxShipped, clientId, companyId], options + [maxShipped, clientFk, companyId], options ); const query = 'SELECT vn.hasAnyNegativeBase() AS base'; const [result] = await models.InvoiceOut.rawSql(query, [], options); From 957b0c71ca8922f5493574c854c518e85f9bff55 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 8 Apr 2024 10:06:33 +0200 Subject: [PATCH 02/29] refs #6574 feat: add order --- db/routines/vn/procedures/item_getBalance.sql | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/db/routines/vn/procedures/item_getBalance.sql b/db/routines/vn/procedures/item_getBalance.sql index 95596d3bc..d84605176 100644 --- a/db/routines/vn/procedures/item_getBalance.sql +++ b/db/routines/vn/procedures/item_getBalance.sql @@ -173,7 +173,8 @@ BEGIN lineFk, isPicked, clientType, - claimFk + claimFk, + `order` FROM tItemDiary LEFT JOIN alertLevel a ON a.id = tItemDiary.alertLevel; @@ -197,7 +198,8 @@ BEGIN 0 lineFk, 0 isPicked, 0 clientType, - 0 claimFk + 0 claimFk, + `order` UNION ALL SELECT shipped, alertlevel, @@ -213,7 +215,8 @@ BEGIN lineFk, isPicked, clientType, - claimFk + claimFk, + `order` FROM tItemDiary WHERE shipped >= vDate; END IF; From 42b033dde295fbba1e8196be4e3f218f864293b1 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 8 Apr 2024 11:35:10 +0200 Subject: [PATCH 03/29] refs #6574 feat: add order --- db/routines/vn/procedures/item_getBalance.sql | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/db/routines/vn/procedures/item_getBalance.sql b/db/routines/vn/procedures/item_getBalance.sql index d84605176..e7a3641e0 100644 --- a/db/routines/vn/procedures/item_getBalance.sql +++ b/db/routines/vn/procedures/item_getBalance.sql @@ -156,27 +156,27 @@ BEGIN SET @shipped := ''; SELECT DATE(@shipped:= shipped) shipped, - alertLevel, - stateName, - origin, - reference, - clientFk, - name, - `in` invalue, - `out`, - @a := @a + IFNULL(`in`, 0) - IFNULL(`out`, 0) balance, + t.alertLevel, + t.stateName, + t.origin, + t.reference, + t.clientFk, + t.name, + t.`in` invalue, + t.`out`, + @a := @a + IFNULL(t.`in`, 0) - IFNULL(t.`out`, 0) balance, @currentLineFk := IF (@shipped < util.VN_CURDATE() OR (@shipped = util.VN_CURDATE() AND (isPicked OR a.`code` >= 'ON_PREPARATION')), - lineFk, + t.lineFk, @currentLineFk) lastPreparedLineFk, - isTicket, - lineFk, - isPicked, - clientType, - claimFk, - `order` - FROM tItemDiary - LEFT JOIN alertLevel a ON a.id = tItemDiary.alertLevel; + t.isTicket, + t.lineFk, + t.isPicked, + t.clientType, + t.claimFk, + t.`order` + FROM tItemDiary t + LEFT JOIN alertLevel a ON a.id = t.alertLevel; ELSE SELECT SUM(`in`) - SUM(`out`) INTO @a @@ -199,7 +199,7 @@ BEGIN 0 isPicked, 0 clientType, 0 claimFk, - `order` + NULL `order` UNION ALL SELECT shipped, alertlevel, From 2f7f2374224f58d3c1e87b1f256abf63c749ea7f Mon Sep 17 00:00:00 2001 From: sergiodt Date: Mon, 8 Apr 2024 13:28:38 +0200 Subject: [PATCH 04/29] refs #6574 feat: add order --- db/routines/vn/procedures/item_getBalance.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/item_getBalance.sql b/db/routines/vn/procedures/item_getBalance.sql index e7a3641e0..11af7e570 100644 --- a/db/routines/vn/procedures/item_getBalance.sql +++ b/db/routines/vn/procedures/item_getBalance.sql @@ -155,7 +155,7 @@ BEGIN SET @currentLineFk := 0; SET @shipped := ''; - SELECT DATE(@shipped:= shipped) shipped, + SELECT DATE(@shipped:= t.shipped) shipped, t.alertLevel, t.stateName, t.origin, @@ -166,7 +166,7 @@ BEGIN t.`out`, @a := @a + IFNULL(t.`in`, 0) - IFNULL(t.`out`, 0) balance, @currentLineFk := IF (@shipped < util.VN_CURDATE() - OR (@shipped = util.VN_CURDATE() AND (isPicked OR a.`code` >= 'ON_PREPARATION')), + OR (@shipped = util.VN_CURDATE() AND (t.isPicked OR a.`code` >= 'ON_PREPARATION')), t.lineFk, @currentLineFk) lastPreparedLineFk, t.isTicket, From 84997eacd5b42f923a4395dcc5bba9bce47c16ab Mon Sep 17 00:00:00 2001 From: jcasado Date: Mon, 8 Apr 2024 14:38:54 +0200 Subject: [PATCH 05/29] refs: 6697 remove claim quantity --- modules/claim/back/methods/claim/createFromSales.js | 2 +- modules/claim/back/models/claim-beginning.json | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/claim/back/methods/claim/createFromSales.js b/modules/claim/back/methods/claim/createFromSales.js index 30093e43d..e5022d57e 100644 --- a/modules/claim/back/methods/claim/createFromSales.js +++ b/modules/claim/back/methods/claim/createFromSales.js @@ -83,7 +83,7 @@ module.exports = Self => { const newClaimBeginning = models.ClaimBeginning.create({ saleFk: sale.id, claimFk: newClaim.id, - quantity: sale.quantity + }, myOptions); promises.push(newClaimBeginning); diff --git a/modules/claim/back/models/claim-beginning.json b/modules/claim/back/models/claim-beginning.json index d224586da..ba6e83808 100644 --- a/modules/claim/back/models/claim-beginning.json +++ b/modules/claim/back/models/claim-beginning.json @@ -16,8 +16,7 @@ "description": "Identifier" }, "quantity": { - "type": "number", - "required": true + "type": "number" } }, "relations": { From bc9149ec37981ca69fd0b0706d8f6faf502af445 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 11 Apr 2024 14:32:26 +0200 Subject: [PATCH 06/29] feat: tipo de cambio php to js --- back/methods/collection/exchangeRateUpdate.js | 66 +++++++++++++++++++ back/model-config.json | 5 +- back/models/collection.js | 1 + back/models/reference-rate.json | 40 +++++++++++ db/dump/fixtures.before.sql | 3 +- loopback/locale/es.json | 11 +++- 6 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 back/methods/collection/exchangeRateUpdate.js create mode 100644 back/models/reference-rate.json diff --git a/back/methods/collection/exchangeRateUpdate.js b/back/methods/collection/exchangeRateUpdate.js new file mode 100644 index 000000000..8525fa980 --- /dev/null +++ b/back/methods/collection/exchangeRateUpdate.js @@ -0,0 +1,66 @@ +const axios = require('axios'); +const {DOMParser} = require('xmldom'); +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethod('exchangeRateUpdate', { + description: 'Updates the exchange rates from an XML feed', + accessType: 'WRITE', + accepts: [], + http: { + path: '/exchangeRateUpdate', + verb: 'post' + }, + returns: { + arg: 'result', + type: 'object', + root: true + } + }); + + Self.exchangeRateUpdate = async() => { + const response = await axios.get('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml'); + const xmlData = response.data; + + const doc = new DOMParser().parseFromString(xmlData, 'text/xml'); + const cubes = doc.getElementsByTagName('Cube'); + + const models = Self.app.models; + + const maxDateRecord = await models.ReferenceRate.findOne({order: 'dated DESC'}); + let maxDate = maxDateRecord ? new Date(maxDateRecord.dated) : null; + + for (const cube of cubes) { + if (cube.attributes.getNamedItem('time')) { + const xmlDate = new Date(cube.getAttribute('time')); + if (!maxDate || maxDate < xmlDate) { + for (const rateCube of cube.childNodes) { + if (rateCube.nodeType === Node.ELEMENT_NODE) { + const currencyCode = rateCube.getAttribute('currency'); + const rate = rateCube.getAttribute('rate'); + if (['USD', 'CNY', 'GBP'].includes(currencyCode)) { + const currency = await models.Currency.findOne({where: {code: currencyCode}}); + if (!currency) throw new UserError(`Currency not found for code: ${currencyCode}`); + + try { + await models.ReferenceRate.upsertWithWhere( + {currencyFk: currency.id, dated: xmlDate}, + { + currencyFk: currency.id, + dated: xmlDate, + value: rate + } + ); + } catch (error) { + console.error(`Failed to upsert rate for ${currencyCode} on ${xmlDate}: ${error}`); + // Handle or throw the error accordingly + throw error; + } + } + } + } + } + } + } + }; +}; diff --git a/back/model-config.json b/back/model-config.json index f48ec11e6..10e606f3c 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -124,6 +124,9 @@ "Postcode": { "dataSource": "vn" }, + "ReferenceRate": { + "dataSource": "vn" + }, "SageWithholding": { "dataSource": "vn" }, @@ -175,4 +178,4 @@ "WorkerActivityType": { "dataSource": "vn" } -} \ No newline at end of file +} diff --git a/back/models/collection.js b/back/models/collection.js index f2c2f1566..68c0bd13e 100644 --- a/back/models/collection.js +++ b/back/models/collection.js @@ -5,4 +5,5 @@ module.exports = Self => { require('../methods/collection/getTickets')(Self); require('../methods/collection/assign')(Self); require('../methods/collection/getSales')(Self); + require('../methods/collection/exchangeRateUpdate')(Self); }; diff --git a/back/models/reference-rate.json b/back/models/reference-rate.json new file mode 100644 index 000000000..3553df5c5 --- /dev/null +++ b/back/models/reference-rate.json @@ -0,0 +1,40 @@ +{ + "name": "ReferenceRate", + "base": "PersistedModel", + "idInjection": false, + "options": { + "mysql": { + "table": "referenceRate" + } + }, + "properties": { + "currencyFk": { + "type": "number", + "required": true, + "id": 1, + "mysql": { + "dataType": "tinyint", + "dataLength": 3, + "unsigned": true, + "primaryKey": true + } + }, + "dated": { + "type": "date", + "required": true, + "id": 2 + }, + "value": { + "type": "number", + "required": true + } + }, + "acls": [ + { + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + } + ] +} diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 6fb70cb58..c84a08f87 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -160,7 +160,8 @@ INSERT INTO `vn`.`currency`(`id`, `code`, `name`, `ratio`) (1, 'EUR', 'Euro', 1), (2, 'USD', 'Dollar USA', 1.4), (3, 'GBP', 'Libra', 1), - (4, 'JPY', 'Yen Japones', 1); + (4, 'JPY', 'Yen Japones', 1), + (5, 'CNY', 'Yuan Chino', 1.2); INSERT INTO `vn`.`country`(`id`, `country`, `isUeeMember`, `code`, `currencyFk`, `ibanLength`, `continentFk`, `hasDailyInvoice`, `CEE`) VALUES diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 8b02f3048..50cd305fa 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -352,5 +352,14 @@ "The line could not be marked": "La linea no puede ser marcada", "This password can only be changed by the user themselves": "Esta contraseña solo puede ser modificada por el propio usuario", "They're not your subordinate": "No es tu subordinado/a.", - "No results found": "No se han encontrado resultados" + "No results found": "No se han encontrado resultados", + "ReferenceError: app is not defined": "ReferenceError: app is not defined", + "TypeError: Cannot read properties of undefined (reading 'ReferenceRate')": "TypeError: Cannot read properties of undefined (reading 'ReferenceRate')", + "Error: ER_BAD_FIELD_ERROR: Unknown column 'date' in 'order clause'": "Error: ER_BAD_FIELD_ERROR: Unknown column 'date' in 'order clause'", + "ReferenceError: ReferenceRate is not defined": "ReferenceError: ReferenceRate is not defined", + "ValidationError: The `ReferenceRate` instance is not valid. Details: `currencyFk` can't be blank (value: NaN).": "ValidationError: The `ReferenceRate` instance is not valid. Details: `currencyFk` can't be blank (value: NaN).", + "ReferenceError: Currency is not defined": "ReferenceError: Currency is not defined", + "UserError: Currency not found for code: CNY": "UserError: Currency not found for code: CNY", + "Error: ER_DUP_ENTRY: Duplicate entry '2-2024-04-03' for key 'PRIMARY'": "Error: ER_DUP_ENTRY: Duplicate entry '2-2024-04-03' for key 'PRIMARY'", + "Error: ER_DUP_ENTRY: Duplicate entry '2-2024-04-08' for key 'PRIMARY'": "Error: ER_DUP_ENTRY: Duplicate entry '2-2024-04-08' for key 'PRIMARY'" } \ No newline at end of file From bb6ea31bf715e59f49a656fa505a722f50761010 Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 12 Apr 2024 10:26:32 +0200 Subject: [PATCH 07/29] feat: funcional a falta de test --- back/methods/collection/exchangeRateUpdate.js | 41 ++++++++++--------- back/models/collection.json | 6 ++- back/models/reference-rate.json | 17 ++++---- db/versions/10992-goldenIvy/00-acl.sql | 2 + .../10992-goldenIvy/00-referenceRate.sql | 4 ++ 5 files changed, 40 insertions(+), 30 deletions(-) create mode 100644 db/versions/10992-goldenIvy/00-acl.sql create mode 100644 db/versions/10992-goldenIvy/00-referenceRate.sql diff --git a/back/methods/collection/exchangeRateUpdate.js b/back/methods/collection/exchangeRateUpdate.js index 8525fa980..093ee6e48 100644 --- a/back/methods/collection/exchangeRateUpdate.js +++ b/back/methods/collection/exchangeRateUpdate.js @@ -28,33 +28,36 @@ module.exports = Self => { const models = Self.app.models; const maxDateRecord = await models.ReferenceRate.findOne({order: 'dated DESC'}); - let maxDate = maxDateRecord ? new Date(maxDateRecord.dated) : null; - for (const cube of cubes) { - if (cube.attributes.getNamedItem('time')) { + const maxDate = maxDateRecord && maxDateRecord.dated ? new Date(maxDateRecord.dated) : null; + + for (let i = 0; i < cubes.length; i++) { + const cube = cubes[i]; + if (cube.nodeType === 1 && cube.attributes.getNamedItem('time')) { const xmlDate = new Date(cube.getAttribute('time')); - if (!maxDate || maxDate < xmlDate) { - for (const rateCube of cube.childNodes) { - if (rateCube.nodeType === Node.ELEMENT_NODE) { + const xmlDateWithoutTime = new Date(xmlDate.getFullYear(), xmlDate.getMonth(), xmlDate.getDate()); + if (!maxDate || maxDate < xmlDateWithoutTime) { + for (let j = 0; j < cube.childNodes.length; j++) { + const rateCube = cube.childNodes[j]; + if (rateCube.nodeType === doc.ELEMENT_NODE) { const currencyCode = rateCube.getAttribute('currency'); const rate = rateCube.getAttribute('rate'); if (['USD', 'CNY', 'GBP'].includes(currencyCode)) { const currency = await models.Currency.findOne({where: {code: currencyCode}}); if (!currency) throw new UserError(`Currency not found for code: ${currencyCode}`); + const existingRate = await models.ReferenceRate.findOne({ + where: {currencyFk: currency.id, dated: xmlDate} + }); - try { - await models.ReferenceRate.upsertWithWhere( - {currencyFk: currency.id, dated: xmlDate}, - { - currencyFk: currency.id, - dated: xmlDate, - value: rate - } - ); - } catch (error) { - console.error(`Failed to upsert rate for ${currencyCode} on ${xmlDate}: ${error}`); - // Handle or throw the error accordingly - throw error; + if (existingRate) { + if (existingRate.value !== rate) + await existingRate.updateAttributes({value: rate}); + } else { + await models.ReferenceRate.create({ + currencyFk: currency.id, + dated: xmlDate, + value: rate + }); } } } diff --git a/back/models/collection.json b/back/models/collection.json index 3e428ef60..cb8dc3d7c 100644 --- a/back/models/collection.json +++ b/back/models/collection.json @@ -1,6 +1,11 @@ { "name": "Collection", "base": "VnModel", + "options": { + "mysql": { + "table": "collection" + } + }, "acls": [{ "property": "validations", "accessType": "EXECUTE", @@ -9,4 +14,3 @@ "permission": "ALLOW" }] } - \ No newline at end of file diff --git a/back/models/reference-rate.json b/back/models/reference-rate.json index 3553df5c5..b77213b29 100644 --- a/back/models/reference-rate.json +++ b/back/models/reference-rate.json @@ -8,21 +8,18 @@ } }, "properties": { + "id": { + "type": "number", + "id": true, + "description": "Identifier" + }, "currencyFk": { "type": "number", - "required": true, - "id": 1, - "mysql": { - "dataType": "tinyint", - "dataLength": 3, - "unsigned": true, - "primaryKey": true - } + "required": true }, "dated": { "type": "date", - "required": true, - "id": 2 + "required": true }, "value": { "type": "number", diff --git a/db/versions/10992-goldenIvy/00-acl.sql b/db/versions/10992-goldenIvy/00-acl.sql new file mode 100644 index 000000000..551905be1 --- /dev/null +++ b/db/versions/10992-goldenIvy/00-acl.sql @@ -0,0 +1,2 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES ('Collection', 'exchangeRateUpdate', '*', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/versions/10992-goldenIvy/00-referenceRate.sql b/db/versions/10992-goldenIvy/00-referenceRate.sql new file mode 100644 index 000000000..db53f328f --- /dev/null +++ b/db/versions/10992-goldenIvy/00-referenceRate.sql @@ -0,0 +1,4 @@ +ALTER TABLE vn.referenceRate DROP INDEX `PRIMARY`; +ALTER TABLE vn.referenceRate ADD id INT auto_increment PRIMARY KEY; +ALTER TABLE vn.referenceRate CHANGE id id int(11) auto_increment NOT NULL FIRST; +CREATE UNIQUE INDEX referenceRate_currencyFk_IDX USING BTREE ON vn.referenceRate (currencyFk,dated); From e8001b72e464395d05a44cc1c437a255d4fa38fa Mon Sep 17 00:00:00 2001 From: jgallego Date: Sat, 13 Apr 2024 09:05:54 +0200 Subject: [PATCH 08/29] feat: minor changes --- back/methods/collection/exchangeRateUpdate.js | 13 +++---------- back/models/reference-rate.json | 1 - loopback/locale/es.json | 13 ++----------- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/back/methods/collection/exchangeRateUpdate.js b/back/methods/collection/exchangeRateUpdate.js index 093ee6e48..b1272d73a 100644 --- a/back/methods/collection/exchangeRateUpdate.js +++ b/back/methods/collection/exchangeRateUpdate.js @@ -10,11 +10,6 @@ module.exports = Self => { http: { path: '/exchangeRateUpdate', verb: 'post' - }, - returns: { - arg: 'result', - type: 'object', - root: true } }); @@ -29,16 +24,14 @@ module.exports = Self => { const maxDateRecord = await models.ReferenceRate.findOne({order: 'dated DESC'}); - const maxDate = maxDateRecord && maxDateRecord.dated ? new Date(maxDateRecord.dated) : null; + const maxDate = maxDateRecord?.dated ? new Date(maxDateRecord.dated) : null; - for (let i = 0; i < cubes.length; i++) { - const cube = cubes[i]; + for (const cube of Array.from(cubes)) { if (cube.nodeType === 1 && cube.attributes.getNamedItem('time')) { const xmlDate = new Date(cube.getAttribute('time')); const xmlDateWithoutTime = new Date(xmlDate.getFullYear(), xmlDate.getMonth(), xmlDate.getDate()); if (!maxDate || maxDate < xmlDateWithoutTime) { - for (let j = 0; j < cube.childNodes.length; j++) { - const rateCube = cube.childNodes[j]; + for (const rateCube of Array.from(cube.childNodes)) { if (rateCube.nodeType === doc.ELEMENT_NODE) { const currencyCode = rateCube.getAttribute('currency'); const rate = rateCube.getAttribute('rate'); diff --git a/back/models/reference-rate.json b/back/models/reference-rate.json index b77213b29..fe732f3ef 100644 --- a/back/models/reference-rate.json +++ b/back/models/reference-rate.json @@ -1,7 +1,6 @@ { "name": "ReferenceRate", "base": "PersistedModel", - "idInjection": false, "options": { "mysql": { "table": "referenceRate" diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 50cd305fa..18ead3769 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -352,14 +352,5 @@ "The line could not be marked": "La linea no puede ser marcada", "This password can only be changed by the user themselves": "Esta contraseña solo puede ser modificada por el propio usuario", "They're not your subordinate": "No es tu subordinado/a.", - "No results found": "No se han encontrado resultados", - "ReferenceError: app is not defined": "ReferenceError: app is not defined", - "TypeError: Cannot read properties of undefined (reading 'ReferenceRate')": "TypeError: Cannot read properties of undefined (reading 'ReferenceRate')", - "Error: ER_BAD_FIELD_ERROR: Unknown column 'date' in 'order clause'": "Error: ER_BAD_FIELD_ERROR: Unknown column 'date' in 'order clause'", - "ReferenceError: ReferenceRate is not defined": "ReferenceError: ReferenceRate is not defined", - "ValidationError: The `ReferenceRate` instance is not valid. Details: `currencyFk` can't be blank (value: NaN).": "ValidationError: The `ReferenceRate` instance is not valid. Details: `currencyFk` can't be blank (value: NaN).", - "ReferenceError: Currency is not defined": "ReferenceError: Currency is not defined", - "UserError: Currency not found for code: CNY": "UserError: Currency not found for code: CNY", - "Error: ER_DUP_ENTRY: Duplicate entry '2-2024-04-03' for key 'PRIMARY'": "Error: ER_DUP_ENTRY: Duplicate entry '2-2024-04-03' for key 'PRIMARY'", - "Error: ER_DUP_ENTRY: Duplicate entry '2-2024-04-08' for key 'PRIMARY'": "Error: ER_DUP_ENTRY: Duplicate entry '2-2024-04-08' for key 'PRIMARY'" -} \ No newline at end of file + "No results found": "No se han encontrado resultados" +} From 77a1aa4de62f7e87804cbcf72b9a314ab9e710ac Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 16 Apr 2024 08:45:03 +0200 Subject: [PATCH 09/29] feat: @7108 test --- back/methods/collection/exchangeRateUpdate.js | 8 +-- .../spec/exchangeRateUpdate.spec.js | 52 +++++++++++++++++++ 2 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 back/methods/collection/spec/exchangeRateUpdate.spec.js diff --git a/back/methods/collection/exchangeRateUpdate.js b/back/methods/collection/exchangeRateUpdate.js index b1272d73a..3ad06b242 100644 --- a/back/methods/collection/exchangeRateUpdate.js +++ b/back/methods/collection/exchangeRateUpdate.js @@ -17,8 +17,10 @@ module.exports = Self => { const response = await axios.get('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml'); const xmlData = response.data; - const doc = new DOMParser().parseFromString(xmlData, 'text/xml'); - const cubes = doc.getElementsByTagName('Cube'); + const doc = new DOMParser({errorHandler: {warning: () => {}}})?.parseFromString(xmlData, 'text/xml'); + const cubes = doc?.getElementsByTagName('Cube'); + if (!cubes || cubes.length === 0) + throw new UserError('No cubes found. Exiting the method.'); const models = Self.app.models; @@ -27,7 +29,7 @@ module.exports = Self => { const maxDate = maxDateRecord?.dated ? new Date(maxDateRecord.dated) : null; for (const cube of Array.from(cubes)) { - if (cube.nodeType === 1 && cube.attributes.getNamedItem('time')) { + if (cube.nodeType === doc.ELEMENT_NODE && cube.attributes.getNamedItem('time')) { const xmlDate = new Date(cube.getAttribute('time')); const xmlDateWithoutTime = new Date(xmlDate.getFullYear(), xmlDate.getMonth(), xmlDate.getDate()); if (!maxDate || maxDate < xmlDateWithoutTime) { diff --git a/back/methods/collection/spec/exchangeRateUpdate.spec.js b/back/methods/collection/spec/exchangeRateUpdate.spec.js new file mode 100644 index 000000000..7086c37a3 --- /dev/null +++ b/back/methods/collection/spec/exchangeRateUpdate.spec.js @@ -0,0 +1,52 @@ +describe('exchangeRateUpdate functionality', function() { + const axios = require('axios'); + const models = require('vn-loopback/server/server').models; + + beforeEach(function() { + spyOn(axios, 'get').and.returnValue(Promise.resolve({ + data: ` + + + + + ` + })); + }); + + it('should process XML data and update or create rates in the database', async function() { + spyOn(models.ReferenceRate, 'findOne').and.returnValue(Promise.resolve(null)); + spyOn(models.ReferenceRate, 'create').and.returnValue(Promise.resolve()); + + await models.Collection.exchangeRateUpdate(); + + expect(models.ReferenceRate.create).toHaveBeenCalledTimes(2); + }); + + it('should not create or update rates when no XML data is available', async function() { + axios.get.and.returnValue(Promise.resolve({})); + spyOn(models.ReferenceRate, 'create'); + + let thrownError = null; + try { + await models.Collection.exchangeRateUpdate(); + } catch (error) { + thrownError = error; + } + + expect(thrownError.message).toBe('No cubes found. Exiting the method.'); + }); + + it('should handle errors gracefully', async function() { + axios.get.and.returnValue(Promise.reject(new Error('Network error'))); + let error; + + try { + await models.Collection.exchangeRateUpdate(); + } catch (e) { + error = e; + } + + expect(error).toBeDefined(); + expect(error.message).toBe('Network error'); + }); +}); From b0c4f7fd3c1052bec05c9a11f86d935aaf3ed1ee Mon Sep 17 00:00:00 2001 From: jgallego Date: Mon, 22 Apr 2024 11:45:58 +0200 Subject: [PATCH 10/29] feat: moved files to invoiceIn --- back/models/collection.js | 1 - loopback/locale/en.json | 433 +++++++++--------- .../methods/invoice-in}/exchangeRateUpdate.js | 0 .../specs}/exchangeRateUpdate.spec.js | 6 +- modules/invoiceIn/back/models/invoice-in.js | 1 + 5 files changed, 221 insertions(+), 220 deletions(-) rename {back/methods/collection => modules/invoiceIn/back/methods/invoice-in}/exchangeRateUpdate.js (100%) rename {back/methods/collection/spec => modules/invoiceIn/back/methods/invoice-in/specs}/exchangeRateUpdate.spec.js (90%) diff --git a/back/models/collection.js b/back/models/collection.js index 68c0bd13e..f2c2f1566 100644 --- a/back/models/collection.js +++ b/back/models/collection.js @@ -5,5 +5,4 @@ module.exports = Self => { require('../methods/collection/getTickets')(Self); require('../methods/collection/assign')(Self); require('../methods/collection/getSales')(Self); - require('../methods/collection/exchangeRateUpdate')(Self); }; diff --git a/loopback/locale/en.json b/loopback/locale/en.json index a0e60550f..9a3a1f52a 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -1,217 +1,217 @@ { - "State cannot be blank": "State cannot be blank", - "Cannot be blank": "Cannot be blank", - "The credit must be an integer greater than or equal to zero": "The credit must be an integer greater than or equal to zero", - "The grade must be an integer greater than or equal to zero": "The grade must be an integer greater than or equal to zero", - "Invalid email": "Invalid email", - "Name cannot be blank": "Name cannot be blank", - "Phone cannot be blank": "Phone cannot be blank", - "Description should have maximum of 45 characters": "Description should have maximum of 45 characters", - "Period cannot be blank": "Period cannot be blank", - "Sample type cannot be blank": "Sample type cannot be blank", - "That payment method requires an IBAN": "That payment method requires an IBAN", - "That payment method requires a BIC": "That payment method requires a BIC", - "The default consignee can not be unchecked": "The default consignee can not be unchecked", - "Enter an integer different to zero": "Enter an integer different to zero", - "Package cannot be blank": "Package cannot be blank", - "The price of the item changed": "The price of the item changed", - "The sales of this ticket can't be modified": "The sales of this ticket can't be modified", - "Cannot check Equalization Tax in this NIF/CIF": "Cannot check Equalization Tax in this NIF/CIF", - "You can't create an order for a frozen client": "You can't create an order for a frozen client", - "This address doesn't exist": "This address doesn't exist", - "Warehouse cannot be blank": "Warehouse cannot be blank", - "Agency cannot be blank": "Agency cannot be blank", - "The IBAN does not have the correct format": "The IBAN does not have the correct format", - "You can't make changes on the basic data of an confirmed order or with rows": "You can't make changes on the basic data of an confirmed order or with rows", - "You can't create a ticket for an inactive client": "You can't create a ticket for an inactive client", - "Worker cannot be blank": "Worker cannot be blank", - "You must delete the claim id %d first": "You must delete the claim id %d first", - "You don't have enough privileges": "You don't have enough privileges", - "Tag value cannot be blank": "Tag value cannot be blank", - "A client with that Web User name already exists": "A client with that Web User name already exists", - "The warehouse can't be repeated": "The warehouse can't be repeated", - "Barcode must be unique": "Barcode must be unique", - "You don't have enough privileges to do that": "You don't have enough privileges to do that", - "You can't create a ticket for a frozen client": "You can't create a ticket for a frozen client", - "can't be blank": "can't be blank", - "Street cannot be empty": "Street cannot be empty", - "City cannot be empty": "City cannot be empty", - "EXTENSION_INVALID_FORMAT": "Invalid extension", - "The secret can't be blank": "The secret can't be blank", - "Invalid TIN": "Invalid Tax number", - "This ticket can't be invoiced": "This ticket can't be invoiced", - "The value should be a number": "The value should be a number", - "The current ticket can't be modified": "The current ticket can't be modified", - "Extension format is invalid": "Extension format is invalid", - "NO_ZONE_FOR_THIS_PARAMETERS": "NO_ZONE_FOR_THIS_PARAMETERS", - "This client can't be invoiced": "This client can't be invoiced", - "You must provide the correction information to generate a corrective invoice": "You must provide the correction information to generate a corrective invoice", - "The introduced hour already exists": "The introduced hour already exists", - "Invalid parameters to create a new ticket": "Invalid parameters to create a new ticket", - "Concept cannot be blank": "Concept cannot be blank", - "Ticket id cannot be blank": "Ticket id cannot be blank", - "Weekday cannot be blank": "Weekday cannot be blank", - "This ticket can not be modified": "This ticket can not be modified", - "You can't delete a confirmed order": "You can't delete a confirmed order", - "Value has an invalid format": "Value has an invalid format", - "The postcode doesn't exist. Please enter a correct one": "The postcode doesn't exist. Please enter a correct one", - "Swift / BIC can't be empty": "Swift / BIC can't be empty", - "Deleted sales from ticket": "I have deleted the following lines from the ticket [{{ticketId}}]({{{ticketUrl}}}): {{{deletions}}}", - "Added sale to ticket": "I have added the following line to the ticket [{{ticketId}}]({{{ticketUrl}}}): {{{addition}}}", - "Changed sale discount": "I have changed the following lines discounts from the ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", - "Created claim": "I have created the claim [{{claimId}}]({{{claimUrl}}}) for the following lines from the ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", - "Changed sale price": "I have changed the price of [{{itemId}} {{concept}}]({{{itemUrl}}}) ({{quantity}}) from {{oldPrice}}€ ➔ *{{newPrice}}€* of the ticket [{{ticketId}}]({{{ticketUrl}}})", - "Changed sale quantity": "I have changed the quantity of [{{itemId}} {{concept}}]({{{itemUrl}}}) from {{oldQuantity}} ➔ *{{newQuantity}}* of the ticket [{{ticketId}}]({{{ticketUrl}}})", - "Changed sale reserved state": "I have changed the following lines reserved state from the ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", - "Bought units from buy request": "Bought {{quantity}} units of [{{itemId}} {{concept}}]({{{urlItem}}}) for the ticket id [{{ticketId}}]({{{url}}})", - "MESSAGE_INSURANCE_CHANGE": "I have changed the insurence credit of client [{{clientName}} ({{clientId}})]({{{url}}}) to *{{credit}} €*", - "Changed client paymethod": "I have changed the pay method for client [{{clientName}} ({{clientId}})]({{{url}}})", - "Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} ({{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [{{ticketId}}]({{{ticketUrl}}})", - "Change quantity": "{{concept}} change of {{oldQuantity}} to {{newQuantity}}", - "Claim will be picked": "The product from the claim [({{claimId}})]({{{claimUrl}}}) from the client *{{clientName}}* will be picked, with the pickup type *{{claimPickup}}*", - "Claim state has changed to": "The state of the claim [({{claimId}})]({{{claimUrl}}}) from client *{{clientName}}* has changed to *{{newState}}*", - "Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member", - "Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member", - "Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}", - "Landing cannot be lesser than shipment": "Landing cannot be lesser than shipment", - "NOT_ZONE_WITH_THIS_PARAMETERS": "There's no zone available for this day", - "Created absence": "The worker {{author}} has added an absence of type '{{absenceType}}' to {{employee}} for day {{dated}}.", - "Deleted absence": "The worker {{author}} has deleted an absence of type '{{absenceType}}' to {{employee}} for day {{dated}}.", - "I have deleted the ticket id": "I have deleted the ticket id [{{id}}]({{{url}}})", - "I have restored the ticket id": "I have restored the ticket id [{{id}}]({{{url}}})", - "Changed this data from the ticket": "I have changed the data from the ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", - "The grade must be similar to the last one": "The grade must be similar to the last one", - "agencyModeFk": "Agency", - "clientFk": "Client", - "zoneFk": "Zone", - "warehouseFk": "Warehouse", - "shipped": "Shipped", - "landed": "Landed", - "addressFk": "Address", - "companyFk": "Company", - "agency": "Agency", - "delivery": "Delivery", - "You need to fill sage information before you check verified data": "You need to fill sage information before you check verified data", - "The social name cannot be empty": "The social name cannot be empty", - "The nif cannot be empty": "The nif cannot be empty", - "Amount cannot be zero": "Amount cannot be zero", - "Company has to be official": "Company has to be official", - "Unable to clone this travel": "Unable to clone this travel", - "The observation type can't be repeated": "The observation type can't be repeated", - "New ticket request has been created with price": "New ticket request has been created *'{{description}}'* for day *{{shipped}}*, with a quantity of *{{quantity}}* and a price of *{{price}} €*", - "New ticket request has been created": "New ticket request has been created *'{{description}}'* for day *{{shipped}}*, with a quantity of *{{quantity}}*", - "There's a new urgent ticket": "There's a new urgent ticket: [{{title}}](https://cau.verdnatura.es/WorkOrder.do?woMode=viewWO&woID={{issueId}})", - "Swift / BIC cannot be empty": "Swift / BIC cannot be empty", - "Role name must be written in camelCase": "Role name must be written in camelCase", - "Client assignment has changed": "I did change the salesperson ~*\"<{{previousWorkerName}}>\"*~ by *\"<{{currentWorkerName}}>\"* from the client [{{clientName}} ({{clientId}})]({{{url}}})", - "None": "None", - "error densidad = 0": "error densidad = 0", - "This document already exists on this ticket": "This document already exists on this ticket", - "serial non editable": "This serial doesn't allow to set a reference", - "nickname": "nickname", - "State": "State", - "regular": "regular", - "reserved": "reserved", - "Global invoicing failed": "[Global invoicing] Wasn't able to invoice some of the clients", - "A ticket with a negative base can't be invoiced": "A ticket with a negative base can't be invoiced", - "This client is not invoiceable": "This client is not invoiceable", - "INACTIVE_PROVIDER": "Inactive provider", - "reference duplicated": "reference duplicated", - "The PDF document does not exist": "The PDF document does not exists. Try regenerating it from 'Regenerate invoice PDF' option", - "This item is not available": "This item is not available", - "Deny buy request": "Purchase request for ticket id [{{ticketId}}]({{{url}}}) has been rejected. Reason: {{observation}}", - "The type of business must be filled in basic data": "The type of business must be filled in basic data", - "The worker has hours recorded that day": "The worker has hours recorded that day", - "isWithoutNegatives": "isWithoutNegatives", - "routeFk": "routeFk", - "Not enough privileges to edit a client with verified data": "Not enough privileges to edit a client with verified data", - "Can't change the password of another worker": "Can't change the password of another worker", - "No hay un contrato en vigor": "There is no existing contract", - "No está permitido trabajar": "Not allowed to work", - "Dirección incorrecta": "Wrong direction", - "No se permite fichar a futuro": "It is not allowed to sign in the future", - "Descanso diario 12h.": "Daily rest 12h.", - "Fichadas impares": "Odd signs", - "Descanso diario 9h.": "Daily rest 9h.", - "Descanso semanal 36h. / 72h.": "Weekly rest 36h. / 72h.", - "Verify email": "Verify email", - "Click on the following link to verify this email. If you haven't requested this email, just ignore it": "Click on the following link to verify this email. If you haven't requested this email, just ignore it", - "Password does not meet requirements": "Password does not meet requirements", - "You don't have privileges to change the zone": "You don't have privileges to change the zone or for these parameters there are more than one shipping options, talk to agencies", - "Not enough privileges to edit a client": "Not enough privileges to edit a client", - "Claim pickup order sent": "Claim pickup order sent [{{claimId}}]({{{claimUrl}}}) to client *{{clientName}}*", - "You don't have grant privilege": "You don't have grant privilege", - "You don't own the role and you can't assign it to another user": "You don't own the role and you can't assign it to another user", - "Email verify": "Email verify", - "Ticket merged": "Ticket [{{originId}}]({{{originFullPath}}}) ({{{originDated}}}) merged with [{{destinationId}}]({{{destinationFullPath}}}) ({{{destinationDated}}})", - "App locked": "App locked by user {{userId}}", - "The sales of the receiver ticket can't be modified": "The sales of the receiver ticket can't be modified", - "Receipt's bank was not found": "Receipt's bank was not found", - "This receipt was not compensated": "This receipt was not compensated", - "Client's email was not found": "Client's email was not found", - "Tickets with associated refunds": "Tickets with associated refunds can't be deleted. This ticket is associated with refund Nº %d", - "It is not possible to modify tracked sales": "It is not possible to modify tracked sales", - "It is not possible to modify sales that their articles are from Floramondo": "It is not possible to modify sales that their articles are from Floramondo", - "It is not possible to modify cloned sales": "It is not possible to modify cloned sales", - "Warehouse inventory not set": "Almacén inventario no está establecido", - "Component cost not set": "Componente coste no está estabecido", - "Description cannot be blank": "Description cannot be blank", - "company": "Company", - "country": "Country", - "clientId": "Id client", - "clientSocialName": "Client", - "amount": "Amount", - "taxableBase": "Taxable base", - "ticketFk": "Id ticket", - "isActive": "Active", - "hasToInvoice": "Invoice", - "isTaxDataChecked": "Data checked", - "comercialId": "Id Comercial", - "comercialName": "Comercial", - "Added observation": "Added observation", - "Comment added to client": "Comment added to client", - "This ticket is already a refund": "This ticket is already a refund", - "A claim with that sale already exists": "A claim with that sale already exists", - "Pass expired": "The password has expired, change it from Salix", - "Can't transfer claimed sales": "Can't transfer claimed sales", - "Invalid quantity": "Invalid quantity", - "Failed to upload delivery note": "Error to upload delivery note {{id}}", - "Mail not sent": "There has been an error sending the invoice to the client [{{clientId}}]({{{clientUrl}}}), please check the email address", - "The renew period has not been exceeded": "The renew period has not been exceeded", - "You can not use the same password": "You can not use the same password", - "Valid priorities": "Valid priorities: %d", - "hasAnyNegativeBase": "Negative basis of tickets: {{ticketsIds}}", - "hasAnyPositiveBase": "Positive basis of tickets: {{ticketsIds}}", - "This ticket cannot be left empty.": "This ticket cannot be left empty. %s", - "Social name should be uppercase": "Social name should be uppercase", - "Street should be uppercase": "Street should be uppercase", - "You don't have enough privileges.": "You don't have enough privileges.", - "This ticket is locked": "This ticket is locked", - "This ticket is not editable.": "This ticket is not editable.", - "The ticket doesn't exist.": "The ticket doesn't exist.", - "The sales do not exists": "The sales do not exists", - "Ticket without Route": "Ticket without route", - "Select a different client": "Select a different client", - "Fill all the fields": "Fill all the fields", - "Error while generating PDF": "Error while generating PDF", - "Can't invoice to future": "Can't invoice to future", - "This ticket is already invoiced": "This ticket is already invoiced", - "Negative basis of tickets: 23": "Negative basis of tickets: 23", - "Booking completed": "Booking complete", - "The ticket is in preparation": "The ticket [{{ticketId}}]({{{ticketUrl}}}) of the sales person {{salesPersonId}} is in preparation", - "You can only add negative amounts in refund tickets": "You can only add negative amounts in refund tickets", - "Bank entity must be specified": "Bank entity must be specified", - "Try again": "Try again", - "keepPrice": "keepPrice", - "Cannot past travels with entries": "Cannot past travels with entries", - "It was not able to remove the next expeditions:": "It was not able to remove the next expeditions: {{expeditions}}", - "Incorrect pin": "Incorrect pin.", - "The notification subscription of this worker cant be modified": "The notification subscription of this worker cant be modified", - "Name should be uppercase": "Name should be uppercase", - "You cannot update these fields": "You cannot update these fields", - "CountryFK cannot be empty": "Country cannot be empty", - "You are not allowed to modify the alias": "You are not allowed to modify the alias", - "You already have the mailAlias": "You already have the mailAlias", + "State cannot be blank": "State cannot be blank", + "Cannot be blank": "Cannot be blank", + "The credit must be an integer greater than or equal to zero": "The credit must be an integer greater than or equal to zero", + "The grade must be an integer greater than or equal to zero": "The grade must be an integer greater than or equal to zero", + "Invalid email": "Invalid email", + "Name cannot be blank": "Name cannot be blank", + "Phone cannot be blank": "Phone cannot be blank", + "Description should have maximum of 45 characters": "Description should have maximum of 45 characters", + "Period cannot be blank": "Period cannot be blank", + "Sample type cannot be blank": "Sample type cannot be blank", + "That payment method requires an IBAN": "That payment method requires an IBAN", + "That payment method requires a BIC": "That payment method requires a BIC", + "The default consignee can not be unchecked": "The default consignee can not be unchecked", + "Enter an integer different to zero": "Enter an integer different to zero", + "Package cannot be blank": "Package cannot be blank", + "The price of the item changed": "The price of the item changed", + "The sales of this ticket can't be modified": "The sales of this ticket can't be modified", + "Cannot check Equalization Tax in this NIF/CIF": "Cannot check Equalization Tax in this NIF/CIF", + "You can't create an order for a frozen client": "You can't create an order for a frozen client", + "This address doesn't exist": "This address doesn't exist", + "Warehouse cannot be blank": "Warehouse cannot be blank", + "Agency cannot be blank": "Agency cannot be blank", + "The IBAN does not have the correct format": "The IBAN does not have the correct format", + "You can't make changes on the basic data of an confirmed order or with rows": "You can't make changes on the basic data of an confirmed order or with rows", + "You can't create a ticket for an inactive client": "You can't create a ticket for an inactive client", + "Worker cannot be blank": "Worker cannot be blank", + "You must delete the claim id %d first": "You must delete the claim id %d first", + "You don't have enough privileges": "You don't have enough privileges", + "Tag value cannot be blank": "Tag value cannot be blank", + "A client with that Web User name already exists": "A client with that Web User name already exists", + "The warehouse can't be repeated": "The warehouse can't be repeated", + "Barcode must be unique": "Barcode must be unique", + "You don't have enough privileges to do that": "You don't have enough privileges to do that", + "You can't create a ticket for a frozen client": "You can't create a ticket for a frozen client", + "can't be blank": "can't be blank", + "Street cannot be empty": "Street cannot be empty", + "City cannot be empty": "City cannot be empty", + "EXTENSION_INVALID_FORMAT": "Invalid extension", + "The secret can't be blank": "The secret can't be blank", + "Invalid TIN": "Invalid Tax number", + "This ticket can't be invoiced": "This ticket can't be invoiced", + "The value should be a number": "The value should be a number", + "The current ticket can't be modified": "The current ticket can't be modified", + "Extension format is invalid": "Extension format is invalid", + "NO_ZONE_FOR_THIS_PARAMETERS": "NO_ZONE_FOR_THIS_PARAMETERS", + "This client can't be invoiced": "This client can't be invoiced", + "You must provide the correction information to generate a corrective invoice": "You must provide the correction information to generate a corrective invoice", + "The introduced hour already exists": "The introduced hour already exists", + "Invalid parameters to create a new ticket": "Invalid parameters to create a new ticket", + "Concept cannot be blank": "Concept cannot be blank", + "Ticket id cannot be blank": "Ticket id cannot be blank", + "Weekday cannot be blank": "Weekday cannot be blank", + "This ticket can not be modified": "This ticket can not be modified", + "You can't delete a confirmed order": "You can't delete a confirmed order", + "Value has an invalid format": "Value has an invalid format", + "The postcode doesn't exist. Please enter a correct one": "The postcode doesn't exist. Please enter a correct one", + "Swift / BIC can't be empty": "Swift / BIC can't be empty", + "Deleted sales from ticket": "I have deleted the following lines from the ticket [{{ticketId}}]({{{ticketUrl}}}): {{{deletions}}}", + "Added sale to ticket": "I have added the following line to the ticket [{{ticketId}}]({{{ticketUrl}}}): {{{addition}}}", + "Changed sale discount": "I have changed the following lines discounts from the ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", + "Created claim": "I have created the claim [{{claimId}}]({{{claimUrl}}}) for the following lines from the ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", + "Changed sale price": "I have changed the price of [{{itemId}} {{concept}}]({{{itemUrl}}}) ({{quantity}}) from {{oldPrice}}€ ➔ *{{newPrice}}€* of the ticket [{{ticketId}}]({{{ticketUrl}}})", + "Changed sale quantity": "I have changed the quantity of [{{itemId}} {{concept}}]({{{itemUrl}}}) from {{oldQuantity}} ➔ *{{newQuantity}}* of the ticket [{{ticketId}}]({{{ticketUrl}}})", + "Changed sale reserved state": "I have changed the following lines reserved state from the ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", + "Bought units from buy request": "Bought {{quantity}} units of [{{itemId}} {{concept}}]({{{urlItem}}}) for the ticket id [{{ticketId}}]({{{url}}})", + "MESSAGE_INSURANCE_CHANGE": "I have changed the insurence credit of client [{{clientName}} ({{clientId}})]({{{url}}}) to *{{credit}} €*", + "Changed client paymethod": "I have changed the pay method for client [{{clientName}} ({{clientId}})]({{{url}}})", + "Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} ({{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [{{ticketId}}]({{{ticketUrl}}})", + "Change quantity": "{{concept}} change of {{oldQuantity}} to {{newQuantity}}", + "Claim will be picked": "The product from the claim [({{claimId}})]({{{claimUrl}}}) from the client *{{clientName}}* will be picked, with the pickup type *{{claimPickup}}*", + "Claim state has changed to": "The state of the claim [({{claimId}})]({{{claimUrl}}}) from client *{{clientName}}* has changed to *{{newState}}*", + "Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member", + "Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member", + "Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}", + "Landing cannot be lesser than shipment": "Landing cannot be lesser than shipment", + "NOT_ZONE_WITH_THIS_PARAMETERS": "There's no zone available for this day", + "Created absence": "The worker {{author}} has added an absence of type '{{absenceType}}' to {{employee}} for day {{dated}}.", + "Deleted absence": "The worker {{author}} has deleted an absence of type '{{absenceType}}' to {{employee}} for day {{dated}}.", + "I have deleted the ticket id": "I have deleted the ticket id [{{id}}]({{{url}}})", + "I have restored the ticket id": "I have restored the ticket id [{{id}}]({{{url}}})", + "Changed this data from the ticket": "I have changed the data from the ticket [{{ticketId}}]({{{ticketUrl}}}): {{{changes}}}", + "The grade must be similar to the last one": "The grade must be similar to the last one", + "agencyModeFk": "Agency", + "clientFk": "Client", + "zoneFk": "Zone", + "warehouseFk": "Warehouse", + "shipped": "Shipped", + "landed": "Landed", + "addressFk": "Address", + "companyFk": "Company", + "agency": "Agency", + "delivery": "Delivery", + "You need to fill sage information before you check verified data": "You need to fill sage information before you check verified data", + "The social name cannot be empty": "The social name cannot be empty", + "The nif cannot be empty": "The nif cannot be empty", + "Amount cannot be zero": "Amount cannot be zero", + "Company has to be official": "Company has to be official", + "Unable to clone this travel": "Unable to clone this travel", + "The observation type can't be repeated": "The observation type can't be repeated", + "New ticket request has been created with price": "New ticket request has been created *'{{description}}'* for day *{{shipped}}*, with a quantity of *{{quantity}}* and a price of *{{price}} €*", + "New ticket request has been created": "New ticket request has been created *'{{description}}'* for day *{{shipped}}*, with a quantity of *{{quantity}}*", + "There's a new urgent ticket": "There's a new urgent ticket: [{{title}}](https://cau.verdnatura.es/WorkOrder.do?woMode=viewWO&woID={{issueId}})", + "Swift / BIC cannot be empty": "Swift / BIC cannot be empty", + "Role name must be written in camelCase": "Role name must be written in camelCase", + "Client assignment has changed": "I did change the salesperson ~*\"<{{previousWorkerName}}>\"*~ by *\"<{{currentWorkerName}}>\"* from the client [{{clientName}} ({{clientId}})]({{{url}}})", + "None": "None", + "error densidad = 0": "error densidad = 0", + "This document already exists on this ticket": "This document already exists on this ticket", + "serial non editable": "This serial doesn't allow to set a reference", + "nickname": "nickname", + "State": "State", + "regular": "regular", + "reserved": "reserved", + "Global invoicing failed": "[Global invoicing] Wasn't able to invoice some of the clients", + "A ticket with a negative base can't be invoiced": "A ticket with a negative base can't be invoiced", + "This client is not invoiceable": "This client is not invoiceable", + "INACTIVE_PROVIDER": "Inactive provider", + "reference duplicated": "reference duplicated", + "The PDF document does not exist": "The PDF document does not exists. Try regenerating it from 'Regenerate invoice PDF' option", + "This item is not available": "This item is not available", + "Deny buy request": "Purchase request for ticket id [{{ticketId}}]({{{url}}}) has been rejected. Reason: {{observation}}", + "The type of business must be filled in basic data": "The type of business must be filled in basic data", + "The worker has hours recorded that day": "The worker has hours recorded that day", + "isWithoutNegatives": "isWithoutNegatives", + "routeFk": "routeFk", + "Not enough privileges to edit a client with verified data": "Not enough privileges to edit a client with verified data", + "Can't change the password of another worker": "Can't change the password of another worker", + "No hay un contrato en vigor": "There is no existing contract", + "No está permitido trabajar": "Not allowed to work", + "Dirección incorrecta": "Wrong direction", + "No se permite fichar a futuro": "It is not allowed to sign in the future", + "Descanso diario 12h.": "Daily rest 12h.", + "Fichadas impares": "Odd signs", + "Descanso diario 9h.": "Daily rest 9h.", + "Descanso semanal 36h. / 72h.": "Weekly rest 36h. / 72h.", + "Verify email": "Verify email", + "Click on the following link to verify this email. If you haven't requested this email, just ignore it": "Click on the following link to verify this email. If you haven't requested this email, just ignore it", + "Password does not meet requirements": "Password does not meet requirements", + "You don't have privileges to change the zone": "You don't have privileges to change the zone or for these parameters there are more than one shipping options, talk to agencies", + "Not enough privileges to edit a client": "Not enough privileges to edit a client", + "Claim pickup order sent": "Claim pickup order sent [{{claimId}}]({{{claimUrl}}}) to client *{{clientName}}*", + "You don't have grant privilege": "You don't have grant privilege", + "You don't own the role and you can't assign it to another user": "You don't own the role and you can't assign it to another user", + "Email verify": "Email verify", + "Ticket merged": "Ticket [{{originId}}]({{{originFullPath}}}) ({{{originDated}}}) merged with [{{destinationId}}]({{{destinationFullPath}}}) ({{{destinationDated}}})", + "App locked": "App locked by user {{userId}}", + "The sales of the receiver ticket can't be modified": "The sales of the receiver ticket can't be modified", + "Receipt's bank was not found": "Receipt's bank was not found", + "This receipt was not compensated": "This receipt was not compensated", + "Client's email was not found": "Client's email was not found", + "Tickets with associated refunds": "Tickets with associated refunds can't be deleted. This ticket is associated with refund Nº %d", + "It is not possible to modify tracked sales": "It is not possible to modify tracked sales", + "It is not possible to modify sales that their articles are from Floramondo": "It is not possible to modify sales that their articles are from Floramondo", + "It is not possible to modify cloned sales": "It is not possible to modify cloned sales", + "Warehouse inventory not set": "Almacén inventario no está establecido", + "Component cost not set": "Componente coste no está estabecido", + "Description cannot be blank": "Description cannot be blank", + "company": "Company", + "country": "Country", + "clientId": "Id client", + "clientSocialName": "Client", + "amount": "Amount", + "taxableBase": "Taxable base", + "ticketFk": "Id ticket", + "isActive": "Active", + "hasToInvoice": "Invoice", + "isTaxDataChecked": "Data checked", + "comercialId": "Id Comercial", + "comercialName": "Comercial", + "Added observation": "Added observation", + "Comment added to client": "Comment added to client", + "This ticket is already a refund": "This ticket is already a refund", + "A claim with that sale already exists": "A claim with that sale already exists", + "Pass expired": "The password has expired, change it from Salix", + "Can't transfer claimed sales": "Can't transfer claimed sales", + "Invalid quantity": "Invalid quantity", + "Failed to upload delivery note": "Error to upload delivery note {{id}}", + "Mail not sent": "There has been an error sending the invoice to the client [{{clientId}}]({{{clientUrl}}}), please check the email address", + "The renew period has not been exceeded": "The renew period has not been exceeded", + "You can not use the same password": "You can not use the same password", + "Valid priorities": "Valid priorities: %d", + "hasAnyNegativeBase": "Negative basis of tickets: {{ticketsIds}}", + "hasAnyPositiveBase": "Positive basis of tickets: {{ticketsIds}}", + "This ticket cannot be left empty.": "This ticket cannot be left empty. %s", + "Social name should be uppercase": "Social name should be uppercase", + "Street should be uppercase": "Street should be uppercase", + "You don't have enough privileges.": "You don't have enough privileges.", + "This ticket is locked": "This ticket is locked", + "This ticket is not editable.": "This ticket is not editable.", + "The ticket doesn't exist.": "The ticket doesn't exist.", + "The sales do not exists": "The sales do not exists", + "Ticket without Route": "Ticket without route", + "Select a different client": "Select a different client", + "Fill all the fields": "Fill all the fields", + "Error while generating PDF": "Error while generating PDF", + "Can't invoice to future": "Can't invoice to future", + "This ticket is already invoiced": "This ticket is already invoiced", + "Negative basis of tickets: 23": "Negative basis of tickets: 23", + "Booking completed": "Booking complete", + "The ticket is in preparation": "The ticket [{{ticketId}}]({{{ticketUrl}}}) of the sales person {{salesPersonId}} is in preparation", + "You can only add negative amounts in refund tickets": "You can only add negative amounts in refund tickets", + "Bank entity must be specified": "Bank entity must be specified", + "Try again": "Try again", + "keepPrice": "keepPrice", + "Cannot past travels with entries": "Cannot past travels with entries", + "It was not able to remove the next expeditions:": "It was not able to remove the next expeditions: {{expeditions}}", + "Incorrect pin": "Incorrect pin.", + "The notification subscription of this worker cant be modified": "The notification subscription of this worker cant be modified", + "Name should be uppercase": "Name should be uppercase", + "You cannot update these fields": "You cannot update these fields", + "CountryFK cannot be empty": "Country cannot be empty", + "You are not allowed to modify the alias": "You are not allowed to modify the alias", + "You already have the mailAlias": "You already have the mailAlias", "This machine is already in use.": "This machine is already in use.", "the plate does not exist": "The plate {{plate}} does not exist", "We do not have availability for the selected item": "We do not have availability for the selected item", @@ -223,6 +223,7 @@ "printerNotExists": "The printer does not exist", "There are not picking tickets": "There are not picking tickets", "ticketCommercial": "The ticket {{ ticket }} for the salesperson {{ salesMan }} is in preparation. (automatically generated message)", - "This password can only be changed by the user themselves": "This password can only be changed by the user themselves", - "They're not your subordinate": "They're not your subordinate" -} + "This password can only be changed by the user themselves": "This password can only be changed by the user themselves", + "They're not your subordinate": "They're not your subordinate", + "InvoiceIn is already booked": "InvoiceIn is already booked" +} \ No newline at end of file diff --git a/back/methods/collection/exchangeRateUpdate.js b/modules/invoiceIn/back/methods/invoice-in/exchangeRateUpdate.js similarity index 100% rename from back/methods/collection/exchangeRateUpdate.js rename to modules/invoiceIn/back/methods/invoice-in/exchangeRateUpdate.js diff --git a/back/methods/collection/spec/exchangeRateUpdate.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/exchangeRateUpdate.spec.js similarity index 90% rename from back/methods/collection/spec/exchangeRateUpdate.spec.js rename to modules/invoiceIn/back/methods/invoice-in/specs/exchangeRateUpdate.spec.js index 7086c37a3..0fd7ea165 100644 --- a/back/methods/collection/spec/exchangeRateUpdate.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in/specs/exchangeRateUpdate.spec.js @@ -17,7 +17,7 @@ describe('exchangeRateUpdate functionality', function() { spyOn(models.ReferenceRate, 'findOne').and.returnValue(Promise.resolve(null)); spyOn(models.ReferenceRate, 'create').and.returnValue(Promise.resolve()); - await models.Collection.exchangeRateUpdate(); + await models.InvoiceIn.exchangeRateUpdate(); expect(models.ReferenceRate.create).toHaveBeenCalledTimes(2); }); @@ -28,7 +28,7 @@ describe('exchangeRateUpdate functionality', function() { let thrownError = null; try { - await models.Collection.exchangeRateUpdate(); + await models.InvoiceIn.exchangeRateUpdate(); } catch (error) { thrownError = error; } @@ -41,7 +41,7 @@ describe('exchangeRateUpdate functionality', function() { let error; try { - await models.Collection.exchangeRateUpdate(); + await models.InvoiceIn.exchangeRateUpdate(); } catch (e) { error = e; } diff --git a/modules/invoiceIn/back/models/invoice-in.js b/modules/invoiceIn/back/models/invoice-in.js index af5efbcdf..31cdc1abe 100644 --- a/modules/invoiceIn/back/models/invoice-in.js +++ b/modules/invoiceIn/back/models/invoice-in.js @@ -10,6 +10,7 @@ module.exports = Self => { require('../methods/invoice-in/invoiceInEmail')(Self); require('../methods/invoice-in/getSerial')(Self); require('../methods/invoice-in/corrective')(Self); + require('../methods/invoice-in/exchangeRateUpdate')(Self); Self.rewriteDbError(function(err) { if (err.code === 'ER_ROW_IS_REFERENCED_2' && err.sqlMessage.includes('vehicleInvoiceIn')) From cc06698214cc92b3d31263e721cf244f83401e9a Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 23 Apr 2024 15:37:04 +0200 Subject: [PATCH 11/29] hotFix(ticket): refs #7225 fix advanced and movable --- .../vn/procedures/ticket_canAdvance.sql | 48 ++++++------------- .../vn/procedures/ticket_getMovable.sql | 2 +- 2 files changed, 15 insertions(+), 35 deletions(-) diff --git a/db/routines/vn/procedures/ticket_canAdvance.sql b/db/routines/vn/procedures/ticket_canAdvance.sql index 8852a3010..ab6a27364 100644 --- a/db/routines/vn/procedures/ticket_canAdvance.sql +++ b/db/routines/vn/procedures/ticket_canAdvance.sql @@ -8,38 +8,14 @@ BEGIN * @param vDateToAdvance Fecha a cuando se quiere adelantar. * @param vWarehouseFk Almacén */ - DECLARE vDateInventory DATE; - SELECT inventoried INTO vDateInventory FROM config; - - CREATE OR REPLACE TEMPORARY TABLE tmp.stock - (itemFk INT PRIMARY KEY, - amount INT) - ENGINE = MEMORY; - - INSERT INTO tmp.stock(itemFk, amount) - SELECT itemFk, SUM(quantity) amount FROM - ( - SELECT itemFk, quantity - FROM itemTicketOut - WHERE shipped >= vDateInventory - AND shipped < vDateFuture - AND warehouseFk = vWarehouseFk - UNION ALL - SELECT itemFk, quantity - FROM itemEntryIn - WHERE landed >= vDateInventory - AND landed <= vDateToAdvance - AND isVirtualStock = FALSE - AND warehouseInFk = vWarehouseFk - UNION ALL - SELECT itemFk, quantity - FROM itemEntryOut - WHERE shipped >= vDateInventory - AND shipped < vDateFuture - AND warehouseOutFk = vWarehouseFk - ) t - GROUP BY itemFk HAVING amount != 0; + CALL item_getStock(vWarehouseFk, vDateToAdvance, NULL); + CALL item_getMinacum( + vWarehouseFk, + vDateToAdvance, + DATEDIFF(DATE_SUB(vDateFuture, INTERVAL 1 DAY), vDateToAdvance), + NULL + ); CREATE OR REPLACE TEMPORARY TABLE tmp.filter (INDEX (id)) @@ -87,7 +63,7 @@ BEGIN count(s.id) futureLines, GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt, CAST(SUM(litros) AS DECIMAL(10,0)) futureLiters, - SUM((s.quantity <= IFNULL(st.amount,0))) hasStock, + SUM(s.quantity <= (IFNULL(il.stock,0) + IFNULL(im.amount, 0))) hasStock, z.id futureZoneFk, z.name futureZoneName, st.classColor, @@ -107,7 +83,9 @@ BEGIN JOIN agencyMode am ON t.agencyModeFk = am.id JOIN zone z ON t.zoneFk = z.id LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk - LEFT JOIN tmp.stock st ON st.itemFk = i.id + LEFT JOIN tmp.itemMinacum im ON im.itemFk = i.id + AND im.warehouseFk = vWarehouseFk + LEFT JOIN tmp.itemList il ON il.itemFk = i.id WHERE t.shipped BETWEEN vDateFuture AND util.dayend(vDateFuture) AND t.warehouseFk = vWarehouseFk GROUP BY t.id @@ -146,6 +124,8 @@ BEGIN ) dest ON dest.addressFk = origin.addressFk WHERE origin.hasStock; - DROP TEMPORARY TABLE tmp.stock; + DROP TEMPORARY TABLE IF EXISTS + tmp.itemList, + tmp.itemMinacum; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_getMovable.sql b/db/routines/vn/procedures/ticket_getMovable.sql index eee165538..d7bcf517b 100644 --- a/db/routines/vn/procedures/ticket_getMovable.sql +++ b/db/routines/vn/procedures/ticket_getMovable.sql @@ -21,7 +21,7 @@ BEGIN WHERE t.id = vTicketFk; -- Añadimos un dia más para calcular el stock hasta vNewShipped inclusive - CALL item_getStock(vWarehouseFk, DATE_ADD(vNewShipped, INTERVAL 1 DAY), NULL); + CALL item_getStock(vWarehouseFk, vNewShipped, NULL); CALL item_getMinacum( vWarehouseFk, vNewShipped, From e36e997844dd27541cb3abea0284d5fe2cf717ac Mon Sep 17 00:00:00 2001 From: robert Date: Wed, 24 Apr 2024 08:04:28 +0200 Subject: [PATCH 12/29] feat: refs #6223 ticketCalculateClon --- db/routines/vn/procedures/ticketCalculateClon.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/ticketCalculateClon.sql b/db/routines/vn/procedures/ticketCalculateClon.sql index 7ded84f45..a56491590 100644 --- a/db/routines/vn/procedures/ticketCalculateClon.sql +++ b/db/routines/vn/procedures/ticketCalculateClon.sql @@ -29,7 +29,7 @@ BEGIN FROM sale WHERE ticketFk = vTicketNew AND price > 0; - CALL sale_recalcComponent('imbalance'); + CALL sale_recalcComponent('buyerDiscount'); DROP TEMPORARY TABLE IF EXISTS tmp.recalculateSales; From 73f7d09b0e1b6527e3a3259b39841b8ed9affc50 Mon Sep 17 00:00:00 2001 From: jgallego Date: Wed, 24 Apr 2024 08:14:07 +0200 Subject: [PATCH 13/29] feat: #7108 acl a invoiceIn --- db/versions/10992-goldenIvy/00-acl.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/10992-goldenIvy/00-acl.sql b/db/versions/10992-goldenIvy/00-acl.sql index 551905be1..5bbb08909 100644 --- a/db/versions/10992-goldenIvy/00-acl.sql +++ b/db/versions/10992-goldenIvy/00-acl.sql @@ -1,2 +1,2 @@ INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES ('Collection', 'exchangeRateUpdate', '*', 'ALLOW', 'ROLE', 'employee'); + VALUES ('invoiceIn', 'exchangeRateUpdate', '*', 'ALLOW', 'ROLE', 'employee'); From 0cd740ce0ca79e70ca1132a94564471a342ca44e Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 24 Apr 2024 10:42:50 +0200 Subject: [PATCH 14/29] test: refs #7225 fix back test --- modules/ticket/back/methods/ticket/priceDifference.js | 4 ++-- .../back/methods/ticket/specs/priceDifference.spec.js | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/modules/ticket/back/methods/ticket/priceDifference.js b/modules/ticket/back/methods/ticket/priceDifference.js index 7dc85bd3d..7db03e268 100644 --- a/modules/ticket/back/methods/ticket/priceDifference.js +++ b/modules/ticket/back/methods/ticket/priceDifference.js @@ -118,7 +118,7 @@ module.exports = Self => { const [salesMovable] = await Self.rawSql(query, params, myOptions); const itemMovable = new Map(); - for (sale of salesMovable) { + for (let sale of salesMovable) { const saleMovable = sale.movable ? sale.movable : 0; itemMovable.set(sale.id, saleMovable); } @@ -129,7 +129,7 @@ module.exports = Self => { const [difComponents] = await Self.rawSql(query, params, myOptions); const map = new Map(); - for (difComponent of difComponents) + for (let difComponent of difComponents) map.set(difComponent.saleFk, difComponent); for (sale of salesObj.items) { diff --git a/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js b/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js index d01f0c1bb..e5c06b6dd 100644 --- a/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js +++ b/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js @@ -1,5 +1,4 @@ const models = require('vn-loopback/server/server').models; -const UserError = require('vn-loopback/util/user-error'); const ForbiddenError = require('vn-loopback/util/forbiddenError'); describe('sale priceDifference()', () => { @@ -83,12 +82,10 @@ describe('sale priceDifference()', () => { warehouseId: 1 }; - const result = await models.Ticket.priceDifference(ctx, options); - const firstItem = result.items[0]; - const secondtItem = result.items[1]; + const {items} = await models.Ticket.priceDifference(ctx, options); - expect(firstItem.movable).toEqual(380); - expect(secondtItem.movable).toEqual(1790); + expect(items[0].movable).toEqual(410); + expect(items[1].movable).toEqual(1810); await tx.rollback(); } catch (e) { From d1659ce04c87ffb7bb531c07de854fd19cd7cf84 Mon Sep 17 00:00:00 2001 From: jcasado Date: Wed, 24 Apr 2024 11:19:15 +0200 Subject: [PATCH 15/29] refs #6697 fix claimQuantity --- modules/claim/back/methods/claim/createFromSales.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/claim/back/methods/claim/createFromSales.js b/modules/claim/back/methods/claim/createFromSales.js index e5022d57e..1af479dbb 100644 --- a/modules/claim/back/methods/claim/createFromSales.js +++ b/modules/claim/back/methods/claim/createFromSales.js @@ -83,7 +83,6 @@ module.exports = Self => { const newClaimBeginning = models.ClaimBeginning.create({ saleFk: sale.id, claimFk: newClaim.id, - }, myOptions); promises.push(newClaimBeginning); From eced03f69bc10fdca1deeced089fa7de82cc33d8 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 24 Apr 2024 11:40:24 +0200 Subject: [PATCH 16/29] fix(ticket_getMovable): refs #7225 stock add ifnull --- db/routines/vn/procedures/ticket_canAdvance.sql | 6 +++--- db/routines/vn/procedures/ticket_getMovable.sql | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/db/routines/vn/procedures/ticket_canAdvance.sql b/db/routines/vn/procedures/ticket_canAdvance.sql index ab6a27364..d1ca7b5e2 100644 --- a/db/routines/vn/procedures/ticket_canAdvance.sql +++ b/db/routines/vn/procedures/ticket_canAdvance.sql @@ -124,8 +124,8 @@ BEGIN ) dest ON dest.addressFk = origin.addressFk WHERE origin.hasStock; - DROP TEMPORARY TABLE IF EXISTS - tmp.itemList, - tmp.itemMinacum; + DROP TEMPORARY TABLE IF EXISTS + tmp.itemList, + tmp.itemMinacum; END$$ DELIMITER ; diff --git a/db/routines/vn/procedures/ticket_getMovable.sql b/db/routines/vn/procedures/ticket_getMovable.sql index d7bcf517b..512151bd4 100644 --- a/db/routines/vn/procedures/ticket_getMovable.sql +++ b/db/routines/vn/procedures/ticket_getMovable.sql @@ -38,7 +38,7 @@ BEGIN s.discount, i.image, i.subName, - il.stock + IFNULL(im.amount, 0) AS movable + IFNULL(il.stock,0) + IFNULL(im.amount, 0) AS movable FROM ticket t JOIN sale s ON s.ticketFk = t.id JOIN item i ON i.id = s.itemFk @@ -48,8 +48,8 @@ BEGIN WHERE t.id = vTicketFk; DROP TEMPORARY TABLE IF EXISTS - tmp.itemList, - tmp.itemMinacum; + tmp.itemList, + tmp.itemMinacum; END$$ DELIMITER ; From aeee012c2b353608afc45e495a0d0ed5bcbb6ee1 Mon Sep 17 00:00:00 2001 From: jcasado Date: Wed, 24 Apr 2024 11:43:10 +0200 Subject: [PATCH 17/29] refs #6697 fix sql test --- db/versions/11014-orangePalmetto/00-firstScript.sql | 2 ++ .../claim/back/methods/claim/specs/createFromSales.spec.js | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 db/versions/11014-orangePalmetto/00-firstScript.sql diff --git a/db/versions/11014-orangePalmetto/00-firstScript.sql b/db/versions/11014-orangePalmetto/00-firstScript.sql new file mode 100644 index 000000000..fe85c7ec6 --- /dev/null +++ b/db/versions/11014-orangePalmetto/00-firstScript.sql @@ -0,0 +1,2 @@ +-- Place your SQL code here +ALTER TABLE vn.claimBeginning MODIFY COLUMN quantity double DEFAULT 0 NULL; diff --git a/modules/claim/back/methods/claim/specs/createFromSales.spec.js b/modules/claim/back/methods/claim/specs/createFromSales.spec.js index fe009c1c3..25414d1db 100644 --- a/modules/claim/back/methods/claim/specs/createFromSales.spec.js +++ b/modules/claim/back/methods/claim/specs/createFromSales.spec.js @@ -37,7 +37,7 @@ describe('Claim createFromSales()', () => { let claimBeginning = await models.ClaimBeginning.findOne({where: {claimFk: claim.id}}, options); expect(claimBeginning.saleFk).toEqual(newSale[0].id); - expect(claimBeginning.quantity).toEqual(newSale[0].quantity); + expect(claimBeginning.quantity).toEqual(0); await tx.rollback(); } catch (e) { @@ -67,7 +67,7 @@ describe('Claim createFromSales()', () => { const claimBeginning = await models.ClaimBeginning.findOne({where: {claimFk: claim.id}}, options); expect(claimBeginning.saleFk).toEqual(newSale[0].id); - expect(claimBeginning.quantity).toEqual(newSale[0].quantity); + expect(claimBeginning.quantity).toEqual(0); await tx.rollback(); } catch (e) { From 69486fb29f9d59cd1d9e6a72437077fcc1c87c9f Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 24 Apr 2024 14:15:27 +0200 Subject: [PATCH 18/29] fix(componentUpdate): refs #7225 fix transfer all lines to newTicket --- modules/ticket/back/methods/ticket/componentUpdate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index 0786b72c8..8bea731b7 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -150,7 +150,7 @@ module.exports = Self => { const salesNewTicket = salesMovable.filter(sale => (sale.movable ? sale.movable : 0) >= sale.quantity); const salesNewTicketLength = salesNewTicket.length; - if (salesNewTicketLength && sales.length != salesNewTicketLength) { + if (salesNewTicketLength && (args.newTicket || sales.length != salesNewTicketLength)) { const newTicket = await models.Ticket.transferSales( ctx, args.id, From 88b06ebef546f5fd07faee2fab49bebc9f9fd0fa Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 25 Apr 2024 08:49:22 +0200 Subject: [PATCH 19/29] feat: refs #7211 check if there's available clockIn --- db/routines/vn/procedures/workerTimeControl_clockIn.sql | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/workerTimeControl_clockIn.sql b/db/routines/vn/procedures/workerTimeControl_clockIn.sql index e58528487..a3991913e 100644 --- a/db/routines/vn/procedures/workerTimeControl_clockIn.sql +++ b/db/routines/vn/procedures/workerTimeControl_clockIn.sql @@ -121,15 +121,17 @@ BEGIN CALL util.throw(vErrorCode); END IF; + -- DIRECCION CORRECTA CALL workerTimeControl_direction(vWorkerFk, vTimed); IF (SELECT - IF(IF(option1 IN ('inMiddle', 'outMiddle'), + IF((IF(option1 IN ('inMiddle', 'outMiddle'), 'middle', option1) <> vDirection AND IF(option2 IN ('inMiddle', 'outMiddle'), 'middle', - IFNULL(option2, '')) <> vDirection, + IFNULL(option2, '')) <> vDirection) + OR (option1 IS NULL AND option2 IS NULL), TRUE , FALSE) FROM tmp.workerTimeControlDirection From c9dfccbc53abcf84ae1a692e6f9242a1f32a94a2 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 25 Apr 2024 09:35:53 +0200 Subject: [PATCH 20/29] feat: refs #7211 add test & changelog --- CHANGELOG.md | 3 +++ .../worker-time-control/specs/clockIn.spec.js | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b938797e..5aaa57192 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [24.20.01] - 2024-05-14 +### Fixed +- (Worker -> time-control) Corrección de errores + ## [24.18.01] - 2024-05-07 ## [24.16.01] - 2024-04-18 diff --git a/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js b/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js index 343eb2a71..826ea6077 100644 --- a/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js +++ b/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js @@ -1,5 +1,6 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); +const { async } = require('regenerator-runtime'); describe('workerTimeControl clockIn()', () => { const workerId = 9; @@ -99,6 +100,32 @@ describe('workerTimeControl clockIn()', () => { } }); + it('should throw an error trying to add an "in" entry if the last clockIn is not out', async() => { + activeCtx.accessToken.userId = HHRRId; + const workerId = teamBossId; + const tx = await models.WorkerTimeControl.beginTransaction({}); + try { + const options = {transaction: tx}; + + ctx.args = {timed: "2000-12-25T21:00:00.000Z", direction: 'in'}; + await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); + + ctx.args = {timed: "2000-12-25T22:00:00.000Z", direction: 'middle'}; + await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); + + ctx.args = {timed: "2000-12-25T22:30:00.000Z", direction: 'middle'}; + await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); + + ctx.args = {timed: "2000-12-26T01:00:00.000Z", direction: 'in'}; + await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); + + await tx.rollback(); + } catch (e) { + expect(e.message).toBe('Dirección incorrecta'); + await tx.rollback(); + } + }); + describe('as Role errors', () => { it('should add if the current user is team boss and the target user is himself', async() => { activeCtx.accessToken.userId = teamBossId; From a4f1183df646f953144305f87ab1ca96dd695349 Mon Sep 17 00:00:00 2001 From: jgallego Date: Thu, 25 Apr 2024 13:11:57 +0200 Subject: [PATCH 21/29] feat: refs #7108 pascalCase --- db/versions/10992-goldenIvy/00-acl.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/10992-goldenIvy/00-acl.sql b/db/versions/10992-goldenIvy/00-acl.sql index 5bbb08909..1d1c3ce91 100644 --- a/db/versions/10992-goldenIvy/00-acl.sql +++ b/db/versions/10992-goldenIvy/00-acl.sql @@ -1,2 +1,2 @@ INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) - VALUES ('invoiceIn', 'exchangeRateUpdate', '*', 'ALLOW', 'ROLE', 'employee'); + VALUES ('InvoiceIn', 'exchangeRateUpdate', '*', 'ALLOW', 'ROLE', 'employee'); From 931c2c4f5ebd7f740d1d23387a4d03cc7a7ae1a3 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 25 Apr 2024 13:12:06 +0200 Subject: [PATCH 22/29] feat: refs #7211 error & locale --- loopback/locale/es.json | 3 ++- .../invoiceOut/back/methods/invoiceOut/createManualInvoice.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index ea9e0b8ef..61b2d1425 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -354,5 +354,6 @@ "They're not your subordinate": "No es tu subordinado/a.", "No results found": "No se han encontrado resultados", "InvoiceIn is already booked": "La factura recibida está contabilizada", - "Select ticket or client": "Elija un ticket o un client" + "Select ticket or client": "Elija un ticket o un client", + "It was not able to create the invoice": "No se pudo crear la factura" } diff --git a/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js index 9803f20f7..0259ff40b 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js @@ -142,7 +142,7 @@ module.exports = Self => { throw e; } - if (!newInvoice.id) throw new UserError(`...`); + if (!newInvoice.id) throw new UserError('It was not able to create the invoice:'); await Self.createPdf(ctx, newInvoice.id); From 4e864fed52de35f4698ba990a08bb20008917475 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 25 Apr 2024 15:38:21 +0200 Subject: [PATCH 23/29] fix: refs #7211 tests --- .../specs/createManualInvoice.spec.js | 69 +++++++------------ 1 file changed, 25 insertions(+), 44 deletions(-) diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/createManualInvoice.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/createManualInvoice.spec.js index b166caf78..55739e570 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/createManualInvoice.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/createManualInvoice.spec.js @@ -1,13 +1,10 @@ -const models = require('vn-loopback/server/server').models; +const {models} = require('vn-loopback/server/server'); const LoopBackContext = require('loopback-context'); describe('InvoiceOut createManualInvoice()', () => { - const userId = 1; const ticketId = 16; const clientId = 1106; - const activeCtx = { - accessToken: {userId: userId}, - }; + const activeCtx = {accessToken: {userId: 1}}; const ctx = {req: activeCtx}; it('should throw an error trying to invoice again', async() => { @@ -18,13 +15,8 @@ describe('InvoiceOut createManualInvoice()', () => { let error; try { - ctx.args = { - ticketFk: ticketId, - serial: 'T', - taxArea: 'CEE' - }; - await models.InvoiceOut.createManualInvoice(ctx, options); - await models.InvoiceOut.createManualInvoice(ctx, options); + await createInvoice(ctx, options, undefined, ticketId); + await createInvoice(ctx, options, undefined, ticketId); await tx.rollback(); } catch (e) { @@ -47,17 +39,9 @@ describe('InvoiceOut createManualInvoice()', () => { let error; try { const ticket = await models.Ticket.findById(ticketId, null, options); - await ticket.updateAttributes({ - totalWithVat: 0 - }, options); - - ctx.args = { - ticketFk: ticketId, - serial: 'T', - taxArea: 'CEE' - }; - await models.InvoiceOut.createManualInvoice(ctx, options); + await ticket.updateAttributes({totalWithVat: 0}, options); + await createInvoice(ctx, options, undefined, ticketId); await tx.rollback(); } catch (e) { error = e; @@ -75,13 +59,7 @@ describe('InvoiceOut createManualInvoice()', () => { let error; try { - ctx.args = { - clientFk: clientId, - serial: 'T', - taxArea: 'CEE' - }; - await models.InvoiceOut.createManualInvoice(ctx, options); - + await createInvoice(ctx, options, clientId); await tx.rollback(); } catch (e) { error = e; @@ -103,16 +81,9 @@ describe('InvoiceOut createManualInvoice()', () => { let error; try { const client = await models.Client.findById(clientId, null, options); - await client.updateAttributes({ - isTaxDataChecked: false - }, options); + await client.updateAttributes({isTaxDataChecked: false}, options); - ctx.args = { - ticketFk: ticketId, - serial: 'T', - taxArea: 'CEE' - }; - await models.InvoiceOut.createManualInvoice(ctx, options); + await createInvoice(ctx, options, undefined, ticketId); await tx.rollback(); } catch (e) { @@ -130,12 +101,7 @@ describe('InvoiceOut createManualInvoice()', () => { const options = {transaction: tx}; try { - ctx.args = { - ticketFk: ticketId, - serial: 'T', - taxArea: 'CEE' - }; - const result = await models.InvoiceOut.createManualInvoice(ctx, options); + const result = await createInvoice(ctx, options, undefined, ticketId); expect(result.id).toEqual(jasmine.any(Number)); @@ -146,3 +112,18 @@ describe('InvoiceOut createManualInvoice()', () => { } }); }); + +function createInvoice( + ctx, + options, + clientFk = undefined, + ticketFk = undefined, + maxShipped = undefined, + serial = 'T', + taxArea = 'CEE', + reference = undefined +) { + return models.InvoiceOut.createManualInvoice( + ctx, clientFk, ticketFk, maxShipped, serial, taxArea, reference, options + ); +} From f7cdbd39f08e2119f110ae66f4ec34bc9d752568 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 25 Apr 2024 16:08:52 +0200 Subject: [PATCH 24/29] fix: refs #7211 tests --- .../procedures/workerTimeControl_clockIn.sql | 9 +++++-- .../worker-time-control/specs/clockIn.spec.js | 26 ------------------- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/db/routines/vn/procedures/workerTimeControl_clockIn.sql b/db/routines/vn/procedures/workerTimeControl_clockIn.sql index a3991913e..a1ce53bc2 100644 --- a/db/routines/vn/procedures/workerTimeControl_clockIn.sql +++ b/db/routines/vn/procedures/workerTimeControl_clockIn.sql @@ -139,12 +139,17 @@ BEGIN SET vIsError = TRUE; END IF; - DROP TEMPORARY TABLE tmp.workerTimeControlDirection; + IF vIsError THEN SET vErrorCode = 'WRONG_DIRECTION'; + IF(SELECT option1 IS NULL AND option2 IS NULL + FROM tmp.workerTimeControlDirection) THEN + + SET vErrorCode = 'DAY_MAX_TIME'; + END IF; CALL util.throw(vErrorCode); END IF; - + DROP TEMPORARY TABLE tmp.workerTimeControlDirection; -- FICHADAS IMPARES SELECT timed INTO vLastIn FROM workerTimeControl diff --git a/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js b/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js index 826ea6077..cfff42172 100644 --- a/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js +++ b/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js @@ -1,6 +1,5 @@ const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); -const { async } = require('regenerator-runtime'); describe('workerTimeControl clockIn()', () => { const workerId = 9; @@ -47,31 +46,6 @@ describe('workerTimeControl clockIn()', () => { } }); - it('should throw an error trying to change a middle hour to out not resting 12h', async() => { - activeCtx.accessToken.userId = HHRRId; - const workerId = teamBossId; - - const tx = await models.WorkerTimeControl.beginTransaction({}); - try { - const options = {transaction: tx}; - - const entryTime = "2000-12-25T11:00:00.000Z"; - ctx.args = {timed: entryTime, direction: 'in'}; - await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); - - const middleTime ="2000-12-26T11:00:00.000Z"; - ctx.args = {timed: middleTime, direction: 'middle'}; - const middleEntryTime = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); - - const direction = 'out'; - await models.WorkerTimeControl.updateTimeEntry(ctx, middleEntryTime.id, direction, options); - await tx.rollback(); - } catch (e) { - expect(e.message).toBe('Superado el tiempo máximo entre entrada y salida'); - await tx.rollback(); - } - }); - it('should updates the time entry direction and remaining not be manual', async() => { activeCtx.accessToken.userId = HHRRId; const workerId = teamBossId; From 180a484c558195926366f51b145aa759309bd0d9 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 25 Apr 2024 16:14:34 +0200 Subject: [PATCH 25/29] fix: refs #7211 rollback --- .../worker-time-control/specs/clockIn.spec.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js b/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js index cfff42172..daf7284ac 100644 --- a/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js +++ b/modules/worker/back/methods/worker-time-control/specs/clockIn.spec.js @@ -45,6 +45,31 @@ describe('workerTimeControl clockIn()', () => { throw e; } }); + + it('should throw an error trying to change a middle hour to out not resting 12h', async() => { + activeCtx.accessToken.userId = HHRRId; + const workerId = teamBossId; + + const tx = await models.WorkerTimeControl.beginTransaction({}); + try { + const options = {transaction: tx}; + + const entryTime = "2000-12-25T11:00:00.000Z"; + ctx.args = {timed: entryTime, direction: 'in'}; + await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); + + const middleTime ="2000-12-26T11:00:00.000Z"; + ctx.args = {timed: middleTime, direction: 'middle'}; + const middleEntryTime = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options); + + const direction = 'out'; + await models.WorkerTimeControl.updateTimeEntry(ctx, middleEntryTime.id, direction, options); + await tx.rollback(); + } catch (e) { + expect(e.message).toBe('Superado el tiempo máximo entre entrada y salida'); + await tx.rollback(); + } + }); it('should updates the time entry direction and remaining not be manual', async() => { activeCtx.accessToken.userId = HHRRId; From 32da39899ab642d484f2dffd7c3aacdf94afabe5 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 25 Apr 2024 17:16:43 +0200 Subject: [PATCH 26/29] fix: refs #7211 test e2e --- e2e/paths/09-invoice-out/03_manualInvoice.spec.js | 2 +- .../invoiceOut/back/methods/invoiceOut/createManualInvoice.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/paths/09-invoice-out/03_manualInvoice.spec.js b/e2e/paths/09-invoice-out/03_manualInvoice.spec.js index dfaa55ef9..6addbbe56 100644 --- a/e2e/paths/09-invoice-out/03_manualInvoice.spec.js +++ b/e2e/paths/09-invoice-out/03_manualInvoice.spec.js @@ -40,7 +40,7 @@ describe('InvoiceOut manual invoice path', () => { await page.waitToClick(selectors.invoiceOutIndex.createInvoice); await page.waitForSelector(selectors.invoiceOutIndex.manualInvoiceForm); - await page.autocompleteSearch(selectors.invoiceOutIndex.manualInvoiceClient, 'Max Eisenhardt'); + await page.autocompleteSearch(selectors.invoiceOutIndex.manualInvoiceClient, 'Bruce Wayne'); await page.autocompleteSearch(selectors.invoiceOutIndex.manualInvoiceSerial, 'Global nacional'); await page.autocompleteSearch(selectors.invoiceOutIndex.manualInvoiceTaxArea, 'national'); await page.waitToClick(selectors.invoiceOutIndex.saveInvoice); diff --git a/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js index 0259ff40b..c46da0ba5 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/createManualInvoice.js @@ -142,7 +142,7 @@ module.exports = Self => { throw e; } - if (!newInvoice.id) throw new UserError('It was not able to create the invoice:'); + if (!newInvoice.id) throw new UserError('It was not able to create the invoice'); await Self.createPdf(ctx, newInvoice.id); From b09fa1e2fbfff3417c062eac72842be2ce91216a Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 25 Apr 2024 17:22:30 +0200 Subject: [PATCH 27/29] feat: refs #7019 changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5aaa57192..a672e7986 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - (Worker -> time-control) Corrección de errores +- (InvoiceOut -> Crear factura) Cuando falla al crear una factura, se devuelve un error ## [24.18.01] - 2024-05-07 From 326c5c97bda1acf60aeec0d67fef132d6d57dca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 25 Apr 2024 19:02:05 +0200 Subject: [PATCH 28/29] Hotfix test farmingDeliveryNote --- db/versions/11007-greenRose/00-firstScript.sql | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 db/versions/11007-greenRose/00-firstScript.sql diff --git a/db/versions/11007-greenRose/00-firstScript.sql b/db/versions/11007-greenRose/00-firstScript.sql new file mode 100644 index 000000000..897533da1 --- /dev/null +++ b/db/versions/11007-greenRose/00-firstScript.sql @@ -0,0 +1,16 @@ +CREATE OR REPLACE TABLE `vn`.`farmingDeliveryNote` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `farmingFk` int(10) unsigned NOT NULL, + `deliveryNoteFk` int(11) NOT NULL, + `amount` decimal(10,2) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `farmingDeliveryNoteFk_FK` (`deliveryNoteFk`), + KEY `farmingDeliveryNoteFk_FK_1` (`farmingFk`), + CONSTRAINT `farmingDeliveryNoteFk_FK` FOREIGN KEY (`deliveryNoteFk`) REFERENCES `deliveryNote` (`id`), + CONSTRAINT `farmingDeliveryNoteFk_FK_1` FOREIGN KEY (`farmingFk`) REFERENCES `farming` (`id`) +); + +INSERT IGNORE INTO `vn`.`farmingDeliveryNote` (farmingFk, deliveryNoteFk, amount) + SELECT farmingFk, id, amount + FROM deliveryNote dn + WHERE farmingFk; \ No newline at end of file From f25d3c14c683c9f64466bb7091f32d868515d34d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Thu, 25 Apr 2024 19:06:06 +0200 Subject: [PATCH 29/29] Hotfix test farmingDeliveryNote --- db/versions/11007-greenRose/00-firstScript.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/11007-greenRose/00-firstScript.sql b/db/versions/11007-greenRose/00-firstScript.sql index 897533da1..154a75532 100644 --- a/db/versions/11007-greenRose/00-firstScript.sql +++ b/db/versions/11007-greenRose/00-firstScript.sql @@ -12,5 +12,5 @@ CREATE OR REPLACE TABLE `vn`.`farmingDeliveryNote` ( INSERT IGNORE INTO `vn`.`farmingDeliveryNote` (farmingFk, deliveryNoteFk, amount) SELECT farmingFk, id, amount - FROM deliveryNote dn + FROM vn.deliveryNote dn WHERE farmingFk; \ No newline at end of file