2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 03:19:01 +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) {
const value = filters[key];
if (value instanceof Array) {
const condition = value[0];
// if its like, we should add the wildcard "%" if the user has not added
if (value[0].toLowerCase()==='includes') {
value[0] = 'like';
if (condition.toLowerCase()==='includes') {
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]}%`;
}
conditions.push(`${key} ${value[0]} ?`);
conditions.push(`ifnull(${key}, '') ${condition} ?`);
values.push(value[1]);
} else {
conditions.push(`${key} = ?`);
conditions.push(`ifnull(${key}, '') = ?`);
values.push(value);
}
}