fix: refs #6276 test item_card & general fixes
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-01-25 12:14:14 +01:00
parent 01340408c6
commit 63fb3db8a1
6 changed files with 27 additions and 25 deletions

View File

@ -13,16 +13,21 @@ module.exports = Self => {
},
});
Self.assignCollection = async ctx => {
Self.assignCollection = async(ctx, options) => {
const userId = ctx.req.accessToken.userId;
const myOptions = {userId};
const $t = ctx.req.__;
await Self.rawSql('CALL vn.collection_assign(?, @vCollectionFk)', [userId]);
if (typeof options == 'object')
Object.assign(myOptions, options);
await Self.rawSql('CALL vn.collection_assign(?, @vCollectionFk)', [userId], myOptions);
const [assignedCollection] = await Self.rawSql('SELECT @vCollectionFk');
const {'@vCollectionFk': collectionFk} = assignedCollection;
if (!collectionFk) throw new UserError('No hay tickets para sacar');
await Self.rawSql('CALL vn.collection_printSticker(?, NULL)', [collectionFk]);
if (!collectionFk) throw new UserError($t('There are not picking tickets'));
await Self.rawSql('CALL vn.collection_printSticker(?, NULL)', [collectionFk], myOptions);
return collectionFk;
};

View File

@ -30,8 +30,8 @@ module.exports = Self => {
Self.getSalesFromTicketOrCollection = async(ctx, collectionOrTicketFk, print, source, options) => {
const userId = ctx.req.accessToken.userId;
const models = Self.app.models;
const myOptions = {userId};
const $t = ctx.req.__;
if (typeof options == 'object')
Object.assign(myOptions, options);
@ -53,22 +53,20 @@ module.exports = Self => {
if (print) await Self.rawSql('CALL vn.collection_printSticker(?,NULL)', [id], myOptions);
if (tickets.length) await sendRocketTickets(tickets);
if (tickets.length) await sendRocketTickets(tickets, $t);
return getCollection(id, tickets, sales, placements, myOptions);
};
async function sendRocketTickets(tickets) {
async function sendRocketTickets(tickets, $t) {
for (let ticket of tickets) {
let observations = ticket.observaciones.split(' ');
for (let observation of observations) {
const salesMan = ticket.salesPersonFk;
if (!observation.startsWith('#') && !observation.startsWith('@')) return;
await models.Chat.send(ctx,
observation,
`El ticket ${ticket.ticketFk} del comercial ${salesMan} está en preparación.(mensaje creado automáticamente)`
$t('ticketCommercial', {ticket: ticket.ticketFk, salesMan})
);
}
}
@ -83,7 +81,7 @@ module.exports = Self => {
const {ticketFk} = ticket;
ticket.sales = [];
const barcodes = await getBarcodes(ticketFk);
const barcodes = await getBarcodes(ticketFk, options);
await Self.rawSql(
'CALL util.log_add(?, ?, ?, ?, ?, ?, ?, ?)',
['vn', 'ticket', 'Ticket', ticketFk, ticketFk, 'select', null, null],
@ -140,7 +138,7 @@ module.exports = Self => {
return collection;
}
async function getBarcodes(ticketId) {
async function getBarcodes(ticketId, options) {
const query =
`SELECT s.id movementId,
b.code,
@ -152,7 +150,7 @@ module.exports = Self => {
LEFT JOIN vn.travel tr ON tr.id = e.travelFk
WHERE s.ticketFk = ?
AND tr.landed >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR)`;
return Self.rawSql(query, [ticketId]);
return Self.rawSql(query, [ticketId], options);
}
async function setState(source, id, options) {

View File

@ -213,6 +213,8 @@
"this state does not exist": "This state does not exist",
"The line could not be marked": "The line could not be marked",
"The sale can not be tracked": "The sale can not be tracked",
"Shelving not valid": "Shelving not valid"
"Shelving not valid": "Shelving not valid",
"printerNotExists": "The printer does not exist",
"There are not picking tickets": "There are not picking tickets",
"ticketCommercial": "The ticket {{ ticket }} for the salesperson {{ salesMan }} is in preparation. (automatically generated message)"
}

View File

@ -352,5 +352,7 @@
"The sale can not be tracked": "La línea no puede ser rastreada",
"Shelving not valid": "Carro no válido",
"Carro no válido": "Carro no válido",
"printerNotExists": "printerNotExists"
"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)"
}

View File

@ -27,7 +27,7 @@ module.exports = Self => {
Self.card = async(itemFk, warehouseFk) => {
const models = Self.app.models;
const [result] = await Self.rawSql('CALL vn.item_getInfo(?, ?)', [itemFk, warehouseFk]);
const [[itemInfo]] = await Self.rawSql('CALL vn.item_getInfo(?, ?)', [itemFk, warehouseFk]);
const barcodeItems = await Self.rawSql('SELECT vn.barcodeToItem(?) as realIdItem', [itemFk]);
const [realIdItem] = barcodeItems.map(barcodeItem => barcodeItem.realIdItem);
@ -40,12 +40,7 @@ module.exports = Self => {
}
});
let itemInfo;
if (result.length) {
itemInfo = {...result[0]};
itemInfo.barcodes = barcodes;
}
if (itemInfo) itemInfo.barcodes = barcodes;
return itemInfo;
};
};

View File

@ -3,10 +3,10 @@ const {models} = require('vn-loopback/server/server');
describe('item card()', () => {
const itemFk = 1;
const warehouseFk = 1;
it('WIP: should get something', async() => {
it('should get an item with several barcodes', async() => {
const card = await models.Item.card(itemFk, warehouseFk);
expect(card).toBeDefined();
expect(card.barcodes);
expect(card.barcodes.length).toBeTruthy();
});
});