Skip to content

Commit

Permalink
Merge pull request frappe#21737 from ankush/perf/workflow_transitions
Browse files Browse the repository at this point in the history
perf: workflow transitions and bulk workflow
  • Loading branch information
ankush committed Jul 20, 2023
2 parents b2d32a2 + c90374c commit fb2ab0b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
6 changes: 1 addition & 5 deletions frappe/model/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,7 @@ def send_email_alert(workflow_name):


def get_workflow_field_value(workflow_name, field):
value = frappe.cache.hget("workflow_" + workflow_name, field)
if value is None:
value = frappe.db.get_value("Workflow", workflow_name, field)
frappe.cache.hset("workflow_" + workflow_name, field, value)
return value
return frappe.get_cached_value("Workflow", workflow_name, field)


@frappe.whitelist()
Expand Down
32 changes: 24 additions & 8 deletions frappe/public/js/frappe/list/list_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
this.workflow_action_items = {};

const actions = this.actions_menu_items.concat(this.workflow_action_menu_items);
actions.map((item) => {
actions.forEach((item) => {
const $item = this.page.add_actions_menu_item(item.label, item.action, item.standard);
if (item.class) {
$item.addClass(item.class);
Expand Down Expand Up @@ -549,7 +549,6 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
if (toggle) {
this.page.show_actions_menu();
this.page.clear_primary_action();
this.toggle_workflow_actions();
} else {
this.page.hide_actions_menu();
this.set_primary_action();
Expand Down Expand Up @@ -597,7 +596,6 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
render() {
this.render_list();
this.set_rows_as_checked();
this.on_row_checked();
this.render_count();
}

Expand Down Expand Up @@ -1318,6 +1316,11 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {

this.update_checkbox($target);
});

let me = this;
this.page.actions_btn_group.on("show.bs.dropdown", () => {
me.toggle_workflow_actions();
});
}

setup_like() {
Expand Down Expand Up @@ -1673,18 +1676,25 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {

get_workflow_action_menu_items() {
const workflow_actions = [];
const me = this;

if (frappe.model.has_workflow(this.doctype)) {
const actions = frappe.workflow.get_all_transition_actions(this.doctype);
actions.forEach((action) => {
workflow_actions.push({
label: __(action),
name: action,
action: () => {
frappe.xcall("frappe.model.workflow.bulk_workflow_approval", {
docnames: this.get_checked_items(true),
doctype: this.doctype,
action: action,
});
me.disable_list_update = true;
frappe
.xcall("frappe.model.workflow.bulk_workflow_approval", {
docnames: this.get_checked_items(true),
doctype: this.doctype,
action: action,
})
.finally(() => {
me.disable_list_update = false;
});
},
is_workflow_action: true,
});
Expand All @@ -1695,14 +1705,20 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {

toggle_workflow_actions() {
if (!frappe.model.has_workflow(this.doctype)) return;

Object.keys(this.workflow_action_items).forEach((key) => {
this.workflow_action_items[key].addClass("disabled");
});
const checked_items = this.get_checked_items();

frappe
.xcall("frappe.model.workflow.get_common_transition_actions", {
docs: checked_items,
doctype: this.doctype,
})
.then((actions) => {
Object.keys(this.workflow_action_items).forEach((key) => {
this.workflow_action_items[key].removeClass("disabled");
this.workflow_action_items[key].toggle(actions.includes(key));
});
});
Expand Down
2 changes: 1 addition & 1 deletion frappe/workflow/doctype/workflow/workflow.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"label": "Don't Override Status"
},
{
"default": "1",
"default": "0",
"description": "Emails will be sent with next possible workflow actions",
"fieldname": "send_email_alert",
"fieldtype": "Check",
Expand Down
1 change: 0 additions & 1 deletion frappe/workflow/doctype/workflow/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def validate(self):
def on_update(self):
self.update_doc_status()
frappe.clear_cache(doctype=self.document_type)
frappe.cache.delete_key("workflow_" + self.name) # clear cache created in model/workflow.py

def create_custom_field_for_workflow_state(self):
frappe.clear_cache(doctype=self.document_type)
Expand Down

0 comments on commit fb2ab0b

Please sign in to comment.