feat: refs #6822 modify transaction

This commit is contained in:
Robert Ferrús 2025-01-07 12:02:32 +01:00
parent 1b90317b67
commit c4c9b5640e
4 changed files with 13 additions and 14 deletions

View File

@ -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$$

View File

@ -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());

View File

@ -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();

View File

@ -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;