fix: refs #6276 fix acl, addSaleByCode & tests
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
88dfdb157f
commit
e17fc91415
|
@ -18,6 +18,5 @@
|
|||
"salix",
|
||||
"fdescribe",
|
||||
"Loggable"
|
||||
],
|
||||
"CodeGPT.apiKey": "CodeGPT Plus Beta"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -5,6 +5,5 @@ module.exports = Self => {
|
|||
require('../methods/collection/previousLabel')(Self);
|
||||
require('../methods/collection/getTickets')(Self);
|
||||
require('../methods/collection/assignCollection')(Self);
|
||||
require('../methods/collection/addItem')(Self);
|
||||
require('../methods/collection/getSalesFromTicketOrCollection')(Self);
|
||||
};
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
||||
VALUES
|
||||
('Collection', 'assignCollection', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||
('ExpeditionPallet', 'getPallet', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
('MachineWorker','updateInTime','WRITE','ALLOW','ROLE','employee'),
|
||||
('MobileAppVersionControl','getVersion','READ','ALLOW','ROLE','employee'),
|
||||
('SaleTracking','deleteTracking','WRITE','ALLOW','ROLE','employee'),
|
||||
('SaleTracking','updateTracking','WRITE','ALLOW','ROLE','employee'),
|
||||
('SaleTracking','mark','WRITE','ALLOW','ROLE','employee'),
|
||||
('ItemBarcode','deleteByItemAndCode','WRITE','ALLOW','ROLE','employee'),
|
||||
('Collection','addItem','WRITE','ALLOW','ROLE','employee'),
|
||||
('ExpeditionPallet', '*', 'READ', 'ALLOW', 'ROLE', 'production'),
|
||||
('MobileAppVersionControl', '*', 'READ', 'ALLOW', 'ROLE', 'production'),
|
||||
('Collection', 'assignCollection', 'WRITE', 'ALLOW', 'ROLE', 'production'),
|
||||
('Collection', 'addItem', 'WRITE', 'ALLOW', 'ROLE', 'production'),
|
||||
('Sale', 'getFromSectorCollection', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
('Collection', 'addItem', 'WRITE', 'ALLOW', 'ROLE', 'production');
|
||||
('ExpeditionPallet', 'getPallet', 'READ', 'ALLOW', 'ROLE', 'production'),
|
||||
('MachineWorker','updateInTime','WRITE','ALLOW','ROLE','production'),
|
||||
('MobileAppVersionControl','getVersion','READ','ALLOW','ROLE','production'),
|
||||
('SaleTracking','deleteTracking','WRITE','ALLOW','ROLE','production'),
|
||||
('SaleTracking','updateTracking','WRITE','ALLOW','ROLE','production'),
|
||||
('SaleTracking','mark','WRITE','ALLOW','ROLE','production'),
|
||||
('ExpeditionPallet', '*', 'READ', 'ALLOW', 'ROLE', 'production'),
|
||||
('Collection', 'assignCollection', 'WRITE', 'ALLOW', 'ROLE', 'production'),
|
||||
('Sale', 'getFromSectorCollection', 'READ', 'ALLOW', 'ROLE', 'production'),
|
||||
('Ticket', 'addSaleByCode', 'WRITE', 'ALLOW', 'ROLE', 'production');
|
||||
|
|
@ -346,12 +346,9 @@
|
|||
"You are already using a machine": "Ya estás usando una máquina.",
|
||||
"This worker does not exist": "Este trabajador no existe",
|
||||
"this state does not exist": "Este estado no existe",
|
||||
"Este estado no existe": "Este estado no existe",
|
||||
"The line could not be marked": "No se ha podido marcar la línea",
|
||||
"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",
|
||||
"printerNotExists": "No existe la impresora",
|
||||
"There are not picking tickets": "No hay tickets para sacar",
|
||||
"ticketCommercial": "El ticket {{ticket}} del comercial {{salesMan}} está en preparación.(mensaje creado automáticamente)"
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('makeMulti', {
|
||||
description: 'Add a record or update it if it already exists.',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'shelvingFk',
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'items',
|
||||
type: ['number'],
|
||||
required: true,
|
||||
description: 'array of item foreign keys'
|
||||
},
|
||||
{
|
||||
arg: 'warehouseFk',
|
||||
type: 'number',
|
||||
required: true
|
||||
}],
|
||||
|
||||
http: {
|
||||
path: `/makeMulti`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.makeMulti = async(shelvingFk, items, warehouseFk, options) => {
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
const discardItems = [];
|
||||
|
||||
try {
|
||||
for (let item of items) {
|
||||
if (!discardItems.includes(item)) {
|
||||
let quantity = items.reduce((acc, cur) => {
|
||||
return acc + (cur === item ? 1 : 0);
|
||||
}, 0);
|
||||
discardItems.push(item);
|
||||
|
||||
const [result] = await Self.rawSql('SELECT vn.itemPacking(?, ?) itemPacking',
|
||||
[item, warehouseFk], myOptions);
|
||||
let packing;
|
||||
|
||||
if (result) packing = result.itemPacking;
|
||||
if (!packing) packing = 1;
|
||||
|
||||
quantity = quantity * packing;
|
||||
|
||||
await Self.rawSql('CALL vn.itemShelving_add(?, ?, ?, NULL, NULL, ?, ?)',
|
||||
[shelvingFk, item, quantity, packing, warehouseFk], myOptions
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (tx) await tx.commit();
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -39,13 +39,14 @@ module.exports = Self => {
|
|||
};
|
||||
|
||||
let itemShelvings = await models.ItemShelving.find(filterItemShelvings, myOptions);
|
||||
|
||||
if (itemShelvings) {
|
||||
const [alternatives] = await models.ItemShelving.rawSql('CALL vn.itemShelving_getAlternatives(?)',
|
||||
[shelvingFk], myOptions
|
||||
);
|
||||
|
||||
if (itemShelvings) {
|
||||
return itemShelvings.map(itemShelving => {
|
||||
const item = itemShelving.item();
|
||||
|
||||
const carros = alternatives.filter(alternative => alternative.itemFk == itemShelving.itemFk);
|
||||
|
||||
return {
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
describe('item makeMulti()', () => {
|
||||
const warehouseFk = 1;
|
||||
|
||||
beforeAll(async() => {
|
||||
ctx = {
|
||||
accessToken: {userId: 9},
|
||||
req: {
|
||||
headers: {origin: 'http://localhost'},
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
it('should add two new records', async() => {
|
||||
const shelvingFk = 'ZPP';
|
||||
const items = [1, 1, 1, 2];
|
||||
const tx = await models.ItemShelving.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
try {
|
||||
await models.ItemShelving.makeMulti(shelvingFk, items, warehouseFk, options);
|
||||
const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options);
|
||||
|
||||
expect(itemShelvings.length).toEqual(2);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should update the visible items', async() => {
|
||||
const shelvingFk = 'GVC';
|
||||
const items = [2, 2];
|
||||
const tx = await models.ItemShelving.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
try {
|
||||
const {visible: itemsBefore} = await models.ItemShelving.findOne({
|
||||
where: {shelvingFk, itemFk: items[0]}
|
||||
}, options);
|
||||
await models.ItemShelving.makeMulti(shelvingFk, items, warehouseFk, options);
|
||||
const {visible: itemsAfter} = await models.ItemShelving.findOne({
|
||||
where: {shelvingFk, itemFk: items[0]}
|
||||
}, options);
|
||||
|
||||
expect(itemsAfter).toEqual(itemsBefore + 2);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -1,6 +1,6 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
describe('itemShelving return()', () => {
|
||||
fdescribe('itemShelving return()', () => {
|
||||
beforeAll(async() => {
|
||||
ctx = {
|
||||
req: {
|
||||
|
@ -9,15 +9,6 @@ describe('itemShelving return()', () => {
|
|||
};
|
||||
});
|
||||
|
||||
it('should return a list of items and alternative locations', async() => {
|
||||
const shelvingFk = 'PCC';
|
||||
const itemShelvings = await models.ItemShelving.return(shelvingFk);
|
||||
|
||||
expect(itemShelvings[0].itemFk).toEqual(999997);
|
||||
expect(itemShelvings[0].quantity).toEqual(10);
|
||||
expect(itemShelvings[0].carros.length).toEqual(1);
|
||||
});
|
||||
|
||||
it('should return a list of items without alternatives', async() => {
|
||||
const shelvingFk = 'HEJ';
|
||||
const itemShelvings = await models.ItemShelving.return(shelvingFk);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/item-shelving/deleteItemShelvings')(Self);
|
||||
require('../methods/item-shelving/getInventory')(Self);
|
||||
require('../methods/item-shelving/makeMulti')(Self);
|
||||
require('../methods/item-shelving/return')(Self);
|
||||
require('../methods/item-shelving/updateFromSale')(Self);
|
||||
};
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('addItem', {
|
||||
Self.remoteMethodCtx('addSaleByCode', {
|
||||
description: 'Add a collection',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
|
@ -8,33 +7,26 @@ module.exports = Self => {
|
|||
arg: 'code',
|
||||
type: 'string',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
}, {
|
||||
arg: 'quantity',
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
}, {
|
||||
arg: 'ticketFk',
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'warehouseFk',
|
||||
type: 'number',
|
||||
required: true
|
||||
},
|
||||
|
||||
],
|
||||
http: {
|
||||
path: `/addItem`,
|
||||
path: `/addSaleByCode`,
|
||||
verb: 'POST'
|
||||
},
|
||||
});
|
||||
|
||||
Self.addItem = async(ctx, code, quantity, ticketFk, warehouseFk, options) => {
|
||||
Self.addSaleByCode = async(ctx, code, quantity, ticketFk, options) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
const $t = ctx.req.__;
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
|
@ -46,11 +38,8 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
try {
|
||||
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'));
|
||||
|
||||
await models.Ticket.addSale(ctx, ticketFk, item.id, quantity, myOptions);
|
||||
const [{itemFk}] = await Self.rawSql('SELECT barcodeToItem(?) itemFk', [code], myOptions);
|
||||
await models.Ticket.addSale(ctx, ticketFk, itemFk, quantity, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
} catch (e) {
|
|
@ -1,7 +1,7 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('collection addItem()', () => {
|
||||
describe('Ticket addSaleByCode()', () => {
|
||||
const quantity = 3;
|
||||
const ticketFk = 24;
|
||||
const warehouseFk = 1;
|
||||
|
@ -26,7 +26,7 @@ describe('collection addItem()', () => {
|
|||
const code = '1111111111';
|
||||
|
||||
const salesBefore = await models.Sale.find(null, options);
|
||||
await models.Collection.addItem(activeCtx, code, quantity, ticketFk, warehouseFk, options);
|
||||
await models.Ticket.addSaleByCode(activeCtx, code, quantity, ticketFk, warehouseFk, options);
|
||||
const salesAfter = await models.Sale.find(null, options);
|
||||
|
||||
expect(salesAfter.length).toEqual(salesBefore.length + 1);
|
||||
|
@ -36,21 +36,4 @@ describe('collection addItem()', () => {
|
|||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw an error when the item is not available', async() => {
|
||||
const code = '00000000000';
|
||||
const tx = await models.Sale.beginTransaction({});
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
|
||||
await models.Collection.addItem(activeCtx, code, quantity, ticketFk, warehouseFk, options);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
const error = e;
|
||||
|
||||
expect(error.message).toEqual('We do not have availability for the selected item');
|
||||
}
|
||||
});
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
module.exports = Self => {
|
||||
require('./ticket-methods')(Self);
|
||||
require('../methods/ticket/state')(Self);
|
||||
require('../methods/ticket/addSaleByCode')(Self);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue