8179-testToMaster #3176
|
@ -26,12 +26,20 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.getStockBoughtDetail = async(workerFk, dated) => {
|
Self.getStockBoughtDetail = async(workerFk, dated) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
await models.StockBought.rawSql(`CALL vn.item_calculateStock(?)`, [dated]);
|
const myOptions = {};
|
||||||
const tx = await models.Collection.beginTransaction({});
|
let tx;
|
||||||
const options = {transaction: tx};
|
|
||||||
let result;
|
let result;
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
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(
|
result = await Self.rawSql(
|
||||||
`SELECT b.entryFk entryFk,
|
`SELECT b.entryFk entryFk,
|
||||||
i.id itemFk,
|
i.id itemFk,
|
||||||
|
@ -53,13 +61,14 @@ module.exports = Self => {
|
||||||
JOIN volumeConfig vc
|
JOIN volumeConfig vc
|
||||||
WHERE ic.display
|
WHERE ic.display
|
||||||
AND w.id = ?`,
|
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) {
|
} catch (e) {
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue