#6276 createNewWarehouse methods migrated from silex to salix #1850
|
@ -1,10 +1,10 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('assignCollection', {
|
||||
Self.remoteMethodCtx('assign', {
|
||||
description: 'Assign a collection',
|
||||
accessType: 'WRITE',
|
||||
http: {
|
||||
path: `/assignCollection`,
|
||||
path: `/assign`,
|
||||
verb: 'POST'
|
||||
},
|
||||
returns: {
|
||||
|
@ -13,7 +13,7 @@ module.exports = Self => {
|
|||
},
|
||||
});
|
||||
|
||||
Self.assignCollection = async(ctx, options) => {
|
||||
Self.assign = async(ctx, options) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const myOptions = {userId};
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('getSalesFromTicketOrCollection', {
|
||||
Self.remoteMethodCtx('getSales', {
|
||||
description: 'Get sales from ticket or collection',
|
||||
accessType: 'READ',
|
||||
accepts: [
|
||||
|
@ -23,12 +23,12 @@ module.exports = Self => {
|
|||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/getSalesFromTicketOrCollection`,
|
||||
path: `/getSales`,
|
||||
verb: 'GET'
|
||||
},
|
||||
});
|
||||
|
||||
Self.getSalesFromTicketOrCollection = async(ctx, collectionOrTicketFk, print, source, options) => {
|
||||
Self.getSales = async(ctx, collectionOrTicketFk, print, source, options) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const myOptions = {userId};
|
||||
const $t = ctx.req.__;
|
||||
|
@ -62,11 +62,11 @@ module.exports = Self => {
|
|||
let observations = ticket.observaciones.split(' ');
|
||||
|
||||
for (let observation of observations) {
|
||||
const salesMan = ticket.salesPersonFk;
|
||||
const salesPerson = ticket.salesPersonFk;
|
||||
if (!observation.startsWith('#') && !observation.startsWith('@')) return;
|
||||
await models.Chat.send(ctx,
|
||||
observation,
|
||||
$t('ticketCommercial', {ticket: ticket.ticketFk, salesMan})
|
||||
$t('ticketCommercial', {ticket: ticket.ticketFk, salesPerson})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -92,9 +92,8 @@ module.exports = Self => {
|
|||
if (sale.ticketFk == ticketFk) {
|
||||
sale.placements = [];
|
||||
for (const salePlacement of placements) {
|
||||
let placement;
|
||||
if (salePlacement.saleFk == sale.saleFk && salePlacement.order) {
|
||||
placement = {
|
||||
const placement = {
|
||||
saleFk: salePlacement.saleFk,
|
||||
itemFk: salePlacement.itemFk,
|
||||
placement: salePlacement.placement,
|
|
@ -1,7 +1,7 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('ticket assignCollection()', () => {
|
||||
describe('ticket assign()', () => {
|
||||
let ctx;
|
||||
let options;
|
||||
let tx;
|
||||
|
@ -30,7 +30,7 @@ describe('ticket assignCollection()', () => {
|
|||
|
||||
it('should throw an error when there is not picking tickets', async() => {
|
||||
try {
|
||||
await models.Collection.assignCollection(ctx, options);
|
||||
await models.Collection.assign(ctx, options);
|
||||
} catch (e) {
|
||||
expect(e.message).toEqual('There are not picking tickets');
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
describe('collection getSalesFromTicketOrCollection()', () => {
|
||||
describe('collection getSales()', () => {
|
||||
const collectionOrTicketFk = 999999;
|
||||
const print = true;
|
||||
const source = 'CHECKER';
|
||||
|
@ -18,7 +18,7 @@ describe('collection getSalesFromTicketOrCollection()', () => {
|
|||
const tx = await models.Collection.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
try {
|
||||
const collection = await models.Collection.getSalesFromTicketOrCollection(ctx,
|
||||
const collection = await models.Collection.getSales(ctx,
|
||||
collectionOrTicketFk, print, source, options);
|
||||
|
||||
const [firstTicket] = collection.tickets;
|
||||
|
@ -47,7 +47,7 @@ describe('collection getSalesFromTicketOrCollection()', () => {
|
|||
try {
|
||||
const printQueueBefore = await models.Collection.rawSql(
|
||||
query, [], options);
|
||||
await models.Collection.getSalesFromTicketOrCollection(ctx,
|
||||
await models.Collection.getSales(ctx,
|
||||
collectionOrTicketFk, true, source, options);
|
||||
const printQueueAfter = await models.Collection.rawSql(
|
||||
query, [], options);
|
|
@ -50,13 +50,13 @@ module.exports = Self => {
|
|||
if (machineWorker) {
|
||||
const {maxHours} = await models.MachineWorkerConfig.findOne({fields: ['maxHours']}, myOptions);
|
||||
const hoursDifference = (Date.vnNow() - machineWorker.inTime.getTime()) / (60 * 60 * 1000);
|
||||
const isHimSelf = userId == machineWorker.workerFk;
|
||||
const isHimself = userId == machineWorker.workerFk;
|
||||
const isSameMachine = machine.id == machineWorker.machineFk;
|
||||
|
||||
if (hoursDifference < maxHours && !isHimSelf)
|
||||
if (hoursDifference < maxHours && !isHimself)
|
||||
throw new UserError($t('This machine is already in use.'));
|
||||
|
||||
if (hoursDifference < maxHours && isHimSelf && !isSameMachine)
|
||||
if (hoursDifference < maxHours && isHimself && !isSameMachine)
|
||||
throw new UserError($t('You are already using a machine'));
|
||||
|
||||
await machineWorker.updateAttributes({
|
||||
|
|
|
@ -3,6 +3,6 @@ module.exports = Self => {
|
|||
require('../methods/collection/setSaleQuantity')(Self);
|
||||
require('../methods/collection/previousLabel')(Self);
|
||||
require('../methods/collection/getTickets')(Self);
|
||||
require('../methods/collection/assignCollection')(Self);
|
||||
require('../methods/collection/getSalesFromTicketOrCollection')(Self);
|
||||
require('../methods/collection/assign')(Self);
|
||||
require('../methods/collection/getSales')(Self);
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
||||
VALUES
|
||||
('Collection', 'assignCollection', 'WRITE', 'ALLOW', 'ROLE', 'production'),
|
||||
('Collection', 'assign', 'WRITE', 'ALLOW', 'ROLE', 'production'),
|
||||
('ExpeditionPallet', 'getPallet', 'READ', 'ALLOW', 'ROLE', 'production'),
|
||||
('MachineWorker','updateInTime','WRITE','ALLOW','ROLE','production'),
|
||||
('MobileAppVersionControl','getVersion','READ','ALLOW','ROLE','production'),
|
||||
|
@ -8,7 +8,4 @@ INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalTyp
|
|||
('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');
|
||||
|
||||
('Sale', 'getFromSectorCollection', 'READ', 'ALLOW', 'ROLE', 'production');
|
|
@ -1,5 +1,5 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('return', {
|
||||
Self.remoteMethod('getAlternative', {
|
||||
description: 'Returns a list of items and possible alternative locations',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
|
@ -12,12 +12,12 @@ module.exports = Self => {
|
|||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/return`,
|
||||
path: `/getAlternative`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.return = async(shelvingFk, options) => {
|
||||
Self.getAlternative = async(shelvingFk, options) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
describe('itemShelving return()', () => {
|
||||
describe('itemShelving getAlternative()', () => {
|
||||
beforeAll(async() => {
|
||||
ctx = {
|
||||
req: {
|
||||
|
@ -11,14 +11,14 @@ describe('itemShelving return()', () => {
|
|||
|
||||
it('should return a list of items without alternatives', async() => {
|
||||
const shelvingFk = 'HEJ';
|
||||
const itemShelvings = await models.ItemShelving.return(shelvingFk);
|
||||
const itemShelvings = await models.ItemShelving.getAlternative(shelvingFk);
|
||||
|
||||
expect(itemShelvings[0].carros.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('should return an empty list', async() => {
|
||||
const shelvingFk = 'ZZP';
|
||||
const itemShelvings = await models.ItemShelving.return(shelvingFk);
|
||||
const itemShelvings = await models.ItemShelving.getAlternative(shelvingFk);
|
||||
|
||||
expect(itemShelvings.length).toEqual(0);
|
||||
});
|
|
@ -1,14 +1,14 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('card', {
|
||||
Self.remoteMethod('get', {
|
||||
description: 'Get the data from an item',
|
||||
accessType: 'READ',
|
||||
http: {
|
||||
path: `/card`,
|
||||
path: `/get`,
|
||||
verb: 'GET'
|
||||
},
|
||||
accepts: [
|
||||
{
|
||||
arg: 'itemFk',
|
||||
arg: 'barcode',
|
||||
type: 'number',
|
||||
required: true,
|
||||
},
|
||||
|
@ -24,7 +24,7 @@ module.exports = Self => {
|
|||
},
|
||||
});
|
||||
|
||||
Self.card = async(itemFk, warehouseFk, options) => {
|
||||
Self.get = async(barcode, warehouseFk, options) => {
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
|
@ -32,19 +32,17 @@ module.exports = Self => {
|
|||
|
||||
const models = Self.app.models;
|
||||
|
||||
const [[itemInfo]] = await Self.rawSql('CALL vn.item_getInfo(?, ?)', [itemFk, warehouseFk], myOptions);
|
||||
const [[itemInfo]] = await Self.rawSql('CALL vn.item_getInfo(?, ?)', [barcode, warehouseFk], myOptions);
|
||||
|
||||
const barcodeItems = await Self.rawSql('SELECT vn.barcodeToItem(?) as realIdItem', [itemFk], myOptions);
|
||||
const [realIdItem] = barcodeItems.map(barcodeItem => barcodeItem.realIdItem);
|
||||
if (itemInfo) {
|
||||
itemInfo.barcodes = await models.ItemBarcode.find({
|
||||
fields: ['code'],
|
||||
where: {
|
||||
itemFk: itemInfo.id
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const barcodes = await models.ItemBarcode.find({
|
||||
fields: ['code'],
|
||||
where: {
|
||||
itemFk: realIdItem
|
||||
}
|
||||
});
|
||||
|
||||
if (itemInfo) itemInfo.barcodes = barcodes;
|
||||
return itemInfo;
|
||||
};
|
||||
};
|
|
@ -1,10 +1,10 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
describe('item card()', () => {
|
||||
const itemFk = 1;
|
||||
describe('item get()', () => {
|
||||
const barcode = 1;
|
||||
const warehouseFk = 1;
|
||||
it('should get an item with several barcodes', async() => {
|
||||
const card = await models.Item.card(itemFk, warehouseFk);
|
||||
const card = await models.Item.get(barcode, warehouseFk);
|
||||
|
||||
expect(card).toBeDefined();
|
||||
expect(card.barcodes.length).toBeTruthy();
|
|
@ -1,6 +1,6 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/item-shelving/deleteItemShelvings')(Self);
|
||||
require('../methods/item-shelving/getInventory')(Self);
|
||||
require('../methods/item-shelving/return')(Self);
|
||||
require('../methods/item-shelving/getAlternative')(Self);
|
||||
require('../methods/item-shelving/updateFromSale')(Self);
|
||||
};
|
||||
|
|
|
@ -17,7 +17,7 @@ module.exports = Self => {
|
|||
require('../methods/item/buyerWasteEmail')(Self);
|
||||
require('../methods/item/labelPdf')(Self);
|
||||
require('../methods/item/setVisibleDiscard')(Self);
|
||||
require('../methods/item/card')(Self);
|
||||
require('../methods/item/get')(Self);
|
||||
|
||||
Self.validatesPresenceOf('originFk', {message: 'Cannot be blank'});
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('addSaleByCode', {
|
||||
description: 'Add a collection',
|
||||
accessType: 'WRITE',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'code',
|
||||
arg: 'barcode',
|
||||
type: 'string',
|
||||
required: true
|
||||
}, {
|
||||
|
@ -29,7 +28,7 @@ module.exports = Self => {
|
|||
},
|
||||
});
|
||||
|
||||
Self.addSaleByCode = async(ctx, code, quantity, ticketFk, warehouseFk, options) => {
|
||||
Self.addSaleByCode = async(ctx, barcode, quantity, ticketFk, warehouseFk, options) => {
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
|
@ -42,10 +41,8 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
try {
|
||||
const [[item]] = await Self.rawSql('CALL vn.item_getInfo(?,?)', [code, warehouseFk], myOptions);
|
||||
if (!item?.available) throw new UserError('We do not have availability for the selected item');
|
||||
|
||||
await Self.rawSql('CALL vn.collection_addItem(?, ?, ?)', [item.id, quantity, ticketFk], myOptions);
|
||||
const [[item]] = await Self.rawSql('CALL vn.item_getInfo(?,?)', [barcode, warehouseFk], myOptions);
|
||||
await Self.addSale(ctx, ticketFk, item.id, quantity, myOptions);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
} catch (e) {
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('add', {
|
||||
description: 'Add a new operator',
|
||||
accessType: 'WRITE',
|
||||
http: {
|
||||
path: `/add`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.add = async(ctx, options) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const isOperator = await Self.findById(userId, myOptions);
|
||||
if (!isOperator) await Self.create({workerFk: userId}, myOptions);
|
||||
};
|
||||
};
|
|
@ -1,58 +0,0 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
describe('operator add()', () => {
|
||||
const noOperator = 104;
|
||||
const operator = 9;
|
||||
|
||||
beforeAll(async() => {
|
||||
ctx = {
|
||||
req: {
|
||||
accessToken: {},
|
||||
headers: {origin: 'http://localhost'},
|
||||
__: value => value
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
it('should not add an existent operator', async() => {
|
||||
const tx = await models.Operator.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
ctx.req.accessToken.userId = operator;
|
||||
|
||||
try {
|
||||
const operatorBefore = await models.Operator.find(null, options);
|
||||
const isOperator = await models.Operator.findOne(null, options);
|
||||
|
||||
expect(isOperator).toBeDefined();
|
||||
|
||||
await models.Operator.add(ctx, options);
|
||||
const operatorAfter = await models.Operator.find(null, options);
|
||||
|
||||
expect(operatorBefore.length).toEqual(operatorAfter.length);
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
}
|
||||
});
|
||||
|
||||
it('should add a new operator successfully', async() => {
|
||||
const tx = await models.Operator.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
ctx.req.accessToken.userId = noOperator;
|
||||
|
||||
try {
|
||||
const operatorBefore = await models.Operator.find(null, options);
|
||||
await models.Operator.add(ctx, options);
|
||||
const operatorAfter = await models.Operator.find(null, options);
|
||||
|
||||
const isOperator = await models.Operator.findOne(null, options);
|
||||
|
||||
expect(operatorBefore.length).toEqual(operatorAfter.length - 1);
|
||||
expect(isOperator).toBeDefined();
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -1,6 +1,4 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/operator/add')(Self);
|
||||
|
||||
Self.observe('after save', async function(ctx) {
|
||||
const instance = ctx.data || ctx.instance;
|
||||
const models = Self.app.models;
|
||||
|
|
Loading…
Reference in New Issue