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

View File

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

View File

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

View File

@ -13,7 +13,7 @@ describe('itemShelving getAlternative()', () => {
const shelvingFk = 'HEJ'; const shelvingFk = 'HEJ';
const itemShelvings = await models.ItemShelving.getAlternative(shelvingFk); 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() => { it('should return an empty list', async() => {

View File

@ -73,7 +73,7 @@ module.exports = Self => {
userFk: userId userFk: userId
}, myOptions); }, 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); 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); await Self.updateTracking(ctx, saleFk, originalQuantity, code, isChecked, null, isScanned, myOptions);
try { try {
const buy = await models.Buy.findById(buyFk, myOptions); const {itemOriginalFk} = await models.Buy.findById(buyFk, {fields: ['itemOriginalFk']}, myOptions);
if (buy.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'); throw new UserError('The sale cannot be tracked');
} }