2
0
mirror of https://github.com/frappe/books.git synced 2025-01-08 01:14:39 +00:00

Merge pull request #1022 from mildred/mildred/turn-off-filtering

feat: allow to turn off filtering
This commit is contained in:
Akshay 2025-01-03 09:16:32 +05:30 committed by GitHub
commit 633aa1b76c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 55 additions and 23 deletions

View File

@ -64,6 +64,14 @@
"readOnly": true,
"section": "Default"
},
{
"fieldname": "allowFilterBypass",
"label": "Allow to bypass filters",
"fieldtype": "Check",
"default": false,
"description": "When linking documents, if no match is found and filtering is in effect, allow to disable filters.",
"section": "Default"
},
{
"fieldname": "locale",
"label": "Locale",

View File

@ -11,7 +11,7 @@ export default {
name: 'Link',
extends: AutoComplete,
data() {
return { results: [] };
return { results: [], filtersDisabled: false };
},
watch: {
value: {
@ -53,7 +53,7 @@ export default {
getTargetSchemaName() {
return this.df.target;
},
async getOptions() {
async getOptions(filters) {
const schemaName = this.getTargetSchemaName();
if (!schemaName) {
return [];
@ -64,7 +64,6 @@ export default {
}
const schema = fyo.schemaMap[schemaName];
const filters = await this.getFilters();
const fields = [
...new Set(['name', schema.titleField, this.df.groupBy]),
@ -86,7 +85,8 @@ export default {
.filter(Boolean));
},
async getSuggestions(keyword = '') {
let options = await this.getOptions();
let filters = this.filtersDisabled ? null : await this.getFilters();
let options = await this.getOptions(filters || {});
if (keyword) {
options = options
@ -96,21 +96,34 @@ export default {
.map(({ item }) => item);
}
if (this.doc && this.df.create) {
options = options.concat(this.getCreateNewOption());
if (options.length === 0 && !this.df.emptyMessage) {
if (filters && !!fyo.singles.SystemSettings?.allowFilterBypass) {
options = [
{
component: markRaw({
template:
'<span class="text-gray-600 dark:text-gray-400">{{ t`No results found, disable filters` }}</span>',
}),
action: () => this.disableFiltering(),
actionOnly: true,
},
];
} else if (!this.doc || !this.df.create) {
options = [
{
component: markRaw({
template:
'<span class="text-gray-600 dark:text-gray-400">{{ t`No results found` }}</span>',
}),
action: () => {},
actionOnly: true,
},
];
}
}
if (options.length === 0 && !this.df.emptyMessage) {
return [
{
component: markRaw({
template:
'<span class="text-gray-600 dark:text-gray-400">{{ t`No results found` }}</span>',
}),
action: () => {},
actionOnly: true,
},
];
if (this.doc && this.df.create) {
options = options.concat(this.getCreateNewOption());
}
return options;
@ -137,6 +150,14 @@ export default {
}),
};
},
disableFiltering(keyword) {
this.filtersDisabled = true;
this.results = [];
setTimeout(() => {
this.toggleDropdown(true);
this.updateSuggestions(keyword);
}, 1);
},
async openNewDoc() {
const schemaName = this.df.target;
const name =
@ -163,7 +184,7 @@ export default {
return createFilters;
}
const filters = await this.getFilters();
const filters = (await this.getFilters()) ?? {};
return getCreateFiltersFromListViewFilters(filters);
},
async getFilters() {
@ -171,17 +192,17 @@ export default {
const getFilters = fyo.models[schemaName]?.filters?.[fieldname];
if (getFilters === undefined) {
return {};
return null;
}
if (this.doc) {
return (await getFilters(this.doc)) ?? {};
return await getFilters(this.doc);
}
try {
return (await getFilters()) ?? {};
return await getFilters();
} catch {
return {};
return null;
}
},
},

View File

@ -572,6 +572,7 @@ No,Non,
"No filters selected","Aucun filtre sélectionné",
"No linked entries found",,
"No results found","Aucun résultat trouvé",
"No results found, disable filters","Aucun résultat trouvé, désactiver les filtres",
"No rows added. Select a file or add rows.",,
"No transactions yet","Aucune transaction pour le moment",
"Non Active Serial Number ${0} cannot be used as Manufacture raw material",,
@ -1055,4 +1056,6 @@ Yes,Oui,
"check values and click on","Vérifiez les valeurs et cliquez sur",
"in Batch ${0}",,
john@doe.com,,
"to apply changes","pour appliquer les changements",
"to apply changes","pour appliquer les changements",
"Allow to bypass filters","Autoriser la désactivation des filtres"
"When linking documents, if no match is found and filtering is in effect, allow to disable filters.","Lors de la sélection d'un document lié, autoriser à désactiver les filtres si aucun résultat n'est trouvé"

Can't render this file because it has a wrong number of fields in line 1060.