Merge branch 'test' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
commit
f99b1beb86
|
@ -3,15 +3,21 @@
|
||||||
"base": "VnModel",
|
"base": "VnModel",
|
||||||
"options": {
|
"options": {
|
||||||
"mysql": {
|
"mysql": {
|
||||||
"table": "productionConfig"
|
"table": "productionConfig"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": {
|
"id": {
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"required": true,
|
"required": true,
|
||||||
"id": true
|
"id": true
|
||||||
},
|
},
|
||||||
|
"sectorFromCode": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"sectorToCode": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"backupPrinterNotificationDelay": {
|
"backupPrinterNotificationDelay": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
-- Place your SQL code here
|
||||||
|
|
||||||
|
USE vn;
|
||||||
|
|
||||||
|
ALTER TABLE vn.productionConfig ADD itemOlderReviewHours int(11) DEFAULT 0 NOT NULL COMMENT 'Horas que se tienen en cuenta para comprobar si un ítem es más viejo.';
|
|
@ -0,0 +1,9 @@
|
||||||
|
-- Place your SQL code here
|
||||||
|
|
||||||
|
USE vn;
|
||||||
|
|
||||||
|
ALTER TABLE vn.productionConfig ADD sectorFromCode varchar(15) NULL COMMENT 'Sector origen que se revisa ítems más nuevos al parkinear';
|
||||||
|
ALTER TABLE vn.productionConfig ADD sectorToCode varchar(15) NULL COMMENT 'Sector destino que se revisa ítems más nuevos al parkinear';
|
||||||
|
|
||||||
|
ALTER TABLE vn.productionConfig ADD CONSTRAINT productionConfig_sector_FK FOREIGN KEY (sectorFromCode) REFERENCES vn.sector(code) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
ALTER TABLE vn.productionConfig ADD CONSTRAINT productionConfig_sector_FK_1 FOREIGN KEY (sectorToCode) REFERENCES vn.sector(code) ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
@ -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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -351,7 +351,7 @@
|
||||||
"You are not allowed to modify the alias": "No estás autorizado a modificar el alias",
|
"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 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",
|
"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.",
|
"They're not your subordinate": "No es tu subordinado/a.",
|
||||||
"No results found": "No se han encontrado resultados",
|
"No results found": "No se han encontrado resultados",
|
||||||
"InvoiceIn is already booked": "La factura recibida está contabilizada",
|
"InvoiceIn is already booked": "La factura recibida está contabilizada",
|
||||||
|
|
|
@ -13,7 +13,11 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.setUnverifiedPassword = async(id, pass, options) => {
|
Self.setUnverifiedPassword = async(id, pass, options) => {
|
||||||
const {emailVerified} = await models.VnUser.findById(id, {fields: ['emailVerified']}, 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);
|
await models.VnUser.setPassword(id, pass, options);
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('getListItemNewer', {
|
||||||
|
description:
|
||||||
|
'Get boolean if any or specific item of the shelving has older created in another shelving or parking',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'shelvingFk',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description: 'Shelving code'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'parking',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description: 'Parking code'
|
||||||
|
},
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: 'Array',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/getListItemNewer`,
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.getListItemNewer = async(shelvingFk, parking, options) => {
|
||||||
|
const myOptions = {};
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const [isParkingToReview] = await Self.rawSql(`
|
||||||
|
SELECT COUNT(p.id) parkingToReview
|
||||||
|
FROM vn.parking p
|
||||||
|
JOIN vn.sector s ON s.id = p.sectorFk
|
||||||
|
JOIN vn.productionConfig pc
|
||||||
|
WHERE p.code = ? AND s.code = pc.sectorToCode;`,
|
||||||
|
[parking], myOptions);
|
||||||
|
|
||||||
|
if (isParkingToReview['parkingToReview'] < 1) return [];
|
||||||
|
|
||||||
|
const result = await Self.rawSql(`
|
||||||
|
WITH tItemShelving AS(
|
||||||
|
SELECT is2.itemFk, is2.created, p.sectorFK, is2.id
|
||||||
|
FROM vn.itemShelving is2
|
||||||
|
JOIN vn.shelving sh ON sh.code = is2.shelvingFk
|
||||||
|
JOIN vn.parking p ON p.id = sh.parkingFk
|
||||||
|
JOIN vn.sector s ON s.id = p.sectorFk
|
||||||
|
JOIN vn.productionConfig pc
|
||||||
|
WHERE is2.shelvingFk = ? AND s.code = pc.sectorFromCode
|
||||||
|
), tItemInSector AS (
|
||||||
|
SELECT is2.itemFk, is2.created, is2.shelvingFk
|
||||||
|
FROM vn.itemShelving is2
|
||||||
|
JOIN vn.shelving sh ON sh.code = is2.shelvingFk
|
||||||
|
JOIN vn.parking p ON p.id = sh.parkingFk
|
||||||
|
JOIN vn.sector s ON s.id = p.sectorFk
|
||||||
|
JOIN vn.productionConfig pc
|
||||||
|
WHERE is2.shelvingFk <> ?
|
||||||
|
AND s.code = pc.sectorFromCode)
|
||||||
|
SELECT ti.itemFK, tis.shelvingFk
|
||||||
|
FROM tItemShelving ti
|
||||||
|
JOIN tItemInSector tis ON tis.itemFk = ti.itemFk
|
||||||
|
JOIN vn.productionConfig pc
|
||||||
|
WHERE ti.created > tis.created + INTERVAL pc.itemOlderReviewHours HOUR;`,
|
||||||
|
[shelvingFk, shelvingFk], myOptions);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
};
|
|
@ -1,63 +0,0 @@
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
|
||||||
module.exports = Self => {
|
|
||||||
Self.remoteMethod('hasItemOlder', {
|
|
||||||
description:
|
|
||||||
'Get boolean if any or specific item of the shelving has older created in another shelving or parking',
|
|
||||||
accessType: 'READ',
|
|
||||||
accepts: [{
|
|
||||||
arg: 'shelvingFkIn',
|
|
||||||
type: 'string',
|
|
||||||
required: true,
|
|
||||||
description: 'Shelving code'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'parking',
|
|
||||||
type: 'string',
|
|
||||||
description: 'Parking code'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'shelvingFkOut',
|
|
||||||
type: 'string',
|
|
||||||
description: 'Shelving code'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'itemFk',
|
|
||||||
type: 'integer',
|
|
||||||
description: 'Item id'
|
|
||||||
}],
|
|
||||||
returns: {
|
|
||||||
type: 'boolean',
|
|
||||||
root: true
|
|
||||||
},
|
|
||||||
http: {
|
|
||||||
path: `/hasItemOlder`,
|
|
||||||
verb: 'GET'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Self.hasItemOlder = async(shelvingFkIn, parking, shelvingFkOut, itemFk, options) => {
|
|
||||||
if (!parking && !shelvingFkOut) throw new UserError('Missing data: parking or shelving');
|
|
||||||
|
|
||||||
const myOptions = {};
|
|
||||||
if (typeof options == 'object')
|
|
||||||
Object.assign(myOptions, options);
|
|
||||||
|
|
||||||
const result = await Self.rawSql(`
|
|
||||||
SELECT COUNT(ish.id) countItemOlder
|
|
||||||
FROM vn.itemShelving ish
|
|
||||||
JOIN (
|
|
||||||
SELECT ish.itemFk, created,shelvingFk
|
|
||||||
FROM vn.itemShelving ish
|
|
||||||
JOIN vn.shelving s ON ish.shelvingFk = s.code
|
|
||||||
WHERE ish.shelvingFk = ?
|
|
||||||
)sub ON sub.itemFK = ish.itemFk
|
|
||||||
JOIN vn.shelving s ON s.code = ish.shelvingFk
|
|
||||||
JOIN vn.parking p ON p.id = s.parkingFk
|
|
||||||
WHERE sub.created > ish.created
|
|
||||||
AND (p.code <> ? OR ? IS NULL)
|
|
||||||
AND (ish.shelvingFk <> ? OR ? IS NULL)
|
|
||||||
AND (ish.itemFk <> ? OR ? IS NULL)`,
|
|
||||||
[shelvingFkIn, parking, parking, shelvingFkOut, shelvingFkOut, itemFk, itemFk], myOptions);
|
|
||||||
return result[0]['countItemOlder'] > 0;
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
|
||||||
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
|
describe('itemShelving getListItemNewer()', () => {
|
||||||
|
it('should return true because there is an older item', async() => {
|
||||||
|
const shelving = 'NCC';
|
||||||
|
const parking = 'A-47-1';
|
||||||
|
|
||||||
|
const sectorCamHighCode = 'CAMARA SECTOR D';
|
||||||
|
const sectorCamCode = 'NAVE ALGEMESI';
|
||||||
|
|
||||||
|
const sectorCamCodeHighId = 1;
|
||||||
|
const sectorCamCodeId = 9991;
|
||||||
|
|
||||||
|
const tx = await models.Sector.beginTransaction({});
|
||||||
|
const myOptions = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const sectorHighCam = await models.Sector.findById(sectorCamCodeHighId, null, myOptions);
|
||||||
|
await sectorHighCam.updateAttributes({
|
||||||
|
code: sectorCamHighCode
|
||||||
|
});
|
||||||
|
|
||||||
|
const sectorCam = await models.Sector.findById(sectorCamCodeId, null, myOptions);
|
||||||
|
await sectorCam.updateAttributes({
|
||||||
|
code: sectorCamCode
|
||||||
|
});
|
||||||
|
|
||||||
|
const config = await models.ProductionConfig.findOne();
|
||||||
|
|
||||||
|
await config.updateAttributes({
|
||||||
|
sectorToCode: sectorCamHighCode,
|
||||||
|
sectorFromCode: sectorCamCode
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await models.ItemShelving.getListItemNewer(shelving, parking, myOptions);
|
||||||
|
|
||||||
|
expect(result.length).toEqual(2);
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,45 +0,0 @@
|
||||||
|
|
||||||
const {models} = require('vn-loopback/server/server');
|
|
||||||
|
|
||||||
describe('itemShelving hasOlder()', () => {
|
|
||||||
it('should return false because there are not older items', async() => {
|
|
||||||
const shelvingFkIn = 'GVC';
|
|
||||||
const shelvingFkOut = 'HEJ';
|
|
||||||
const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, null, shelvingFkOut);
|
|
||||||
|
|
||||||
expect(result).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false because there are not older items in parking', async() => {
|
|
||||||
const shelvingFkIn = 'HEJ';
|
|
||||||
const parking = '700-01';
|
|
||||||
const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, parking);
|
|
||||||
|
|
||||||
expect(result).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true because there is an older item', async() => {
|
|
||||||
const shelvingFkIn = 'UXN';
|
|
||||||
const shelvingFkOut = 'PCC';
|
|
||||||
const parking = 'A-01-1';
|
|
||||||
const itemFk = 1;
|
|
||||||
|
|
||||||
const tx = await models.ItemShelving.beginTransaction({});
|
|
||||||
const myOptions = {transaction: tx};
|
|
||||||
const filter = {where: {shelvingFk: shelvingFkOut}
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
const itemShelvingBefore = await models.ItemShelving.findOne(filter, myOptions);
|
|
||||||
await itemShelvingBefore.updateAttributes({
|
|
||||||
itemFk: itemFk
|
|
||||||
}, myOptions);
|
|
||||||
const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, parking, null, null, myOptions);
|
|
||||||
|
|
||||||
expect(result).toBe(true);
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -4,5 +4,5 @@ module.exports = Self => {
|
||||||
require('../methods/item-shelving/getInventory')(Self);
|
require('../methods/item-shelving/getInventory')(Self);
|
||||||
require('../methods/item-shelving/getAlternative')(Self);
|
require('../methods/item-shelving/getAlternative')(Self);
|
||||||
require('../methods/item-shelving/updateFromSale')(Self);
|
require('../methods/item-shelving/updateFromSale')(Self);
|
||||||
require('../methods/item-shelving/hasItemOlder')(Self);
|
require('../methods/item-shelving/getListItemNewer')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -145,15 +145,10 @@ module.exports = Self => {
|
||||||
|
|
||||||
const newTicket = await models.Ticket.new(ctx, myOptions);
|
const newTicket = await models.Ticket.new(ctx, myOptions);
|
||||||
|
|
||||||
const ticketRefund = await models.TicketRefund.findOne({
|
await models.TicketRefund.create({
|
||||||
where: {refundTicketFk: ticketId}
|
originalTicketFk: ticketId,
|
||||||
|
refundTicketFk: newTicket.id
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
if (negative && (withWarehouse || !ticketRefund?.id)) {
|
|
||||||
await models.TicketRefund.create({
|
|
||||||
originalTicketFk: ticketId,
|
|
||||||
refundTicketFk: newTicket.id
|
|
||||||
}, myOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
return newTicket;
|
return newTicket;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
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');
|
||||||
|
|
||||||
describe('ticket state()', () => {
|
xdescribe('ticket state()', () => {
|
||||||
const salesPersonId = 18;
|
const salesPersonId = 18;
|
||||||
const employeeId = 1;
|
const employeeId = 1;
|
||||||
const productionId = 49;
|
const productionId = 49;
|
||||||
|
@ -113,6 +113,7 @@ describe('ticket state()', () => {
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
spyOn(models.Chat, 'sendCheckingPresence').and.callThrough();
|
||||||
const ticket = await models.Ticket.create(sampleTicket, options);
|
const ticket = await models.Ticket.create(sampleTicket, options);
|
||||||
activeCtx.accessToken.userId = salesPersonId;
|
activeCtx.accessToken.userId = salesPersonId;
|
||||||
const assignedState = await models.State.findOne({where: {code: 'PICKER_DESIGNED'}}, options);
|
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(paramsAssigned.userFk);
|
||||||
expect(resAssigned.userFk).toBe(1);
|
expect(resAssigned.userFk).toBe(1);
|
||||||
expect(resAssigned.id).toBeDefined();
|
expect(resAssigned.id).toBeDefined();
|
||||||
|
expect(models.Chat.sendCheckingPresence).not.toHaveBeenCalled();
|
||||||
|
|
||||||
activeCtx.accessToken.userId = productionId;
|
activeCtx.accessToken.userId = productionId;
|
||||||
const packedState = await models.State.findOne({where: {code: 'PACKED'}}, options);
|
const packedState = await models.State.findOne({where: {code: 'PACKED'}}, options);
|
||||||
|
@ -183,5 +185,37 @@ describe('ticket state()', () => {
|
||||||
throw e;
|
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;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ module.exports = Self => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
let newStateOrder;
|
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
@ -41,16 +40,11 @@ module.exports = Self => {
|
||||||
throw new UserError('State cannot be blank');
|
throw new UserError('State cannot be blank');
|
||||||
|
|
||||||
if (params.stateFk) {
|
if (params.stateFk) {
|
||||||
const {code, order} = await models.State.findById(
|
const {code} = await models.State.findById(params.stateFk, {fields: ['code']}, myOptions);
|
||||||
params.stateFk,
|
|
||||||
{fields: ['code', 'order']},
|
|
||||||
myOptions);
|
|
||||||
params.code = code;
|
params.code = code;
|
||||||
newStateOrder = order;
|
|
||||||
} else {
|
} 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;
|
params.stateFk = id;
|
||||||
newStateOrder = order;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!params.userFk) {
|
if (!params.userFk) {
|
||||||
|
@ -70,59 +64,7 @@ module.exports = Self => {
|
||||||
if ((ticketState && !oldStateAllowed) || !newStateAllowed)
|
if ((ticketState && !oldStateAllowed) || !newStateAllowed)
|
||||||
throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED');
|
throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED');
|
||||||
|
|
||||||
const ticket = await models.Ticket.findById(params.ticketFk, {
|
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [params.ticketFk, params.code], myOptions);
|
||||||
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);
|
|
||||||
|
|
||||||
const ticketTracking = await models.TicketTracking.findOne({
|
const ticketTracking = await models.TicketTracking.findOne({
|
||||||
where: {ticketFk: params.ticketFk},
|
where: {ticketFk: params.ticketFk},
|
||||||
|
|
|
@ -42,7 +42,9 @@ describe('worker setPassword()', () => {
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} 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();
|
await tx.rollback();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
? 'Click to allow the user to be disabled'
|
? 'Click to allow the user to be disabled'
|
||||||
: 'Click to exclude the user from getting disabled'}}
|
: 'Click to exclude the user from getting disabled'}}
|
||||||
</vn-item>
|
</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
|
Change password
|
||||||
</vn-item>
|
</vn-item>
|
||||||
</slot-menu>
|
</slot-menu>
|
||||||
|
|
Loading…
Reference in New Issue