#2687 - Travel CloneWithEntries #1887

Merged
jsegarra merged 20 commits from 2687_travel_cloneWithEntries into dev 2024-01-24 10:55:20 +00:00
3 changed files with 8 additions and 26 deletions
Showing only changes of commit b5b58faee4 - Show all commits

View File

@ -10,8 +10,7 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_cloneWithEntries`(
IN vWarehouseInFk INT, IN vWarehouseInFk INT,
IN vRef VARCHAR(255), IN vRef VARCHAR(255),
IN vAgencyModeFk INT, IN vAgencyModeFk INT,
OUT vNewTravelFk INT, OUT vNewTravelFk INT)
OUT vXTx BOOLEAN )
BEGIN BEGIN
/** /**
* Clona un travel junto con sus entradas y compras * Clona un travel junto con sus entradas y compras
@ -43,8 +42,7 @@ BEGIN
RESIGNAL; RESIGNAL;
END; END;
-- START TRANSACTION; CALL util.tx_start(vTx);
CALL util.tx_start(vTx);
INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk, agencyModeFk, `ref`, isDelivered, isReceived, m3, cargoSupplierFk, kg,clonedFrom) INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk, agencyModeFk, `ref`, isDelivered, isReceived, m3, cargoSupplierFk, kg,clonedFrom)
SELECT vDateStart, vDateEnd, vWarehouseInFk, vWarehouseOutFk, vAgencyModeFk, vRef, isDelivered, isReceived, m3,cargoSupplierFk, kg,vTravelFk SELECT vDateStart, vDateEnd, vWarehouseInFk, vWarehouseOutFk, vAgencyModeFk, vRef, isDelivered, isReceived, m3,cargoSupplierFk, kg,vTravelFk
@ -66,13 +64,8 @@ BEGIN
LEAVE l; LEAVE l;
END IF; END IF;
-- CALL util.tx_start(vTx); CALL entry_cloneHeader(vAuxEntryFk, vNewEntryFk, vNewTravelFk);
CALL entry_cloneHeader(vAuxEntryFk, vNewEntryFk, vNewTravelFk); CALL entry_copyBuys(vAuxEntryFk, vNewEntryFk);
-- CALL util.tx_commit(vTx);
-- CALL util.tx_start(vTx);
CALL entry_copyBuys(vAuxEntryFk, vNewEntryFk);
-- CALL util.tx_commit(vTx);
SELECT evaNotes INTO vEvaNotes SELECT evaNotes INTO vEvaNotes
FROM entry FROM entry
@ -87,8 +80,6 @@ BEGIN
SET @isModeInventory = FALSE; SET @isModeInventory = FALSE;
CLOSE vRsEntry; CLOSE vRsEntry;
-- COMMIT;
SET vXTx = vTx;
CALL util.tx_commit(vTx); CALL util.tx_commit(vTx);
END$$ END$$
DELIMITER ; DELIMITER ;

View File

@ -28,6 +28,7 @@ module.exports = Self => {
const conn = Self.dataSource.connector; const conn = Self.dataSource.connector;
const myOptions = {}; const myOptions = {};
let tx = options?.transaction; let tx = options?.transaction;
try { try {
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
@ -36,8 +37,7 @@ module.exports = Self => {
tx = await Self.beginTransaction({}); tx = await Self.beginTransaction({});
myOptions.transaction = tx; myOptions.transaction = tx;
} }
if (myOptions.transaction !== tx)
throw new Error('transaction ID not match');
const travel = await Self.findById(id, { const travel = await Self.findById(id, {
fields: [ fields: [
'id', 'id',
@ -58,7 +58,7 @@ module.exports = Self => {
let stmts = []; let stmts = [];
let stmt; let stmt;
stmt = new ParameterizedSQL( stmt = new ParameterizedSQL(
`CALL travel_cloneWithEntries(?, ?, ?, ?, ?, ?, ?, @vTravelFk, @vNewTx)`, [ `CALL travel_cloneWithEntries(?, ?, ?, ?, ?, ?, ?, @vTravelFk)`, [
id, id,
started, started,
ended, ended,
@ -73,8 +73,6 @@ module.exports = Self => {
const sql = ParameterizedSQL.join(stmts, ';'); const sql = ParameterizedSQL.join(stmts, ';');
const result = await conn.executeStmt(sql, myOptions); const result = await conn.executeStmt(sql, myOptions);
// if (tx) await tx.commit();
const [lastInsert] = result[newTravelIndex]; const [lastInsert] = result[newTravelIndex];
if (!lastInsert.id) if (!lastInsert.id)

View File

@ -22,23 +22,16 @@ fdescribe('Travel cloneWithEntries()', () => {
const newTravel = await models.Travel.findById(travelId); const newTravel = await models.Travel.findById(travelId);
expect(newTravelId).not.toEqual(travelId); expect(newTravelId).not.toEqual(travelId);
expect(newTravel.ref).toEqual('fifth travel'); expect(newTravel.ref).toEqual('fifth travel');
expect(newTravel.warehouseInFk).toEqual(warehouseThree); expect(newTravel.warehouseInFk).toEqual(warehouseThree);
expect(newTravel.warehouseOutFk).toEqual(warehouseThree); expect(newTravel.warehouseOutFk).toEqual(warehouseThree);
expect(newTravel.agencyModeFk).toEqual(agencyModeOne); expect(newTravel.agencyModeFk).toEqual(agencyModeOne);
expect(travelEntries.length).toBeGreaterThan(0); expect(travelEntries.length).toBeGreaterThan(0);
await tx.rollback(); await tx.rollback();
const travelRemoved = await models.Travel.findById(newTravelId, options); const travelRemoved = await models.Travel.findById(newTravelId, options);
expect(travelRemoved).toBeNull(); expect(travelRemoved).toBeNull();
// await models.Entry.destroyAll({
// travelFk: newTravelId
// }, options);
// await models.Travel.destroyById(newTravelId, options);
} catch (e) { } catch (e) {
if (tx) await tx.rollback(); if (tx) await tx.rollback();
throw e; throw e;