Merge branch 'dev' into 7731-clientViesCode
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Robert Ferrús 2025-01-14 06:19:19 +00:00
commit 29d0a7ac1a
9 changed files with 83 additions and 66 deletions

View File

@ -27,38 +27,47 @@ module.exports = Self => {
});
Self.sendCheckingPresence = async(ctx, recipientId, message) => {
if (!recipientId) return false;
const models = Self.app.models;
const userId = ctx.req.accessToken.userId;
const sender = await models.VnUser.findById(userId, {fields: ['id']});
const recipient = await models.VnUser.findById(recipientId, null);
// Prevent sending messages to yourself
if (recipientId == userId) return false;
if (!recipient)
throw new Error(`Could not send message "${message}" to worker id ${recipientId} from user ${userId}`);
if (!isProduction())
message = `[Test:Environment to user ${userId}] ` + message;
const chat = await models.Chat.create({
senderFk: sender.id,
recipient: `@${recipient.name}`,
dated: Date.vnNew(),
checkUserStatus: 1,
message: message,
status: 'sending',
attempts: 0
});
try {
await Self.sendCheckingUserStatus(chat);
await Self.updateChat(chat, 'sent');
} catch (error) {
await Self.updateChat(chat, 'error', error);
}
const models = Self.app.models;
const sender = await models.VnUser.findById(userId, {fields: ['id']});
const error = `Could not send message from user ${userId}`;
return true;
if (!recipientId) throw new Error(error);
const recipient = await models.VnUser.findById(recipientId, null);
if (!recipient)
throw new Error(error);
// Prevent sending messages to yourself
if (recipientId == userId) return false;
if (!isProduction())
message = `[Test:Environment to user ${userId}] ` + message;
const chat = await models.Chat.create({
senderFk: sender.id,
recipient: `@${recipient.name}`,
dated: Date.vnNew(),
checkUserStatus: 1,
message: message,
status: 'sending',
attempts: 0
});
try {
await Self.sendCheckingUserStatus(chat);
await Self.updateChat(chat, 'sent');
} catch (error) {
await Self.updateChat(chat, 'error', error);
}
return true;
} catch (e) {
await Self.rawSql(`
INSERT INTO util.debug (variable, value)
VALUES ('sendCheckingPresence_error', ?)
`, [`User: ${userId}, recipient: ${recipientId}, message: ${message}, error: ${e}`]);
throw e;
}
};
};

View File

@ -16,10 +16,11 @@ BEGIN
TRUE,
sc.userFk,
s.id
FROM vn.sectorCollection sc
JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id
JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk
JOIN vn.state s ON s.code = 'OK PREVIOUS'
FROM sectorCollection sc
JOIN sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id
JOIN saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk
JOIN state s ON s.code = 'OK PREVIOUS'
JOIN itemShelvingSale iss ON iss.saleFk = sgd.saleFk
WHERE sc.id = vSectorCollectionFk;
END$$
DELIMITER ;

View File

@ -211,6 +211,7 @@
"Name should be uppercase": "Name should be uppercase",
"You cannot update these fields": "You cannot update these fields",
"CountryFK cannot be empty": "Country cannot be empty",
"No tickets to invoice": "There are no tickets to invoice that meet the invoicing requirements",
"You are not allowed to modify the alias": "You are not allowed to modify the alias",
"You already have the mailAlias": "You already have the mailAlias",
"This machine is already in use.": "This machine is already in use.",
@ -251,4 +252,4 @@
"Price cannot be blank": "Price cannot be blank",
"There are tickets to be invoiced": "There are tickets to be invoiced",
"The address of the customer must have information about Incoterms and Customs Agent": "The address of the customer must have information about Incoterms and Customs Agent"
}
}

View File

@ -339,7 +339,7 @@
"Incorrect pin": "Pin incorrecto.",
"You already have the mailAlias": "Ya tienes este alias de correo",
"The alias cant be modified": "Este alias de correo no puede ser modificado",
"No tickets to invoice": "No hay tickets para facturar",
"No tickets to invoice": "No hay tickets para facturar que cumplan los requisitos de facturación",
"this warehouse has not dms": "El Almacén no acepta documentos",
"This ticket already has a cmr saved": "Este ticket ya tiene un cmr guardado",
"Name should be uppercase": "El nombre debe ir en mayúscula",

View File

@ -339,7 +339,7 @@
"Incorrect pin": "Pin incorrect.",
"You already have the mailAlias": "Vous avez déjà cet alias de courrier",
"The alias cant be modified": "Cet alias de courrier ne peut pas être modifié",
"No tickets to invoice": "Pas de tickets à facturer",
"No tickets to invoice": "Il n'y a pas de tickets à facturer qui répondent aux exigences de facturation",
"this warehouse has not dms": "L'entrepôt n'accepte pas les documents",
"This ticket already has a cmr saved": "Ce ticket a déjà un cmr enregistré",
"Name should be uppercase": "Le nom doit être en majuscules",

View File

@ -339,7 +339,7 @@
"Incorrect pin": "PIN incorreto.",
"You already have the mailAlias": "Você já tem o alias de e-mail",
"The alias cant be modified": "O alias não pode ser modificado",
"No tickets to invoice": "Não há tickets para faturar",
"No tickets to invoice": "Não há bilhetes para faturar que atendam aos requisitos de faturamento",
"this warehouse has not dms": "Este armazém não tem DMS",
"This ticket already has a cmr saved": "Este ticket já tem um CMR salvo",
"Name should be uppercase": "O nome deve estar em maiúsculas",

View File

@ -49,12 +49,6 @@ module.exports = Self => {
}
try {
const clientCanBeInvoiced =
await Self.app.models.Client.canBeInvoiced(clientId, companyFk, myOptions);
if (!clientCanBeInvoiced)
throw new UserError(`This client can't be invoiced`);
const vIsAllInvoiceable = false;
await Self.rawSql('CALL ticketPackaging_add(?, ?, ?, ?)', [
clientId,

View File

@ -1,4 +1,5 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('InvoiceOut clientsToInvoice()', () => {
const userId = 1;
@ -20,6 +21,21 @@ describe('InvoiceOut clientsToInvoice()', () => {
headers: {origin: 'http://localhost'}
};
const ctx = {req: activeCtx};
let tx;
let options;
beforeEach(async() => {
LoopBackContext.getCurrentContext = () => ({
active: activeCtx,
});
tx = await models.InvoiceOut.beginTransaction({});
options = {transaction: tx};
});
afterEach(async() => {
await tx.rollback();
});
it('should return a list of clients to invoice', async() => {
spyOn(models.InvoiceOut, 'rawSql').and.callFake(query => {
@ -37,24 +53,14 @@ describe('InvoiceOut clientsToInvoice()', () => {
}
});
const tx = await models.InvoiceOut.beginTransaction({});
const options = {transaction: tx};
const addresses = await models.InvoiceOut.clientsToInvoice(
ctx, clientId, invoiceDate, maxShipped, companyFk, options);
try {
const addresses = await models.InvoiceOut.clientsToInvoice(
ctx, clientId, invoiceDate, maxShipped, companyFk, options);
expect(addresses.length).toBeGreaterThan(0);
expect(addresses[0].clientId).toBe(clientId);
expect(addresses[0].clientName).toBe('Test Client');
expect(addresses[0].id).toBe(1);
expect(addresses[0].nickname).toBe('Address 1');
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
expect(addresses.length).toBeGreaterThan(0);
expect(addresses[0].clientId).toBe(clientId);
expect(addresses[0].clientName).toBe('Test Client');
expect(addresses[0].id).toBe(1);
expect(addresses[0].nickname).toBe('Address 1');
});
it('should handle errors and rollback transaction', async() => {
@ -62,14 +68,20 @@ describe('InvoiceOut clientsToInvoice()', () => {
return Promise.reject(new Error('Test Error'));
});
const tx = await models.InvoiceOut.beginTransaction({});
const options = {transaction: tx};
try {
await models.InvoiceOut.clientsToInvoice(ctx, clientId, invoiceDate, maxShipped, companyFk, options);
} catch (e) {
expect(e.message).toBe('Test Error');
await tx.rollback();
}
});
it('should return all list', async() => {
const minShipped = Date.vnNew();
minShipped.setFullYear(maxShipped.getFullYear() - 1);
const toInvoice = await models.InvoiceOut.clientsToInvoice(
ctx, null, invoiceDate, maxShipped, companyFk, options);
expect(toInvoice).toBeDefined();
});
});

View File

@ -30,7 +30,7 @@ module.exports = Self => {
Object.assign(myOptions, options);
const query =
`SELECT DISTINCT u.id, u.nickname
`SELECT DISTINCT u.id, u.nickname, w.firstName, w.lastName
FROM itemType it
JOIN worker w ON w.id = it.workerFk
JOIN account.user u ON u.id = w.id`;