Merge pull request '#6964 _ itemOlder' (!2197) from 6964_itemOlder into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #2197 Reviewed-by: Alex Moreno <alexm@verdnatura.es> Reviewed-by: Carlos Andrés <carlosap@verdnatura.es>
This commit is contained in:
commit
cf10ed0f13
|
@ -0,0 +1,4 @@
|
||||||
|
-- Place your SQL code here
|
||||||
|
|
||||||
|
INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId)
|
||||||
|
VALUES('ItemShelving', 'hasItemOlder', 'READ', 'ALLOW', 'ROLE', 'production');
|
|
@ -350,4 +350,4 @@
|
||||||
"The line could not be marked": "La linea no puede ser marcada",
|
"The line could not be marked": "La linea no puede ser marcada",
|
||||||
"This password can only be changed by the user themselves": "Esta contraseña solo puede ser modificada por el propio usuario",
|
"This password can only be changed by the user themselves": "Esta contraseña solo puede ser modificada por el propio usuario",
|
||||||
"They're not your subordinate": "No es tu subordinado/a."
|
"They're not your subordinate": "No es tu subordinado/a."
|
||||||
}
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('hasItemOlder', {
|
||||||
|
description:
|
||||||
|
'Get boolean if any or specific item of the shelving has older created in another shelving or parking',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'shelvingFkIn',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
description: 'Shelving code'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'parking',
|
||||||
|
type: 'string',
|
||||||
|
description: 'Parking code'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'shelvingFkOut',
|
||||||
|
type: 'string',
|
||||||
|
description: 'Shelving code'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'itemFk',
|
||||||
|
type: 'integer',
|
||||||
|
description: 'Item id'
|
||||||
|
}],
|
||||||
|
returns: {
|
||||||
|
type: 'boolean',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/hasItemOlder`,
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.hasItemOlder = async(shelvingFkIn, parking, shelvingFkOut, itemFk, options) => {
|
||||||
|
if (!parking && !shelvingFkOut) throw new UserError('Missing data: parking or shelving');
|
||||||
|
|
||||||
|
const myOptions = {};
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const result = await Self.rawSql(`
|
||||||
|
SELECT COUNT(ish.id) countItemOlder
|
||||||
|
FROM vn.itemShelving ish
|
||||||
|
JOIN (
|
||||||
|
SELECT ish.itemFk, created,shelvingFk
|
||||||
|
FROM vn.itemShelving ish
|
||||||
|
JOIN vn.shelving s ON ish.shelvingFk = s.code
|
||||||
|
WHERE ish.shelvingFk = ?
|
||||||
|
)sub ON sub.itemFK = ish.itemFk
|
||||||
|
JOIN vn.shelving s ON s.code = ish.shelvingFk
|
||||||
|
JOIN vn.parking p ON p.id = s.parkingFk
|
||||||
|
WHERE sub.created > ish.created
|
||||||
|
AND (p.code <> ? OR ? IS NULL)
|
||||||
|
AND (ish.shelvingFk <> ? OR ? IS NULL)
|
||||||
|
AND (ish.itemFk <> ? OR ? IS NULL)`,
|
||||||
|
[shelvingFkIn, parking, parking, shelvingFkOut, shelvingFkOut, itemFk, itemFk], myOptions);
|
||||||
|
return result[0]['countItemOlder'] > 0;
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,45 @@
|
||||||
|
|
||||||
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
|
describe('itemShelving hasOlder()', () => {
|
||||||
|
it('should return false because there are not older items', async() => {
|
||||||
|
const shelvingFkIn = 'GVC';
|
||||||
|
const shelvingFkOut = 'HEJ';
|
||||||
|
const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, null, shelvingFkOut);
|
||||||
|
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false because there are not older items in parking', async() => {
|
||||||
|
const shelvingFkIn = 'HEJ';
|
||||||
|
const parking = '700-01';
|
||||||
|
const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, parking);
|
||||||
|
|
||||||
|
expect(result).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true because there is an older item', async() => {
|
||||||
|
const shelvingFkIn = 'UXN';
|
||||||
|
const shelvingFkOut = 'PCC';
|
||||||
|
const parking = 'A-01-1';
|
||||||
|
const itemFk = 1;
|
||||||
|
|
||||||
|
const tx = await models.ItemShelving.beginTransaction({});
|
||||||
|
const myOptions = {transaction: tx};
|
||||||
|
const filter = {where: {shelvingFk: shelvingFkOut}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
const itemShelvingBefore = await models.ItemShelving.findOne(filter, myOptions);
|
||||||
|
await itemShelvingBefore.updateAttributes({
|
||||||
|
itemFk: itemFk
|
||||||
|
}, myOptions);
|
||||||
|
const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, parking, null, null, myOptions);
|
||||||
|
|
||||||
|
expect(result).toBe(true);
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -4,4 +4,5 @@ module.exports = Self => {
|
||||||
require('../methods/item-shelving/getInventory')(Self);
|
require('../methods/item-shelving/getInventory')(Self);
|
||||||
require('../methods/item-shelving/getAlternative')(Self);
|
require('../methods/item-shelving/getAlternative')(Self);
|
||||||
require('../methods/item-shelving/updateFromSale')(Self);
|
require('../methods/item-shelving/updateFromSale')(Self);
|
||||||
|
require('../methods/item-shelving/hasItemOlder')(Self);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue