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
|
||||
SET b.`workerBusinessProfessionalCategoryFk` = 2
|
||||
WHERE b.`workerFk` = 1110;
|
||||
UPDATE `vn`.`business` b
|
||||
SET b.`departmentFk` = 53
|
||||
WHERE b.`workerFk` = 72;
|
||||
|
||||
UPDATE `vn`.`business` b
|
||||
SET b.`departmentFk` = 43
|
||||
|
|
|
@ -9,7 +9,9 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`item_getLack`(
|
|||
vSize INT,
|
||||
vOrigen INT,
|
||||
vLack INT,
|
||||
vWarehouseFk INT
|
||||
vWarehouseFk INT,
|
||||
vCategoryFk INT,
|
||||
vTypeFk INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
|
@ -26,10 +28,12 @@ BEGIN
|
|||
|
||||
SELECT i.id itemFk,
|
||||
i.longName,
|
||||
i.name,
|
||||
w.id warehouseFk,
|
||||
p.`name` producer,
|
||||
i.`size`,
|
||||
i.category,
|
||||
it.categoryFk,
|
||||
w.name warehouse,
|
||||
SUM(IFNULL(sub.amount,0)) lack,
|
||||
i.inkFk,
|
||||
|
@ -59,13 +63,15 @@ BEGIN
|
|||
AND ic.display
|
||||
AND it.code != 'GEN'
|
||||
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 (vColor IS NULL OR vColor = i.inkFk)
|
||||
AND (vSize IS NULL OR vSize = i.`size`)
|
||||
AND (vOrigen IS NULL OR vOrigen = w.id)
|
||||
AND (vLack IS NULL OR vLack = sub.amount)
|
||||
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
|
||||
HAVING lack < 0;
|
||||
|
||||
|
|
|
@ -90,6 +90,7 @@ module.exports = Self => {
|
|||
});
|
||||
await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
return resultReplaceItem;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
|
|
|
@ -15,12 +15,12 @@ module.exports = Self => {
|
|||
http: {source: 'query'}
|
||||
},
|
||||
{
|
||||
arg: 'id',
|
||||
arg: 'itemFk',
|
||||
type: 'number',
|
||||
description: 'The item id',
|
||||
},
|
||||
{
|
||||
arg: 'longname',
|
||||
arg: 'longName',
|
||||
type: 'string',
|
||||
description: 'Article name',
|
||||
},
|
||||
|
@ -30,9 +30,9 @@ module.exports = Self => {
|
|||
description: 'Supplier id',
|
||||
},
|
||||
{
|
||||
arg: 'colour',
|
||||
arg: 'inkFk',
|
||||
type: 'string',
|
||||
description: 'Colour\'s item',
|
||||
description: 'InkFk\'s item',
|
||||
},
|
||||
{
|
||||
arg: 'size',
|
||||
|
@ -49,6 +49,16 @@ module.exports = Self => {
|
|||
type: 'number',
|
||||
description: 'The warehouse id',
|
||||
},
|
||||
{
|
||||
arg: 'typeFk',
|
||||
type: 'number',
|
||||
description: 'The type id',
|
||||
},
|
||||
{
|
||||
arg: 'categoryFk',
|
||||
type: 'number',
|
||||
description: 'The category id',
|
||||
},
|
||||
{
|
||||
arg: 'lack',
|
||||
type: 'number',
|
||||
|
@ -80,9 +90,9 @@ module.exports = Self => {
|
|||
Object.assign(myOptions, options);
|
||||
|
||||
const filterKeyOrder = [
|
||||
'id', 'force', 'days', 'longname', 'supplier',
|
||||
'colour', 'size', 'originFk',
|
||||
'lack', 'warehouseFk'
|
||||
'itemFk', 'force', 'days', 'longName', 'supplier',
|
||||
'inkFk', 'size', 'originFk',
|
||||
'lack', 'warehouseFk', 'categoryFk', 'typeFk'
|
||||
];
|
||||
|
||||
delete ctx?.args?.ctx;
|
||||
|
|
|
@ -37,8 +37,8 @@ module.exports = Self => {
|
|||
if (typeof options == 'object') Object.assign(myOptions, options);
|
||||
const vDated = (Date.vnNew());
|
||||
vDated.setHours(0, 0, 0, 0);
|
||||
const scopeDays = filter.where.scopeDays ?? 0;
|
||||
let alertLevels = filter.where.alertLevelCode;
|
||||
const scopeDays = filter?.where?.scopeDays ?? 0;
|
||||
let alertLevels = filter?.where?.alertLevelCode;
|
||||
|
||||
if (!alertLevels)
|
||||
alertLevels = (await Self.app.models.AlertLevel.find({fields: ['code']})).map(({code}) => code);
|
||||
|
@ -46,7 +46,7 @@ module.exports = Self => {
|
|||
const stmt = new ParameterizedSQL(`
|
||||
SELECT s.id,
|
||||
st.code,
|
||||
t.id,
|
||||
t.id ticketFk,
|
||||
t.nickname,
|
||||
c.id customerId,
|
||||
t.shipped,
|
||||
|
|
|
@ -25,7 +25,7 @@ describe('Item Lack', () => {
|
|||
|
||||
it('should return data with filter.id', async() => {
|
||||
const filter = {
|
||||
id: 5
|
||||
itemFk: 5
|
||||
};
|
||||
const result = await models.Ticket.itemLack(ctx, filter, options);
|
||||
|
||||
|
@ -34,7 +34,7 @@ describe('Item Lack', () => {
|
|||
|
||||
it('should return data with filter.longname', async() => {
|
||||
const filter = {
|
||||
longname: 'Ranged weapon pistol 9mm'
|
||||
longName: 'Ranged weapon pistol 9mm'
|
||||
};
|
||||
const result = await models.Ticket.itemLack(ctx, filter, options);
|
||||
|
||||
|
@ -43,7 +43,7 @@ describe('Item Lack', () => {
|
|||
|
||||
it('should return data with filter.color', async() => {
|
||||
const filter = {
|
||||
colour: 'WHT'
|
||||
inkFk: 'WHT'
|
||||
};
|
||||
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() => {
|
||||
const data =
|
||||
{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).not.toEqual(result.newTicket);
|
||||
expect('split').toEqual(result.status);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -10,7 +10,7 @@ module.exports = Self => {
|
|||
http: {source: 'body'}
|
||||
},
|
||||
{
|
||||
arg: 'date',
|
||||
arg: 'landed',
|
||||
type: 'date',
|
||||
required: true,
|
||||
}
|
||||
|
@ -25,8 +25,7 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.split = async(ctx, ticket, options) => {
|
||||
const {ticketFk} = ticket;
|
||||
Self.split = async(ctx, {ticketFk, sales}, landed, options) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
@ -51,18 +50,21 @@ module.exports = Self => {
|
|||
[ticketFk], myOptions);
|
||||
|
||||
if (vNewTicket === 0) return result;
|
||||
const sales = await models.Sale.find({
|
||||
where: {id: {inq: ticket.sales}}
|
||||
const salesToUpdate = await models.Sale.find({
|
||||
where: {id: {inq: sales}}
|
||||
}, myOptions);
|
||||
|
||||
const updateIsPicked = sales.map(({sid}) => Self.rawSql(`
|
||||
const updateIsPicked = salesToUpdate.map(({sid}) => Self.rawSql(`
|
||||
UPDATE vn.sale SET isPicked = (id = ?) WHERE ticketFk = ?`,
|
||||
[sid, ticketFk], myOptions));
|
||||
|
||||
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);
|
||||
|
||||
const newTicket = await models.Ticket.findById(vNewTicket, null, myOptions);
|
||||
await newTicket.updateAttributes({landed}, myOptions);
|
||||
if (tx) await tx.commit();
|
||||
return {ticket: ticketFk, newTicket: vNewTicket, status: 'split'};
|
||||
} catch (e) {
|
||||
|
|
|
@ -43,8 +43,16 @@ module.exports = Self => {
|
|||
const {code} = await models.State.findById(params.stateFk, {fields: ['code']}, myOptions);
|
||||
params.code = code;
|
||||
} 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.code = code;
|
||||
}
|
||||
|
||||
if (!params.userFk) {
|
||||
|
|
Loading…
Reference in New Issue