hotfix: ledger_next transacciones refs #7523
gitea/salix/pipeline/pr-master This commit looks good
Details
gitea/salix/pipeline/pr-master This commit looks good
Details
This commit is contained in:
parent
9a7074d600
commit
1927fbce45
|
@ -98,8 +98,8 @@ async function test() {
|
|||
const SpecReporter = require('jasmine-spec-reporter').SpecReporter;
|
||||
runner.addReporter(new SpecReporter({
|
||||
spec: {
|
||||
displaySuccessful: opts.ci,
|
||||
displayPending: opts.ci
|
||||
displaySuccessful: true,
|
||||
displayPending: true
|
||||
},
|
||||
summary: {
|
||||
displayPending: false,
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
},
|
||||
"vn": {
|
||||
"view": {
|
||||
"expeditionPallet_Print": "06613719475fcdba8309607c38cc78efc2e348cca7bc96b48dc3ae3c12426f54"
|
||||
"expeditionPallet_Print": "ced2b84a114fcb99fce05f0c34f4fc03f3fa387bef92621be1bc306608a84345"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ BEGIN
|
|||
*
|
||||
* @param isTx es true si existe transacción asociada
|
||||
*/
|
||||
IF isTx THEN
|
||||
IF NOT isTx THEN
|
||||
COMMIT;
|
||||
END IF;
|
||||
END$$
|
||||
|
|
|
@ -6,8 +6,9 @@ BEGIN
|
|||
*
|
||||
* @param isTx es true si existe transacción asociada
|
||||
*/
|
||||
IF isTx THEN
|
||||
IF NOT isTx THEN
|
||||
ROLLBACK;
|
||||
RESIGNAL;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -6,7 +6,7 @@ BEGIN
|
|||
*
|
||||
* @param isTx es true si existe transacción asociada
|
||||
*/
|
||||
IF isTx THEN
|
||||
IF NOT isTx THEN
|
||||
START TRANSACTION;
|
||||
END IF;
|
||||
END$$
|
||||
|
|
|
@ -12,24 +12,19 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_nextTx`(
|
|||
* @return vLastBookEntry Id del asiento
|
||||
*/
|
||||
BEGIN
|
||||
DECLARE vhasTx BOOL DEFAULT @@in_transaction;
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
ROLLBACK;
|
||||
CALL util.tx_rollback(vhasTx);
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
IF vFiscalYear IS NULL THEN
|
||||
CALL util.throw('Fiscal year is required');
|
||||
END IF;
|
||||
|
||||
IF @@in_transaction THEN
|
||||
CALL util.throw('This procedure should not be executed within a transaction');
|
||||
END IF;
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
CALL util.tx_start(vhasTx);
|
||||
CALL ledger_next(vFiscalYear, vLastBookEntry);
|
||||
|
||||
COMMIT;
|
||||
CALL util.tx_commit(vhasTx);
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -26,18 +26,17 @@ module.exports = Self => {
|
|||
|
||||
Self.cloneWithEntries = async(ctx, id, options) => {
|
||||
const conn = Self.dataSource.connector;
|
||||
let tx;
|
||||
const myOptions = {};
|
||||
let tx = options?.transaction;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
try {
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
const travel = await Self.findById(id, {
|
||||
fields: [
|
||||
'id',
|
||||
|
@ -89,6 +88,8 @@ module.exports = Self => {
|
|||
'ref'
|
||||
]
|
||||
}, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
return newTravel.id;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
|
|
|
@ -7,19 +7,22 @@ describe('Travel cloneWithEntries()', () => {
|
|||
const ctx = {req: {accessToken: {userId: currentUserId}}};
|
||||
let newTravelId;
|
||||
it(`should clone the travel and the containing entries`, async() => {
|
||||
const tx = await models.Travel.beginTransaction({
|
||||
});
|
||||
const tx = await models.Travel.beginTransaction({});
|
||||
const warehouseThree = 3;
|
||||
const agencyModeOne = 1;
|
||||
let travelRemoved;
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
newTravelId = await models.Travel.cloneWithEntries(ctx, travelId, options);
|
||||
const travelEntries = await models.Entry.find({
|
||||
where: {
|
||||
travelFk: newTravelId
|
||||
}
|
||||
}, options);
|
||||
const newTravel = await models.Travel.findById(travelId);
|
||||
const newTravel = await models.Travel.findById(travelId, null, options);
|
||||
travelRemoved = await models.Travel.findById(newTravelId);
|
||||
|
||||
expect(newTravelId).not.toEqual(travelId);
|
||||
expect(newTravel.ref).toEqual('fifth travel');
|
||||
|
@ -27,14 +30,9 @@ describe('Travel cloneWithEntries()', () => {
|
|||
expect(newTravel.warehouseOutFk).toEqual(warehouseThree);
|
||||
expect(newTravel.agencyModeFk).toEqual(agencyModeOne);
|
||||
expect(travelEntries.length).toBeGreaterThan(0);
|
||||
await models.Entry.destroyAll({
|
||||
travelFk: newTravelId
|
||||
}, options);
|
||||
await models.Travel.destroyById(newTravelId, options);
|
||||
await tx.rollback();
|
||||
const travelRemoved = await models.Travel.findById(newTravelId, options);
|
||||
|
||||
expect(travelRemoved).toBeNull();
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
|
|
Loading…
Reference in New Issue