Merge pull request 'fix: refs #6731 fix ticketRequest' (!2364) from 6731-fixTicketRequestLog into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #2364
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
Jon Elias 2024-04-30 10:19:29 +00:00
commit 2b9bfb5d85
8 changed files with 42 additions and 39 deletions

View File

@ -1,19 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketRequest_Add`(vDescription VARCHAR(255), vQuantity INT, vPrice DOUBLE, vTicketFk INT, vBuyerCode VARCHAR(3))
BEGIN
INSERT INTO vn.ticketRequest(description,
quantity,
price,
ticketFk,
buyerCode,
requesterFk)
VALUES(vDescription,
vQuantity,
vPrice,
vTicketFk,
vBuyerCode,
vn.getUser());
END$$
DELIMITER ;

View File

@ -14,7 +14,7 @@ BEGIN
END IF;
IF NEW.attenderFk IS NULL THEN
SET NEW.attenderFk = (SELECT w.id FROM worker w WHERE w.code = NEW.buyerCode);
SET NEW.attenderFk = (SELECT defaultAttenderFk FROM ticketConfig LIMIT 1);
END IF;
END$$
DELIMITER ;

View File

@ -12,9 +12,5 @@ BEGIN
IF NEW.salesPersonCode <> OLD.salesPersonCode THEN
SET NEW.requesterFk = (SELECT w.id FROM worker w WHERE w.code = NEW.salesPersonCode);
END IF;
IF NEW.buyerCode <> OLD.buyerCode THEN
SET NEW.attenderFk = (SELECT w.id FROM worker w WHERE w.code = NEW.buyerCode);
END IF;
END$$
DELIMITER ;

View File

@ -0,0 +1,7 @@
-- Place your SQL code here
ALTER TABLE `vn`.`ticketRequest`
CHANGE IF EXISTS `buyerCode` `buyerCode__` varchar(3) NOT NULL COMMENT '@deprecated 2024-04-23 refs #6731 field not used';
ALTER TABLE `vn`.`ticketConfig` ADD COLUMN IF NOT EXISTS `defaultAttenderFk` int unsigned;
ALTER TABLE vn.ticketConfig ADD CONSTRAINT ticketConfig_worker_FK FOREIGN KEY (defaultAttenderFk) REFERENCES vn.worker(id);

View File

@ -223,7 +223,7 @@
"printerNotExists": "The printer does not exist",
"There are not picking tickets": "There are not picking tickets",
"ticketCommercial": "The ticket {{ ticket }} for the salesperson {{ salesMan }} is in preparation. (automatically generated message)",
"This password can only be changed by the user themselves": "This password can only be changed by the user themselves",
"They're not your subordinate": "They're not your subordinate",
"This password can only be changed by the user themselves": "This password can only be changed by the user themselves",
"They're not your subordinate": "They're not your subordinate",
"InvoiceIn is already booked": "InvoiceIn is already booked"
}

View File

@ -92,9 +92,7 @@ describe('ticket-request confirm()', () => {
const request = await models.TicketRequest.findById(requestId, null, options);
expect(request.saleFk).toBeNull();
await request.updateAttributes({saleFk: 2}, options);
await request.updateAttributes({saleFk: 2});
ctx.args = {
itemFk: itemId,
id: requestId,
@ -102,7 +100,6 @@ describe('ticket-request confirm()', () => {
};
await models.TicketRequest.confirm(ctx, options);
await tx.rollback();
} catch (e) {
await tx.rollback();

View File

@ -23,6 +23,16 @@
},
"daysForWarningClaim": {
"type": "number"
},
"defaultAttenderFk": {
"type": "number"
}
},
"relations": {
"attender": {
"type": "belongsTo",
"model": "Worker",
"foreignKey": "defaultAttenderFk"
}
}
}

View File

@ -8,21 +8,21 @@ module.exports = function(Self) {
require('../methods/ticket-request/getItemTypeWorker')(Self);
Self.observe('before save', async function(ctx) {
if (ctx.isNewInstance) {
const loopBackContext = LoopBackContext.getCurrentContext();
const filter = {where: {id: loopBackContext.active.accessToken.userId}};
const models = Self.app.models;
const worker = await models.Worker.findOne(filter);
const loopBackContext = LoopBackContext.getCurrentContext();
const filter = {where: {id: loopBackContext.active.accessToken.userId}};
const models = Self.app.models;
const worker = await models.Worker.findOne(filter);
const instance = ctx.instance;
const attenderFk = instance?.attenderFk;
const instance = ctx.instance;
if (ctx.isNewInstance) {
instance.requesterFk = worker.id;
const httpCtx = {req: loopBackContext.active};
const httpRequest = httpCtx.req.http .req;
const $t = httpRequest.__;
const attenderId = instance.attenderFk;
if (attenderId) {
if (attenderFk) {
const ticket = await models.Ticket.findById(instance.ticketFk);
let messageText = 'New ticket request has been created';
if (instance.price)
@ -35,8 +35,20 @@ module.exports = function(Self) {
quantity: instance.quantity,
price: instance.price
});
await models.Chat.sendCheckingPresence(httpCtx, attenderId, message);
await models.Chat.sendCheckingPresence(httpCtx, attenderFk, message);
} else {
const {defaultAttenderFk} = await models.TicketConfig.findOne();
Object.assign(instance, {attenderFk: defaultAttenderFk});
}
}
});
Self.observe('after save', async function(ctx) {
const models = Self.app.models;
const instance = ctx.instance;
if (instance?.attenderFk === null && !ctx.isNewInstance) {
const {defaultAttenderFk} = await models.TicketConfig.findOne();
await models.TicketRequest.updateAll({id: instance.id}, {attenderFk: defaultAttenderFk});
}
});
};