From 605da52286b59b4cfc70edcd45927e6ed87911b5 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 29 Jul 2022 12:22:03 +0200 Subject: [PATCH] fix: replace it.warehouseFk by userConfig.warehouseFk --- modules/entry/back/methods/entry/latestBuysFilter.js | 4 +++- modules/item/back/methods/item/filter.js | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/entry/back/methods/entry/latestBuysFilter.js b/modules/entry/back/methods/entry/latestBuysFilter.js index bb0e4437c..42e44a31d 100644 --- a/modules/entry/back/methods/entry/latestBuysFilter.js +++ b/modules/entry/back/methods/entry/latestBuysFilter.js @@ -148,6 +148,8 @@ module.exports = Self => { stmt = new ParameterizedSQL(`CALL cache.visible_refresh(@calc_id, FALSE, ?)`, [warehouse.id]); stmts.push(stmt); + const userConfig = await models.UserConfig.getUserConfig(ctx, myOptions); + const date = new Date(); date.setHours(0, 0, 0, 0); stmt = new ParameterizedSQL(` @@ -201,7 +203,7 @@ module.exports = Self => { LEFT JOIN cache.visible v ON v.item_id = lb.item_id AND v.calc_id = @calc_id JOIN item i ON i.id = lb.item_id - JOIN itemType it ON it.id = i.typeFk + JOIN itemType it ON it.id = i.typeFk AND lb.warehouse_id = ${userConfig.warehouseFk} JOIN buy b ON b.id = lb.buy_id LEFT JOIN itemCategory ic ON ic.id = it.categoryFk LEFT JOIN itemType t ON t.id = i.typeFk diff --git a/modules/item/back/methods/item/filter.js b/modules/item/back/methods/item/filter.js index b8e856ba1..724502601 100644 --- a/modules/item/back/methods/item/filter.js +++ b/modules/item/back/methods/item/filter.js @@ -86,6 +86,7 @@ module.exports = Self => { Self.filter = async(ctx, filter, options) => { const conn = Self.dataSource.connector; + const models = Self.app.models; const myOptions = {}; if (typeof options == 'object') @@ -140,6 +141,8 @@ module.exports = Self => { filter = mergeFilters(filter, {where}); + const userConfig = await models.UserConfig.getUserConfig(ctx, myOptions); + const stmts = []; const stmt = new ParameterizedSQL( `SELECT @@ -179,7 +182,7 @@ module.exports = Self => { LEFT JOIN intrastat intr ON intr.id = i.intrastatFk LEFT JOIN producer pr ON pr.id = i.producerFk LEFT JOIN origin ori ON ori.id = i.originFk - LEFT JOIN cache.last_buy lb ON lb.item_id = i.id + LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = ${userConfig.warehouseFk} LEFT JOIN buy b ON b.id = lb.buy_id LEFT JOIN entry e ON e.id = b.entryFk LEFT JOIN supplier s ON s.id = e.supplierFk`