Merge branch 'dev' into 3368-export_database
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
cdbd1964a6
|
@ -85,9 +85,10 @@ module.exports = Self => {
|
|||
};
|
||||
|
||||
if (sale.quantity == originalSale.quantity) {
|
||||
await models.Sale.updateAll({
|
||||
id: sale.id
|
||||
}, {ticketFk: ticketId}, myOptions);
|
||||
query = `UPDATE sale
|
||||
SET ticketFk = ?
|
||||
WHERE id = ?`;
|
||||
await Self.rawSql(query, [ticketId, sale.id], myOptions);
|
||||
} else if (sale.quantity != originalSale.quantity) {
|
||||
await transferPartialSale(
|
||||
ticketId, originalSale, sale, myOptions);
|
||||
|
@ -170,29 +171,31 @@ module.exports = Self => {
|
|||
|
||||
// Update original sale
|
||||
const rest = originalSale.quantity - sale.quantity;
|
||||
const originalInstance = await models.Sale.findById(sale.id, null, options);
|
||||
await originalInstance.updateAttribute('quantity', rest, options);
|
||||
query = `UPDATE sale
|
||||
SET quantity = ?
|
||||
WHERE id = ?`;
|
||||
await Self.rawSql(query, [rest, sale.id], options);
|
||||
|
||||
// Clone sale with new quantity
|
||||
const newSale = originalSale;
|
||||
newSale.id = undefined;
|
||||
newSale.ticketFk = ticketId;
|
||||
newSale.quantity = sale.quantity;
|
||||
|
||||
const createdSale = await models.Sale.create(newSale, options);
|
||||
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
|
||||
FROM sale
|
||||
WHERE id = ?`;
|
||||
await Self.rawSql(query, [ticketId, sale.quantity, sale.id], options);
|
||||
const [lastInsertedSale] = await Self.rawSql('SELECT LAST_INSERT_ID() AS id', null, options);
|
||||
|
||||
// Clone sale components
|
||||
const saleComponents = await models.SaleComponent.find({
|
||||
where: {saleFk: sale.id}
|
||||
}, options);
|
||||
const newComponents = saleComponents.map(component => {
|
||||
component.saleFk = createdSale.id;
|
||||
component.saleFk = lastInsertedSale.id;
|
||||
|
||||
return component;
|
||||
});
|
||||
|
||||
await models.SaleComponent.create(newComponents, options);
|
||||
|
||||
return originalInstance;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue