7631_testToMaster_2426 #2634

Merged
alexm merged 147 commits from 7631_testToMaster_2426 into master 2024-06-25 06:36:59 +00:00
8 changed files with 66 additions and 75 deletions
Showing only changes of commit f84e85e443 - Show all commits

View File

@ -0,0 +1,14 @@
-- Place your SQL code here
USE vn;
ALTER TABLE vn.itemShelving DROP FOREIGN KEY itemShelvingBuy_FK;
ALTER TABLE vn.itemShelving DROP FOREIGN KEY itemShelving_fk2;
ALTER TABLE vn.itemShelving DROP INDEX itemShelving_UN;
ALTER TABLE vn.itemShelving ADD CONSTRAINT itemShelving_fk2 FOREIGN KEY (shelvingFk) REFERENCES vn.shelving(code) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE vn.itemShelving ADD CONSTRAINT itemShelvingBuy_FK FOREIGN KEY (buyFk) REFERENCES vn.buy(id) ON DELETE RESTRICT ON UPDATE RESTRICT;

View File

@ -351,7 +351,7 @@
"You are not allowed to modify the alias": "No estás autorizado a modificar el alias",
"The address of the customer must have information about Incoterms and Customs Agent": "El consignatario del cliente debe tener informado Incoterms y Agente de aduanas",
"The line could not be marked": "La linea no puede ser marcada",
"This password can only be changed by the user themselves": "Esta contraseña solo puede ser modificada por el propio usuario",
"Through this procedure, it is not possible to modify the password of users with verified email": "Mediante este procedimiento, no es posible modificar la contraseña de usuarios con correo verificado",
"They're not your subordinate": "No es tu subordinado/a.",
"No results found": "No se han encontrado resultados",
"InvoiceIn is already booked": "La factura recibida está contabilizada",
@ -366,4 +366,4 @@
"It has been invoiced but the PDF could not be generated": "Se ha facturado pero no se ha podido generar el PDF",
"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",
"Payment method is required": "El método de pago es obligatorio"
}
}

View File

@ -13,7 +13,11 @@ module.exports = Self => {
Self.setUnverifiedPassword = async(id, pass, options) => {
const {emailVerified} = await models.VnUser.findById(id, {fields: ['emailVerified']}, options);
if (emailVerified) throw new ForbiddenError('This password can only be changed by the user themselves');
if (emailVerified) {
throw new ForbiddenError(
'Through this procedure, it is not possible to modify the password of users with verified email'
);
}
await models.VnUser.setPassword(id, pass, options);
};

View File

@ -145,15 +145,10 @@ module.exports = Self => {
const newTicket = await models.Ticket.new(ctx, myOptions);
const ticketRefund = await models.TicketRefund.findOne({
where: {refundTicketFk: ticketId}
await models.TicketRefund.create({
originalTicketFk: ticketId,
refundTicketFk: newTicket.id
}, myOptions);
if (negative && (withWarehouse || !ticketRefund?.id)) {
await models.TicketRefund.create({
originalTicketFk: ticketId,
refundTicketFk: newTicket.id
}, myOptions);
}
return newTicket;
}

View File

@ -1,7 +1,7 @@
const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('ticket state()', () => {
xdescribe('ticket state()', () => {
const salesPersonId = 18;
const employeeId = 1;
const productionId = 49;
@ -113,6 +113,7 @@ describe('ticket state()', () => {
try {
const options = {transaction: tx};
spyOn(models.Chat, 'sendCheckingPresence').and.callThrough();
const ticket = await models.Ticket.create(sampleTicket, options);
activeCtx.accessToken.userId = salesPersonId;
const assignedState = await models.State.findOne({where: {code: 'PICKER_DESIGNED'}}, options);
@ -124,6 +125,7 @@ describe('ticket state()', () => {
expect(resAssigned.userFk).toBe(paramsAssigned.userFk);
expect(resAssigned.userFk).toBe(1);
expect(resAssigned.id).toBeDefined();
expect(models.Chat.sendCheckingPresence).not.toHaveBeenCalled();
activeCtx.accessToken.userId = productionId;
const packedState = await models.State.findOne({where: {code: 'PACKED'}}, options);
@ -183,5 +185,37 @@ describe('ticket state()', () => {
throw e;
}
});
it('should not call sendCheckingPresence if sales.length is 0 because quantities are equal', async() => {
const tx = await models.TicketTracking.beginTransaction({});
spyOn(models.Chat, 'sendCheckingPresence').and.callThrough();
try {
const options = {transaction: tx};
const ticket = await models.Ticket.create(sampleTicket, options);
activeCtx.accessToken.userId = productionId;
const sampleSale = {
ticketFk: ticket.id,
itemFk: 1,
concept: 'Test',
quantity: 10,
originalQuantity: 10
};
await models.Sale.create(sampleSale, options);
const packedState = await models.State.findOne({where: {code: 'PACKED'}}, options);
const params = {ticketFk: ticket.id, stateFk: packedState.id};
await models.Ticket.state(ctx, params, options);
expect(models.Chat.sendCheckingPresence).not.toHaveBeenCalled();
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -26,7 +26,6 @@ module.exports = Self => {
const models = Self.app.models;
const myOptions = {};
let tx;
let newStateOrder;
if (typeof options == 'object')
Object.assign(myOptions, options);
@ -41,16 +40,11 @@ module.exports = Self => {
throw new UserError('State cannot be blank');
if (params.stateFk) {
const {code, order} = await models.State.findById(
params.stateFk,
{fields: ['code', 'order']},
myOptions);
const {code} = await models.State.findById(params.stateFk, {fields: ['code']}, myOptions);
params.code = code;
newStateOrder = order;
} else {
const {id, order} = await models.State.findOne({where: {code: params.code}}, myOptions);
const {id} = await models.State.findOne({where: {code: params.code}}, myOptions);
params.stateFk = id;
newStateOrder = order;
}
if (!params.userFk) {
@ -70,59 +64,7 @@ module.exports = Self => {
if ((ticketState && !oldStateAllowed) || !newStateAllowed)
throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED');
const ticket = await models.Ticket.findById(params.ticketFk, {
include: [{
relation: 'client',
scope: {
fields: ['salesPersonFk']
}
}],
fields: ['id', 'clientFk']
}, myOptions);
const salesPersonFk = ticket.client().salesPersonFk;
const stateChecked = await models.State.findOne({fields: ['order'], where: {code: 'CHECKED'}});
if (salesPersonFk && newStateOrder >= stateChecked.order) {
const sales = await Self.rawSql(`
SELECT DISTINCT s.id,
s.itemFk,
s.concept,
s.originalQuantity AS oldQuantity,
s.quantity AS newQuantity
FROM vn.sale s
WHERE s.ticketFk = ?
AND s.originalQuantity IS NOT NULL
AND s.originalQuantity <> s.quantity
`, [params.ticketFk], myOptions);
if (sales.length) {
let changes = '';
const url = await models.Url.getUrl();
const $t = ctx.req.__;
for (let sale of sales) {
changes += `\r\n-` + $t('Changes in sales', {
itemId: sale.itemFk,
concept: sale.concept,
oldQuantity: sale.oldQuantity,
newQuantity: sale.newQuantity,
itemUrl: `${url}item/${sale.itemFk}/summary`
});
const currentSale = await models.Sale.findById(sale.id, null, myOptions);
await currentSale.updateAttributes({
originalQuantity: currentSale.quantity
}, myOptions);
}
const message = $t('Changed sale quantity', {
ticketId: ticket.id,
changes: changes,
ticketUrl: `${url}ticket/${ticket.id}/sale`
});
await models.Chat.sendCheckingPresence(ctx, salesPersonFk, message, myOptions);
}
}
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticket.id, params.code], myOptions);
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [params.ticketFk, params.code], myOptions);
const ticketTracking = await models.TicketTracking.findOne({
where: {ticketFk: params.ticketFk},

View File

@ -42,7 +42,9 @@ describe('worker setPassword()', () => {
await tx.rollback();
} catch (e) {
expect(e.message).toEqual(`This password can only be changed by the user themselves`);
expect(e.message).toEqual(
'Through this procedure, it is not possible to modify the password of users with verified email'
);
await tx.rollback();
}
});

View File

@ -11,7 +11,7 @@
? 'Click to allow the user to be disabled'
: 'Click to exclude the user from getting disabled'}}
</vn-item>
<vn-item ng-if="!$ctrl.worker.user.emailVerified && $ctrl.vnConfig.storage.currentUserWorkerId !=$ctrl.worker.id" ng-click="setPassword.show()" translate>
<vn-item ng-click="setPassword.show()" translate>
Change password
</vn-item>
</slot-menu>