From 2e4a5029b8304f8a452b0033331c4313e7bc21c1 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 6 Mar 2024 14:52:49 +0100 Subject: [PATCH] refs #6755 fix restore --- modules/ticket/back/methods/ticket/restore.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/ticket/back/methods/ticket/restore.js b/modules/ticket/back/methods/ticket/restore.js index 754c2e562..0d2452df9 100644 --- a/modules/ticket/back/methods/ticket/restore.js +++ b/modules/ticket/back/methods/ticket/restore.js @@ -38,6 +38,15 @@ module.exports = Self => { order: 'creationDate DESC' }, myOptions); + const ticketOG = await models.Ticket.findById(id, { + include: [{ + relation: 'client', + scope: { + fields: ['id', 'salesPersonFk'] + } + }] + }, myOptions); + console.log('id', id); console.log('ticket', ticket); const now = Date.vnNew(); @@ -48,7 +57,7 @@ module.exports = Self => { throw new UserError(`You can only restore a ticket within the first hour after deletion`); // Send notification to salesPerson - const salesPersonId = ticket.client().salesPersonFk; + const salesPersonId = ticketOG.client().salesPersonFk; if (salesPersonId) { const url = await Self.app.models.Url.getUrl(); const message = $t(`I have restored the ticket id`, { @@ -59,12 +68,12 @@ module.exports = Self => { } const fullYear = Date.vnNew().getFullYear(); - const newShipped = ticket.shipped; - const newLanded = ticket.landed; + const newShipped = ticketOG.shipped; + const newLanded = ticketOG.landed; newShipped.setFullYear(fullYear); newLanded.setFullYear(fullYear); - return ticket.updateAttributes({ + return ticketOG.updateAttributes({ shipped: newShipped, landed: newLanded, isDeleted: false