This commit is contained in:
Carlos Jimenez Ruiz 2019-04-10 09:48:52 +02:00
commit 0343aea2a5
4 changed files with 27 additions and 29 deletions

View File

@ -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

View File

@ -49,13 +49,13 @@
<vn-input-number vn-one
label="Price"
field="$ctrl.zone.price"
min="0.00"
min="0"
step="0.10">
</vn-input-number>
<vn-input-number vn-one
label="Bonus"
field="$ctrl.zone.bonus"
min="0.00"
min="0"
step="0.10">
</vn-input-number>
</vn-horizontal>

View File

@ -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];

View File

@ -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',