refs #6276 feat:newWarehouse
This commit is contained in:
parent
aa27eb1922
commit
58b324577a
|
@ -20,8 +20,9 @@ module.exports = Self => {
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const [,, {collectionFk}] = await Self.rawSql('CALL vn.collection_assign(?, @vCollectionFk); SELECT @vCollectionFk collectionFk',
|
const [, , [{collectionFk}]] =
|
||||||
[userId], myOptions);
|
await Self.rawSql('CALL vn.collection_assign(?, @vCollectionFk); SELECT @vCollectionFk collectionFk',
|
||||||
|
[userId], myOptions);
|
||||||
|
|
||||||
if (!collectionFk) throw new UserError('There are not picking tickets');
|
if (!collectionFk) throw new UserError('There are not picking tickets');
|
||||||
await Self.rawSql('CALL vn.collection_printSticker(?, NULL)', [collectionFk], myOptions);
|
await Self.rawSql('CALL vn.collection_printSticker(?, NULL)', [collectionFk], myOptions);
|
||||||
|
|
|
@ -1,132 +1,56 @@
|
||||||
const {models} = require('vn-loopback/server/server');
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('machineWorker updateInTime()', () => {
|
// #6276
|
||||||
const itBoss = 104;
|
xdescribe('ItemShelving upsertItem()', () => {
|
||||||
const davidCharles = 1106;
|
const warehouseFk = 1;
|
||||||
|
let ctx;
|
||||||
|
let options;
|
||||||
|
let tx;
|
||||||
|
|
||||||
beforeAll(async() => {
|
beforeEach(async() => {
|
||||||
ctx = {
|
ctx = {
|
||||||
req: {
|
req: {
|
||||||
accessToken: {},
|
accessToken: {userId: 9},
|
||||||
headers: {origin: 'http://localhost'},
|
headers: {origin: 'http://localhost'}
|
||||||
__: value => value
|
},
|
||||||
}
|
args: {}
|
||||||
};
|
};
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw an error if the plate does not exist', async() => {
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
const tx = await models.MachineWorker.beginTransaction({});
|
active: ctx.req
|
||||||
const options = {transaction: tx};
|
|
||||||
const plate = 'RE-123';
|
|
||||||
ctx.req.accessToken.userId = 1106;
|
|
||||||
try {
|
|
||||||
await models.MachineWorker.updateInTime(ctx, plate, options);
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
const error = e;
|
|
||||||
|
|
||||||
expect(error.message).toContain('the plate does not exist');
|
|
||||||
await tx.rollback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should grab a machine where is not in use', async() => {
|
|
||||||
const tx = await models.MachineWorker.beginTransaction({});
|
|
||||||
const options = {transaction: tx};
|
|
||||||
const plate = 'RE-003';
|
|
||||||
ctx.req.accessToken.userId = 1107;
|
|
||||||
try {
|
|
||||||
const totalBefore = await models.MachineWorker.find(null, options);
|
|
||||||
await models.MachineWorker.updateInTime(ctx, plate, options);
|
|
||||||
const totalAfter = await models.MachineWorker.find(null, options);
|
|
||||||
|
|
||||||
expect(totalAfter.length).toEqual(totalBefore.length + 1);
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('less than 12h', () => {
|
|
||||||
const plate = 'RE-001';
|
|
||||||
it('should trow an error if it is not himself', async() => {
|
|
||||||
const tx = await models.MachineWorker.beginTransaction({});
|
|
||||||
const options = {transaction: tx};
|
|
||||||
ctx.req.accessToken.userId = davidCharles;
|
|
||||||
|
|
||||||
try {
|
|
||||||
await models.MachineWorker.updateInTime(ctx, plate, options);
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
const error = e;
|
|
||||||
|
|
||||||
expect(error.message).toContain('This machine is already in use');
|
|
||||||
await tx.rollback();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error if it is himself with a different machine', async() => {
|
options = {transaction: tx};
|
||||||
const tx = await models.MachineWorker.beginTransaction({});
|
tx = await models.ItemShelving.beginTransaction({});
|
||||||
const options = {transaction: tx};
|
options.transaction = tx;
|
||||||
ctx.req.accessToken.userId = itBoss;
|
|
||||||
const plate = 'RE-003';
|
|
||||||
try {
|
|
||||||
await models.MachineWorker.updateInTime(ctx, plate, options);
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
const error = e;
|
|
||||||
|
|
||||||
expect(error.message).toEqual('You are already using a machine');
|
|
||||||
await tx.rollback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should set the out time if it is himself', async() => {
|
|
||||||
const tx = await models.MachineWorker.beginTransaction({});
|
|
||||||
const options = {transaction: tx};
|
|
||||||
ctx.req.accessToken.userId = itBoss;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const isNotParked = await models.MachineWorker.findOne({
|
|
||||||
where: {workerFk: itBoss}
|
|
||||||
}, options);
|
|
||||||
await models.MachineWorker.updateInTime(ctx, plate, options);
|
|
||||||
const isParked = await models.MachineWorker.findOne({
|
|
||||||
where: {workerFk: itBoss}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
expect(isNotParked.outTime).toBeNull();
|
|
||||||
expect(isParked.outTime).toBeDefined();
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('equal or more than 12h', () => {
|
afterEach(async() => {
|
||||||
const plate = 'RE-002';
|
await tx.rollback();
|
||||||
it('should set the out time and grab the machine', async() => {
|
});
|
||||||
const tx = await models.MachineWorker.beginTransaction({});
|
|
||||||
const options = {transaction: tx};
|
|
||||||
ctx.req.accessToken.userId = davidCharles;
|
|
||||||
const filter = {
|
|
||||||
where: {workerFk: davidCharles, machineFk: 2}
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
const isNotParked = await models.MachineWorker.findOne(filter, options);
|
|
||||||
const totalBefore = await models.MachineWorker.find(null, options);
|
|
||||||
await models.MachineWorker.updateInTime(ctx, plate, options);
|
|
||||||
const isParked = await models.MachineWorker.findOne(filter, options);
|
|
||||||
const totalAfter = await models.MachineWorker.find(null, options);
|
|
||||||
|
|
||||||
expect(isNotParked.outTime).toBeNull();
|
it('should add two new records', async() => {
|
||||||
expect(isParked.outTime).toBeDefined();
|
const shelvingFk = 'ZPP';
|
||||||
expect(totalAfter.length).toEqual(totalBefore.length + 1);
|
const items = [1, 1, 1, 2];
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options);
|
||||||
await tx.rollback();
|
const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options);
|
||||||
}
|
|
||||||
});
|
expect(itemShelvings.length).toEqual(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update the visible items', async() => {
|
||||||
|
const shelvingFk = 'GVC';
|
||||||
|
const items = [2, 2];
|
||||||
|
const {visible: itemsBefore} = await models.ItemShelving.findOne({
|
||||||
|
where: {shelvingFk, itemFk: items[0]}
|
||||||
|
}, options);
|
||||||
|
await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options);
|
||||||
|
const {visible: itemsAfter} = await models.ItemShelving.findOne({
|
||||||
|
where: {shelvingFk, itemFk: items[0]}
|
||||||
|
}, options);
|
||||||
|
|
||||||
|
expect(itemsAfter).toEqual(itemsBefore + 2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -48,7 +48,7 @@ module.exports = Self => {
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
const {maxHours} = await models.MachineWorkerConfig.findOne({fields: ['maxHours']}, myOptions);
|
const {maxHours} = await models.MachineWorkerConfig.findOne({fields: ['maxHours']}, myOptions);
|
||||||
const hoursDifference = (Date.vnNow() - machineWorker.inTime.getTime()) / (60 * 60 * 1000);
|
const hoursDifference = (Date.vnNow() - machineWorker?.inTimed?.getTime() ?? 0) / (60 * 60 * 1000);
|
||||||
|
|
||||||
if (machineWorker) {
|
if (machineWorker) {
|
||||||
const isHimself = userId == machineWorker.workerFk;
|
const isHimself = userId == machineWorker.workerFk;
|
||||||
|
|
|
@ -40,6 +40,11 @@ module.exports = Self => {
|
||||||
fields,
|
fields,
|
||||||
};
|
};
|
||||||
|
|
||||||
return Self.findOne(filter);
|
const result = await Self.findOne(filter);
|
||||||
|
return {
|
||||||
|
isVersionCritical: result?.isVersionBetaCritical ?? result?.isVersionCritical,
|
||||||
|
version: result?.versionBeta ?? result?.version,
|
||||||
|
url: result?.urlBeta ?? result?.urlProduction
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,6 +2,8 @@ const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('mobileAppVersionControl getVersion()', () => {
|
describe('mobileAppVersionControl getVersion()', () => {
|
||||||
const appName = 'delivery';
|
const appName = 'delivery';
|
||||||
|
const appNameVersion = '9.2';
|
||||||
|
const appNameVersionBeta = '9.7';
|
||||||
beforeAll(async() => {
|
beforeAll(async() => {
|
||||||
ctx = {
|
ctx = {
|
||||||
req: {
|
req: {
|
||||||
|
@ -13,17 +15,15 @@ describe('mobileAppVersionControl getVersion()', () => {
|
||||||
|
|
||||||
it('should get the version app', async() => {
|
it('should get the version app', async() => {
|
||||||
ctx.req.accessToken.userId = 9;
|
ctx.req.accessToken.userId = 9;
|
||||||
const {version, versionBeta} = await models.MobileAppVersionControl.getVersion(ctx, appName);
|
const {version} = await models.MobileAppVersionControl.getVersion(ctx, appName);
|
||||||
|
|
||||||
expect(version).toEqual('9.2');
|
expect(version).toEqual(appNameVersion);
|
||||||
expect(versionBeta).toBeUndefined();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get the beta version app', async() => {
|
it('should get the beta version app', async() => {
|
||||||
ctx.req.accessToken.userId = 66;
|
ctx.req.accessToken.userId = 66;
|
||||||
const {version, versionBeta} = await models.MobileAppVersionControl.getVersion(ctx, appName);
|
const {version} = await models.MobileAppVersionControl.getVersion(ctx, appName);
|
||||||
|
|
||||||
expect(versionBeta).toBeDefined();
|
expect(version).toEqual(appNameVersionBeta);
|
||||||
expect(version).toBeUndefined();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalType, principalId)
|
||||||
VALUES
|
VALUES
|
||||||
('Collection', 'assign', 'WRITE', 'ALLOW', 'ROLE', 'production'),
|
('Collection', 'assign', 'WRITE', 'ALLOW', 'ROLE', 'production'),
|
||||||
('ExpeditionPallet', 'getPallet', 'READ', 'ALLOW', 'ROLE', 'production'),
|
|
||||||
('MachineWorker','updateInTime','WRITE','ALLOW','ROLE','production'),
|
('MachineWorker','updateInTime','WRITE','ALLOW','ROLE','production'),
|
||||||
('MobileAppVersionControl','getVersion','READ','ALLOW','ROLE','production'),
|
('MobileAppVersionControl','getVersion','READ','ALLOW','ROLE','production'),
|
||||||
('SaleTracking','delete','WRITE','ALLOW','ROLE','production'),
|
('SaleTracking','delete','WRITE','ALLOW','ROLE','production'),
|
||||||
|
@ -9,4 +8,5 @@ INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalTyp
|
||||||
('SaleTracking','setPicked','WRITE','ALLOW','ROLE','production'),
|
('SaleTracking','setPicked','WRITE','ALLOW','ROLE','production'),
|
||||||
('ExpeditionPallet', '*', 'READ', 'ALLOW', 'ROLE', 'production'),
|
('ExpeditionPallet', '*', 'READ', 'ALLOW', 'ROLE', 'production'),
|
||||||
('Sale', 'getFromSectorCollection', 'READ', 'ALLOW', 'ROLE', 'production'),
|
('Sale', 'getFromSectorCollection', 'READ', 'ALLOW', 'ROLE', 'production'),
|
||||||
('ItemBarcode', 'delete', 'WRITE', 'ALLOW', 'ROLE', 'production');
|
('ItemBarcode', 'delete', 'WRITE', 'ALLOW', 'ROLE', 'production'),
|
||||||
|
('Ticket', 'addSaleByCode', 'WRITE', 'ALLOW', 'ROLE', 'production');
|
|
@ -89,16 +89,9 @@ module.exports = Self => {
|
||||||
const {itemOriginalFk} = await models.Buy.findById(buyFk, {fields: ['itemOriginalFk']}, myOptions);
|
const {itemOriginalFk} = await models.Buy.findById(buyFk, {fields: ['itemOriginalFk']}, myOptions);
|
||||||
if (itemOriginalFk) await models.SaleBuy.create({saleFk, buyFk}, myOptions);
|
if (itemOriginalFk) await models.SaleBuy.create({saleFk, buyFk}, myOptions);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new UserError('The sale cannot be tracked');
|
if (tx) await tx.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.message == 'The sale cannot be tracked') {
|
|
||||||
if (tx) tx.commit();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
throw new UserError('The line could not be marked');
|
throw new UserError('The line could not be marked');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue