From ed77347fe1a92776d9c1de7137002b60b6be3522 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 25 Jan 2024 15:41:55 +0100 Subject: [PATCH 01/16] fix: #6557 replace procedure --- modules/worker/back/methods/worker/mySubordinates.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/worker/back/methods/worker/mySubordinates.js b/modules/worker/back/methods/worker/mySubordinates.js index b6711e3827..540bb8551f 100644 --- a/modules/worker/back/methods/worker/mySubordinates.js +++ b/modules/worker/back/methods/worker/mySubordinates.js @@ -30,13 +30,12 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - stmts.push(new ParameterizedSQL('CALL vn.subordinateGetList(?)', [userId])); - const queryIndex = stmts.push('SELECT * FROM tmp.subordinate') - 1; - stmts.push('DROP TEMPORARY TABLE tmp.subordinate'); + stmts.push(new ParameterizedSQL('CALL vn.worker_getHierarchy(?)', [userId])); + const queryIndex = stmts.push('SELECT * FROM tmp.workerHierarchyList') - 1; + stmts.push('DROP TEMPORARY TABLE tmp.workerHierarchyList'); const sql = ParameterizedSQL.join(stmts, ';'); const result = await conn.executeStmt(sql, myOptions); - return result[queryIndex]; }; }; From e5d466b697e33513ea98b74b855f4c17877a8ba8 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 26 Jan 2024 08:30:43 +0100 Subject: [PATCH 02/16] fix: refs #6703 drop & replace sale refund by clone --- modules/ticket/back/methods/sale/clone.js | 28 +++++ modules/ticket/back/methods/sale/refund.js | 61 ----------- .../back/methods/sale/specs/refund.spec.js | 101 ------------------ modules/ticket/back/methods/ticket/refund.js | 2 +- modules/ticket/back/models/sale.js | 1 - 5 files changed, 29 insertions(+), 164 deletions(-) delete mode 100644 modules/ticket/back/methods/sale/refund.js delete mode 100644 modules/ticket/back/methods/sale/specs/refund.spec.js diff --git a/modules/ticket/back/methods/sale/clone.js b/modules/ticket/back/methods/sale/clone.js index f8eb4d1439..8397499f7c 100644 --- a/modules/ticket/back/methods/sale/clone.js +++ b/modules/ticket/back/methods/sale/clone.js @@ -1,4 +1,32 @@ module.exports = Self => { + Self.remoteMethodCtx('clone', { + description: 'Clone sales and services provided', + accessType: 'WRITE', + accepts: [ + { + arg: 'salesIds', + type: ['number'], + }, { + arg: 'servicesIds', + type: ['number'] + }, { + arg: 'withWarehouse', + type: 'boolean', + required: true + }, { + arg: 'negative', + type: 'boolean' + } + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/refund`, + verb: 'post' + } + }); Self.clone = async(ctx, salesIds, servicesIds, withWarehouse, negative, options) => { const models = Self.app.models; const myOptions = {}; diff --git a/modules/ticket/back/methods/sale/refund.js b/modules/ticket/back/methods/sale/refund.js deleted file mode 100644 index 19a8dfbb0b..0000000000 --- a/modules/ticket/back/methods/sale/refund.js +++ /dev/null @@ -1,61 +0,0 @@ -module.exports = Self => { - Self.remoteMethodCtx('refund', { - description: 'Create refund tickets with sales and services if provided', - accessType: 'WRITE', - accepts: [ - { - arg: 'salesIds', - type: ['number'], - }, - { - arg: 'servicesIds', - type: ['number'] - }, - { - arg: 'withWarehouse', - type: 'boolean', - required: true - } - ], - returns: { - type: ['object'], - root: true - }, - http: { - path: `/refund`, - verb: 'post' - } - }); - - Self.refund = async(ctx, salesIds, servicesIds, withWarehouse, options) => { - const models = Self.app.models; - const myOptions = {userId: ctx.req.accessToken.userId}; - let tx; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - - try { - const refundsTicket = await models.Sale.clone( - ctx, - salesIds, - servicesIds, - withWarehouse, - true, - myOptions - ); - - if (tx) await tx.commit(); - - return refundsTicket; - } catch (e) { - if (tx) await tx.rollback(); - throw e; - } - }; -}; diff --git a/modules/ticket/back/methods/sale/specs/refund.spec.js b/modules/ticket/back/methods/sale/specs/refund.spec.js deleted file mode 100644 index ab5e1e281b..0000000000 --- a/modules/ticket/back/methods/sale/specs/refund.spec.js +++ /dev/null @@ -1,101 +0,0 @@ -const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); - -describe('Sale refund()', () => { - const userId = 5; - const ctx = {req: {accessToken: userId}, args: {}}; - const activeCtx = { - accessToken: {userId}, - }; - const servicesIds = [3]; - const withWarehouse = true; - - beforeEach(() => { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - }); - - it('should create ticket with the selected lines', async() => { - const tx = await models.Sale.beginTransaction({}); - const salesIds = [7, 8]; - - try { - const options = {transaction: tx}; - - const refundedTickets = await models.Sale.refund(ctx, salesIds, servicesIds, withWarehouse, options); - - expect(refundedTickets).toBeDefined(); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); - - it('should create one ticket for each unique ticketFk in the sales', async() => { - const tx = await models.Sale.beginTransaction({}); - const salesIds = [6, 7]; - - try { - const options = {transaction: tx}; - const ticketsBefore = await models.Ticket.find({}, options); - - const tickets = await models.Sale.refund(ctx, salesIds, servicesIds, withWarehouse, options); - - const refundedTicket = await getTicketRefund(tickets[0].id, options); - const ticketsAfter = await models.Ticket.find({}, options); - const salesLength = refundedTicket.ticketSales().length; - const componentsLength = refundedTicket.ticketSales()[0].components().length; - - expect(refundedTicket).toBeDefined(); - expect(salesLength).toEqual(1); - expect(ticketsBefore.length).toEqual(ticketsAfter.length - 2); - expect(componentsLength).toEqual(4); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); - - it('should create a ticket without sales', async() => { - const servicesIds = [4]; - const tx = await models.Sale.beginTransaction({}); - const options = {transaction: tx}; - try { - const tickets = await models.Sale.refund(ctx, null, servicesIds, withWarehouse, options); - const refundedTicket = await getTicketRefund(tickets[0].id, options); - - expect(refundedTicket).toBeDefined(); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); -}); - -async function getTicketRefund(id, options) { - return models.Ticket.findOne({ - where: { - id - }, - include: [ - { - relation: 'ticketSales', - scope: { - include: { - relation: 'components' - } - } - }, - { - relation: 'ticketServices', - } - ] - }, options); -} diff --git a/modules/ticket/back/methods/ticket/refund.js b/modules/ticket/back/methods/ticket/refund.js index 4fed022606..b079954532 100644 --- a/modules/ticket/back/methods/ticket/refund.js +++ b/modules/ticket/back/methods/ticket/refund.js @@ -45,7 +45,7 @@ module.exports = Self => { const services = await models.TicketService.find(filter, myOptions); const servicesIds = services.map(service => service.id); - const refundedTickets = await models.Sale.refund(ctx, salesIds, servicesIds, withWarehouse, myOptions); + const refundedTickets = await models.Sale.clone(ctx, salesIds, servicesIds, withWarehouse, true, myOptions); if (tx) await tx.commit(); diff --git a/modules/ticket/back/models/sale.js b/modules/ticket/back/models/sale.js index dd092573d1..30fb74b752 100644 --- a/modules/ticket/back/models/sale.js +++ b/modules/ticket/back/models/sale.js @@ -9,7 +9,6 @@ module.exports = Self => { require('../methods/sale/updateQuantity')(Self); require('../methods/sale/updateConcept')(Self); require('../methods/sale/recalculatePrice')(Self); - require('../methods/sale/refund')(Self); require('../methods/sale/canEdit')(Self); require('../methods/sale/usesMana')(Self); require('../methods/sale/clone')(Self); From 4fc780967f17256d49ea0cf5724219bb4dfc7f08 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 26 Jan 2024 15:32:50 +0100 Subject: [PATCH 03/16] fix: refs #6703 tests --- db/changes/240601/00-cloneAcl.sql | 4 ++++ modules/ticket/back/methods/sale/clone.js | 4 ++-- modules/ticket/back/methods/ticket/refund.js | 2 +- modules/ticket/front/sale/index.js | 2 +- modules/ticket/front/sale/index.spec.js | 2 +- modules/ticket/front/services/index.js | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 db/changes/240601/00-cloneAcl.sql diff --git a/db/changes/240601/00-cloneAcl.sql b/db/changes/240601/00-cloneAcl.sql new file mode 100644 index 0000000000..bc6e22ee00 --- /dev/null +++ b/db/changes/240601/00-cloneAcl.sql @@ -0,0 +1,4 @@ +UPDATE salix.ACL + SET property='clone' + WHERE model = 'Sale' + AND property = 'refund' \ No newline at end of file diff --git a/modules/ticket/back/methods/sale/clone.js b/modules/ticket/back/methods/sale/clone.js index 8397499f7c..77c40d8a07 100644 --- a/modules/ticket/back/methods/sale/clone.js +++ b/modules/ticket/back/methods/sale/clone.js @@ -23,8 +23,8 @@ module.exports = Self => { root: true }, http: { - path: `/refund`, - verb: 'post' + path: `/clone`, + verb: 'POST' } }); Self.clone = async(ctx, salesIds, servicesIds, withWarehouse, negative, options) => { diff --git a/modules/ticket/back/methods/ticket/refund.js b/modules/ticket/back/methods/ticket/refund.js index b079954532..7365f34df3 100644 --- a/modules/ticket/back/methods/ticket/refund.js +++ b/modules/ticket/back/methods/ticket/refund.js @@ -20,7 +20,7 @@ module.exports = Self => { }, http: { path: `/refund`, - verb: 'post' + verb: 'POST' } }); diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index ed6d9b10a3..ce6aad5eda 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -524,7 +524,7 @@ class Controller extends Section { const salesIds = sales.map(sale => sale.id); const params = {salesIds: salesIds, withWarehouse: withWarehouse}; - const query = 'Sales/refund'; + const query = 'Sales/clone'; this.$http.post(query, params).then(res => { const [refundTicket] = res.data; this.vnApp.showSuccess(this.$t('The following refund ticket have been created', { diff --git a/modules/ticket/front/sale/index.spec.js b/modules/ticket/front/sale/index.spec.js index 36be32f52d..6b1da108ef 100644 --- a/modules/ticket/front/sale/index.spec.js +++ b/modules/ticket/front/sale/index.spec.js @@ -729,7 +729,7 @@ describe('Ticket', () => { salesIds: [1, 4], }; const refundTicket = {id: 99}; - $httpBackend.expect('POST', 'Sales/refund', params).respond(200, [refundTicket]); + $httpBackend.expect('POST', 'Sales/clone', params).respond(200, [refundTicket]); controller.createRefund(); $httpBackend.flush(); diff --git a/modules/ticket/front/services/index.js b/modules/ticket/front/services/index.js index d8c209ea4f..08a76f9ba0 100644 --- a/modules/ticket/front/services/index.js +++ b/modules/ticket/front/services/index.js @@ -56,7 +56,7 @@ class Controller extends Section { if (!this.checkeds.length) return; const params = {servicesIds: this.checkeds, withWarehouse: false}; - const query = 'Sales/refund'; + const query = 'Sales/clone'; this.$http.post(query, params).then(res => { const refundTicket = res.data; this.vnApp.showSuccess(this.$t('The following refund ticket have been created', { From 9b8c58ba7d4f95bcfc84b07f1ffd93f1753a6b9a Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 29 Jan 2024 16:00:24 +0100 Subject: [PATCH 04/16] refs #6270 makeInvoice --- .../ticket/back/methods/ticket/makeInvoice.js | 9 ++++- modules/ticket/front/descriptor-menu/index.js | 40 ++++++++++--------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/modules/ticket/back/methods/ticket/makeInvoice.js b/modules/ticket/back/methods/ticket/makeInvoice.js index 83222a4ee0..1fcbd41303 100644 --- a/modules/ticket/back/methods/ticket/makeInvoice.js +++ b/modules/ticket/back/methods/ticket/makeInvoice.js @@ -110,7 +110,14 @@ module.exports = function(Self) { if (tx) await tx.commit(); - return resultInvoice.id; + const notificationInfo = { + clientName: firstTicket.clientFk.name, + clientEmail: firstTicket.clientFk.email, + ticketId: resultInvoice.id, + url: ctx.req.headers.referer + }; + + return {invoiceId: resultInvoice.id, notificationInfo}; } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index cd819e6235..4e33d2c437 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -248,26 +248,30 @@ class Controller extends Section { if (this.ticket.address.incotermsFk && !this.ticket.weight && !force) return this.$.withoutWeightConfirmation.show(); - const client = this.ticket.client; - if (client.hasElectronicInvoice) { - this.$http.post(`NotificationQueues`, { - notificationFk: 'invoice-electronic', - authorFk: client.id, - params: JSON.stringify( - { - 'name': client.name, - 'email': client.email, - 'ticketId': this.id, - 'url': window.location.href - }) - }).then(() => { - this.vnApp.showSuccess(this.$t('Invoice sent')); - }); - } - return this.$http.post(`Tickets/invoiceTickets`, {ticketsIds: [this.id]}) .then(() => this.reload()) - .then(() => this.vnApp.showSuccess(this.$t('Ticket invoiced'))); + .then(() => { + const client = this.ticket.client; + + if (client.hasElectronicInvoice) { + const notificationData = { + name: client.name, + email: client.email, + ticketId: this.id, + url: window.location.href + }; + + this.$http.post(`NotificationQueues`, { + notificationFk: 'invoice-electronic', + authorFk: client.id, + params: JSON.stringify(notificationData) + }).then(() => { + this.vnApp.showSuccess(this.$t('Invoice sent')); + }); + } + + this.vnApp.showSuccess(this.$t('Ticket invoiced')); + }); } createPdfInvoice() { From 50c1531083f450971fc814fd8fcb29b8b6d35050 Mon Sep 17 00:00:00 2001 From: Jbreso Date: Tue, 30 Jan 2024 10:31:29 +0100 Subject: [PATCH 05/16] feat: refs#Eliminar vistas vn2008 --- db/routines/vn2008/views/Equipos.sql | 8 -------- db/routines/vn2008/views/deliveryPoint.sql | 7 ------- db/routines/vn2008/views/device_user.sql | 6 ------ db/routines/vn2008/views/escritos.sql | 9 --------- 4 files changed, 30 deletions(-) delete mode 100644 db/routines/vn2008/views/Equipos.sql delete mode 100644 db/routines/vn2008/views/deliveryPoint.sql delete mode 100644 db/routines/vn2008/views/device_user.sql delete mode 100644 db/routines/vn2008/views/escritos.sql diff --git a/db/routines/vn2008/views/Equipos.sql b/db/routines/vn2008/views/Equipos.sql deleted file mode 100644 index fd1210237a..0000000000 --- a/db/routines/vn2008/views/Equipos.sql +++ /dev/null @@ -1,8 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`Equipos` -AS SELECT `h`.`code` AS `alias`, - `h`.`description` AS `descripcion`, - `h`.`workerFk` AS `trabajador_id`, - `h`.`windowsSerial` AS `windowsSerial` -FROM `vn`.`host` `h` diff --git a/db/routines/vn2008/views/deliveryPoint.sql b/db/routines/vn2008/views/deliveryPoint.sql deleted file mode 100644 index 7763bc9fa4..0000000000 --- a/db/routines/vn2008/views/deliveryPoint.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`deliveryPoint` -AS SELECT `dp`.`id` AS `id`, - `dp`.`name` AS `name`, - `dp`.`ubication` AS `ubication` -FROM `vn`.`deliveryPoint` `dp` diff --git a/db/routines/vn2008/views/device_user.sql b/db/routines/vn2008/views/device_user.sql deleted file mode 100644 index 52a2faafa7..0000000000 --- a/db/routines/vn2008/views/device_user.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`device_user` -AS SELECT `dpu`.`deviceProductionFk` AS `device_id`, - `dpu`.`userFk` AS `user_id` -FROM `vn`.`deviceProductionUser` `dpu` diff --git a/db/routines/vn2008/views/escritos.sql b/db/routines/vn2008/views/escritos.sql deleted file mode 100644 index b99bc13d76..0000000000 --- a/db/routines/vn2008/views/escritos.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`escritos` -AS SELECT `s`.`id` AS `id`, - `s`.`code` AS `abrev`, - `s`.`description` AS `descripcion`, - `s`.`isVisible` AS `visible`, - `s`.`hasCompany` AS `hasCompany` -FROM `vn`.`sample` `s` From 509d5cea14c8912dde579cf1f663ef77687016f4 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 30 Jan 2024 15:54:03 +0100 Subject: [PATCH 06/16] refs #6270 fix back --- .../ticket/back/methods/ticket/makeInvoice.js | 26 +++++++++++++------ modules/ticket/front/descriptor-menu/index.js | 23 +--------------- .../invoice-electronic/invoice-electronic.js | 2 +- 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/modules/ticket/back/methods/ticket/makeInvoice.js b/modules/ticket/back/methods/ticket/makeInvoice.js index 1fcbd41303..706da6f399 100644 --- a/modules/ticket/back/methods/ticket/makeInvoice.js +++ b/modules/ticket/back/methods/ticket/makeInvoice.js @@ -108,16 +108,26 @@ module.exports = function(Self) { await Self.rawSql('CALL invoiceOutBooking(?)', [resultInvoice.id], myOptions); + const client = await models.Client.findById(clientId, + {fields: ['hasElectronicInvoice', 'name', 'email']}, myOptions); + if (client.hasElectronicInvoice) { + const url = await models.Url.getUrl(); + await models.NotificationQueue.create({ + notificationFk: 'invoice-electronic', + authorFk: client.id, + params: JSON.stringify( + { + 'name': client.name, + 'email': client.email, + 'ticketId': ticketsIds.join(','), + 'url': url + 'ticket/index?q=' + encodeURIComponent(JSON.stringify({clientFk: clientId})) + }) + }, myOptions); + } + if (tx) await tx.commit(); - const notificationInfo = { - clientName: firstTicket.clientFk.name, - clientEmail: firstTicket.clientFk.email, - ticketId: resultInvoice.id, - url: ctx.req.headers.referer - }; - - return {invoiceId: resultInvoice.id, notificationInfo}; + return resultInvoice.id; } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index 4e33d2c437..c254900ccd 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -250,28 +250,7 @@ class Controller extends Section { return this.$http.post(`Tickets/invoiceTickets`, {ticketsIds: [this.id]}) .then(() => this.reload()) - .then(() => { - const client = this.ticket.client; - - if (client.hasElectronicInvoice) { - const notificationData = { - name: client.name, - email: client.email, - ticketId: this.id, - url: window.location.href - }; - - this.$http.post(`NotificationQueues`, { - notificationFk: 'invoice-electronic', - authorFk: client.id, - params: JSON.stringify(notificationData) - }).then(() => { - this.vnApp.showSuccess(this.$t('Invoice sent')); - }); - } - - this.vnApp.showSuccess(this.$t('Ticket invoiced')); - }); + .then(() => this.vnApp.showSuccess(this.$t('Ticket invoiced'))); } createPdfInvoice() { diff --git a/print/templates/email/invoice-electronic/invoice-electronic.js b/print/templates/email/invoice-electronic/invoice-electronic.js index 2e1e739acb..1ec6d1374b 100644 --- a/print/templates/email/invoice-electronic/invoice-electronic.js +++ b/print/templates/email/invoice-electronic/invoice-electronic.js @@ -10,7 +10,7 @@ module.exports = { required: true }, ticketId: { - type: [Number], + type: [String], required: true }, url: { From a6ea4ed0485db8d5257bfe07e5c493294379d05d Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 30 Jan 2024 16:42:11 +0100 Subject: [PATCH 07/16] Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 6270-electronicInvoiceBack --- loopback/locale/en.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 568916bef4..059da63563 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -203,5 +203,7 @@ "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" + "The notification subscription of this worker cant be modified": "The notification subscription of this worker cant be modified", + "Fecha fuera de rango": "Fecha fuera de rango", + "There is no zone for these parameters 34": "There is no zone for these parameters 34" } \ No newline at end of file From c136395d1e65edf1bd81c5cff5e570c961e539da Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 31 Jan 2024 09:16:38 +0100 Subject: [PATCH 08/16] fix: refs #6703 fix conflicts --- .../{10832-purpleAralia => 10856-greenAralia}/00-cloneAcl.sql | 0 modules/ticket/front/sale/index.js | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename db/versions/{10832-purpleAralia => 10856-greenAralia}/00-cloneAcl.sql (100%) diff --git a/db/versions/10832-purpleAralia/00-cloneAcl.sql b/db/versions/10856-greenAralia/00-cloneAcl.sql similarity index 100% rename from db/versions/10832-purpleAralia/00-cloneAcl.sql rename to db/versions/10856-greenAralia/00-cloneAcl.sql diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index ce6aad5eda..f295efae9a 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -523,7 +523,7 @@ class Controller extends Section { if (!sales) return; const salesIds = sales.map(sale => sale.id); - const params = {salesIds: salesIds, withWarehouse: withWarehouse}; + const params = {salesIds: salesIds, withWarehouse: withWarehouse,}; const query = 'Sales/clone'; this.$http.post(query, params).then(res => { const [refundTicket] = res.data; From e6eac5470934f90ee7ba2055e1969a33336db98d Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 31 Jan 2024 09:59:32 +0100 Subject: [PATCH 09/16] fix: refs #6703 tests & front --- .../back/methods/sale/specs/clone.spec.js | 38 +++++++++++++++++++ modules/ticket/front/sale/index.js | 2 +- modules/ticket/front/sale/index.spec.js | 1 + modules/ticket/front/services/index.js | 4 +- 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/modules/ticket/back/methods/sale/specs/clone.spec.js b/modules/ticket/back/methods/sale/specs/clone.spec.js index 26506485ab..f52f7ba38f 100644 --- a/modules/ticket/back/methods/sale/specs/clone.spec.js +++ b/modules/ticket/back/methods/sale/specs/clone.spec.js @@ -67,4 +67,42 @@ describe('Ticket cloning - clone function', () => { expect(services.length).toBeGreaterThan(0); } }); + + it('should create a ticket without sales', async() => { + const servicesIds = [4]; + const tx = await models.Sale.beginTransaction({}); + const options = {transaction: tx}; + try { + const tickets = await models.Sale.clone(ctx, null, servicesIds, false, options); + const refundedTicket = await getTicketRefund(tickets[0].id, options); + + expect(refundedTicket).toBeDefined(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); + +async function getTicketRefund(id, options) { + return models.Ticket.findOne({ + where: { + id + }, + include: [ + { + relation: 'ticketSales', + scope: { + include: { + relation: 'components' + } + } + }, + { + relation: 'ticketServices', + } + ] + }, options); +} diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index f295efae9a..1cd5560a47 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -523,7 +523,7 @@ class Controller extends Section { if (!sales) return; const salesIds = sales.map(sale => sale.id); - const params = {salesIds: salesIds, withWarehouse: withWarehouse,}; + const params = {salesIds: salesIds, withWarehouse: withWarehouse, negative: true}; const query = 'Sales/clone'; this.$http.post(query, params).then(res => { const [refundTicket] = res.data; diff --git a/modules/ticket/front/sale/index.spec.js b/modules/ticket/front/sale/index.spec.js index 6b1da108ef..fb1c925d41 100644 --- a/modules/ticket/front/sale/index.spec.js +++ b/modules/ticket/front/sale/index.spec.js @@ -727,6 +727,7 @@ describe('Ticket', () => { jest.spyOn(controller.$state, 'go'); const params = { salesIds: [1, 4], + negative: true }; const refundTicket = {id: 99}; $httpBackend.expect('POST', 'Sales/clone', params).respond(200, [refundTicket]); diff --git a/modules/ticket/front/services/index.js b/modules/ticket/front/services/index.js index 08a76f9ba0..fadf2ad4f5 100644 --- a/modules/ticket/front/services/index.js +++ b/modules/ticket/front/services/index.js @@ -55,10 +55,10 @@ class Controller extends Section { createRefund() { if (!this.checkeds.length) return; - const params = {servicesIds: this.checkeds, withWarehouse: false}; + const params = {servicesIds: this.checkeds, withWarehouse: false, negative: true}; const query = 'Sales/clone'; this.$http.post(query, params).then(res => { - const refundTicket = res.data; + const [refundTicket] = res.data; this.vnApp.showSuccess(this.$t('The following refund ticket have been created', { ticketId: refundTicket.id })); From cfe7fa0790be0d9e861fd618fba1ebec0806541e Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 1 Feb 2024 08:52:05 +0100 Subject: [PATCH 10/16] refs #6703 try --- db/dump/fixtures.before.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 3803730bd7..85e24f282f 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3067,3 +3067,4 @@ INSERT INTO `vn`.`clientSms` (`id`, `clientFk`, `smsFk`, `ticketFk`) (4, 1103, 4, 32), (13, 1101, 1, NULL), (14, 1101, 4, 27); + From bb91035b77c35a0d33cedd83bbeb42cce491d0c2 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 1 Feb 2024 08:52:40 +0100 Subject: [PATCH 11/16] refs #6703 try --- db/dump/fixtures.before.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 85e24f282f..3803730bd7 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3067,4 +3067,3 @@ INSERT INTO `vn`.`clientSms` (`id`, `clientFk`, `smsFk`, `ticketFk`) (4, 1103, 4, 32), (13, 1101, 1, NULL), (14, 1101, 4, 27); - From 1ffbb30d77689ffc9dd9e7c219c5f335a3ada3f0 Mon Sep 17 00:00:00 2001 From: josepd Date: Fri, 2 Feb 2024 14:05:27 +0100 Subject: [PATCH 12/16] refs #6689 feat: delete view vn2008 --- db/routines/vn2008/views/Prioridades.sql | 6 ------ db/routines/vn2008/views/person_user.sql | 10 ---------- db/routines/vn2008/views/person_user_idtrabajador.sql | 9 --------- db/routines/vn2008/views/reference_min.sql | 7 ------- db/versions/10869-crimsonDracena/00-firstScript.sql | 1 + 5 files changed, 1 insertion(+), 32 deletions(-) delete mode 100644 db/routines/vn2008/views/Prioridades.sql delete mode 100644 db/routines/vn2008/views/person_user.sql delete mode 100644 db/routines/vn2008/views/person_user_idtrabajador.sql delete mode 100644 db/routines/vn2008/views/reference_min.sql create mode 100644 db/versions/10869-crimsonDracena/00-firstScript.sql diff --git a/db/routines/vn2008/views/Prioridades.sql b/db/routines/vn2008/views/Prioridades.sql deleted file mode 100644 index 7e89a538fa..0000000000 --- a/db/routines/vn2008/views/Prioridades.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`Prioridades` -AS SELECT `qp`.`id` AS `Id_Prioridad`, - `qp`.`priority` AS `Prioridad` -FROM `vn`.`queuePriority` `qp` diff --git a/db/routines/vn2008/views/person_user.sql b/db/routines/vn2008/views/person_user.sql deleted file mode 100644 index 1fb470c886..0000000000 --- a/db/routines/vn2008/views/person_user.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`person_user` -AS SELECT `u`.`id` AS `id`, - `u`.`role` AS `mysql_user_id`, - `u`.`name` AS `name`, - `u`.`password` AS `password`, - `u`.`active` AS `active`, - `u`.`lastPassChange` AS `last_pass_change` -FROM `account`.`user` `u` diff --git a/db/routines/vn2008/views/person_user_idtrabajador.sql b/db/routines/vn2008/views/person_user_idtrabajador.sql deleted file mode 100644 index 1eb45f4647..0000000000 --- a/db/routines/vn2008/views/person_user_idtrabajador.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`person_user_idtrabajador` -AS SELECT `t`.`Id_Trabajador` AS `Id_Trabajador` -FROM ( - `vn2008`.`person_user` `p` - JOIN `vn2008`.`Trabajadores` `t` ON(`p`.`id` = `t`.`user_id`) - ) -WHERE `t`.`user_id` = `account`.`myUser_getId`() diff --git a/db/routines/vn2008/views/reference_min.sql b/db/routines/vn2008/views/reference_min.sql deleted file mode 100644 index d40ae12a31..0000000000 --- a/db/routines/vn2008/views/reference_min.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`reference_min` -AS SELECT `rc`.`dated` AS `date`, - `rc`.`value` AS `rate`, - `rc`.`currencyFk` AS `moneda_id` -FROM `vn`.`referenceCurrent` `rc` diff --git a/db/versions/10869-crimsonDracena/00-firstScript.sql b/db/versions/10869-crimsonDracena/00-firstScript.sql new file mode 100644 index 0000000000..e5e3c3a4b5 --- /dev/null +++ b/db/versions/10869-crimsonDracena/00-firstScript.sql @@ -0,0 +1 @@ +REVOKE SELECT ON TABLE reference_min FROM logistic; From 518d057cf3cd4f7c5923da90eb907e8daf5d363a Mon Sep 17 00:00:00 2001 From: Jbreso Date: Fri, 2 Feb 2024 14:31:23 +0100 Subject: [PATCH 13/16] refs #6686 feat: Delete views vn2008 --- db/routines/vn2008/views/edi_feature.sql | 10 ---------- db/routines/vn2008/views/edi_genus.sql | 9 --------- db/routines/vn2008/views/edi_item_feature.sql | 11 ----------- db/routines/vn2008/views/edi_plant.sql | 10 ---------- db/routines/vn2008/views/edi_type.sql | 10 ---------- db/routines/vn2008/views/edi_value.sql | 10 ---------- 6 files changed, 60 deletions(-) delete mode 100644 db/routines/vn2008/views/edi_feature.sql delete mode 100644 db/routines/vn2008/views/edi_genus.sql delete mode 100644 db/routines/vn2008/views/edi_item_feature.sql delete mode 100644 db/routines/vn2008/views/edi_plant.sql delete mode 100644 db/routines/vn2008/views/edi_type.sql delete mode 100644 db/routines/vn2008/views/edi_value.sql diff --git a/db/routines/vn2008/views/edi_feature.sql b/db/routines/vn2008/views/edi_feature.sql deleted file mode 100644 index 7789eac060..0000000000 --- a/db/routines/vn2008/views/edi_feature.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`edi_feature` -AS SELECT `edi`.`feature`.`item_id` AS `item_id`, - `edi`.`feature`.`feature_type_id` AS `feature_type_id`, - `edi`.`feature`.`feature_value` AS `feature_value`, - `edi`.`feature`.`entry_date` AS `entry_date`, - `edi`.`feature`.`expiry_date` AS `expiry_date`, - `edi`.`feature`.`change_date_time` AS `change_date_time` -FROM `edi`.`feature` diff --git a/db/routines/vn2008/views/edi_genus.sql b/db/routines/vn2008/views/edi_genus.sql deleted file mode 100644 index c87ef2243a..0000000000 --- a/db/routines/vn2008/views/edi_genus.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`edi_genus` -AS SELECT `edi`.`genus`.`genus_id` AS `genus_id`, - `edi`.`genus`.`latin_genus_name` AS `latin_genus_name`, - `edi`.`genus`.`entry_date` AS `entry_date`, - `edi`.`genus`.`expiry_date` AS `expiry_date`, - `edi`.`genus`.`change_date_time` AS `change_date_time` -FROM `edi`.`genus` diff --git a/db/routines/vn2008/views/edi_item_feature.sql b/db/routines/vn2008/views/edi_item_feature.sql deleted file mode 100644 index 216bd7cf62..0000000000 --- a/db/routines/vn2008/views/edi_item_feature.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`edi_item_feature` -AS SELECT `edi`.`item_feature`.`item_id` AS `item_id`, - `edi`.`item_feature`.`presentation_order` AS `presentation_order`, - `edi`.`item_feature`.`feature` AS `feature`, - `edi`.`item_feature`.`regulation_type` AS `regulation_type`, - `edi`.`item_feature`.`entry_date` AS `entry_date`, - `edi`.`item_feature`.`expiry_date` AS `expiry_date`, - `edi`.`item_feature`.`change_date_time` AS `change_date_time` -FROM `edi`.`item_feature` diff --git a/db/routines/vn2008/views/edi_plant.sql b/db/routines/vn2008/views/edi_plant.sql deleted file mode 100644 index 3537998db8..0000000000 --- a/db/routines/vn2008/views/edi_plant.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`edi_plant` -AS SELECT `edi`.`plant`.`plant_id` AS `plant_id`, - `edi`.`plant`.`genus_id` AS `genus_id`, - `edi`.`plant`.`specie_id` AS `specie_id`, - `edi`.`plant`.`entry_date` AS `entry_date`, - `edi`.`plant`.`expiry_date` AS `expiry_date`, - `edi`.`plant`.`change_date_time` AS `change_date_time` -FROM `edi`.`plant` diff --git a/db/routines/vn2008/views/edi_type.sql b/db/routines/vn2008/views/edi_type.sql deleted file mode 100644 index 95d73a1ff5..0000000000 --- a/db/routines/vn2008/views/edi_type.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`edi_type` -AS SELECT `edi`.`type`.`type_id` AS `type_id`, - `edi`.`type`.`type_group_id` AS `type_group_id`, - `edi`.`type`.`description` AS `description`, - `edi`.`type`.`entry_date` AS `entry_date`, - `edi`.`type`.`expiry_date` AS `expiry_date`, - `edi`.`type`.`change_date_time` AS `change_date_time` -FROM `edi`.`type` diff --git a/db/routines/vn2008/views/edi_value.sql b/db/routines/vn2008/views/edi_value.sql deleted file mode 100644 index 27829aa9e2..0000000000 --- a/db/routines/vn2008/views/edi_value.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn2008`.`edi_value` -AS SELECT `edi`.`value`.`type_id` AS `type_id`, - `edi`.`value`.`type_value` AS `type_value`, - `edi`.`value`.`type_description` AS `type_description`, - `edi`.`value`.`entry_date` AS `entry_date`, - `edi`.`value`.`expiry_date` AS `expiry_date`, - `edi`.`value`.`change_date_time` AS `change_date_time` -FROM `edi`.`value` From e704f2eaf7387f569fb5b56da9bd5c527b75e22a Mon Sep 17 00:00:00 2001 From: josepd Date: Mon, 5 Feb 2024 07:11:50 +0100 Subject: [PATCH 14/16] feat: refs #6689 Deleted view vn2008 --- db/versions/10869-crimsonDracena/00-firstScript.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/10869-crimsonDracena/00-firstScript.sql b/db/versions/10869-crimsonDracena/00-firstScript.sql index e5e3c3a4b5..0042d24e30 100644 --- a/db/versions/10869-crimsonDracena/00-firstScript.sql +++ b/db/versions/10869-crimsonDracena/00-firstScript.sql @@ -1 +1 @@ -REVOKE SELECT ON TABLE reference_min FROM logistic; +REVOKE SELECT ON TABLE vn2008.reference_min FROM logistic; From d2fec7beee6fb3120eb806be6ba21aa041cafe95 Mon Sep 17 00:00:00 2001 From: davidd Date: Mon, 5 Feb 2024 07:30:04 +0100 Subject: [PATCH 15/16] refs #6642 --- db/routines/vn/views/ticketStateToday.sql | 13 ++++++------- db/routines/vn/views/zoneEstimatedDelivery.sql | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/db/routines/vn/views/ticketStateToday.sql b/db/routines/vn/views/ticketStateToday.sql index cf1f24539f..2ee65b7c28 100644 --- a/db/routines/vn/views/ticketStateToday.sql +++ b/db/routines/vn/views/ticketStateToday.sql @@ -1,16 +1,15 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vn`.`ticketStateToday` -AS SELECT `ts`.`ticketFk` AS `ticket`, +AS SELECT + `ts`.`ticketFk` AS `ticketFk`, `ts`.`state` AS `state`, `ts`.`productionOrder` AS `productionOrder`, `ts`.`alertLevel` AS `alertLevel`, - `ts`.`userFk` AS `worker`, + `ts`.`userFk` AS `userFk`, `ts`.`code` AS `code`, `ts`.`updated` AS `updated`, `ts`.`isPicked` AS `isPicked` -FROM ( - `vn`.`ticketState` `ts` - JOIN `vn`.`ticket` `t` ON(`t`.`id` = `ts`.`ticketFk`) - ) -WHERE `t`.`shipped` BETWEEN `util`.`VN_CURDATE`() AND `MIDNIGHT`(`util`.`VN_CURDATE`()) +FROM `ticketState` `ts` + JOIN `ticket` `t` ON `t`.`id` = `ts`.`ticketFk` +WHERE `t`.`shipped` BETWEEN `util`.`VN_CURDATE`() AND `MIDNIGHT`(`util`.`VN_CURDATE`()); diff --git a/db/routines/vn/views/zoneEstimatedDelivery.sql b/db/routines/vn/views/zoneEstimatedDelivery.sql index e52d5487eb..621d1a8f00 100644 --- a/db/routines/vn/views/zoneEstimatedDelivery.sql +++ b/db/routines/vn/views/zoneEstimatedDelivery.sql @@ -9,7 +9,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` lhp.m3, dl.minSpeed FROM ticket t - JOIN ticketStateToday tst ON tst.ticket = t.id + JOIN ticketStateToday tst ON tst.ticketFk = t.id JOIN state s ON s.id = tst.state JOIN saleVolume sv ON sv.ticketFk = t.id LEFT JOIN lastHourProduction lhp ON lhp.warehouseFk = t.warehouseFk From 99fbb956693c84af7e186d9272c03dfe90b263cd Mon Sep 17 00:00:00 2001 From: jorgep Date: Mon, 5 Feb 2024 09:35:20 +0100 Subject: [PATCH 16/16] fix: refs #6703 test back --- .../ticket/back/methods/sale/specs/clone.spec.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/modules/ticket/back/methods/sale/specs/clone.spec.js b/modules/ticket/back/methods/sale/specs/clone.spec.js index f52f7ba38f..e2220c028f 100644 --- a/modules/ticket/back/methods/sale/specs/clone.spec.js +++ b/modules/ticket/back/methods/sale/specs/clone.spec.js @@ -70,19 +70,11 @@ describe('Ticket cloning - clone function', () => { it('should create a ticket without sales', async() => { const servicesIds = [4]; - const tx = await models.Sale.beginTransaction({}); - const options = {transaction: tx}; - try { - const tickets = await models.Sale.clone(ctx, null, servicesIds, false, options); - const refundedTicket = await getTicketRefund(tickets[0].id, options); - expect(refundedTicket).toBeDefined(); + const tickets = await models.Sale.clone(ctx, null, servicesIds, false, false, options); + const refundedTicket = await getTicketRefund(tickets[0].id, options); - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } + expect(refundedTicket).toBeDefined(); }); });