#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
4 changed files with 76 additions and 32 deletions
Showing only changes of commit 08dd37e9e4 - Show all commits

View File

@ -7,18 +7,11 @@ module.exports = Self => {
arg: 'collectionOrTicketFk',
type: 'number',
required: true
},
{
arg: 'sectorFk',
type: 'number',
}, {
arg: 'print',
type: 'boolean',
required: true
},
{
arg: 'printFk',
type: 'number',
required: true
},
{
}, {
arg: 'source',
type: 'string',
required: true
@ -35,36 +28,34 @@ module.exports = Self => {
},
});
Self.getSalesFromTicketOrCollection = async(ctx, collectionOrTicketFk, sectorFk, printFk, source, options) => {
Self.getSalesFromTicketOrCollection = async(ctx, collectionOrTicketFk, print, source, options) => {
const userId = ctx.req.accessToken.userId;
const models = Self.app.models;
const myOptions = {};
const myOptions = {userId};
if (typeof options == 'object')
Object.assign(myOptions, options);
const [collectionOrTicket] = await Self.rawSql('SELECT vn.ticket_get(?) as id', [collectionOrTicketFk]);
const [{id}] = await Self.rawSql('SELECT vn.ticket_get(?) as id',
[collectionOrTicketFk],
myOptions);
const [tickets] = await Self.rawSql('CALL vn.collection_getTickets(?)', [collectionOrTicket.id]);
const [tickets] = await Self.rawSql('CALL vn.collection_getTickets(?)', [id], myOptions);
if (source == 'PRECHECKER' || source == 'ON_CHECKING') {
await Self.rawSql(
'CALL vn.ticketStateToday_setState(?,?)',
[collectionOrTicket.id, source]
);
}
const [sales] = await Self.rawSql('CALL vn.sale_getFromTicketOrCollection(?)', [collectionOrTicket.id]);
await setState(source, id, myOptions);
const [sales] = await Self.rawSql('CALL vn.sale_getFromTicketOrCollection(?)',
[id], myOptions);
const isPicker = source == 'CHECKER';
const [placements] = await Self.rawSql(
'CALL vn.collectionPlacement_get(?, ?)', [collectionOrTicket.id, isPicker]
const [placements] = await Self.rawSql('CALL vn.collectionPlacement_get(?, ?)',
[id, isPicker], myOptions
);
if (printFk == 1) await Self.rawSql('CALL vn.collection_printSticker(?,NULL)', [collectionOrTicket.id]);
if (print) await Self.rawSql('CALL vn.collection_printSticker(?,NULL)', [id], myOptions);
if (tickets.length) await sendRocketTickets(tickets);
return getCollection(collectionOrTicket.id, tickets, sales, placements);
return getCollection(id, tickets, sales, placements, myOptions);
async function sendRocketTickets(tickets) {
for (let ticket of tickets) {
@ -83,7 +74,7 @@ module.exports = Self => {
}
}
async function getCollection(id, tickets, sales, placements) {
async function getCollection(id, tickets, sales, placements, options) {
const collection = {
collectionFk: id,
tickets: [],
@ -95,7 +86,8 @@ module.exports = Self => {
const barcodes = await getBarcodes(ticketFk);
await Self.rawSql(
'CALL util.log_add(?, ?, ?, ?, ?, ?, ?, ?)',
['vn', 'ticket', 'Ticket', ticketFk, ticketFk, 'select', null, null]
['vn', 'ticket', 'Ticket', ticketFk, ticketFk, 'select', null, null],
options
);
for (let sale of sales) {
@ -106,7 +98,7 @@ module.exports = Self => {
sale.barcodes = [];
for (const barcode of barcodes) {
if (barcode.movementId) {
if (barcode.movementId == sale.saleFk) {
if (barcode.code) {
sale.barcodes.push(barcode.code);
sale.barcodes.push(`0 ${barcode.code}`);
@ -142,5 +134,19 @@ module.exports = Self => {
AND tr.landed >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR)`;
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';
if (state) {
await Self.rawSql(
'CALL vn.ticketStateToday_setState(?,?)',
[id, source],
options
);
}
}
};
};

View File

@ -0,0 +1,35 @@
const {models} = require('vn-loopback/server/server');
fdescribe('collection getSalesFromTicketOrCollection()', () => {
const collectionOrTicketFk = 999999;
const print = true;
const source = 'CHECKER';
beforeAll(() => {
ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'http://localhost'},
}
};
});
it('should return a collection with tickets, placements and barcodes settled correctly', async() => {
const options = {};
const collection = await models.Collection.getSalesFromTicketOrCollection(ctx,
collectionOrTicketFk, print, source, options);
const [firstTicket] = collection.tickets;
const [firstSale] = firstTicket.sales;
const [firstPlacement] = firstSale.placements;
expect(collection.tickets.length).toBeGreaterThan(0);
expect(collection.collectionFk).toEqual(firstTicket.ticketFk);
expect(firstSale.ticketFk).toEqual(firstTicket.ticketFk);
expect(firstSale.placements.length).toBeGreaterThan(0);
expect(firstSale.barcodes.length).toBeGreaterThan(0);
expect(firstSale.saleFk).toEqual(firstPlacement.saleFk);
});
});

View File

@ -3711,4 +3711,6 @@ INSERT INTO vn.machineWorker(workerFk,machineFk,inTimed) VALUES (104,1,'2001-01-
UPDATE vn.buy SET itemOriginalFk = 1 WHERE id = 1;
UPDATE vn.saleTracking SET stateFk = 26 WHERE id = 5;
UPDATE vn.saleTracking SET stateFk = 26 WHERE id = 5;
INSERT INTO vn.report (name) VALUES ('LabelCollection')

View File

@ -351,5 +351,6 @@
"No se ha podido marcar la línea": "No se ha podido marcar la línea",
"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"
"Carro no válido": "Carro no válido",
"printerNotExists": "printerNotExists"
}