diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 4461087f0..aec4a3a3a 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -771,10 +771,10 @@ INSERT INTO `vn`.`saleTracking`(`saleFk`, `isChecked`, `created`, `originalQuant INSERT INTO `vn`.`itemBarcode`(`id`, `itemFk`, `code`) VALUES - (1, 1 ,1 ), - (2, 1 ,2 ), - (3, 1 ,3 ), - (4, 2 ,4 ); + (1, 1, 1111111111), + (2, 1, 2222222222), + (3, 1, 3333333333), + (4, 2, 4444444444); INSERT INTO `vn`.`itemPlacement`(`id`, `itemFk`, `warehouseFk`, `code`) VALUES diff --git a/modules/agency/front/basic-data/index.html b/modules/agency/front/basic-data/index.html index 1dfeaa1c6..b6f615cef 100644 --- a/modules/agency/front/basic-data/index.html +++ b/modules/agency/front/basic-data/index.html @@ -49,13 +49,13 @@ diff --git a/modules/item/back/methods/item/filter.js b/modules/item/back/methods/item/filter.js index e0673a9fd..0da463ad4 100644 --- a/modules/item/back/methods/item/filter.js +++ b/modules/item/back/methods/item/filter.js @@ -72,7 +72,7 @@ module.exports = Self => { switch (param) { case 'search': return /^\d+$/.test(value) - ? {'i.id': {inq: value}} + ? {or: [{'i.id': value}, {'ib.code': value}]} : {'i.name': {like: `%${value}%`}}; case 'id': return {'i.id': value}; @@ -89,9 +89,6 @@ module.exports = Self => { } }); - /* case 'hasVisible': - return value ? {'v.visible': {gt: 0}} : {'v.visible': {or: [{lte: 0}, {neq: null}]}}; */ - filter = mergeFilters(ctx.args.filter, {where}); let stmts = []; let stmt; @@ -117,22 +114,10 @@ module.exports = Self => { LEFT JOIN origin ori ON ori.id = i.originFk LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = t.warehouseFk LEFT JOIN vn.buy b ON b.id = lb.buy_id - LEFT JOIN itemPlacement itn ON itn.itemFk = i.id AND itn.warehouseFk = t.warehouseFk` + LEFT JOIN itemPlacement itn ON itn.itemFk = i.id AND itn.warehouseFk = t.warehouseFk + LEFT JOIN itemBarcode ib ON ib.itemFk = i.id` ); - /* if (ctx.args.hasVisible !== undefined) { - stmts.push('CALL cache.visible_refresh(@visibleCalc, false, 1)'); - stmts.push('CALL cache.visible_refresh(@visibleCalc, false, 44)'); - let joinAvailable = new ParameterizedSQL( - `LEFT JOIN cache.visible v - ON v.item_id = i.id` - ); - stmt.merge(joinAvailable); - } */ - /* where v.visible > 0 -where v.visible <= 0 OR v.visible IS NULL -*/ - if (ctx.args.tags) { let i = 1; for (const tag of ctx.args.tags) { @@ -156,13 +141,10 @@ where v.visible <= 0 OR v.visible IS NULL } stmt.merge(conn.makeWhere(filter.where)); - - /* if (ctx.args.hasVisible !== undefined) - stmt.merge(`GROUP BY i.id`); - */ + stmt.merge(`GROUP BY i.id`); stmt.merge(conn.makePagination(filter)); - let itemsIndex = stmts.push(stmt) - 1; + let itemsIndex = stmts.push(stmt) - 1; let sql = ParameterizedSQL.join(stmts, ';'); let result = await conn.executeStmt(sql); return itemsIndex === 0 ? result : result[itemsIndex]; diff --git a/modules/item/back/methods/item/specs/filter.spec.js b/modules/item/back/methods/item/specs/filter.spec.js index ecaa7aabe..7efb50033 100644 --- a/modules/item/back/methods/item/specs/filter.spec.js +++ b/modules/item/back/methods/item/specs/filter.spec.js @@ -1,6 +1,22 @@ const app = require('vn-loopback/server/server'); describe('item filter()', () => { + it('should return 1 result filtering by id', async() => { + let filter = {}; + let result = await app.models.Item.filter({args: {filter: filter, search: 1}}); + + expect(result.length).toEqual(1); + expect(result[0].id).toEqual(1); + }); + + it('should return 1 result filtering by barcode', async() => { + let filter = {}; + let result = await app.models.Item.filter({args: {filter: filter, search: 4444444444}}); + + expect(result.length).toEqual(1); + expect(result[0].id).toEqual(2); + }); + it('should return 1 result using filter and tags', async() => { let filter = { order: 'isActive ASC, name',