Merge branch 'master' of https: refs #6404//gitea.verdnatura.es/verdnatura/salix into 6404-sendMailOnDeadLine
gitea/salix/pipeline/pr-master There was a failure building this commit
Details
gitea/salix/pipeline/pr-master There was a failure building this commit
Details
This commit is contained in:
commit
65fae086aa
|
@ -1,7 +1,7 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`midnight`()
|
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `util`.`midnight`()
|
||||||
RETURNS datetime
|
RETURNS datetime
|
||||||
NOT DETERMINISTIC
|
DETERMINISTIC
|
||||||
READS SQL DATA
|
READS SQL DATA
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ BEGIN
|
||||||
DECLARE vIsTooLittle TINYINT(1);
|
DECLARE vIsTooLittle TINYINT(1);
|
||||||
|
|
||||||
SELECT (SUM(IFNULL(sv.litros, 0)) < vc.minTicketVolume
|
SELECT (SUM(IFNULL(sv.litros, 0)) < vc.minTicketVolume
|
||||||
OR IFNULL(t.totalWithoutVat, 0) < vc.minTicketValue) INTO vIsTooLittle
|
AND IFNULL(t.totalWithoutVat, 0) < vc.minTicketValue) INTO vIsTooLittle
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
LEFT JOIN saleVolume sv ON sv.ticketFk = t.id
|
LEFT JOIN saleVolume sv ON sv.ticketFk = t.id
|
||||||
JOIN volumeConfig vc
|
JOIN volumeConfig vc
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
DELIMITER $$
|
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_checkBooked`(
|
|
||||||
vSelf INT
|
|
||||||
)
|
|
||||||
BEGIN
|
|
||||||
/**
|
|
||||||
* Comprueba si una entrada está contabilizada,
|
|
||||||
* y si lo está retorna un throw.
|
|
||||||
*
|
|
||||||
* @param vSelf Id de entrada
|
|
||||||
*/
|
|
||||||
DECLARE vIsBooked BOOL;
|
|
||||||
|
|
||||||
SELECT isBooked INTO vIsBooked
|
|
||||||
FROM `entry`
|
|
||||||
WHERE id = vSelf;
|
|
||||||
|
|
||||||
IF vIsBooked AND NOT IFNULL(@isModeInventory, FALSE) THEN
|
|
||||||
CALL util.throw('Entry is already booked');
|
|
||||||
END IF;
|
|
||||||
END$$
|
|
||||||
DELIMITER ;
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_isEditable`(
|
||||||
|
vSelf INT
|
||||||
|
)
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Comprueba si una entrada se puede actualizar
|
||||||
|
* si no se puede retorna un throw.
|
||||||
|
*
|
||||||
|
* @param vSelf Id de entrada
|
||||||
|
*/
|
||||||
|
DECLARE vIsEditable BOOL;
|
||||||
|
|
||||||
|
SELECT e.isBooked INTO vIsEditable
|
||||||
|
FROM `entry` e
|
||||||
|
JOIN entryType et ON et.code = e.typeFk
|
||||||
|
WHERE NOT et.isInformal
|
||||||
|
AND e.id = vSelf;
|
||||||
|
|
||||||
|
IF vIsEditable AND NOT IFNULL(@isModeInventory, FALSE) THEN
|
||||||
|
CALL util.throw('Entry is not editable');
|
||||||
|
END IF;
|
||||||
|
END$$
|
||||||
|
DELIMITER ;
|
|
@ -18,7 +18,7 @@ BEGIN
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
JOIN sale s ON s.ticketFk = t.id
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
||||||
WHERE t.shipped >= util.midnight()
|
WHERE t.shipped >= util.VN_CURDATE()
|
||||||
AND (vComponentFk IS NULL OR sc.componentFk = vComponentFk)
|
AND (vComponentFk IS NULL OR sc.componentFk = vComponentFk)
|
||||||
GROUP BY s.id) sub;
|
GROUP BY s.id) sub;
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ BEGIN
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT t.id ticketFk, FALSE hasProblem
|
SELECT t.id ticketFk, FALSE hasProblem
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
WHERE t.shipped >= util.midnight()
|
WHERE t.shipped >= util.VN_CURDATE()
|
||||||
AND (vClientFk IS NULL OR t.clientFk = vClientFk);
|
AND (vClientFk IS NULL OR t.clientFk = vClientFk);
|
||||||
|
|
||||||
UPDATE tmp.ticket t
|
UPDATE tmp.ticket t
|
||||||
|
|
|
@ -13,7 +13,7 @@ BEGIN
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT t.id ticketFk, FALSE hasProblem
|
SELECT t.id ticketFk, FALSE hasProblem
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
WHERE t.shipped >= util.midnight()
|
WHERE t.shipped >= util.VN_CURDATE()
|
||||||
AND (vSelf IS NULL OR t.id = vSelf);
|
AND (vSelf IS NULL OR t.id = vSelf);
|
||||||
|
|
||||||
UPDATE tmp.ticket t
|
UPDATE tmp.ticket t
|
||||||
|
|
|
@ -14,7 +14,7 @@ BEGIN
|
||||||
SELECT t.id ticketFk, IF(c.isTaxDataChecked, FALSE, TRUE) hasProblem
|
SELECT t.id ticketFk, IF(c.isTaxDataChecked, FALSE, TRUE) hasProblem
|
||||||
FROM ticket t
|
FROM ticket t
|
||||||
JOIN client c ON c.id = t.clientFk
|
JOIN client c ON c.id = t.clientFk
|
||||||
WHERE t.shipped >= util.midnight()
|
WHERE t.shipped >= util.VN_CURDATE()
|
||||||
AND (c.id = vClientFk OR vClientFk IS NULL);
|
AND (c.id = vClientFk OR vClientFk IS NULL);
|
||||||
|
|
||||||
CALL ticket_setProblem('isTaxDataChecked');
|
CALL ticket_setProblem('isTaxDataChecked');
|
||||||
|
|
|
@ -16,7 +16,7 @@ BEGIN
|
||||||
SELECT t.id ticketFk
|
SELECT t.id ticketFk
|
||||||
FROM vn.ticket t
|
FROM vn.ticket t
|
||||||
LEFT JOIN vn.sale s ON s.ticketFk = t.id
|
LEFT JOIN vn.sale s ON s.ticketFk = t.id
|
||||||
WHERE t.shipped >= util.midnight()
|
WHERE t.shipped >= util.VN_CURDATE()
|
||||||
AND (s.itemFk = vItemFk OR vItemFk IS NULL)
|
AND (s.itemFk = vItemFk OR vItemFk IS NULL)
|
||||||
GROUP BY t.id
|
GROUP BY t.id
|
||||||
)SELECT ticketFk, ticket_isTooLittle(ticketFk) hasProblem
|
)SELECT ticketFk, ticket_isTooLittle(ticketFk) hasProblem
|
||||||
|
|
|
@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`buy_beforeDelete`
|
||||||
BEFORE DELETE ON `buy`
|
BEFORE DELETE ON `buy`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
CALL entry_checkBooked(OLD.entryFk);
|
CALL entry_isEditable(OLD.entryFk);
|
||||||
IF OLD.printedStickers <> 0 THEN
|
IF OLD.printedStickers <> 0 THEN
|
||||||
CALL util.throw("it is not possible to delete buys with printed labels ");
|
CALL util.throw("it is not possible to delete buys with printed labels ");
|
||||||
END IF;
|
END IF;
|
||||||
|
|
|
@ -15,7 +15,7 @@ trig: BEGIN
|
||||||
LEAVE trig;
|
LEAVE trig;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
CALL entry_checkBooked(NEW.entryFk);
|
CALL entry_isEditable(NEW.entryFk);
|
||||||
IF NEW.printedStickers <> 0 THEN
|
IF NEW.printedStickers <> 0 THEN
|
||||||
CALL util.throw('it is not possible to create buy lines with printedstickers other than 0');
|
CALL util.throw('it is not possible to create buy lines with printedstickers other than 0');
|
||||||
END IF;
|
END IF;
|
||||||
|
|
|
@ -13,7 +13,7 @@ trig:BEGIN
|
||||||
LEAVE trig;
|
LEAVE trig;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
CALL entry_checkBooked(OLD.entryFk);
|
CALL entry_isEditable(OLD.entryFk);
|
||||||
SET NEW.editorFk = account.myUser_getId();
|
SET NEW.editorFk = account.myUser_getId();
|
||||||
|
|
||||||
SELECT defaultEntry INTO vDefaultEntry
|
SELECT defaultEntry INTO vDefaultEntry
|
||||||
|
|
|
@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`entry_beforeDelete`
|
||||||
BEFORE DELETE ON `entry`
|
BEFORE DELETE ON `entry`
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
BEGIN
|
BEGIN
|
||||||
CALL entry_checkBooked(OLD.id);
|
CALL entry_isEditable(OLD.id);
|
||||||
DELETE FROM buy WHERE entryFk = OLD.id;
|
DELETE FROM buy WHERE entryFk = OLD.id;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -9,7 +9,7 @@ BEGIN
|
||||||
DECLARE vTotalBuy INT;
|
DECLARE vTotalBuy INT;
|
||||||
|
|
||||||
IF NEW.isBooked = OLD.isBooked THEN
|
IF NEW.isBooked = OLD.isBooked THEN
|
||||||
CALL entry_checkBooked(OLD.id);
|
CALL entry_isEditable(OLD.id);
|
||||||
ELSE
|
ELSE
|
||||||
IF NEW.isBooked THEN
|
IF NEW.isBooked THEN
|
||||||
SELECT COUNT(*) INTO vTotalBuy
|
SELECT COUNT(*) INTO vTotalBuy
|
||||||
|
|
|
@ -8,7 +8,9 @@ BEGIN
|
||||||
SET hasNewRoute = TRUE
|
SET hasNewRoute = TRUE
|
||||||
WHERE ticketFk = NEW.id;
|
WHERE ticketFk = NEW.id;
|
||||||
|
|
||||||
CALL ticket_doCmr(NEW.id);
|
IF NEW.cmrFk THEN
|
||||||
|
CALL ticket_doCmr(NEW.id);
|
||||||
|
END IF;
|
||||||
END IF;
|
END IF;
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
|
@ -20,7 +20,7 @@ FROM (
|
||||||
`vn`.`saleGroup` `sg`
|
`vn`.`saleGroup` `sg`
|
||||||
JOIN `vn`.`saleGroupDetail` `sgd` ON(`sgd`.`saleGroupFk` = `sg`.`id`)
|
JOIN `vn`.`saleGroupDetail` `sgd` ON(`sgd`.`saleGroupFk` = `sg`.`id`)
|
||||||
)
|
)
|
||||||
JOIN `vn`.`sale` `s` ON(`s`.`id` = `sgd`.`saleFk`)
|
JOIN `vn`.`sale` `s` FORCE INDEX (PRIMARY) ON(`s`.`id` = `sgd`.`saleFk`)
|
||||||
)
|
)
|
||||||
JOIN `vn`.`ticketState` `tls` ON(`tls`.`ticketFk` = `s`.`ticketFk`)
|
JOIN `vn`.`ticketState` `tls` ON(`tls`.`ticketFk` = `s`.`ticketFk`)
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
CREATE INDEX ticketLog_creationDate_IDX USING BTREE ON vn.ticketLog (creationDate,changedModel,`action`);
|
|
@ -227,5 +227,8 @@
|
||||||
"They're not your subordinate": "They're not your subordinate",
|
"They're not your subordinate": "They're not your subordinate",
|
||||||
"InvoiceIn is already booked": "InvoiceIn is already booked",
|
"InvoiceIn is already booked": "InvoiceIn is already booked",
|
||||||
"This workCenter is already assigned to this agency": "This workCenter is already assigned to this agency",
|
"This workCenter is already assigned to this agency": "This workCenter is already assigned to this agency",
|
||||||
"You can only have one PDA": "You can only have one PDA"
|
"You can only have one PDA": "You can only have one PDA",
|
||||||
}
|
"It has been invoiced but the PDF could not be generated": "It has been invoiced but the PDF could not be generated",
|
||||||
|
"It has been invoiced but the PDF of refund not be generated": "It has been invoiced but the PDF of refund not be generated"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -360,6 +360,6 @@
|
||||||
"ticketCommercial": "El ticket {{ ticket }} para el vendedor {{ salesMan }} está en preparación. (mensaje generado automáticamente)",
|
"ticketCommercial": "El ticket {{ ticket }} para el vendedor {{ salesMan }} está en preparación. (mensaje generado automáticamente)",
|
||||||
"This PDA is already assigned to another user": "Este PDA ya está asignado a otro usuario",
|
"This PDA is already assigned to another user": "Este PDA ya está asignado a otro usuario",
|
||||||
"You can only have one PDA": "Solo puedes tener un PDA",
|
"You can only have one PDA": "Solo puedes tener un PDA",
|
||||||
"1) Fecha de recogida incorrecta (fecha cerrada).": "1) Fecha de recogida incorrecta (fecha cerrada).",
|
"It has been invoiced but the PDF could not be generated": "Se ha facturado pero no se ha podido generar el PDF",
|
||||||
"This expedition is not a MRW shipment": "This expedition is not a MRW shipment"
|
"It has been invoiced but the PDF of refund not be generated": "Se ha facturado pero no se ha podido generar el PDF del abono"
|
||||||
}
|
}
|
||||||
|
|
|
@ -356,5 +356,7 @@
|
||||||
"InvoiceIn is already booked": "La facture reçue est déjà comptabilisée",
|
"InvoiceIn is already booked": "La facture reçue est déjà comptabilisée",
|
||||||
"This workCenter is already assigned to this agency": "Ce centre de travail est déjà assigné à cette agence",
|
"This workCenter is already assigned to this agency": "Ce centre de travail est déjà assigné à cette agence",
|
||||||
"Select ticket or client": "Choisissez un ticket ou un client",
|
"Select ticket or client": "Choisissez un ticket ou un client",
|
||||||
"It was not able to create the invoice": "Il n'a pas été possible de créer la facture"
|
"It was not able to create the invoice": "Il n'a pas été possible de créer la facture",
|
||||||
}
|
"It has been invoiced but the PDF could not be generated": "La facture a été émise mais le PDF n'a pas pu être généré",
|
||||||
|
"It has been invoiced but the PDF of refund not be generated": "Il a été facturé mais le PDF de remboursement n'a pas été généré"
|
||||||
|
}
|
||||||
|
|
|
@ -356,5 +356,7 @@
|
||||||
"InvoiceIn is already booked": "InvoiceIn já está reservado",
|
"InvoiceIn is already booked": "InvoiceIn já está reservado",
|
||||||
"This workCenter is already assigned to this agency": "Este centro de trabalho já está atribuído a esta agência",
|
"This workCenter is already assigned to this agency": "Este centro de trabalho já está atribuído a esta agência",
|
||||||
"Select ticket or client": "Selecione um ticket ou cliente",
|
"Select ticket or client": "Selecione um ticket ou cliente",
|
||||||
"It was not able to create the invoice": "Não foi possível criar a fatura"
|
"It was not able to create the invoice": "Não foi possível criar a fatura",
|
||||||
}
|
"It has been invoiced but the PDF could not be generated": "Foi faturado, mas o PDF não pôde ser gerado",
|
||||||
|
"It has been invoiced but the PDF of refund not be generated": "Foi faturado mas não foi gerado o PDF do reembolso"
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
const LoopBackContext = require('loopback-context');
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
|
@ -17,26 +16,27 @@ describe('InvoiceOut transferInvoice()', () => {
|
||||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
active: activeCtx
|
active: activeCtx
|
||||||
});
|
});
|
||||||
spyOn(models.InvoiceOut, 'makePdfAndNotify');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the id of the created issued invoice', async() => {
|
it('should return the id of the created issued invoice', async() => {
|
||||||
const tx = await models.InvoiceOut.beginTransaction({});
|
const tx = await models.InvoiceOut.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
const args = {
|
const id = 4;
|
||||||
id: '4',
|
const newClient = 1;
|
||||||
refFk: 'T4444444',
|
spyOn(models.InvoiceOut, 'makePdfList');
|
||||||
newClientFk: 1,
|
|
||||||
cplusRectificationTypeFk: 1,
|
|
||||||
siiTypeInvoiceOutFk: 1,
|
|
||||||
invoiceCorrectionTypeFk: 1
|
|
||||||
};
|
|
||||||
ctx.args = args;
|
|
||||||
try {
|
try {
|
||||||
const {clientFk: oldClient} = await models.InvoiceOut.findById(args.id, {fields: ['clientFk']});
|
const {clientFk: oldClient} = await models.InvoiceOut.findById(id, {fields: ['clientFk']});
|
||||||
const invoicesBefore = await models.InvoiceOut.find({}, options);
|
const invoicesBefore = await models.InvoiceOut.find({}, options);
|
||||||
const result = await models.InvoiceOut.transferInvoice(
|
const result = await models.InvoiceOut.transferInvoice(
|
||||||
ctx,
|
ctx,
|
||||||
|
id,
|
||||||
|
'T4444444',
|
||||||
|
newClient,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
true,
|
||||||
options);
|
options);
|
||||||
const invoicesAfter = await models.InvoiceOut.find({}, options);
|
const invoicesAfter = await models.InvoiceOut.find({}, options);
|
||||||
const rectificativeInvoice = invoicesAfter[invoicesAfter.length - 2];
|
const rectificativeInvoice = invoicesAfter[invoicesAfter.length - 2];
|
||||||
|
@ -45,7 +45,7 @@ describe('InvoiceOut transferInvoice()', () => {
|
||||||
expect(result).toBeDefined();
|
expect(result).toBeDefined();
|
||||||
expect(invoicesAfter.length - invoicesBefore.length).toEqual(2);
|
expect(invoicesAfter.length - invoicesBefore.length).toEqual(2);
|
||||||
expect(rectificativeInvoice.clientFk).toEqual(oldClient);
|
expect(rectificativeInvoice.clientFk).toEqual(oldClient);
|
||||||
expect(newInvoice.clientFk).toEqual(args.newClientFk);
|
expect(newInvoice.clientFk).toEqual(newClient);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -54,22 +54,13 @@ describe('InvoiceOut transferInvoice()', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an UserError when it is the same client', async() => {
|
it('should throw an error when it is the same client', async() => {
|
||||||
const tx = await models.InvoiceOut.beginTransaction({});
|
const tx = await models.InvoiceOut.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
const args = {
|
spyOn(models.InvoiceOut, 'makePdfList');
|
||||||
id: '1',
|
|
||||||
refFk: 'T1111111',
|
|
||||||
newClientFk: 1101,
|
|
||||||
cplusRectificationTypeFk: 1,
|
|
||||||
siiTypeInvoiceOutFk: 1,
|
|
||||||
invoiceCorrectionTypeFk: 1
|
|
||||||
};
|
|
||||||
ctx.args = args;
|
|
||||||
try {
|
try {
|
||||||
await models.InvoiceOut.transferInvoice(
|
await models.InvoiceOut.transferInvoice(ctx, '1', 'T1111111', 1101, 1, 1, 1, true, options);
|
||||||
ctx,
|
|
||||||
options);
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
expect(e.message).toBe(`Select a different client`);
|
expect(e.message).toBe(`Select a different client`);
|
||||||
|
@ -77,26 +68,49 @@ describe('InvoiceOut transferInvoice()', () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an UserError when it is refund', async() => {
|
it('should throw an error when it is refund', async() => {
|
||||||
const tx = await models.InvoiceOut.beginTransaction({});
|
const tx = await models.InvoiceOut.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
const args = {
|
spyOn(models.InvoiceOut, 'makePdfList');
|
||||||
id: '1',
|
|
||||||
refFk: 'T1111111',
|
|
||||||
newClientFk: 1102,
|
|
||||||
cplusRectificationTypeFk: 1,
|
|
||||||
siiTypeInvoiceOutFk: 1,
|
|
||||||
invoiceCorrectionTypeFk: 1
|
|
||||||
};
|
|
||||||
ctx.args = args;
|
|
||||||
try {
|
try {
|
||||||
await models.InvoiceOut.transferInvoice(
|
await models.InvoiceOut.transferInvoice(ctx, '1', 'T1111111', 1102, 1, 1, 1, true, options);
|
||||||
ctx,
|
|
||||||
options);
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
expect(e.message).toContain(`This ticket is already a refund`);
|
expect(e.message).toContain(`This ticket is already a refund`);
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should throw an error when pdf failed', async() => {
|
||||||
|
const tx = await models.InvoiceOut.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
spyOn(models.InvoiceOut, 'makePdfList').and.returnValue(() => {
|
||||||
|
throw new Error('test');
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await models.InvoiceOut.transferInvoice(ctx, '1', 'T1111111', 1102, 1, 1, 1, true, options);
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
expect(e.message).toContain(`It has been invoiced but the PDF could not be generated`);
|
||||||
|
await tx.rollback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not generate an invoice', async() => {
|
||||||
|
const tx = await models.InvoiceOut.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
spyOn(models.InvoiceOut, 'makePdfList');
|
||||||
|
|
||||||
|
let response;
|
||||||
|
try {
|
||||||
|
response = await models.InvoiceOut.transferInvoice(ctx, '1', 'T1111111', 1102, 1, 1, 1, false, options);
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(response).not.toBeDefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -37,13 +37,13 @@ module.exports = Self => {
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'checked',
|
arg: 'makeInvoice',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
type: 'boolean',
|
type: 'object',
|
||||||
root: true
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
|
@ -52,11 +52,22 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.transferInvoice = async(ctx, options) => {
|
Self.transferInvoice = async(
|
||||||
|
ctx,
|
||||||
|
id,
|
||||||
|
refFk,
|
||||||
|
newClientFk,
|
||||||
|
cplusRectificationTypeFk,
|
||||||
|
siiTypeInvoiceOutFk,
|
||||||
|
invoiceCorrectionTypeFk,
|
||||||
|
makeInvoice,
|
||||||
|
options
|
||||||
|
) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {userId: ctx.req.accessToken.userId};
|
const myOptions = {userId: ctx.req.accessToken.userId};
|
||||||
const {id, refFk, newClientFk, cplusRectificationTypeFk, siiTypeInvoiceOutFk, invoiceCorrectionTypeFk} = ctx.args;
|
let invoiceId;
|
||||||
const checked = ctx.args.checked;
|
let refundId;
|
||||||
|
|
||||||
let tx;
|
let tx;
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
@ -100,15 +111,29 @@ module.exports = Self => {
|
||||||
};
|
};
|
||||||
const refundTicketIds = refundTickets.map(ticket => ticket.id);
|
const refundTicketIds = refundTickets.map(ticket => ticket.id);
|
||||||
|
|
||||||
await models.Ticket.invoiceTickets(ctx, refundTicketIds, invoiceCorrection, myOptions);
|
refundId = await models.Ticket.invoiceTickets(ctx, refundTicketIds, invoiceCorrection, myOptions);
|
||||||
|
|
||||||
if (!checked) {
|
if (makeInvoice)
|
||||||
const [invoiceId] = await models.Ticket.invoiceTicketsAndPdf(ctx, clonedTicketIds, null, myOptions);
|
invoiceId = await models.Ticket.invoiceTickets(ctx, clonedTicketIds, null, myOptions);
|
||||||
return invoiceId;
|
|
||||||
}
|
tx && await tx.commit();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tx && makeInvoice) {
|
||||||
|
try {
|
||||||
|
await models.InvoiceOut.makePdfList(ctx, invoiceId);
|
||||||
|
} catch (e) {
|
||||||
|
throw new UserError('It has been invoiced but the PDF could not be generated');
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await models.InvoiceOut.makePdfList(ctx, refundId);
|
||||||
|
} catch (e) {
|
||||||
|
throw new UserError('It has been invoiced but the PDF of refund not be generated');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return invoiceId;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -158,7 +158,7 @@ class Controller extends Section {
|
||||||
cplusRectificationTypeFk: this.cplusRectificationType,
|
cplusRectificationTypeFk: this.cplusRectificationType,
|
||||||
siiTypeInvoiceOutFk: this.siiTypeInvoiceOut,
|
siiTypeInvoiceOutFk: this.siiTypeInvoiceOut,
|
||||||
invoiceCorrectionTypeFk: this.invoiceCorrectionType,
|
invoiceCorrectionTypeFk: this.invoiceCorrectionType,
|
||||||
checked: this.checked
|
makeInvoice: this.checked
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$http.get(`Clients/${this.clientId}`).then(response => {
|
this.$http.get(`Clients/${this.clientId}`).then(response => {
|
||||||
|
|
|
@ -135,6 +135,7 @@ module.exports = Self => {
|
||||||
const now = Date.vnNew();
|
const now = Date.vnNew();
|
||||||
|
|
||||||
const ticket = await models.Ticket.findById(ticketId, null, myOptions);
|
const ticket = await models.Ticket.findById(ticketId, null, myOptions);
|
||||||
|
if (!ctx.args) ctx.args = {};
|
||||||
ctx.args.clientId = ticket.clientFk;
|
ctx.args.clientId = ticket.clientFk;
|
||||||
ctx.args.shipped = now;
|
ctx.args.shipped = now;
|
||||||
ctx.args.landed = now;
|
ctx.args.landed = now;
|
||||||
|
|
Loading…
Reference in New Issue