refs #6755 fix restore

This commit is contained in:
Carlos Satorres 2024-03-06 14:52:49 +01:00
parent a14ab90d5a
commit 2e4a5029b8
1 changed files with 13 additions and 4 deletions

View File

@ -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