* Remove six for PY2 compatability since our dependencies are not, PY2 is legacy. * Removed usages of utils from future/past libraries since they are deprecated. This includes 'from __future__ ...' and 'from past...' statements. * Removed compatibility imports for PY2, switched from six imports to standard library imports. * Removed utils code blocks that handle operations depending on PY2/3 versions. * Removed 'from __future__ ...' lines from templates/code generators * Used PY3 syntaxes in place of PY2 compatible blocks. eg: metaclass
67 lines
1.6 KiB
Python
67 lines
1.6 KiB
Python
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
|
# MIT License. See license.txt
|
|
|
|
import frappe, json
|
|
from frappe.desk.form.load import run_onload
|
|
|
|
@frappe.whitelist()
|
|
def savedocs(doc, action):
|
|
"""save / submit / update doclist"""
|
|
try:
|
|
doc = frappe.get_doc(json.loads(doc))
|
|
set_local_name(doc)
|
|
|
|
# action
|
|
doc.docstatus = {"Save":0, "Submit": 1, "Update": 1, "Cancel": 2}[action]
|
|
|
|
if doc.docstatus==1:
|
|
doc.submit()
|
|
else:
|
|
doc.save()
|
|
|
|
# update recent documents
|
|
run_onload(doc)
|
|
send_updated_docs(doc)
|
|
|
|
frappe.msgprint(frappe._("Saved"), indicator='green', alert=True)
|
|
except Exception:
|
|
frappe.errprint(frappe.utils.get_traceback())
|
|
raise
|
|
|
|
@frappe.whitelist()
|
|
def cancel(doctype=None, name=None, workflow_state_fieldname=None, workflow_state=None):
|
|
"""cancel a doclist"""
|
|
try:
|
|
doc = frappe.get_doc(doctype, name)
|
|
if workflow_state_fieldname and workflow_state:
|
|
doc.set(workflow_state_fieldname, workflow_state)
|
|
doc.cancel()
|
|
send_updated_docs(doc)
|
|
frappe.msgprint(frappe._("Cancelled"), indicator='red', alert=True)
|
|
|
|
except Exception:
|
|
frappe.errprint(frappe.utils.get_traceback())
|
|
raise
|
|
|
|
def send_updated_docs(doc):
|
|
from .load import get_docinfo
|
|
get_docinfo(doc)
|
|
|
|
d = doc.as_dict()
|
|
if hasattr(doc, 'localname'):
|
|
d["localname"] = doc.localname
|
|
|
|
frappe.response.docs.append(d)
|
|
|
|
def set_local_name(doc):
|
|
def _set_local_name(d):
|
|
if doc.get('__islocal') or d.get('__islocal'):
|
|
d.localname = d.name
|
|
d.name = None
|
|
|
|
_set_local_name(doc)
|
|
for child in doc.get_all_children():
|
|
_set_local_name(child)
|
|
|
|
if doc.get("__newname"):
|
|
doc.name = doc.get("__newname")
|