Merge pull request 'fix: #6321 - replace arg id by itemFk' (!3455) from fix_ticketNegative into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #3455 Reviewed-by: Jon Elias <jon@verdnatura.es>
This commit is contained in:
commit
b65b884ca9
|
@ -2144,6 +2144,9 @@ UPDATE `vn`.`business`
|
||||||
UPDATE `vn`.`business` b
|
UPDATE `vn`.`business` b
|
||||||
SET b.`workerBusinessProfessionalCategoryFk` = 2
|
SET b.`workerBusinessProfessionalCategoryFk` = 2
|
||||||
WHERE b.`workerFk` = 1110;
|
WHERE b.`workerFk` = 1110;
|
||||||
|
UPDATE `vn`.`business` b
|
||||||
|
SET b.`departmentFk` = 53
|
||||||
|
WHERE b.`workerFk` = 72;
|
||||||
|
|
||||||
UPDATE `vn`.`business` b
|
UPDATE `vn`.`business` b
|
||||||
SET b.`departmentFk` = 43
|
SET b.`departmentFk` = 43
|
||||||
|
|
|
@ -9,7 +9,9 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`item_getLack`(
|
||||||
vSize INT,
|
vSize INT,
|
||||||
vOrigen INT,
|
vOrigen INT,
|
||||||
vLack INT,
|
vLack INT,
|
||||||
vWarehouseFk INT
|
vWarehouseFk INT,
|
||||||
|
vCategoryFk INT,
|
||||||
|
vTypeFk INT
|
||||||
)
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
/**
|
/**
|
||||||
|
@ -26,10 +28,12 @@ BEGIN
|
||||||
|
|
||||||
SELECT i.id itemFk,
|
SELECT i.id itemFk,
|
||||||
i.longName,
|
i.longName,
|
||||||
|
i.name,
|
||||||
w.id warehouseFk,
|
w.id warehouseFk,
|
||||||
p.`name` producer,
|
p.`name` producer,
|
||||||
i.`size`,
|
i.`size`,
|
||||||
i.category,
|
i.category,
|
||||||
|
it.categoryFk,
|
||||||
w.name warehouse,
|
w.name warehouse,
|
||||||
SUM(IFNULL(sub.amount,0)) lack,
|
SUM(IFNULL(sub.amount,0)) lack,
|
||||||
i.inkFk,
|
i.inkFk,
|
||||||
|
@ -59,13 +63,15 @@ BEGIN
|
||||||
AND ic.display
|
AND ic.display
|
||||||
AND it.code != 'GEN'
|
AND it.code != 'GEN'
|
||||||
AND (vSelf IS NULL OR i.id = vSelf)
|
AND (vSelf IS NULL OR i.id = vSelf)
|
||||||
AND (vLongname IS NULL OR i.name = vLongname)
|
AND (vLongname IS NULL OR i.longName LIKE CONCAT('%', vLongname, '%'))
|
||||||
AND (vProducerName IS NULL OR p.`name` LIKE CONCAT('%', vProducerName, '%'))
|
AND (vProducerName IS NULL OR p.`name` LIKE CONCAT('%', vProducerName, '%'))
|
||||||
AND (vColor IS NULL OR vColor = i.inkFk)
|
AND (vColor IS NULL OR vColor = i.inkFk)
|
||||||
AND (vSize IS NULL OR vSize = i.`size`)
|
AND (vSize IS NULL OR vSize = i.`size`)
|
||||||
AND (vOrigen IS NULL OR vOrigen = w.id)
|
AND (vOrigen IS NULL OR vOrigen = w.id)
|
||||||
AND (vLack IS NULL OR vLack = sub.amount)
|
AND (vLack IS NULL OR vLack = sub.amount)
|
||||||
AND (vWarehouseFk IS NULL OR vWarehouseFk = w.id)
|
AND (vWarehouseFk IS NULL OR vWarehouseFk = w.id)
|
||||||
|
AND (vCategoryFk IS NULL OR vCategoryFk = it.categoryFk)
|
||||||
|
AND (vTypeFk IS NULL OR vTypeFk = i.typeFk)
|
||||||
GROUP BY i.id, w.id
|
GROUP BY i.id, w.id
|
||||||
HAVING lack < 0;
|
HAVING lack < 0;
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,7 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message);
|
await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message);
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
return resultReplaceItem;
|
return resultReplaceItem;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
|
|
|
@ -15,12 +15,12 @@ module.exports = Self => {
|
||||||
http: {source: 'query'}
|
http: {source: 'query'}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'id',
|
arg: 'itemFk',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
description: 'The item id',
|
description: 'The item id',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'longname',
|
arg: 'longName',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: 'Article name',
|
description: 'Article name',
|
||||||
},
|
},
|
||||||
|
@ -30,9 +30,9 @@ module.exports = Self => {
|
||||||
description: 'Supplier id',
|
description: 'Supplier id',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'colour',
|
arg: 'inkFk',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: 'Colour\'s item',
|
description: 'InkFk\'s item',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'size',
|
arg: 'size',
|
||||||
|
@ -49,6 +49,16 @@ module.exports = Self => {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
description: 'The warehouse id',
|
description: 'The warehouse id',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
arg: 'typeFk',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The type id',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'categoryFk',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The category id',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
arg: 'lack',
|
arg: 'lack',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
@ -80,9 +90,9 @@ module.exports = Self => {
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const filterKeyOrder = [
|
const filterKeyOrder = [
|
||||||
'id', 'force', 'days', 'longname', 'supplier',
|
'itemFk', 'force', 'days', 'longName', 'supplier',
|
||||||
'colour', 'size', 'originFk',
|
'inkFk', 'size', 'originFk',
|
||||||
'lack', 'warehouseFk'
|
'lack', 'warehouseFk', 'categoryFk', 'typeFk'
|
||||||
];
|
];
|
||||||
|
|
||||||
delete ctx?.args?.ctx;
|
delete ctx?.args?.ctx;
|
||||||
|
|
|
@ -37,8 +37,8 @@ module.exports = Self => {
|
||||||
if (typeof options == 'object') Object.assign(myOptions, options);
|
if (typeof options == 'object') Object.assign(myOptions, options);
|
||||||
const vDated = (Date.vnNew());
|
const vDated = (Date.vnNew());
|
||||||
vDated.setHours(0, 0, 0, 0);
|
vDated.setHours(0, 0, 0, 0);
|
||||||
const scopeDays = filter.where.scopeDays ?? 0;
|
const scopeDays = filter?.where?.scopeDays ?? 0;
|
||||||
let alertLevels = filter.where.alertLevelCode;
|
let alertLevels = filter?.where?.alertLevelCode;
|
||||||
|
|
||||||
if (!alertLevels)
|
if (!alertLevels)
|
||||||
alertLevels = (await Self.app.models.AlertLevel.find({fields: ['code']})).map(({code}) => code);
|
alertLevels = (await Self.app.models.AlertLevel.find({fields: ['code']})).map(({code}) => code);
|
||||||
|
@ -46,7 +46,7 @@ module.exports = Self => {
|
||||||
const stmt = new ParameterizedSQL(`
|
const stmt = new ParameterizedSQL(`
|
||||||
SELECT s.id,
|
SELECT s.id,
|
||||||
st.code,
|
st.code,
|
||||||
t.id,
|
t.id ticketFk,
|
||||||
t.nickname,
|
t.nickname,
|
||||||
c.id customerId,
|
c.id customerId,
|
||||||
t.shipped,
|
t.shipped,
|
||||||
|
|
|
@ -25,7 +25,7 @@ describe('Item Lack', () => {
|
||||||
|
|
||||||
it('should return data with filter.id', async() => {
|
it('should return data with filter.id', async() => {
|
||||||
const filter = {
|
const filter = {
|
||||||
id: 5
|
itemFk: 5
|
||||||
};
|
};
|
||||||
const result = await models.Ticket.itemLack(ctx, filter, options);
|
const result = await models.Ticket.itemLack(ctx, filter, options);
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ describe('Item Lack', () => {
|
||||||
|
|
||||||
it('should return data with filter.longname', async() => {
|
it('should return data with filter.longname', async() => {
|
||||||
const filter = {
|
const filter = {
|
||||||
longname: 'Ranged weapon pistol 9mm'
|
longName: 'Ranged weapon pistol 9mm'
|
||||||
};
|
};
|
||||||
const result = await models.Ticket.itemLack(ctx, filter, options);
|
const result = await models.Ticket.itemLack(ctx, filter, options);
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ describe('Item Lack', () => {
|
||||||
|
|
||||||
it('should return data with filter.color', async() => {
|
it('should return data with filter.color', async() => {
|
||||||
const filter = {
|
const filter = {
|
||||||
colour: 'WHT'
|
inkFk: 'WHT'
|
||||||
};
|
};
|
||||||
const result = await models.Ticket.itemLack(ctx, filter, options);
|
const result = await models.Ticket.itemLack(ctx, filter, options);
|
||||||
|
|
||||||
|
|
|
@ -39,9 +39,13 @@ describe('Split', () => {
|
||||||
it('should split tickets with count 2 and success', async() => {
|
it('should split tickets with count 2 and success', async() => {
|
||||||
const data =
|
const data =
|
||||||
{ticketFk: 14, sales: [33]};
|
{ticketFk: 14, sales: [33]};
|
||||||
const result = await models.Ticket.split(ctx, data, options);
|
const result = await models.Ticket.split(ctx, data, Date.vnNew(), options);
|
||||||
|
const newTicket = await models.Ticket.findById(result.newTicket, null, options);
|
||||||
|
|
||||||
|
expect(newTicket).toBeDefined();
|
||||||
expect(data.ticketFk).toEqual(result.ticket);
|
expect(data.ticketFk).toEqual(result.ticket);
|
||||||
|
expect(data.ticketFk).toEqual(result.ticket);
|
||||||
|
expect(data.ticketFk).not.toEqual(result.newTicket);
|
||||||
expect('split').toEqual(result.status);
|
expect('split').toEqual(result.status);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,7 +10,7 @@ module.exports = Self => {
|
||||||
http: {source: 'body'}
|
http: {source: 'body'}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'date',
|
arg: 'landed',
|
||||||
type: 'date',
|
type: 'date',
|
||||||
required: true,
|
required: true,
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.split = async(ctx, ticket, options) => {
|
Self.split = async(ctx, {ticketFk, sales}, landed, options) => {
|
||||||
const {ticketFk} = ticket;
|
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
let tx;
|
let tx;
|
||||||
|
@ -51,18 +50,21 @@ module.exports = Self => {
|
||||||
[ticketFk], myOptions);
|
[ticketFk], myOptions);
|
||||||
|
|
||||||
if (vNewTicket === 0) return result;
|
if (vNewTicket === 0) return result;
|
||||||
const sales = await models.Sale.find({
|
const salesToUpdate = await models.Sale.find({
|
||||||
where: {id: {inq: ticket.sales}}
|
where: {id: {inq: sales}}
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
const updateIsPicked = sales.map(({sid}) => Self.rawSql(`
|
const updateIsPicked = salesToUpdate.map(({sid}) => Self.rawSql(`
|
||||||
UPDATE vn.sale SET isPicked = (id = ?) WHERE ticketFk = ?`,
|
UPDATE vn.sale SET isPicked = (id = ?) WHERE ticketFk = ?`,
|
||||||
[sid, ticketFk], myOptions));
|
[sid, ticketFk], myOptions));
|
||||||
|
|
||||||
await Promise.all(updateIsPicked);
|
await Promise.all(updateIsPicked);
|
||||||
await Self.transferSales(ctx, ticketFk, vNewTicket, sales, myOptions);
|
await Self.transferSales(ctx, ticketFk, vNewTicket, salesToUpdate, myOptions);
|
||||||
|
|
||||||
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketFk, 'FIXING'], myOptions);
|
await Self.rawSql(`CALL vn.ticket_setState(?, ?)`, [ticketFk, 'FIXING'], myOptions);
|
||||||
|
|
||||||
|
const newTicket = await models.Ticket.findById(vNewTicket, null, myOptions);
|
||||||
|
await newTicket.updateAttributes({landed}, myOptions);
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
return {ticket: ticketFk, newTicket: vNewTicket, status: 'split'};
|
return {ticket: ticketFk, newTicket: vNewTicket, status: 'split'};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -43,8 +43,16 @@ module.exports = Self => {
|
||||||
const {code} = await models.State.findById(params.stateFk, {fields: ['code']}, myOptions);
|
const {code} = await models.State.findById(params.stateFk, {fields: ['code']}, myOptions);
|
||||||
params.code = code;
|
params.code = code;
|
||||||
} else {
|
} else {
|
||||||
const {id} = await models.State.findOne({where: {code: params.code}}, myOptions);
|
const {id, code} = await models.State.findOne({
|
||||||
|
where: {
|
||||||
|
or: [
|
||||||
|
{code: params.code},
|
||||||
|
{id: params.code}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}, myOptions);
|
||||||
params.stateFk = id;
|
params.stateFk = id;
|
||||||
|
params.code = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!params.userFk) {
|
if (!params.userFk) {
|
||||||
|
|
Loading…
Reference in New Issue