#6276 createNewWarehouse methods migrated from silex to salix #1850

Merged
jorgep merged 158 commits from 6276-createNewWarehouse into dev 2024-03-06 11:32:11 +00:00
6 changed files with 124 additions and 105 deletions
Showing only changes of commit 02e38eb711 - Show all commits

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'));
jorgep marked this conversation as resolved Outdated
Outdated
Review

No hace falta usar $t, UserError traduce por defecto.

No hace falta usar $t, UserError traduce por defecto.

Ahora el error se maneja desde Sale.js

Ahora el error se maneja desde Sale.js

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;
jorgep marked this conversation as resolved Outdated

salesPerson

salesPerson
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 = [];
jorgep marked this conversation as resolved Outdated

si solo se usa en el if, porque no la defines dentro?

si solo se usa en el if, porque no la defines dentro?

@jgallego que quieres decir?

@jgallego que quieres decir?

la variable let placement moverla 2 linea abajo, incluso valorar si es const

la variable let placement moverla 2 linea abajo, incluso valorar si es const

debería ser const e ir dentro. Lo cambio

debería ser const e ir dentro. Lo cambio
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]);
}
jorgep marked this conversation as resolved Outdated
Outdated
Review

Aço se pot refactoritzar per
const STATES= {
'PRECHECKER': 'PREVIOUS_CONTROL',
'CHECKER': 'ON_CHECKING'
}

if(STATES[source])

Aço se pot refactoritzar per const STATES= { 'PRECHECKER': 'PREVIOUS_CONTROL', 'CHECKER': 'ON_CHECKING' } if(STATES[source])
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, ?, ?)',
jorgep marked this conversation as resolved Outdated
Outdated
Review

En salix para poder loggear los cambios en CALLs hace falta que el myOptions tenga el userId

En salix para poder loggear los cambios en CALLs hace falta que el myOptions tenga el userId

https://redmine.verdnatura.es/issues/6776 se ha pasado este procedimiento a esta tarea. lo añado ahí para que quien la coja lo tenga puesto.

https://redmine.verdnatura.es/issues/6776 se ha pasado este procedimiento a esta tarea. lo añado ahí para que quien la coja lo tenga puesto.
[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(?)',
jorgep marked this conversation as resolved Outdated

si eso se usa en el if, porque no lo mueves dentro, así en los casos que no haya itemShelvings no es necesario ejecutarlo?

si eso se usa en el if, porque no lo mueves dentro, así en los casos que no haya itemShelvings no es necesario ejecutarlo?
[shelvingFk], myOptions
jorgep marked this conversation as resolved Outdated
Outdated
Review

En salix para poder loggear los cambios en CALLs hace falta que el myOptions tenga el userId

En salix para poder loggear los cambios en CALLs hace falta que el myOptions tenga el userId
);
if (itemShelvings) {

View File

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