Merge branch 'master' into 6404-sendMailOnDeadLine
gitea/salix/pipeline/pr-master This commit looks good
Details
gitea/salix/pipeline/pr-master This commit looks good
Details
This commit is contained in:
commit
47eb6dd8fe
|
@ -1,5 +1,8 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`debugAdd`(vVariable VARCHAR(255), vValue VARCHAR(255))
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `util`.`debugAdd`(
|
||||||
|
vVariable VARCHAR(255),
|
||||||
|
vValue TEXT
|
||||||
|
)
|
||||||
MODIFIES SQL DATA
|
MODIFIES SQL DATA
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -28,6 +28,8 @@ BEGIN
|
||||||
DECLARE vLockName VARCHAR(215);
|
DECLARE vLockName VARCHAR(215);
|
||||||
DECLARE vLockTime INT DEFAULT 30;
|
DECLARE vLockTime INT DEFAULT 30;
|
||||||
DECLARE vFreeWagonFk INT;
|
DECLARE vFreeWagonFk INT;
|
||||||
|
DECLARE vErrorNumber INT;
|
||||||
|
DECLARE vErrorMsg TEXT;
|
||||||
|
|
||||||
DECLARE c1 CURSOR FOR
|
DECLARE c1 CURSOR FOR
|
||||||
SELECT ticketFk, `lines`, m3
|
SELECT ticketFk, `lines`, m3
|
||||||
|
@ -47,12 +49,18 @@ BEGIN
|
||||||
|
|
||||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||||
BEGIN
|
BEGIN
|
||||||
|
GET DIAGNOSTICS CONDITION 1
|
||||||
|
vErrorNumber = MYSQL_ERRNO,
|
||||||
|
vErrorMsg = MESSAGE_TEXT;
|
||||||
|
|
||||||
IF vLockName IS NOT NULL THEN
|
IF vLockName IS NOT NULL THEN
|
||||||
DO RELEASE_LOCK(vLockName);
|
DO RELEASE_LOCK(vLockName);
|
||||||
CALL util.debugAdd(JSON_OBJECT(
|
CALL util.debugAdd('collection_new', JSON_OBJECT(
|
||||||
'type', 'releaseLock',
|
'errorNumber', vErrorNumber,
|
||||||
'userFk', vUserFk
|
'errorMsg', vErrorMsg,
|
||||||
), vLockName); -- Tmp
|
'lockName', vLockName,
|
||||||
|
'userFk', vUserFk
|
||||||
|
)); -- Tmp
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
RESIGNAL;
|
RESIGNAL;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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},
|
||||||
|
|
Loading…
Reference in New Issue