2
0
mirror of https://github.com/frappe/books.git synced 2025-01-10 18:24:40 +00:00

Add ifnull to filterConditions

This commit is contained in:
Faris Ansari 2018-04-09 00:02:06 +05:30
parent e65cf7dc2c
commit 127ee1f6d2

View File

@ -395,17 +395,18 @@ module.exports = class Database extends Observable {
for (let key in filters) { for (let key in filters) {
const value = filters[key]; const value = filters[key];
if (value instanceof Array) { if (value instanceof Array) {
const condition = value[0];
// if its like, we should add the wildcard "%" if the user has not added // if its like, we should add the wildcard "%" if the user has not added
if (value[0].toLowerCase()==='includes') { if (condition.toLowerCase()==='includes') {
value[0] = 'like'; condition = 'like';
} }
if (['like', 'includes'].includes(value[0].toLowerCase()) && !value[1].includes('%')) { if (['like', 'includes'].includes(condition.toLowerCase()) && !value[1].includes('%')) {
value[1] = `%${value[1]}%`; value[1] = `%${value[1]}%`;
} }
conditions.push(`${key} ${value[0]} ?`); conditions.push(`ifnull(${key}, '') ${condition} ?`);
values.push(value[1]); values.push(value[1]);
} else { } else {
conditions.push(`${key} = ?`); conditions.push(`ifnull(${key}, '') = ?`);
values.push(value); values.push(value);
} }
} }