Explorar el Código

[fixes] check if print for Draft and Cancelled document is allowed or not before sending email alert

version-14
mbauskar hace 8 años
committed by Nabin Hait
padre
commit
dce3aed62e
Se han modificado 2 ficheros con 22 adiciones y 3 borrados
  1. +20
    -1
      frappe/email/doctype/email_alert/email_alert.py
  2. +2
    -2
      frappe/www/print.py

+ 20
- 1
frappe/email/doctype/email_alert/email_alert.py Ver fichero

@@ -91,6 +91,23 @@ def get_context(context):

def send(self, doc):
'''Build recipients and send email alert'''

def get_attachment(doc):
""" check print settings are attach the pdf """
if not self.attach_print:
return None

print_settings = frappe.get_doc("Print Settings", "Print Settings")
if (doc.docstatus == 0 and not print_settings.allow_print_for_draft) or \
(doc.docstatus == 2 and not print_settings.allow_print_for_cancelled):

# ignoring attachment as draft and cancelled documents are not allowed to print
status = "Draft" if doc.docstatus == 0 else "Cancelled"
frappe.throw(_("""Not allowed to attach {0} document,
please enable Allow Print For {0} in Print Settings""".format(status)))
else:
return [frappe.attach_print(doc.doctype, doc.name)]

context = get_context(doc)

recipients = []
@@ -133,11 +150,13 @@ def get_context(context):
if "{" in subject:
subject = frappe.render_template(self.subject, context)

attachments = get_attachment(doc)

frappe.sendmail(recipients=recipients, subject=subject,
message= frappe.render_template(self.message, context),
reference_doctype = doc.doctype,
reference_name = doc.name,
attachments = [frappe.attach_print(doc.doctype, doc.name)] if self.attach_print else None)
attachments = attachments)

def load_standard_properties(self, context):
module = get_doc_module(self.module, self.doctype, self.name)


+ 2
- 2
frappe/www/print.py Ver fichero

@@ -76,10 +76,10 @@ def get_html(doc, name=None, print_format=None, meta=None,
validate_print_permission(doc)

if doc.meta.is_submittable:
if doc.docstatus==0 and not print_settings.allow_print_for_draft:
if doc.docstatus==0 and not cint(print_settings.allow_print_for_draft):
frappe.throw(_("Not allowed to print draft documents"), frappe.PermissionError)

if doc.docstatus==2 and not print_settings.allow_print_for_cancelled:
if doc.docstatus==2 and not cint(print_settings.allow_print_for_cancelled):
frappe.throw(_("Not allowed to print cancelled documents"), frappe.PermissionError)

if hasattr(doc, "before_print"):


Cargando…
Cancelar
Guardar