Selaa lähdekoodia

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

version-14
mbauskar 8 vuotta sitten
committed by Nabin Hait
vanhempi
commit
dce3aed62e
2 muutettua tiedostoa jossa 22 lisäystä ja 3 poistoa
  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 Näytä tiedosto

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


def send(self, doc): def send(self, doc):
'''Build recipients and send email alert''' '''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) context = get_context(doc)


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


attachments = get_attachment(doc)

frappe.sendmail(recipients=recipients, subject=subject, frappe.sendmail(recipients=recipients, subject=subject,
message= frappe.render_template(self.message, context), message= frappe.render_template(self.message, context),
reference_doctype = doc.doctype, reference_doctype = doc.doctype,
reference_name = doc.name, 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): def load_standard_properties(self, context):
module = get_doc_module(self.module, self.doctype, self.name) module = get_doc_module(self.module, self.doctype, self.name)


+ 2
- 2
frappe/www/print.py Näytä tiedosto

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


if doc.meta.is_submittable: 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) 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) frappe.throw(_("Not allowed to print cancelled documents"), frappe.PermissionError)


if hasattr(doc, "before_print"): if hasattr(doc, "before_print"):


Ladataan…
Peruuta
Tallenna