Skip to content

Commit

Permalink
Merge pull request #261 from alyf-de/lan-817
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra authored Mar 1, 2024
2 parents 1b444cd + 42391ce commit fb820f7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ frappe.ui.form.on("Catch Log Entry", {
}
},
refresh: (frm) => {
if (frm.doc.docstatus == 0 && !frm.is_new()) {
if (!frm.is_new() && !frappe.workflow.is_read_only(frm.doc.doctype, frm.doc.name)) {
frm.add_custom_button(__("New Catch Log Entry"), () => {
frappe.new_doc(frm.doctype, {
organization: frm.doc.organization,
year: frm.doc.year,
});
});

frm.add_custom_button(__("Delete"), () => frm.savetrash());
}
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import frappe
from frappe import _, get_roles
from frappe.model.document import Document
from frappe.model.workflow import get_workflow


class CatchLogEntry(Document):
Expand Down Expand Up @@ -38,3 +39,22 @@ def validate(self):
),
title=_("Invalid Species"),
)

def before_save(self):
if self.is_new():
return

self.check_workflow_perms()

def on_trash(self):
self.check_workflow_perms()

def check_workflow_perms(self):
"""Raise a PermissionError if the user is not allowed to edit the document
in the current workflow state.
"""
workflow = get_workflow(self.doctype)
workflow_state = self.db_get(workflow.workflow_state_field)
frappe.only_for(
roles=[row.allow_edit for row in workflow.states if row.state == workflow_state],
)

0 comments on commit fb820f7

Please sign in to comment.