From 6236cf062143bc893b04d5f98dfe5b2ec440b6bf Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 12 Jan 2024 16:18:26 +0100 Subject: [PATCH 1/4] hotfix ticketRefund --- modules/ticket/back/methods/sale/clone.js | 71 +++++++++++-------- modules/ticket/back/methods/sale/refund.js | 1 - .../back/methods/sale/specs/refund.spec.js | 57 ++++++++++----- 3 files changed, 79 insertions(+), 50 deletions(-) diff --git a/modules/ticket/back/methods/sale/clone.js b/modules/ticket/back/methods/sale/clone.js index a5ccb6de4..fd8e31e82 100644 --- a/modules/ticket/back/methods/sale/clone.js +++ b/modules/ticket/back/methods/sale/clone.js @@ -14,17 +14,30 @@ module.exports = Self => { } try { - const salesFilter = { - where: {id: {inq: salesIds}}, - include: { - relation: 'components', - scope: { - fields: ['saleFk', 'componentFk', 'value'] + let sales; + let services; + + if (salesIds && salesIds.length) { + sales = await models.Sale.find({ + where: {id: {inq: salesIds}}, + include: { + relation: 'components', + scope: { + fields: ['saleFk', 'componentFk', 'value'] + } } - } - }; - const sales = await models.Sale.find(salesFilter, myOptions); - let ticketsIds = [...new Set(sales.map(sale => sale.ticketFk))]; + }, myOptions); + } + + if (servicesIds && servicesIds.length) { + services = await models.TicketService.find({ + where: {id: {inq: servicesIds}} + }, myOptions); + } + + let ticketsIds = sales ? + [...new Set(sales.map(sale => sale.ticketFk))] : + [...new Set(services.map(service => service.ticketFk))]; const mappedTickets = new Map(); @@ -41,32 +54,28 @@ module.exports = Self => { newTickets.push(newTicket); mappedTickets.set(ticketId, newTicket.id); } + if (sales) { + for (const sale of sales) { + const newTicketId = mappedTickets.get(sale.ticketFk); - for (const sale of sales) { - const newTicketId = mappedTickets.get(sale.ticketFk); + const createdSale = await models.Sale.create({ + ticketFk: newTicketId, + itemFk: sale.itemFk, + quantity: negative ? - sale.quantity : sale.quantity, + concept: sale.concept, + price: sale.price, + discount: sale.discount, + }, myOptions); - const createdSale = await models.Sale.create({ - ticketFk: newTicketId, - itemFk: sale.itemFk, - quantity: negative ? - sale.quantity : sale.quantity, - concept: sale.concept, - price: sale.price, - discount: sale.discount, - }, myOptions); + const components = sale.components(); + for (const component of components) + component.saleFk = createdSale.id; - const components = sale.components(); - for (const component of components) - component.saleFk = createdSale.id; - - await models.SaleComponent.create(components, myOptions); + await models.SaleComponent.create(components, myOptions); + } } - if (servicesIds && servicesIds.length) { - const servicesFilter = { - where: {id: {inq: servicesIds}} - }; - const services = await models.TicketService.find(servicesFilter, myOptions); - + if (services) { for (const service of services) { const newTicketId = mappedTickets.get(service.ticketFk); diff --git a/modules/ticket/back/methods/sale/refund.js b/modules/ticket/back/methods/sale/refund.js index a7831e7e3..e1d23001f 100644 --- a/modules/ticket/back/methods/sale/refund.js +++ b/modules/ticket/back/methods/sale/refund.js @@ -6,7 +6,6 @@ module.exports = Self => { { arg: 'salesIds', type: ['number'], - required: true }, { arg: 'servicesIds', diff --git a/modules/ticket/back/methods/sale/specs/refund.spec.js b/modules/ticket/back/methods/sale/specs/refund.spec.js index 60f77e90c..ab5e1e281 100644 --- a/modules/ticket/back/methods/sale/specs/refund.spec.js +++ b/modules/ticket/back/methods/sale/specs/refund.spec.js @@ -44,24 +44,7 @@ describe('Sale refund()', () => { const tickets = await models.Sale.refund(ctx, salesIds, servicesIds, withWarehouse, options); - const refundedTicket = await models.Ticket.findOne({ - where: { - id: tickets[0].id - }, - include: [ - { - relation: 'ticketSales', - scope: { - include: { - relation: 'components' - } - } - }, - { - relation: 'ticketServices', - } - ] - }, 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; @@ -77,4 +60,42 @@ describe('Sale refund()', () => { 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); +} From c20b9fe212dfbb32db96014733ab8fd7d3c85c9f Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 15 Jan 2024 07:45:40 +0100 Subject: [PATCH 2/4] refs #6656 fix(updateTimeEntry): correct accessType (WRITE) --- .../worker/back/methods/worker-time-control/updateTimeEntry.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/worker/back/methods/worker-time-control/updateTimeEntry.js b/modules/worker/back/methods/worker-time-control/updateTimeEntry.js index 8231be7bb..e9d35f880 100644 --- a/modules/worker/back/methods/worker-time-control/updateTimeEntry.js +++ b/modules/worker/back/methods/worker-time-control/updateTimeEntry.js @@ -3,7 +3,7 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethodCtx('updateTimeEntry', { description: 'Updates a time entry for a worker if the user role is above the worker', - accessType: 'READ', + accessType: 'WRITE', accepts: [{ arg: 'id', type: 'number', From 5bbeda40149fbe44352a1807aa241c0a53809ecc Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 16 Jan 2024 13:05:16 +0100 Subject: [PATCH 3/4] feat: refs #4734 Added viaexpress interdia --- .../viaexpress-config/internationalExpedition.js | 2 +- back/methods/viaexpress-config/renderer.js | 11 ++++++----- back/methods/viaexpress-config/template.ejs | 2 +- back/models/viaexpress-config.json | 3 +++ db/changes/240202/01-viaExpressConfig.sql | 2 ++ .../back/methods/worker-time-control/getClockIn.js | 2 +- 6 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 db/changes/240202/01-viaExpressConfig.sql diff --git a/back/methods/viaexpress-config/internationalExpedition.js b/back/methods/viaexpress-config/internationalExpedition.js index 698bb1dac..df50b21e5 100644 --- a/back/methods/viaexpress-config/internationalExpedition.js +++ b/back/methods/viaexpress-config/internationalExpedition.js @@ -20,7 +20,7 @@ module.exports = Self => { } }); - Self.internationalExpedition = async expeditionFk => { + Self.internationalExpedition = async (expeditionFk) => { const models = Self.app.models; const viaexpressConfig = await models.ViaexpressConfig.findOne({ diff --git a/back/methods/viaexpress-config/renderer.js b/back/methods/viaexpress-config/renderer.js index e9abce5ca..c8533ea6b 100644 --- a/back/methods/viaexpress-config/renderer.js +++ b/back/methods/viaexpress-config/renderer.js @@ -20,11 +20,11 @@ module.exports = Self => { } }); - Self.renderer = async expeditionFk => { + Self.renderer = async (expeditionFk) => { const models = Self.app.models; const viaexpressConfig = await models.ViaexpressConfig.findOne({ - fields: ['client', 'user', 'password', 'defaultWeight', 'deliveryType'] + fields: ['client', 'user', 'password', 'defaultWeight', 'deliveryType', 'agencyModeFk'] }); const expedition = await models.Expedition.findOne({ @@ -34,7 +34,7 @@ module.exports = Self => { { relation: 'ticket', scope: { - fields: ['shipped', 'addressFk', 'clientFk', 'companyFk'], + fields: ['shipped', 'addressFk', 'clientFk', 'companyFk', 'agencyModeFk'], include: [ { relation: 'client', @@ -102,7 +102,6 @@ module.exports = Self => { } ] } - } ] }); @@ -110,13 +109,15 @@ module.exports = Self => { const ticket = expedition.ticket(); const sender = ticket.company().client(); const shipped = ticket.shipped.toISOString(); + const isInterdia = (ticket.agencyModeFk === viaexpressConfig.agencyModeFk) const data = { viaexpressConfig, sender, senderAddress: sender.defaultAddress(), client: ticket.client(), address: ticket.address(), - shipped + shipped, + isInterdia }; const template = fs.readFileSync(__dirname + '/template.ejs', 'utf-8'); diff --git a/back/methods/viaexpress-config/template.ejs b/back/methods/viaexpress-config/template.ejs index 0b6eb468c..f9acfe316 100644 --- a/back/methods/viaexpress-config/template.ejs +++ b/back/methods/viaexpress-config/template.ejs @@ -13,7 +13,7 @@ 0 0 0 - 0 + <%= isInterdia %> 0 diff --git a/back/models/viaexpress-config.json b/back/models/viaexpress-config.json index 8df24201b..acab1f7e6 100644 --- a/back/models/viaexpress-config.json +++ b/back/models/viaexpress-config.json @@ -29,6 +29,9 @@ }, "deliveryType": { "type": "string" + }, + "agencyModeFk": { + "type": "number" } } } diff --git a/db/changes/240202/01-viaExpressConfig.sql b/db/changes/240202/01-viaExpressConfig.sql new file mode 100644 index 000000000..8b7f42c9c --- /dev/null +++ b/db/changes/240202/01-viaExpressConfig.sql @@ -0,0 +1,2 @@ +ALTER TABLE vn.viaexpressConfig ADD agencyModeFk int DEFAULT NULL NULL COMMENT 'Indica el agencyMode que es interdia'; +ALTER TABLE vn.viaexpressConfig ADD CONSTRAINT viaexpressConfig_agencyMode_Fk FOREIGN KEY (agencyModeFK) REFERENCES vn.agencyMode(id) ON DELETE RESTRICT ON UPDATE RESTRICT; diff --git a/modules/worker/back/methods/worker-time-control/getClockIn.js b/modules/worker/back/methods/worker-time-control/getClockIn.js index 470700643..458cadafb 100644 --- a/modules/worker/back/methods/worker-time-control/getClockIn.js +++ b/modules/worker/back/methods/worker-time-control/getClockIn.js @@ -5,7 +5,7 @@ module.exports = Self => { accepts: [ { arg: 'workerFk', - type: 'int', + type: 'number', required: true, }, From ed8210d5da163492255dd2608b1c8535ce3e94f4 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 16 Jan 2024 14:16:11 +0100 Subject: [PATCH 4/4] feat: refs #4734 Requested changes --- db/changes/240202/01-viaExpressConfig.sql | 2 -- db/changes/240203/.gitkeep | 0 db/changes/240203/00-viaExpressConfig.sql | 2 ++ 3 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 db/changes/240202/01-viaExpressConfig.sql create mode 100644 db/changes/240203/.gitkeep create mode 100644 db/changes/240203/00-viaExpressConfig.sql diff --git a/db/changes/240202/01-viaExpressConfig.sql b/db/changes/240202/01-viaExpressConfig.sql deleted file mode 100644 index 8b7f42c9c..000000000 --- a/db/changes/240202/01-viaExpressConfig.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE vn.viaexpressConfig ADD agencyModeFk int DEFAULT NULL NULL COMMENT 'Indica el agencyMode que es interdia'; -ALTER TABLE vn.viaexpressConfig ADD CONSTRAINT viaexpressConfig_agencyMode_Fk FOREIGN KEY (agencyModeFK) REFERENCES vn.agencyMode(id) ON DELETE RESTRICT ON UPDATE RESTRICT; diff --git a/db/changes/240203/.gitkeep b/db/changes/240203/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/db/changes/240203/00-viaExpressConfig.sql b/db/changes/240203/00-viaExpressConfig.sql new file mode 100644 index 000000000..57832e7cd --- /dev/null +++ b/db/changes/240203/00-viaExpressConfig.sql @@ -0,0 +1,2 @@ +ALTER TABLE `vn`.`viaexpressConfig` ADD agencyModeFk int DEFAULT NULL NULL COMMENT 'Indica el agencyMode que es interdia'; +ALTER TABLE `vn`.`viaexpressConfig` ADD CONSTRAINT viaexpressConfig_agencyMode_Fk FOREIGN KEY (agencyModeFK) REFERENCES vn.agencyMode(id) ON DELETE RESTRICT ON UPDATE RESTRICT;