From 1d7e69cb25f809ca2d26c1fa2e90facff815cbc4 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 16 Dec 2024 07:40:49 +0100 Subject: [PATCH 1/6] feat: refs #7584 workerTimeControl_afterDelete --- .../vn/triggers/workerTimeControl_afterDelete.sql | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/db/routines/vn/triggers/workerTimeControl_afterDelete.sql b/db/routines/vn/triggers/workerTimeControl_afterDelete.sql index 27432fccb..762754591 100644 --- a/db/routines/vn/triggers/workerTimeControl_afterDelete.sql +++ b/db/routines/vn/triggers/workerTimeControl_afterDelete.sql @@ -3,10 +3,12 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerTimeControl_after AFTER DELETE ON `workerTimeControl` FOR EACH ROW BEGIN - INSERT INTO workerLog - SET `action` = 'delete', - `changedModel` = 'WorkerTimeControl', - `changedModelId` = OLD.id, - `userFk` = account.myUser_getId(); + IF account.myUser_getId() THEN + INSERT INTO workerLog + SET `action` = 'delete', + `changedModel` = 'WorkerTimeControl', + `changedModelId` = OLD.id, + `userFk` = account.myUser_getId(); + END IF; END$$ DELIMITER ; From 48d2d1d3271eb6d92ef8cda0979e38daed999e30 Mon Sep 17 00:00:00 2001 From: jtubau Date: Thu, 26 Dec 2024 10:41:20 +0100 Subject: [PATCH 2/6] feat: refs #8117 add worker first and last name to item type query --- modules/ticket/back/methods/ticket-request/getItemTypeWorker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket-request/getItemTypeWorker.js b/modules/ticket/back/methods/ticket-request/getItemTypeWorker.js index f160cfaac..2f2a85abb 100644 --- a/modules/ticket/back/methods/ticket-request/getItemTypeWorker.js +++ b/modules/ticket/back/methods/ticket-request/getItemTypeWorker.js @@ -30,7 +30,7 @@ module.exports = Self => { Object.assign(myOptions, options); const query = - `SELECT DISTINCT u.id, u.nickname + `SELECT DISTINCT u.id, u.nickname, w.firstName, w.lastName FROM itemType it JOIN worker w ON w.id = it.workerFk JOIN account.user u ON u.id = w.id`; From 446ffac7f848c3dc47f7667e001778c939baabde Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 9 Jan 2025 13:44:59 +0100 Subject: [PATCH 3/6] feat: sendCheckingPresence debug --- back/methods/chat/sendCheckingPresence.js | 69 +++++++++++++---------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index 7ab5d63fe..83e8da304 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -27,38 +27,47 @@ module.exports = Self => { }); Self.sendCheckingPresence = async(ctx, recipientId, message) => { - if (!recipientId) return false; - const models = Self.app.models; - const userId = ctx.req.accessToken.userId; - const sender = await models.VnUser.findById(userId, {fields: ['id']}); - const recipient = await models.VnUser.findById(recipientId, null); - - // Prevent sending messages to yourself - if (recipientId == userId) return false; - if (!recipient) - throw new Error(`Could not send message "${message}" to worker id ${recipientId} from user ${userId}`); - - if (!isProduction()) - message = `[Test:Environment to user ${userId}] ` + message; - - const chat = await models.Chat.create({ - senderFk: sender.id, - recipient: `@${recipient.name}`, - dated: Date.vnNew(), - checkUserStatus: 1, - message: message, - status: 'sending', - attempts: 0 - }); - try { - await Self.sendCheckingUserStatus(chat); - await Self.updateChat(chat, 'sent'); - } catch (error) { - await Self.updateChat(chat, 'error', error); - } + const models = Self.app.models; + const sender = await models.VnUser.findById(userId, {fields: ['id']}); + const error = `Could not send message from user ${userId}`; - return true; + if (!recipientId) throw new Error(error); + const recipient = await models.VnUser.findById(recipientId, null); + if (!recipient) + throw new Error(error); + + // Prevent sending messages to yourself + if (recipientId == userId) return false; + + if (!isProduction()) + message = `[Test:Environment to user ${userId}] ` + message; + + const chat = await models.Chat.create({ + senderFk: sender.id, + recipient: `@${recipient.name}`, + dated: Date.vnNew(), + checkUserStatus: 1, + message: message, + status: 'sending', + attempts: 0 + }); + + try { + await Self.sendCheckingUserStatus(chat); + await Self.updateChat(chat, 'sent'); + } catch (error) { + await Self.updateChat(chat, 'error', error); + } + + return true; + } catch (e) { + await Self.rawSql(` + INSERT INTO util.debug (variable, value) + VALUES ('sendCheckingPresence_error', ?) + `, [`User: ${userId}, recipient: ${recipientId}, message: ${message}, error: ${e}`]); + throw e; + } }; }; From 1ac75d87ade3d238585c075813fc136601417f3c Mon Sep 17 00:00:00 2001 From: sergiodt Date: Fri, 10 Jan 2025 08:55:45 +0100 Subject: [PATCH 4/6] fix: refs #6861 refs#6861 addPrevOK --- db/routines/vn/procedures/saleTracking_addPrevOK.sql | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/db/routines/vn/procedures/saleTracking_addPrevOK.sql b/db/routines/vn/procedures/saleTracking_addPrevOK.sql index 34d1cfac8..9f823e9a0 100644 --- a/db/routines/vn/procedures/saleTracking_addPrevOK.sql +++ b/db/routines/vn/procedures/saleTracking_addPrevOK.sql @@ -16,10 +16,11 @@ BEGIN TRUE, sc.userFk, s.id - FROM vn.sectorCollection sc - JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id - JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk - JOIN vn.state s ON s.code = 'OK PREVIOUS' + FROM sectorCollection sc + JOIN sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id + JOIN saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk + JOIN state s ON s.code = 'OK PREVIOUS' + JOIN itemShelvingSale iss ON iss.saleFk = sgd.saleFk WHERE sc.id = vSectorCollectionFk; END$$ DELIMITER ; From bdaaffbbd76247d2eaf64635c58fbd8e707bff2b Mon Sep 17 00:00:00 2001 From: robert Date: Fri, 10 Jan 2025 10:33:19 +0100 Subject: [PATCH 5/6] feat: refs #7584 changes request --- db/routines/vn/triggers/workerTimeControl_afterDelete.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/triggers/workerTimeControl_afterDelete.sql b/db/routines/vn/triggers/workerTimeControl_afterDelete.sql index 762754591..96db381b5 100644 --- a/db/routines/vn/triggers/workerTimeControl_afterDelete.sql +++ b/db/routines/vn/triggers/workerTimeControl_afterDelete.sql @@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`workerTimeControl_after AFTER DELETE ON `workerTimeControl` FOR EACH ROW BEGIN - IF account.myUser_getId() THEN + IF account.myUser_getId() IS NOT NULL THEN INSERT INTO workerLog SET `action` = 'delete', `changedModel` = 'WorkerTimeControl', From 9d05b16404da3a7d3d7d5e14300f7b4a9d8baa9f Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 13 Jan 2025 09:18:46 +0100 Subject: [PATCH 6/6] fix: canBeInvoiced only in makeInvoice --- loopback/locale/en.json | 3 +- loopback/locale/es.json | 2 +- loopback/locale/fr.json | 2 +- loopback/locale/pt.json | 2 +- .../methods/invoiceOut/clientsToInvoice.js | 6 --- .../invoiceOut/specs/clientsToInvoice.spec.js | 54 +++++++++++-------- 6 files changed, 38 insertions(+), 31 deletions(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 80da13ae5..8d5eab4bc 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -211,6 +211,7 @@ "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", + "No tickets to invoice": "There are no tickets to invoice that meet the invoicing requirements", "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.", @@ -251,4 +252,4 @@ "Price cannot be blank": "Price cannot be blank", "There are tickets to be invoiced": "There are tickets to be invoiced", "The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent" -} \ No newline at end of file +} diff --git a/loopback/locale/es.json b/loopback/locale/es.json index fcee0e111..cde81e0cb 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -339,7 +339,7 @@ "Incorrect pin": "Pin incorrecto.", "You already have the mailAlias": "Ya tienes este alias de correo", "The alias cant be modified": "Este alias de correo no puede ser modificado", - "No tickets to invoice": "No hay tickets para facturar", + "No tickets to invoice": "No hay tickets para facturar que cumplan los requisitos de facturación", "this warehouse has not dms": "El Almacén no acepta documentos", "This ticket already has a cmr saved": "Este ticket ya tiene un cmr guardado", "Name should be uppercase": "El nombre debe ir en mayúscula", diff --git a/loopback/locale/fr.json b/loopback/locale/fr.json index 9941358be..f49196a8f 100644 --- a/loopback/locale/fr.json +++ b/loopback/locale/fr.json @@ -339,7 +339,7 @@ "Incorrect pin": "Pin incorrect.", "You already have the mailAlias": "Vous avez déjà cet alias de courrier", "The alias cant be modified": "Cet alias de courrier ne peut pas être modifié", - "No tickets to invoice": "Pas de tickets à facturer", + "No tickets to invoice": "Il n'y a pas de tickets à facturer qui répondent aux exigences de facturation", "this warehouse has not dms": "L'entrepôt n'accepte pas les documents", "This ticket already has a cmr saved": "Ce ticket a déjà un cmr enregistré", "Name should be uppercase": "Le nom doit être en majuscules", diff --git a/loopback/locale/pt.json b/loopback/locale/pt.json index e84b30f3d..e2374d35f 100644 --- a/loopback/locale/pt.json +++ b/loopback/locale/pt.json @@ -339,7 +339,7 @@ "Incorrect pin": "PIN incorreto.", "You already have the mailAlias": "Você já tem o alias de e-mail", "The alias cant be modified": "O alias não pode ser modificado", - "No tickets to invoice": "Não há tickets para faturar", + "No tickets to invoice": "Não há bilhetes para faturar que atendam aos requisitos de faturamento", "this warehouse has not dms": "Este armazém não tem DMS", "This ticket already has a cmr saved": "Este ticket já tem um CMR salvo", "Name should be uppercase": "O nome deve estar em maiúsculas", diff --git a/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js b/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js index 7befdcbeb..f66221409 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js +++ b/modules/invoiceOut/back/methods/invoiceOut/clientsToInvoice.js @@ -49,12 +49,6 @@ module.exports = Self => { } try { - const clientCanBeInvoiced = - await Self.app.models.Client.canBeInvoiced(clientId, companyFk, myOptions); - - if (!clientCanBeInvoiced) - throw new UserError(`This client can't be invoiced`); - const vIsAllInvoiceable = false; await Self.rawSql('CALL ticketPackaging_add(?, ?, ?, ?)', [ clientId, diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/clientsToInvoice.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/clientsToInvoice.spec.js index df0566c54..6e536f433 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/clientsToInvoice.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/clientsToInvoice.spec.js @@ -1,4 +1,5 @@ const models = require('vn-loopback/server/server').models; +const LoopBackContext = require('loopback-context'); describe('InvoiceOut clientsToInvoice()', () => { const userId = 1; @@ -20,6 +21,21 @@ describe('InvoiceOut clientsToInvoice()', () => { headers: {origin: 'http://localhost'} }; const ctx = {req: activeCtx}; + let tx; + let options; + + beforeEach(async() => { + LoopBackContext.getCurrentContext = () => ({ + active: activeCtx, + }); + + tx = await models.InvoiceOut.beginTransaction({}); + options = {transaction: tx}; + }); + + afterEach(async() => { + await tx.rollback(); + }); it('should return a list of clients to invoice', async() => { spyOn(models.InvoiceOut, 'rawSql').and.callFake(query => { @@ -37,24 +53,14 @@ describe('InvoiceOut clientsToInvoice()', () => { } }); - const tx = await models.InvoiceOut.beginTransaction({}); - const options = {transaction: tx}; + const addresses = await models.InvoiceOut.clientsToInvoice( + ctx, clientId, invoiceDate, maxShipped, companyFk, options); - try { - const addresses = await models.InvoiceOut.clientsToInvoice( - ctx, clientId, invoiceDate, maxShipped, companyFk, options); - - expect(addresses.length).toBeGreaterThan(0); - expect(addresses[0].clientId).toBe(clientId); - expect(addresses[0].clientName).toBe('Test Client'); - expect(addresses[0].id).toBe(1); - expect(addresses[0].nickname).toBe('Address 1'); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + expect(addresses.length).toBeGreaterThan(0); + expect(addresses[0].clientId).toBe(clientId); + expect(addresses[0].clientName).toBe('Test Client'); + expect(addresses[0].id).toBe(1); + expect(addresses[0].nickname).toBe('Address 1'); }); it('should handle errors and rollback transaction', async() => { @@ -62,14 +68,20 @@ describe('InvoiceOut clientsToInvoice()', () => { return Promise.reject(new Error('Test Error')); }); - const tx = await models.InvoiceOut.beginTransaction({}); - const options = {transaction: tx}; - try { await models.InvoiceOut.clientsToInvoice(ctx, clientId, invoiceDate, maxShipped, companyFk, options); } catch (e) { expect(e.message).toBe('Test Error'); - await tx.rollback(); } }); + + it('should return all list', async() => { + const minShipped = Date.vnNew(); + minShipped.setFullYear(maxShipped.getFullYear() - 1); + + const toInvoice = await models.InvoiceOut.clientsToInvoice( + ctx, null, invoiceDate, maxShipped, companyFk, options); + + expect(toInvoice).toBeDefined(); + }); });