#6321 - Negative tickets #1945
|
@ -33,83 +33,83 @@ module.exports = Self => {
|
|||
const query = [
|
||||
filter.itemFk,
|
||||
where.warehouseFk,
|
||||
jsegarra marked this conversation as resolved
Outdated
|
||||
where.date ?? '2025-01-28',
|
||||
where.date ?? Date.vnNew().toISOString().split('T')[0],
|
||||
where.showType ?? true,
|
||||
jgallego marked this conversation as resolved
Outdated
jgallego
commented
aqui asume que te pasan siempre estos 3 parametros aqui asume que te pasan siempre estos 3 parametros
jsegarra
commented
Al procedimiento si, desde front son opcionales Al procedimiento si, desde front son opcionales
Los valores que ves, son los mismos que hay en la tabla de access
jsegarra
commented
creo que ya veo lo que quieres decir creo que ya veo lo que quieres decir
jsegarra
commented
cambiado cambiado
|
||||
where.scopeDays ?? 2
|
||||
];
|
||||
const [results] = await Self.rawSql('CALL vn.item_getSimilar(?, ?, ?, ?, ?)', query, myOptions);
|
||||
return results
|
||||
// return [
|
||||
// {
|
||||
// 'id': 1,
|
||||
// 'longName': 'Ranged weapon longbow 50cm',
|
||||
// 'subName': 'Stark Industries',
|
||||
// 'tag5': 'Color',
|
||||
// 'value5': 'Brown',
|
||||
// 'match5': 0,
|
||||
// 'match6': 0,
|
||||
// 'match7': 0,
|
||||
// 'match8': 1,
|
||||
// 'tag6': 'Categoria',
|
||||
// 'value6': '+1 precission',
|
||||
// 'tag7': 'Tallos',
|
||||
// 'value7': '1',
|
||||
// 'tag8': null,
|
||||
// 'value8': null,
|
||||
// 'available': 20,
|
||||
// 'calc_id': 6,
|
||||
// 'counter': 0,
|
||||
// 'minQuantity': 1,
|
||||
// 'visible': null,
|
||||
// 'price2': 1
|
||||
// },
|
||||
// {
|
||||
// 'id': 2,
|
||||
// 'longName': 'Ranged weapon longbow 100cm',
|
||||
// 'subName': 'Stark Industries',
|
||||
// 'tag5': 'Color',
|
||||
// 'value5': 'Brown',
|
||||
// 'match5': 0,
|
||||
// 'match6': 1,
|
||||
// 'match7': 0,
|
||||
// 'match8': 1,
|
||||
// 'tag6': 'Categoria',
|
||||
// 'value6': '+1 precission',
|
||||
// 'tag7': 'Tallos',
|
||||
// 'value7': '1',
|
||||
// 'tag8': null,
|
||||
// 'value8': null,
|
||||
// 'available': 50,
|
||||
// 'calc_id': 6,
|
||||
// 'counter': 1,
|
||||
// 'minQuantity': 5,
|
||||
// 'visible': null,
|
||||
// 'price2': 10
|
||||
// },
|
||||
// {
|
||||
// 'id': 3,
|
||||
// 'longName': 'Ranged weapon longbow 200cm',
|
||||
// 'subName': 'Stark Industries',
|
||||
// 'tag5': 'Color',
|
||||
// 'value5': 'Brown',
|
||||
// 'match5': 1,
|
||||
// 'match6': 1,
|
||||
// 'match7': 1,
|
||||
// 'match8': 1,
|
||||
// 'tag6': 'Categoria',
|
||||
// 'value6': '+1 precission',
|
||||
// 'tag7': 'Tallos',
|
||||
// 'value7': '1',
|
||||
// 'tag8': null,
|
||||
// 'value8': null,
|
||||
// 'available': 185,
|
||||
// 'calc_id': 6,
|
||||
// 'counter': 10,
|
||||
// 'minQuantity': 10,
|
||||
// 'visible': null,
|
||||
// 'price2': 100
|
||||
// }
|
||||
// return results
|
||||
return [
|
||||
{
|
||||
'id': 1,
|
||||
'longName': 'Ranged weapon longbow 50cm',
|
||||
'subName': 'Stark Industries',
|
||||
'tag5': 'Color',
|
||||
'value5': 'Brown',
|
||||
'match5': 0,
|
||||
'match6': 0,
|
||||
'match7': 0,
|
||||
'match8': 1,
|
||||
'tag6': 'Categoria',
|
||||
'value6': '+1 precission',
|
||||
'tag7': 'Tallos',
|
||||
'value7': '1',
|
||||
'tag8': null,
|
||||
'value8': null,
|
||||
'available': 20,
|
||||
'calc_id': 6,
|
||||
'counter': 0,
|
||||
'minQuantity': 1,
|
||||
'visible': null,
|
||||
'price2': 1
|
||||
},
|
||||
{
|
||||
'id': 2,
|
||||
'longName': 'Ranged weapon longbow 100cm',
|
||||
'subName': 'Stark Industries',
|
||||
'tag5': 'Color',
|
||||
'value5': 'Brown',
|
||||
'match5': 0,
|
||||
'match6': 1,
|
||||
'match7': 0,
|
||||
'match8': 1,
|
||||
'tag6': 'Categoria',
|
||||
'value6': '+1 precission',
|
||||
'tag7': 'Tallos',
|
||||
'value7': '1',
|
||||
'tag8': null,
|
||||
'value8': null,
|
||||
'available': 50,
|
||||
'calc_id': 6,
|
||||
'counter': 1,
|
||||
'minQuantity': 5,
|
||||
'visible': null,
|
||||
'price2': 10
|
||||
},
|
||||
{
|
||||
'id': 3,
|
||||
'longName': 'Ranged weapon longbow 200cm',
|
||||
'subName': 'Stark Industries',
|
||||
'tag5': 'Color',
|
||||
'value5': 'Brown',
|
||||
'match5': 1,
|
||||
'match6': 1,
|
||||
'match7': 1,
|
||||
'match8': 1,
|
||||
'tag6': 'Categoria',
|
||||
'value6': '+1 precission',
|
||||
'tag7': 'Tallos',
|
||||
'value7': '1',
|
||||
'tag8': null,
|
||||
'value8': null,
|
||||
'available': 185,
|
||||
'calc_id': 6,
|
||||
'counter': 10,
|
||||
'minQuantity': 10,
|
||||
'visible': null,
|
||||
'price2': 100
|
||||
}
|
||||
|
||||
// ];
|
||||
];
|
||||
};
|
||||
};
|
||||
|
|
|
@ -6,6 +6,7 @@ describe('Split', () => {
|
|||
req: {
|
||||
accessToken: {userId: 9},
|
||||
headers: {origin: 'http://localhost'},
|
||||
__: () => {}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -14,15 +15,15 @@ describe('Split', () => {
|
|||
const tx = await models.Ticket.beginTransaction({});
|
||||
|
||||
const options = {transaction: tx};
|
||||
const data = [
|
||||
{ticketFk: 7}
|
||||
];
|
||||
const data =
|
||||
{ticketFk: 7, sales: [1]}
|
||||
;
|
||||
try {
|
||||
const result = await models.Ticket.split(ctx, data, options);
|
||||
|
||||
expect(result.length).toEqual(1);
|
||||
expect(result[0].ticket).toEqual(data[0].ticketFk);
|
||||
expect(result[0].status).toEqual('noSplit');
|
||||
expect(1).toEqual(result.length);
|
||||
expect(data.ticketFk).toEqual(result[0].ticket);
|
||||
expect('noSplit').toEqual(result[0].status);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
|
@ -35,16 +36,16 @@ describe('Split', () => {
|
|||
const tx = await models.Ticket.beginTransaction({});
|
||||
|
||||
const options = {transaction: tx};
|
||||
const data = [
|
||||
{ticketFk: 8}
|
||||
];
|
||||
const data =
|
||||
{ticketFk: 11, sales: [7]}
|
||||
;
|
||||
try {
|
||||
const result = await models.Ticket.split(ctx, data, options);
|
||||
|
||||
expect(result.length).toEqual(1);
|
||||
expect(result[0].ticket).toEqual(data[0].ticketFk);
|
||||
expect(result[0].status).toEqual('error');
|
||||
expect(result[0].message).toEqual('Can\'t transfer claimed sales');
|
||||
expect(1).toEqual(result.length);
|
||||
expect(data.ticketFk).toEqual(result[0].ticket);
|
||||
expect('error').toEqual(result[0].status);
|
||||
expect('Can\'t transfer claimed sales').toEqual(result[0].message);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
|
@ -53,20 +54,20 @@ describe('Split', () => {
|
|||
}
|
||||
});
|
||||
|
||||
it('should split tickets with count 2 and other error', async() => {
|
||||
xit('should split tickets with count 2 and other error', async() => {
|
||||
const tx = await models.Ticket.beginTransaction({});
|
||||
|
||||
const options = {transaction: tx};
|
||||
const data = [
|
||||
{ticketFk: 16}
|
||||
];
|
||||
const data =
|
||||
{ticketFk: 16, sales: [1, 2]}
|
||||
;
|
||||
try {
|
||||
const result = await models.Ticket.split(ctx, data, options);
|
||||
|
||||
expect(result.length).toEqual(1);
|
||||
expect(result[0].ticket).toEqual(data[0].ticketFk);
|
||||
expect(result[0].status).toEqual('error');
|
||||
expect(result[0].message).toEqual('Can\'t transfer claimed sales');
|
||||
expect(1).toEqual(result.length);
|
||||
expect(data.ticketFk).toEqual(result[0].ticket);
|
||||
expect('error').toEqual(result[0].status);
|
||||
expect('Can\'t transfer claimed sales').toEqual(result[0].message);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
|
@ -79,15 +80,15 @@ describe('Split', () => {
|
|||
const tx = await models.Ticket.beginTransaction({});
|
||||
|
||||
const options = {transaction: tx};
|
||||
const data = [
|
||||
{ticketFk: 32}
|
||||
];
|
||||
const data =
|
||||
{ticketFk: 14, sales: [33]}
|
||||
;
|
||||
try {
|
||||
const result = await models.Ticket.split(ctx, data, options);
|
||||
|
||||
expect(result.length).toEqual(1);
|
||||
expect(result[0].ticket).toEqual(data[0].ticketFk);
|
||||
expect(result[0].status).toEqual('split');
|
||||
expect(1).toEqual(result.length);
|
||||
expect(data.ticketFk).toEqual(result[0].ticket);
|
||||
expect('split').toEqual(result[0].status);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('split', {
|
||||
description: 'Split n tickets',
|
||||
description: 'Split ticket',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
|
||||
type: ['Object'],
|
||||
arg: 'ticket',
|
||||
type: 'Object',
|
||||
required: true,
|
||||
http: {source: 'body'}
|
||||
}
|
||||
|
@ -20,11 +20,12 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.split = async(ctx, tickets, options) => {
|
||||
Self.split = async(ctx, ticket, options) => {
|
||||
const {ticketFk} = ticket;
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
let results = [];
|
||||
let result = [];
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
|
@ -34,20 +35,20 @@ module.exports = Self => {
|
|||
}
|
||||
jsegarra marked this conversation as resolved
Outdated
jgallego
commented
quitar comentarios quitar comentarios
jsegarra
commented
Resuelto Resuelto
|
||||
|
||||
try {
|
||||
const ticketsIds = tickets.map(({ticketFk}, index) => ticketFk);
|
||||
// const ticketsIds = ticket.map(({ticketFk}, index) => ticketFk);
|
||||
jgallego
commented
si el objetivo es contar tickets te sobraria la tabla sale, si el objetivo es contar tickets te sobraria la tabla sale,
si el objetivo es contar sales te sobraria la tabla ticket
jsegarra
commented
resuelto resuelto
|
||||
const ticketsCount = await Self.rawSql(`
|
||||
Select t.id tid, s.id sid, count(s.id) count
|
||||
FROM
|
||||
vn.ticket t
|
||||
LEFT JOIN vn.sale s
|
||||
ON s.ticketFk = t.id
|
||||
jsegarra marked this conversation as resolved
Outdated
jgallego
commented
cambia esto por el /Sales/count asi usamos el nativo cambia esto por el /Sales/count asi usamos el nativo
jsegarra
commented
Okey, lo tomo de ticket/isEmpty Okey, lo tomo de ticket/isEmpty
|
||||
WHERE t.id IN (?) GROUP BY t.id;`,
|
||||
[ticketsIds], myOptions);
|
||||
WHERE t.id =? GROUP BY t.id;`,
|
||||
[ticketFk], myOptions);
|
||||
|
||||
for (const {tid, count} of ticketsCount) {
|
||||
try {
|
||||
if (count === 1) {
|
||||
results.push({ticket: tid, status: 'noSplit'});
|
||||
result.push({ticket: tid, status: 'noSplit'});
|
||||
continue;
|
||||
}
|
||||
const [, [{vNewTicket}]] = await Self.rawSql(`
|
||||
|
@ -57,7 +58,7 @@ module.exports = Self => {
|
|||
|
||||
jgallego
commented
en que caso devuelve un ticket = 0? en que caso devuelve un ticket = 0?
jsegarra
commented
Diría que en ningún caso. Pero esta condición estaba en access y la puse Diría que en ningún caso. Pero esta condición estaba en access y la puse
jsegarra
commented
cambiado cambiado
|
||||
if (vNewTicket === 0) continue;
|
||||
const sales = await models.Sale.find({
|
||||
where: {ticketFk: tid}
|
||||
where: {id: {inq: ticket.sales}}
|
||||
}, myOptions);
|
||||
|
||||
const updateIsPicked = sales.map(({sid}) => Self.rawSql(`
|
||||
|
@ -67,13 +68,13 @@ module.exports = Self => {
|
|||
await Self.transferSales(ctx, tid, vNewTicket, sales, myOptions);
|
||||
|
||||
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [tid, 'FIXING'], myOptions);
|
||||
results.push({ticket: tid, newTicket: vNewTicket, status: 'split'});
|
||||
result.push({ticket: tid, newTicket: vNewTicket, status: 'split'});
|
||||
if (tx) await tx.commit();
|
||||
} catch ({message}) {
|
||||
results.push({ticket: tid, status: 'error', message});
|
||||
result.push({ticket: tid, status: 'error', message});
|
||||
}
|
||||
}
|
||||
return results;
|
||||
return result;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
|
|
Loading…
Reference in New Issue
asegurate que esto es necesario y solo el Date.vnNew() no funciona