2
0
mirror of https://github.com/frappe/books.git synced 2024-12-22 10:58:59 +00:00

feat: allow to turn off filtering

This commit is contained in:
Mildred Ki'Lya 2024-11-20 01:54:49 +01:00
parent a2b80a3414
commit 548f39b802
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: {
@ -45,7 +45,7 @@ export default {
getTargetSchemaName() {
return this.df.target;
},
async getOptions() {
async getOptions(filters) {
const schemaName = this.getTargetSchemaName();
if (!schemaName) {
return [];
@ -56,7 +56,6 @@ export default {
}
const schema = fyo.schemaMap[schemaName];
const filters = await this.getFilters();
const fields = [
...new Set(['name', schema.titleField, this.df.groupBy]),
@ -78,7 +77,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
@ -88,21 +88,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;
@ -129,6 +142,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 =
@ -155,7 +176,7 @@ export default {
return createFilters;
}
const filters = await this.getFilters();
const filters = (await this.getFilters()) ?? {};
return getCreateFiltersFromListViewFilters(filters);
},
async getFilters() {
@ -163,17 +184,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.