fix: refs #6276 refactor updateInTime & changes
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Jorge Penadés 2024-03-04 09:21:41 +01:00
parent 026c3c80a4
commit 854a9b62af
5 changed files with 12 additions and 12 deletions

View File

@ -47,9 +47,10 @@ module.exports = Self => {
}
}, myOptions);
const {maxHours} = await models.MachineWorkerConfig.findOne({fields: ['maxHours']}, myOptions);
const hoursDifference = (Date.vnNow() - machineWorker.inTime.getTime()) / (60 * 60 * 1000);
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 isSameMachine = machine.id == machineWorker.machineFk;
@ -62,10 +63,9 @@ module.exports = Self => {
await machineWorker.updateAttributes({
outTime: Date.vnNew()
}, myOptions);
}
if (hoursDifference >= maxHours)
await models.MachineWorker.create({machineFk: machine.id, workerFk: userId}, myOptions);
} else
if (!machineWorker || hoursDifference >= maxHours)
await models.MachineWorker.create({machineFk: machine.id, workerFk: userId}, myOptions);
if (tx) await tx.commit();

View File

@ -1,7 +1,7 @@
module.exports = Self => {
Self.remoteMethod('delete', {
description: 'Delete an ItemBarcode by itemFk and code',
accessType: 'READ',
accessType: 'WRITE',
accepts: [
{
arg: 'barcode',

View File

@ -47,7 +47,7 @@ module.exports = Self => {
return itemShelvings.map(itemShelving => {
const item = itemShelving.item();
const carros = alternatives.filter(alternative => alternative.itemFk == itemShelving.itemFk);
const shelvings = alternatives.filter(alternative => alternative.itemFk == itemShelving.itemFk);
return {
id: itemShelving.id,
@ -56,7 +56,7 @@ module.exports = Self => {
size: item.size,
longName: item.longName,
quantity: itemShelving.visible,
carros
shelvings
};
});
}

View File

@ -13,7 +13,7 @@ describe('itemShelving getAlternative()', () => {
const shelvingFk = 'HEJ';
const itemShelvings = await models.ItemShelving.getAlternative(shelvingFk);
expect(itemShelvings[0].carros.length).toEqual(0);
expect(itemShelvings[0].shelvings.length).toEqual(0);
});
it('should return an empty list', async() => {

View File

@ -73,7 +73,7 @@ module.exports = Self => {
userFk: userId
}, myOptions);
const itemShelving = await models.ItemShelving.findById(itemShelvingFk, myOptions);
const itemShelving = await models.ItemShelving.findById(itemShelvingFk, null, myOptions);
await itemShelving.updateAttributes({visible: itemShelving.visible - quantity}, myOptions);
@ -86,8 +86,8 @@ module.exports = Self => {
await Self.updateTracking(ctx, saleFk, originalQuantity, code, isChecked, null, isScanned, myOptions);
try {
const buy = await models.Buy.findById(buyFk, myOptions);
if (buy.itemOriginalFk) await models.SaleBuy.create({saleFk, buyFk}, myOptions);
const {itemOriginalFk} = await models.Buy.findById(buyFk, {fields: ['itemOriginalFk']}, myOptions);
if (itemOriginalFk) await models.SaleBuy.create({saleFk, buyFk}, myOptions);
} catch (e) {
throw new UserError('The sale cannot be tracked');
}