feat: Added unlocked button for locked documents not in queue

This commit is contained in:
Aradhya 2022-10-08 01:36:40 +05:30
parent c790ad51a3
commit 9074e3e13d
3 changed files with 24 additions and 3 deletions

View file

@ -1,7 +1,10 @@
// Copyright (c) 2022, Frappe Technologies and contributors
// For license information, please see license.txt
frappe.ui.form.on("Submission Queue", {
// refresh: function(frm) {
// }
frappe.ui.form.on('Submission Queue', {
refresh: function(frm) {
frm.add_custom_button(__("Unlock"), () => {
frm.call("unlock_doc")
})
}
});

View file

@ -6,6 +6,9 @@ from frappe import _
from frappe.desk.doctype.notification_log.notification_log import enqueue_create_notification
from frappe.model.document import Document
from frappe.utils import now
from rq.exceptions import NoSuchJobError
from rq.job import Job
from frappe.utils.background_jobs import get_redis_conn
class SubmissionQueue(Document):
@ -79,6 +82,18 @@ class SubmissionQueue(Document):
notify_to = frappe.db.get_value("User", self.enqueued_by, fieldname="email")
enqueue_create_notification([notify_to], notification_doc)
@frappe.whitelist()
def unlock_doc(self):
if self.is_locked:
try:
Job(self.job_id, connection=get_redis_conn())
frappe.msgprint(_("Document already exists in queue!"))
except NoSuchJobError:
self.to_be_queued_doc.unlock()
frappe.msgprint(_("Unlocked document as no such document exists in queue"))
else:
frappe.msgprint(_("Document is already unlocked"))
def queue_submission(doc: Document, action: str):
queue = frappe.new_doc("Submission Queue")

View file

@ -91,6 +91,7 @@ class Document(BaseDocument):
self.doctype = None
self.name = None
self.flags = frappe._dict()
self.is_locked = False
if args and args[0]:
if isinstance(args[0], str):
@ -1492,12 +1493,14 @@ class Document(BaseDocument):
raise frappe.DocumentLockedError
file_lock.create_lock(signature)
frappe.local.locked_documents.append(self)
self.is_locked = True
def unlock(self):
"""Delete the lock file for this document"""
file_lock.delete_lock(self.get_signature())
if self in frappe.local.locked_documents:
frappe.local.locked_documents.remove(self)
self.is_locked = False
# validation helpers
def validate_from_to_dates(self, from_date_field, to_date_field):