diff --git a/db/routines/vn/procedures/entry_clone.sql b/db/routines/vn/procedures/entry_clone.sql index c7cbf1f7b2..511ff4837f 100644 --- a/db/routines/vn/procedures/entry_clone.sql +++ b/db/routines/vn/procedures/entry_clone.sql @@ -12,18 +12,19 @@ BEGIN */ DECLARE vNewEntryFk INT; + DECLARE vIsRequiredTx BOOL DEFAULT NOT @@in_transaction; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - ROLLBACK; + CALL util.tx_rollback(vIsRequiredTx); RESIGNAL; END; - START TRANSACTION; + CALL util.tx_start(vIsRequiredTx); CALL entry_cloneHeader(vSelf, vNewEntryFk, NULL); CALL entry_copyBuys(vSelf, vNewEntryFk); - COMMIT; + CALL util.tx_commit(vIsRequiredTx); SET vOutputEntryFk = vNewEntryFk; END$$ diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql index 63f3f14ab9..1234700387 100644 --- a/db/routines/vn/procedures/entry_transfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -19,16 +19,18 @@ BEGIN DECLARE vAgencyModeFk INT; DECLARE vTomorrow DATETIME DEFAULT util.tomorrow(); + DECLARE vIsRequiredTx BOOL DEFAULT NOT @@in_transaction; DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - ROLLBACK; + CALL util.tx_rollback(vIsRequiredTx); RESIGNAL; END; -- Clonar la entrada CALL entry_clone(vOriginalEntry, vNewEntryFk); - START TRANSACTION; + CALL util.tx_start(vIsRequiredTx); + -- Hay que crear un nuevo travel, con salida hoy y llegada maƱana y asignar la entrada nueva al nuevo travel. SELECT t.warehouseInFk, t.warehouseOutFk, t.`ref`, t.isReceived, t.agencyModeFk @@ -146,7 +148,7 @@ BEGIN -- Limpia la nueva entrada DELETE FROM buy WHERE entryFk = vNewEntryFk AND quantity = 0; - COMMIT; + CALL util.tx_commit(vIsRequiredTx); CALL cache.visible_refresh(@c,TRUE,vWarehouseFk); CALL cache.available_refresh(@c, TRUE, vWarehouseFk, util.VN_CURDATE()); diff --git a/modules/entry/back/methods/entry/specs/transfer.spec.js b/modules/entry/back/methods/entry/specs/transfer.spec.js index 0ab35e4a31..74e89df460 100644 --- a/modules/entry/back/methods/entry/specs/transfer.spec.js +++ b/modules/entry/back/methods/entry/specs/transfer.spec.js @@ -17,13 +17,12 @@ describe('Transfer merchandise from one entry to the next day()', () => { const currentItemShelving = await models.ItemShelving.findOne({where: {id}}, options); await currentItemShelving.updateAttributes({itemFk: item, buyFk: buy}, options); - const result = await models.Entry.transfer(ctx, originalEntry, options); - + const [{newEntryFk}] = await models.Entry.transfer(ctx, originalEntry, options); const originalEntrybuys = await models.Buy.find({where: {entryFk: originalEntry}}, options); - const newEntrybuys = await models.Buy.find({where: {entryFk: result[0].newEntryFk}}, options); + const newEntrybuys = await models.Buy.find({where: {entryFk: newEntryFk}}, options); - const newTravel = await models.Entry.find({where: {id: result[0].newEntryFk}}, options); + await models.Entry.find({where: {id: newEntryFk}}, options); const itemShelvingsWithBuys = await models.Buy.find({ include: { @@ -39,9 +38,6 @@ describe('Transfer merchandise from one entry to the next day()', () => { expect(newEntrybuys.length).toEqual(originalEntrybuys.length - hasItemShelving.length); - await models.Travel.destroyById(newTravel, options); - await models.Entry.destroyById(result[0].newEntryFk, options); - await tx.rollback(); } catch (e) { await tx.rollback(); diff --git a/modules/entry/back/methods/entry/transfer.js b/modules/entry/back/methods/entry/transfer.js index 1c5f38c215..aa4b4c8192 100644 --- a/modules/entry/back/methods/entry/transfer.js +++ b/modules/entry/back/methods/entry/transfer.js @@ -33,7 +33,7 @@ module.exports = Self => { try { await Self.rawSql('CALL vn.entry_transfer(?, @vNewEntry)', [id], myOptions); - const newEntryFk = await Self.rawSql('SELECT @vNewEntry newEntryFk', [], myOptions); + const newEntryFk = await Self.rawSql('SELECT @vNewEntry newEntryFk', null, myOptions); if (tx) await tx.commit(); return newEntryFk;