Bug #422 refactorizar el summary de item
This commit is contained in:
parent
7625f7806b
commit
1d15e82a64
|
@ -20,6 +20,7 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.getSummary = async id => {
|
Self.getSummary = async id => {
|
||||||
|
let promises = [];
|
||||||
let summary = {};
|
let summary = {};
|
||||||
|
|
||||||
// Item basic data and taxes
|
// Item basic data and taxes
|
||||||
|
@ -59,7 +60,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
[summary.item] = await Self.app.models.Item.find(filter);
|
promises.push(Self.app.models.Item.find(filter));
|
||||||
|
|
||||||
// Tags
|
// Tags
|
||||||
filter = {
|
filter = {
|
||||||
|
@ -70,28 +71,35 @@ module.exports = Self => {
|
||||||
relation: 'tag'
|
relation: 'tag'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
summary.tags = await Self.app.models.ItemTag.find(filter);
|
promises.push(Self.app.models.ItemTag.find(filter));
|
||||||
|
|
||||||
// Botanical
|
// Botanical
|
||||||
filter = {
|
filter = {
|
||||||
where: {itemFk: id},
|
where: {itemFk: id},
|
||||||
include: [{relation: 'genus'}, {relation: 'specie'}]
|
include: [{relation: 'genus'}, {relation: 'specie'}]
|
||||||
};
|
};
|
||||||
[summary.botanical] = await Self.app.models.ItemBotanical.find(filter);
|
promises.push(Self.app.models.ItemBotanical.find(filter));
|
||||||
|
|
||||||
// Niches
|
// Niches
|
||||||
filter = {
|
filter = {
|
||||||
where: {itemFk: id},
|
where: {itemFk: id},
|
||||||
include: {relation: 'warehouse'}
|
include: {relation: 'warehouse'}
|
||||||
};
|
};
|
||||||
summary.niches = await Self.app.models.ItemNiche.find(filter);
|
promises.push(Self.app.models.ItemNiche.find(filter));
|
||||||
|
|
||||||
|
let res = await Promise.all(promises);
|
||||||
|
|
||||||
|
[summary.item] = res[0];
|
||||||
|
summary.tags = res[1];
|
||||||
|
[summary.botanical] = res[2];
|
||||||
|
summary.niches = res[3];
|
||||||
|
|
||||||
// Visible Avaible
|
// Visible Avaible
|
||||||
let query = `
|
let query = `
|
||||||
CALL vn.getItemVisibleAvailable(?,curdate(),?,?)`;
|
CALL vn.getItemVisibleAvailable(?,curdate(),?,?)`;
|
||||||
|
|
||||||
let options = [summary.item.id, summary.item.itemType().warehouseFk, false];
|
let options = [summary.item.id, summary.item.itemType().warehouseFk, false];
|
||||||
let [res] = await Self.rawSql(query, options);
|
[res] = await Self.rawSql(query, options);
|
||||||
|
|
||||||
summary.available = res[0].available ? res[0].available : '-';
|
summary.available = res[0].available ? res[0].available : '-';
|
||||||
summary.visible = res[0].visible ? res[0].visible : '-';
|
summary.visible = res[0].visible ? res[0].visible : '-';
|
||||||
|
|
Loading…
Reference in New Issue