fix: refs #6276 fix tests
gitea/salix/pipeline/head Build queued... Details

This commit is contained in:
Jorge Penadés 2024-01-25 08:13:47 +01:00
parent e527780622
commit 02e38eb711
6 changed files with 124 additions and 105 deletions

View File

@ -46,7 +46,7 @@ module.exports = Self => {
}
try {
const [[item]] = await Self.rawSql('CALL vn.item_getInfo(?,?)', [code, warehouseFk]);
const [[item]] = await Self.rawSql('CALL vn.item_getInfo(?,?)', [code, warehouseFk], myOptions);
if (!item?.available) throw new UserError($t('We do not have availability for the selected item'));

View File

@ -56,92 +56,92 @@ module.exports = Self => {
if (tickets.length) await sendRocketTickets(tickets);
return getCollection(id, tickets, sales, placements, myOptions);
};
async function sendRocketTickets(tickets) {
for (let ticket of tickets) {
let observations = ticket.observaciones.split(' ');
async function sendRocketTickets(tickets) {
for (let ticket of tickets) {
let observations = ticket.observaciones.split(' ');
for (let observation of observations) {
const salesMan = ticket.salesPersonFk;
for (let observation of observations) {
const salesMan = ticket.salesPersonFk;
if (!observation.startsWith('#') && !observation.startsWith('@')) return;
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)`
);
}
}
}
async function getCollection(id, tickets, sales, placements, options) {
const collection = {
collectionFk: id,
tickets: [],
};
for (let ticket of tickets) {
const {ticketFk} = ticket;
ticket.sales = [];
const barcodes = await getBarcodes(ticketFk);
await Self.rawSql(
'CALL util.log_add(?, ?, ?, ?, ?, ?, ?, ?)',
['vn', 'ticket', 'Ticket', ticketFk, ticketFk, 'select', null, null],
options
await models.Chat.send(ctx,
observation,
`El ticket ${ticket.ticketFk} del comercial ${salesMan} está en preparación.(mensaje creado automáticamente)`
);
for (let sale of sales) {
if (sale.ticketFk == ticketFk) {
sale.placements = [];
for (const salePlacement of placements) {
let placement;
if (salePlacement.saleFk == sale.saleFk && salePlacement.order) {
placement = {
saleFk: salePlacement.saleFk,
itemFk: salePlacement.itemFk,
placement: salePlacement.placement,
shelving: salePlacement.shelving,
created: salePlacement.created,
visible: salePlacement.visible,
order: salePlacement.order,
grouping: salePlacement.grouping,
priority: salePlacement.priority,
saleOrder: salePlacement.saleOrder,
isPreviousPrepared: salePlacement.isPreviousPrepared,
itemShelvingSaleFk: salePlacement.itemShelvingSaleFk,
ticketFk: salePlacement.ticketFk,
id: salePlacement.id
};
sale.placements.push(placement);
}
}
sale.barcodes = [];
for (const barcode of barcodes) {
if (barcode.movementId == sale.saleFk) {
if (barcode.code) {
sale.barcodes.push(barcode.code);
sale.barcodes.push(`0 ${barcode.code}`);
}
if (barcode.id) {
sale.barcodes.push(barcode.id);
sale.barcodes.push(`0 ${barcode.id}`);
}
}
}
ticket.sales.push(sale);
}
}
collection.tickets.push(ticket);
}
}
}
return collection;
async function getCollection(id, tickets, sales, placements, options) {
const collection = {
collectionFk: id,
tickets: [],
};
for (let ticket of tickets) {
const {ticketFk} = ticket;
ticket.sales = [];
const barcodes = await getBarcodes(ticketFk);
await Self.rawSql(
'CALL util.log_add(?, ?, ?, ?, ?, ?, ?, ?)',
['vn', 'ticket', 'Ticket', ticketFk, ticketFk, 'select', null, null],
options
);
for (let sale of sales) {
if (sale.ticketFk == ticketFk) {
sale.placements = [];
for (const salePlacement of placements) {
let placement;
if (salePlacement.saleFk == sale.saleFk && salePlacement.order) {
placement = {
saleFk: salePlacement.saleFk,
itemFk: salePlacement.itemFk,
placement: salePlacement.placement,
shelving: salePlacement.shelving,
created: salePlacement.created,
visible: salePlacement.visible,
order: salePlacement.order,
grouping: salePlacement.grouping,
priority: salePlacement.priority,
saleOrder: salePlacement.saleOrder,
isPreviousPrepared: salePlacement.isPreviousPrepared,
itemShelvingSaleFk: salePlacement.itemShelvingSaleFk,
ticketFk: salePlacement.ticketFk,
id: salePlacement.id
};
sale.placements.push(placement);
}
}
sale.barcodes = [];
for (const barcode of barcodes) {
if (barcode.movementId == sale.saleFk) {
if (barcode.code) {
sale.barcodes.push(barcode.code);
sale.barcodes.push(`0 ${barcode.code}`);
}
if (barcode.id) {
sale.barcodes.push(barcode.id);
sale.barcodes.push(`0 ${barcode.id}`);
}
}
}
ticket.sales.push(sale);
}
}
collection.tickets.push(ticket);
}
async function getBarcodes(ticketId) {
const query =
return collection;
}
async function getBarcodes(ticketId) {
const query =
`SELECT s.id movementId,
b.code,
c.id
@ -152,21 +152,20 @@ 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]);
}
async function setState(source, id, options) {
let state;
if (source == 'PRECHECKER') state = 'PREVIOUS_CONTROL';
else if (source == 'CHECKER') state = 'ON_CHECKING';
async function setState(source, id, options) {
let state;
if (source == 'PRECHECKER') state = 'PREVIOUS_CONTROL';
else if (source == 'CHECKER') state = 'ON_CHECKING';
if (state) {
await Self.rawSql(
'CALL vn.ticketStateToday_setState(?,?)',
[id, state],
options
);
}
if (state) {
await Self.rawSql(
'CALL vn.ticketStateToday_setState(?,?)',
[id, state],
options
);
}
};
}
};

View File

@ -43,11 +43,14 @@ describe('collection getSalesFromTicketOrCollection()', () => {
it('should print a sticker', async() => {
const tx = await models.Collection.beginTransaction({});
const options = {transaction: tx};
const query = 'SELECT * FROM printQueue pq JOIN printQueueArgs pqa ON pqa.printQueueFk = pq.id';
try {
const printQueueBefore = await models.Collection.rawSql('SELECT * FROM printQueue', [], options);
const printQueueBefore = await models.Collection.rawSql(
query, [], options);
await models.Collection.getSalesFromTicketOrCollection(ctx,
collectionOrTicketFk, print, source, options);
const printQueueAfter = await models.Collection.rawSql('SELECT * FROM printQueue', [], options);
collectionOrTicketFk, true, source, options);
const printQueueAfter = await models.Collection.rawSql(
query, [], options);
expect(printQueueAfter.length).toEqual(printQueueBefore.length + 1);
await tx.rollback();
@ -56,4 +59,24 @@ describe('collection getSalesFromTicketOrCollection()', () => {
throw e;
}
});
it('should getSalesFromTicketOrCollection', async() => {
const tx = await models.Collection.beginTransaction({});
try {
const options = {transaction: tx};
await models.Ticket.updateAll({id: collectionOrTicketFk}, {shipped: '2001-01-02 00:00:00.000'}, options);
const ticketTrackingBefore = await models.TicketTracking.find(null, options);
await models.Collection.getSalesFromTicketOrCollection(ctx,
collectionOrTicketFk, false, source, options);
const ticketTrackingAfter = await models.TicketTracking.find(null, options);
expect(ticketTrackingAfter.length).toEqual(ticketTrackingBefore.length + 1);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -47,7 +47,8 @@ module.exports = Self => {
}, 0);
discardItems.push(item);
const [result] = await Self.rawSql('SELECT vn.itemPacking(?, ?) itemPacking', [item, warehouseFk]);
const [result] = await Self.rawSql('SELECT vn.itemPacking(?, ?) itemPacking',
[item, warehouseFk], myOptions);
let packing;
if (result) packing = result.itemPacking;
@ -56,11 +57,7 @@ module.exports = Self => {
quantity = quantity * packing;
await Self.rawSql('CALL vn.itemShelving_add(?, ?, ?, NULL, NULL, ?, ?)',
[shelvingFk,
item,
quantity,
packing,
warehouseFk]
[shelvingFk, item, quantity, packing, warehouseFk], myOptions
);
}
}

View File

@ -39,8 +39,8 @@ module.exports = Self => {
};
let itemShelvings = await models.ItemShelving.find(filterItemShelvings, myOptions);
const [alternatives] = await models.ItemShelving.rawSql(
'CALL vn.itemShelving_getAlternatives(?)', [shelvingFk]
const [alternatives] = await models.ItemShelving.rawSql('CALL vn.itemShelving_getAlternatives(?)',
[shelvingFk], myOptions
);
if (itemShelvings) {

View File

@ -96,7 +96,7 @@ module.exports = Self => {
neq: null
}
}
});
}, myOptions);
}
if (isBuy)
await models.SaleBuy.create({saleFk, buyFk}, myOptions);