fix: refs #6703 tests & backs

This commit is contained in:
Jorge Penadés 2024-01-31 13:11:15 +01:00
parent 2c1b8bd9db
commit 8f5a5d9cba
14 changed files with 19 additions and 149 deletions

View File

@ -154,15 +154,13 @@ module.exports = Self => {
}
async function setState(source, id, options) {
let state;
if (source == 'PRECHECKER') state = 'PREVIOUS_CONTROL';
else if (source == 'CHECKER') state = 'ON_CHECKING';
if (state) {
const states = {
'PRECHECKER': 'PREVIOUS_CONTROL',
'CHECKER': 'ON_CHECKING'
};
if (states[source]) {
await Self.rawSql(
'CALL vn.ticketStateToday_setState(?,?)',
[id, state],
options
'CALL vn.ticketStateToday_setState(?,?)', [id, states[source]], options
);
}
}

View File

@ -1,18 +0,0 @@
-- Place your SQL code here
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
VALUES
('Collection', 'assignCollection', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
('ExpeditionPallet', 'getPallet', 'READ', 'ALLOW', 'ROLE', 'employee'),
('MachineWorker','updateInTime','WRITE','ALLOW','ROLE','employee'),
('MobileAppVersionControl','getVersion','READ','ALLOW','ROLE','employee'),
('SaleTracking','deleteTracking','WRITE','ALLOW','ROLE','employee'),
('SaleTracking','updateTracking','WRITE','ALLOW','ROLE','employee'),
('SaleTracking','mark','WRITE','ALLOW','ROLE','employee'),
('ItemBarcode','deleteByItemAndCode','WRITE','ALLOW','ROLE','employee'),
('Collection','addItem','WRITE','ALLOW','ROLE','employee'),
('ExpeditionPallet', '*', 'READ', 'ALLOW', 'ROLE', 'production'),
('MobileAppVersionControl', '*', 'READ', 'ALLOW', 'ROLE', 'production'),
('Collection', 'assignCollection', 'WRITE', 'ALLOW', 'ROLE', 'production'),
('Sale', 'getFromSectorCollection', 'READ', 'ALLOW', 'ROLE', 'employee'),
('Collection', 'addItem', 'WRITE', 'ALLOW', 'ROLE', 'production');

View File

@ -206,10 +206,8 @@
"Incorrect pin": "Incorrect pin.",
"This machine is already in use.": "This machine is already in use.",
"the plate does not exist": "The plate {{plate}} does not exist",
"This pallet does not exist": "This pallet does not exist",
"We do not have availability for the selected item": "We do not have availability for the selected item",
"You are already using a machine": "You are already using a machine",
"This worker does not exist": "This worker does not exist",
"this state does not exist": "This state does not exist",
"The line could not be marked": "The line could not be marked",
"The sale cannot be tracked": "The sale cannot be tracked",

View File

@ -341,15 +341,14 @@
"There is no zone for these parameters 999999": "There is no zone for these parameters 999999",
"This machine is already in use.": "Esta máquina ya está en uso.",
"the plate does not exist": "La máquina {{plate}} no existe",
"This pallet does not exist": "Este palet no existe",
"We do not have availability for the selected item": "No tenemos disponible el item seleccionado",
"You are already using a machine": "Ya estás usando una máquina.",
"This worker does not exist": "Este trabajador no existe",
"this state does not exist": "Este estado no existe",
"The line could not be marked": "No se ha podido marcar la línea",
"The sale cannot be tracked": "La línea no puede ser rastreada",
"Shelving not valid": "Carro no válido",
"printerNotExists": "No existe la impresora",
"There are not picking tickets": "No hay tickets para sacar",
"ticketCommercial": "El ticket {{ticket}} del comercial {{salesMan}} está en preparación.(mensaje creado automáticamente)"
"ticketCommercial": "El ticket {{ticket}} del comercial {{salesMan}} está en preparación.(mensaje creado automáticamente)",
"Este trabajador no existe": "Este trabajador no existe"
}

View File

@ -1,60 +0,0 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('getPallet', {
description: 'Get pallet',
accessType: 'READ',
accepts: [
{
arg: 'expeditionFk',
type: 'integer',
},
],
http: {
path: `/getPallet`,
verb: 'GET'
},
returns: {
type: 'object',
root: true
},
});
Self.getPallet = async(ctx, expeditionFk, options) => {
const myOptions = {};
const $t = ctx.req.__;
if (typeof options == 'object')
Object.assign(myOptions, options);
try {
const pallet = await Self.findOne({
fields: ['truckFk'],
where: {
id: expeditionFk
},
include: [
{
relation: 'expeditionTruck',
scope: {
fields: ['eta', 'description']
}
}
],
}, myOptions);
if (pallet) {
const truck = pallet.expeditionTruck();
return {
truckFk: pallet.truckFk,
eta: truck.eta,
description: truck.description
};
}
throw new UserError($t('This pallet does not exist'));
} catch (e) {
return {message: e.message};
}
};
};

View File

@ -1,32 +0,0 @@
const {models} = require('vn-loopback/server/server');
describe('expeditonPallet getPallet()', () => {
beforeAll(async() => {
ctx = {
req: {
headers: {origin: 'http://localhost'},
__: value => value
}
};
});
it('should obtain the pallet data', async() => {
const palletId = 1;
const pallet = await models.ExpeditionPallet.getPallet(ctx, palletId);
expect(pallet).toBeDefined();
expect(pallet.truckFk).toEqual(1);
expect(pallet.description).toEqual('BEST TRUCK IN FLEET');
});
it('should throw an error when the pallet does not exist', async() => {
const palletId = 600;
try {
await models.ExpeditionPallet.getPallet(ctx, palletId);
} catch (e) {
const error = e;
expect(error.message).toEqual('This pallet does not exist');
}
});
});

View File

@ -14,10 +14,6 @@ module.exports = Self => {
type: ['string']
},
],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/delete`,
verb: 'POST'
@ -63,8 +59,6 @@ module.exports = Self => {
await saleTracking.destroy(myOptions);
if (tx) await tx.commit();
return true;
} catch (e) {
if (tx) await tx.rollback();
throw e;

View File

@ -54,7 +54,6 @@ module.exports = Self => {
Self.mark = async(ctx, saleFk, originalQuantity, code, isChecked, buyFk, isScanned, quantity, itemShelvingFk, options) => {
const userId = ctx.req.accessToken.userId;
const models = Self.app.models;
const $t = ctx.req.__;
const myOptions = {};
let tx;
@ -90,18 +89,18 @@ module.exports = Self => {
const buy = await models.Buy.findById(buyFk, myOptions);
if (buy.itemOriginalFk) await models.SaleBuy.create({saleFk, buyFk}, myOptions);
} catch (e) {
throw new UserError($t('The sale cannot be tracked'));
throw new UserError('The sale cannot be tracked');
}
if (tx) await tx.commit();
} catch (e) {
if (e.message == $t('The sale cannot be tracked')) {
if (e.message == 'The sale cannot be tracked') {
if (tx) tx.commit();
throw e;
}
if (tx) await tx.rollback();
throw new UserError($t('The line could not be marked'));
throw new UserError('The line could not be marked');
}
};
};

View File

@ -12,12 +12,11 @@ describe('sale-tracking delete()', () => {
const saleFk = 1;
const stateCode = ['PREPARED'];
const result = await models.SaleTracking.delete(saleFk, stateCode, options);
await models.SaleTracking.delete(saleFk, stateCode, options);
const itemShelvingsAfter = await models.ItemShelvingSale.find(null, options);
const saleTrackingsAfter = await models.SaleTracking.find(null, options);
expect(result).toEqual(true);
expect(saleTrackingsAfter.length).toBeLessThan(saleTrackingsBefore.length);
expect(itemShelvingsAfter.length).toBeLessThan(itemShelvingsBefore.length);

View File

@ -43,7 +43,6 @@ module.exports = Self => {
Self.updateTracking = async(ctx, saleFk, originalQuantity, code, isChecked, buyFk, isScanned = null, options) => {
const userId = ctx.req.accessToken.userId;
const models = Self.app.models;
const $t = ctx.req.__;
const myOptions = {};
let tx;
@ -60,7 +59,7 @@ module.exports = Self => {
where: {code},
}, myOptions);
if (!state) throw new UserError($t('this state does not exist'));
if (!state) throw new UserError('this state does not exist');
const uniqueAttributes = {
saleFk,
workerFk: userId,

View File

@ -1,3 +0,0 @@
module.exports = function(Self) {
require('../methods/expedition-pallet/getPallet')(Self);
};

View File

@ -9,8 +9,7 @@
"properties": {
"saleFk": {
"id": true,
"type": "number",
"forceId": false
"type": "number"
},
"buyFk": {
"type": "number"

View File

@ -72,7 +72,7 @@ module.exports = Self => {
if (item.family == 'EMB') return;
const isInPreparing = await models.ACL.checkAccessAcl(ctx, 'Sale', 'isInPreparing', '*');
if (!ctx.isNEwInstance && isInPreparing) return;
if (!ctx.isNewInstance && isInPreparing) return;
await models.Sale.rawSql(`CALL catalog_calcFromItem(?,?,?,?)`, [
ticket.landed,

View File

@ -1,4 +1,3 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('add', {
description: 'Add a new operator',
@ -12,7 +11,6 @@ module.exports = Self => {
Self.add = async(ctx, options) => {
const userId = ctx.req.accessToken.userId;
const myOptions = {};
const $t = ctx.req.__;
let tx;
if (typeof options == 'object')
@ -24,13 +22,13 @@ module.exports = Self => {
}
try {
await Self.create({
workerFk: userId
});
const isOperator = await Self.findById(user, myOptions);
if (!isOperator) await Self.create({workerFk: userId}, myOptions);
if (tx) await tx.commit();
} catch (e) {
if (tx) await tx.rollback();
throw new UserError($t('This worker does not exist'));
throw e;
}
};
};