fix: refs #7404 add transaction on detail calculate
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Pablo Natek 2024-09-23 10:02:01 +02:00
parent fb1e77f9c4
commit 459f6601b7
1 changed files with 16 additions and 7 deletions

View File

@ -26,12 +26,20 @@ module.exports = Self => {
Self.getStockBoughtDetail = async(workerFk, dated) => {
const models = Self.app.models;
await models.StockBought.rawSql(`CALL vn.item_calculateStock(?)`, [dated]);
const tx = await models.Collection.beginTransaction({});
const options = {transaction: tx};
const myOptions = {};
let tx;
let result;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
await models.StockBought.rawSql(`CALL vn.item_calculateStock(?)`, [dated], options);
await models.StockBought.rawSql(`CALL vn.item_calculateStock(?)`, [dated], myOptions);
result = await Self.rawSql(
`SELECT b.entryFk entryFk,
i.id itemFk,
@ -53,13 +61,14 @@ module.exports = Self => {
JOIN volumeConfig vc
WHERE ic.display
AND w.id = ?`,
[workerFk], options
[workerFk], myOptions
);
await Self.rawSql(`DROP TEMPORARY TABLE tmp.item, tmp.buyUltimate;`, [], options);
await Self.rawSql(`DROP TEMPORARY TABLE tmp.item, tmp.buyUltimate;`, [], myOptions);
if (tx) await tx.commit();
return result;
} catch (e) {
await tx.rollback();
throw e;
}
return result;
};
};