From 6590c6f1fa23af58262d92968a296f48a5239998 Mon Sep 17 00:00:00 2001 From: alexandre Date: Fri, 24 Feb 2023 08:55:04 +0100 Subject: [PATCH] refs #5036 transferSales also transfer sale's logs --- .../ticket/back/methods/ticket/transferSales.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/ticket/back/methods/ticket/transferSales.js b/modules/ticket/back/methods/ticket/transferSales.js index 1b8476184..51fa97e51 100644 --- a/modules/ticket/back/methods/ticket/transferSales.js +++ b/modules/ticket/back/methods/ticket/transferSales.js @@ -142,6 +142,13 @@ module.exports = Self => { ticket: ticketId } }, myOptions); + + query = `UPDATE ticketLog + SET originFk = ? + WHERE changedModel = 'Sale' + AND originFk = ? + AND changedModelId = ?`; + await Self.rawSql(query, [ticketId, id, sale.id], myOptions); } const isTicketEmpty = await models.Ticket.isEmpty(id, myOptions); @@ -178,16 +185,16 @@ module.exports = Self => { // Update original sale const rest = originalSale.quantity - sale.quantity; - query = `UPDATE sale + query = `UPDATE sale SET quantity = ? WHERE id = ?`; await Self.rawSql(query, [rest, sale.id], options); // Clone sale with new quantity - query = `INSERT INTO sale (itemFk, ticketFk, concept, quantity, originalQuantity, price, discount, priceFixed, + query = `INSERT INTO sale (itemFk, ticketFk, concept, quantity, originalQuantity, price, discount, priceFixed, reserved, isPicked, isPriceFixed, isAdded) - SELECT itemFk, ?, concept, ?, originalQuantity, price, discount, priceFixed, - reserved, isPicked, isPriceFixed, isAdded + SELECT itemFk, ?, concept, ?, originalQuantity, price, discount, priceFixed, + reserved, isPicked, isPriceFixed, isAdded FROM sale WHERE id = ?`; await Self.rawSql(query, [ticketId, sale.quantity, sale.id], options);