7167-testToMaster_2414 #2244

Merged
alexm merged 643 commits from 7167-testToMaster_2414 into master 2024-04-04 05:32:41 +00:00
6 changed files with 27 additions and 25 deletions
Showing only changes of commit 63fb3db8a1 - Show all commits

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 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 [assignedCollection] = await Self.rawSql('SELECT @vCollectionFk');
const {'@vCollectionFk': collectionFk} = assignedCollection; const {'@vCollectionFk': collectionFk} = assignedCollection;
if (!collectionFk) throw new UserError('No hay tickets para sacar'); if (!collectionFk) throw new UserError($t('There are not picking tickets'));
await Self.rawSql('CALL vn.collection_printSticker(?, NULL)', [collectionFk]); await Self.rawSql('CALL vn.collection_printSticker(?, NULL)', [collectionFk], myOptions);
return collectionFk; return collectionFk;
}; };

View File

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

View File

@ -213,6 +213,8 @@
"this state does not exist": "This state 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 line could not be marked": "The line could not be marked",
"The sale can not be tracked": "The sale can not be tracked", "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", "The sale can not be tracked": "La línea no puede ser rastreada",
"Shelving not valid": "Carro no válido", "Shelving not valid": "Carro no válido",
"Carro no válido": "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) => { Self.card = async(itemFk, warehouseFk) => {
const models = Self.app.models; 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 barcodeItems = await Self.rawSql('SELECT vn.barcodeToItem(?) as realIdItem', [itemFk]);
const [realIdItem] = barcodeItems.map(barcodeItem => barcodeItem.realIdItem); const [realIdItem] = barcodeItems.map(barcodeItem => barcodeItem.realIdItem);
@ -40,12 +40,7 @@ module.exports = Self => {
} }
}); });
let itemInfo; if (itemInfo) itemInfo.barcodes = barcodes;
if (result.length) {
itemInfo = {...result[0]};
itemInfo.barcodes = barcodes;
}
return itemInfo; return itemInfo;
}; };
}; };

View File

@ -3,10 +3,10 @@ const {models} = require('vn-loopback/server/server');
describe('item card()', () => { describe('item card()', () => {
const itemFk = 1; const itemFk = 1;
const warehouseFk = 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); const card = await models.Item.card(itemFk, warehouseFk);
expect(card).toBeDefined(); expect(card).toBeDefined();
expect(card.barcodes); expect(card.barcodes.length).toBeTruthy();
}); });
}); });