Add logic to check if the document was modified (#5746)
- Check if the document was modified after the workflow action mail was sent. If yes, then show an alert with the latest document preview.
This commit is contained in:
parent
8cb6d83813
commit
ecde50a699
3 changed files with 48 additions and 13 deletions
|
|
@ -1042,7 +1042,7 @@ def compare(val1, condition, val2):
|
|||
|
||||
def respond_as_web_page(title, html, success=None, http_status_code=None,
|
||||
context=None, indicator_color=None, primary_action='/', primary_label = None, fullpage=False,
|
||||
width=None):
|
||||
width=None, template='message'):
|
||||
"""Send response as a web page with a message rather than JSON. Used to show permission errors etc.
|
||||
|
||||
:param title: Page title and heading.
|
||||
|
|
@ -1055,11 +1055,12 @@ def respond_as_web_page(title, html, success=None, http_status_code=None,
|
|||
:param primary_label: label on primary button (defaut is "Home")
|
||||
:param fullpage: hide header / footer
|
||||
:param width: Width of message in pixels
|
||||
:param template: Optionally pass view template
|
||||
"""
|
||||
local.message_title = title
|
||||
local.message = html
|
||||
local.response['type'] = 'page'
|
||||
local.response['route'] = 'message'
|
||||
local.response['route'] = template
|
||||
if http_status_code:
|
||||
local.response['http_status_code'] = http_status_code
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from __future__ import unicode_literals
|
|||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils.background_jobs import enqueue
|
||||
from frappe.utils import get_url
|
||||
from frappe.utils import get_url, get_datetime
|
||||
from frappe.utils.verified_command import get_signed_params, verify_request
|
||||
from frappe import _
|
||||
from frappe.model.workflow import apply_workflow, get_workflow_name, \
|
||||
|
|
@ -55,7 +55,7 @@ def process_workflow_actions(doc, state):
|
|||
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def apply_action(action, doctype, docname, current_state, user):
|
||||
def apply_action(action, doctype, docname, current_state, user, last_modified=None):
|
||||
if not verify_request():
|
||||
return
|
||||
|
||||
|
|
@ -67,14 +67,28 @@ def apply_action(action, doctype, docname, current_state, user):
|
|||
doc_workflow_state = get_doc_workflow_state(doc)
|
||||
|
||||
if doc_workflow_state == current_state:
|
||||
newdoc = apply_workflow(doc, action)
|
||||
frappe.db.commit()
|
||||
frappe.respond_as_web_page(_("Success"),
|
||||
_("{0}: {1} is set to state {2}".format(
|
||||
doctype,
|
||||
frappe.bold(newdoc.get('name')),
|
||||
frappe.bold(get_doc_workflow_state(newdoc))
|
||||
)), indicator_color='green')
|
||||
if not last_modified or get_datetime(doc.modified) == get_datetime(last_modified):
|
||||
newdoc = apply_workflow(doc, action)
|
||||
frappe.db.commit()
|
||||
frappe.respond_as_web_page(_("Success"),
|
||||
_("{0}: {1} is set to state {2}".format(
|
||||
doctype,
|
||||
frappe.bold(newdoc.get('name')),
|
||||
frappe.bold(get_doc_workflow_state(newdoc))
|
||||
)), indicator_color='green')
|
||||
else:
|
||||
response_html_params = {
|
||||
'title': _("Document has been modified!"),
|
||||
'message': "Please review the document before approval",
|
||||
'print_format': frappe.get_print(doc.get('doctype'), doc.get('name')),
|
||||
'action': {
|
||||
'label': action,
|
||||
'link': get_workflow_action_url(action, doc, user)
|
||||
}
|
||||
}
|
||||
frappe.respond_as_web_page(None, None,
|
||||
template="modified_doc_alert",
|
||||
context=response_html_params)
|
||||
else:
|
||||
frappe.respond_as_web_page(_("Link Expired"),
|
||||
_("Document {0} has been set to state {1} by {2}"
|
||||
|
|
@ -161,7 +175,8 @@ def get_workflow_action_url(action, doc, user):
|
|||
"docname": doc.get('name'),
|
||||
"action": action,
|
||||
"current_state": get_doc_workflow_state(doc),
|
||||
"user": user
|
||||
"user": user,
|
||||
"last_modified": doc.get('modified')
|
||||
}
|
||||
|
||||
return get_url(apply_action_method + "?" + get_signed_params(params))
|
||||
|
|
|
|||
19
frappe/www/modified_doc_alert.html
Normal file
19
frappe/www/modified_doc_alert.html
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{% extends "templates/web.html" %}
|
||||
{% block page_content %}
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading" style="display:flex; justify-content:space-between">
|
||||
<h3 class="panel-title">{{ _(title) }}</h3>
|
||||
{% if action %}
|
||||
<a href="{{action.link}}" class="btn btn-sm btn-primary">{{ _(action.label) }}</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="padding">
|
||||
{{ _(message) }}
|
||||
</div>
|
||||
<div class="padding">
|
||||
{{ print_format }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Loading…
Add table
Reference in a new issue