Merge pull request 'master' (!2538) from master into test
Reviewed-on: #2538
This commit is contained in:
commit
f903d7cd2a
|
@ -103,7 +103,7 @@ pipeline {
|
|||
NODE_ENV = ''
|
||||
}
|
||||
steps {
|
||||
sh 'node back/tests.js --ci --junit --network jenkins'
|
||||
sh 'node back/tests.js --junit'
|
||||
}
|
||||
post {
|
||||
always {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_commit`(isTx BOOL)
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_commit`(vIsTx BOOL)
|
||||
BEGIN
|
||||
/**
|
||||
* Confirma los cambios asociados a una transacción.
|
||||
*
|
||||
* @param isTx es true si existe transacción asociada
|
||||
* @param vIsTx es true si existe transacción asociada
|
||||
*/
|
||||
IF isTx THEN
|
||||
IF vIsTx THEN
|
||||
COMMIT;
|
||||
END IF;
|
||||
END$$
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_rollback`(isTx BOOL)
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_rollback`(vIsTx BOOL)
|
||||
BEGIN
|
||||
/**
|
||||
* Deshace los cambios asociados a una transacción.
|
||||
*
|
||||
* @param isTx es true si existe transacción asociada
|
||||
* @param vIsTx es true si existe transacción asociada
|
||||
*/
|
||||
IF isTx THEN
|
||||
IF vIsTx THEN
|
||||
ROLLBACK;
|
||||
END IF;
|
||||
END$$
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_start`(isTx BOOL)
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`tx_start`(vIsTx BOOL)
|
||||
BEGIN
|
||||
/**
|
||||
* Inicia una transacción.
|
||||
*
|
||||
* @param isTx es true si existe transacción asociada
|
||||
* @param vIsTx es true si existe transacción asociada
|
||||
*/
|
||||
IF isTx THEN
|
||||
IF vIsTx THEN
|
||||
START TRANSACTION;
|
||||
END IF;
|
||||
END$$
|
||||
|
|
|
@ -44,7 +44,7 @@ BEGIN
|
|||
JOIN dua d ON d.id = de.duaFk
|
||||
WHERE d.id = vDuaFk
|
||||
LIMIT 1;
|
||||
CALL ledger_next(vFiscalYear, FALSE, vBookEntry);
|
||||
CALL ledger_nextTx(vFiscalYear, vBookEntry);
|
||||
END IF;
|
||||
|
||||
OPEN vInvoicesIn;
|
||||
|
|
|
@ -12,7 +12,7 @@ BEGIN
|
|||
WHERE id = vDuaFk;
|
||||
|
||||
IF vBookNumber IS NULL OR NOT vBookNumber THEN
|
||||
CALL ledger_next(YEAR(vBookDated), FALSE, vBookNumber);
|
||||
CALL ledger_nextTx(YEAR(vBookDated), vBookNumber);
|
||||
END IF;
|
||||
|
||||
-- Apunte de la aduana
|
||||
|
|
|
@ -70,7 +70,7 @@ BEGIN
|
|||
SELECT YEAR(bookEntried) INTO vFiscalYear FROM tInvoiceIn LIMIT 1;
|
||||
|
||||
IF vBookNumber IS NULL THEN
|
||||
CALL ledger_next(vFiscalYear, FALSE, vBookNumber);
|
||||
CALL ledger_nextTx(vFiscalYear, vBookNumber);
|
||||
END IF;
|
||||
|
||||
-- Apunte del proveedor
|
||||
|
|
|
@ -61,7 +61,7 @@ BEGIN
|
|||
WHERE io.id = vInvoice;
|
||||
|
||||
SELECT YEAR(FECHA) INTO vFiscalYear FROM rs LIMIT 1;
|
||||
CALL ledger_next(vFiscalYear, FALSE, vBookNumber);
|
||||
CALL ledger_nextTx(vFiscalYear, vBookNumber);
|
||||
-- Linea del cliente
|
||||
INSERT INTO XDiario(
|
||||
ASIEN,
|
||||
|
|
|
@ -28,7 +28,7 @@ BEGIN
|
|||
DECLARE vIsOriginalAClient BOOL;
|
||||
DECLARE vPayMethodCompensation INT;
|
||||
|
||||
CALL ledger_next(YEAR(vDated), FALSE, vNewBookEntry);
|
||||
CALL ledger_nextTx(YEAR(vDated), vNewBookEntry);
|
||||
|
||||
SELECT COUNT(id) INTO vIsOriginalAClient
|
||||
FROM client
|
||||
|
|
|
@ -1,38 +1,21 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_next`(
|
||||
IN vFiscalYear INT,
|
||||
IN vIsManageTransaction BOOLEAN,
|
||||
OUT vLastBookEntry INT
|
||||
)
|
||||
/**
|
||||
* Devuelve un número de asiento válido, según el contador de asientos
|
||||
* tabla vn.ledgerConfig, si no existe lo inicializa a 1
|
||||
* No inicia transacción, para transaccionar usar vn.ledger_nextTx
|
||||
*
|
||||
* @param vFiscalYear Id del año contable
|
||||
* @return vLastBookEntry Id del asiento
|
||||
*/
|
||||
BEGIN
|
||||
DECLARE vHasStartTransaction BOOLEAN;
|
||||
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
|
||||
IF vHasStartTransaction THEN
|
||||
ROLLBACK TO sp;
|
||||
RESIGNAL;
|
||||
ELSE
|
||||
ROLLBACK;
|
||||
CALL util.throw ('It has not been possible to generate a new ledger');
|
||||
END IF;
|
||||
END;
|
||||
|
||||
IF vFiscalYear IS NULL THEN
|
||||
CALL util.throw('Fiscal year is required');
|
||||
END IF;
|
||||
|
||||
IF NOT vIsManageTransaction THEN
|
||||
SELECT @@in_transaction INTO vHasStartTransaction;
|
||||
|
||||
IF NOT vHasStartTransaction THEN
|
||||
START TRANSACTION;
|
||||
ELSE
|
||||
SAVEPOINT sp;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
SELECT bookEntry + 1 INTO vLastBookEntry
|
||||
FROM ledgerCompany
|
||||
WHERE fiscalYear = vFiscalYear
|
||||
|
@ -48,13 +31,5 @@ BEGIN
|
|||
UPDATE ledgerCompany
|
||||
SET bookEntry = vLastBookEntry
|
||||
WHERE fiscalYear = vFiscalYear;
|
||||
|
||||
IF NOT vIsManageTransaction THEN
|
||||
IF vHasStartTransaction THEN
|
||||
RELEASE SAVEPOINT sp;
|
||||
ELSE
|
||||
COMMIT;
|
||||
END IF;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,30 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_nextTx`(
|
||||
IN vFiscalYear INT,
|
||||
OUT vLastBookEntry INT
|
||||
)
|
||||
/**
|
||||
* Devuelve un número de asiento válido, según el contador de asientos
|
||||
* tabla vn.ledgerConfig, si no existe lo inicializa a 1
|
||||
* Lo hace transaccionando el proceso
|
||||
*
|
||||
* @param vFiscalYear Id del año contable
|
||||
* @return vLastBookEntry Id del asiento
|
||||
*/
|
||||
BEGIN
|
||||
DECLARE vIsRequiredTx BOOL DEFAULT NOT @@in_transaction;
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
CALL util.tx_rollback(vIsRequiredTx);
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
IF vFiscalYear IS NULL THEN
|
||||
CALL util.throw('Fiscal year is required');
|
||||
END IF;
|
||||
|
||||
CALL util.tx_start(vIsRequiredTx);
|
||||
CALL ledger_next(vFiscalYear, vLastBookEntry);
|
||||
CALL util.tx_commit(vIsRequiredTx);
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -24,8 +24,8 @@ BEGIN
|
|||
DECLARE vEvaNotes VARCHAR(255);
|
||||
DECLARE vDone BOOL;
|
||||
DECLARE vAuxEntryFk INT;
|
||||
DECLARE vTx BOOLEAN DEFAULT @@in_transaction;
|
||||
DECLARE vRsEntry CURSOR FOR
|
||||
DECLARE vIsRequiredTx BOOLEAN DEFAULT NOT @@in_transaction;
|
||||
DECLARE vRsEntry CURSOR FOR
|
||||
SELECT e.id
|
||||
FROM entry e
|
||||
JOIN travel t ON t.id = e.travelFk
|
||||
|
@ -35,11 +35,11 @@ BEGIN
|
|||
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
CALL util.tx_rollback(vTx);
|
||||
CALL util.tx_rollback(vIsRequiredTx);
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
CALL util.tx_start(vTx);
|
||||
CALL util.tx_start(vIsRequiredTx);
|
||||
|
||||
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
|
||||
|
@ -76,6 +76,6 @@ BEGIN
|
|||
SET @isModeInventory = FALSE;
|
||||
CLOSE vRsEntry;
|
||||
|
||||
CALL util.tx_commit(vTx);
|
||||
CALL util.tx_commit(vIsRequiredTx);
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -39,7 +39,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`xdiario_new`(
|
|||
*/
|
||||
BEGIN
|
||||
IF vBookNumber IS NULL THEN
|
||||
CALL ledger_next(YEAR(vDated), FALSE, vBookNumber);
|
||||
CALL ledger_nextTx(YEAR(vDated), vBookNumber);
|
||||
END IF;
|
||||
|
||||
INSERT INTO XDiario
|
||||
|
|
|
@ -23,7 +23,7 @@ BEGIN
|
|||
FROM supplier
|
||||
WHERE id = NEW.supplierFk;
|
||||
|
||||
CALL ledger_next(YEAR(NEW.received), TRUE, vNewBookEntry);
|
||||
CALL ledger_next(YEAR(NEW.received), vNewBookEntry);
|
||||
|
||||
INSERT INTO XDiario (
|
||||
ASIEN,
|
||||
|
|
|
@ -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