Example #1
0
def assign_warranty_claim(warranty_claim, method):
	if not frappe.get_all("ToDo", filters={"reference_type": "Warranty Claim", "reference_name": warranty_claim.name}):
		repair_settings = frappe.get_doc("Repair Settings")
		user_emails = []

		for notification in repair_settings.notification_settings:
			if notification.status == warranty_claim.status:
				if notification.user:
					user_emails.append(notification.user)

				if notification.role:
					user_emails.extend(get_emails_from_role(notification.role))

				if notification.cc:
					notification.cc = notification.cc.replace(",", "\n")
					user_emails.extend(notification.cc.split("\n"))

		user_emails = list(set(user_emails))
		admin_email = frappe.db.get_value("User", "Administrator", "email")

		if admin_email in user_emails:
			user_emails.remove(admin_email)

		for user in user_emails:
			assign_to.add({
				'assign_to': user,
				'doctype': "Warranty Claim",
				'name': warranty_claim.name,
				'description': "Service Request {0} just moved to the '{1}' status".format(warranty_claim.name, warranty_claim.status),
				'priority': 'Medium',
				'notify': 1
			})
Example #2
0
    def get_list_of_recipients(self, doc, context):
        recipients = []
        for recipient in self.recipients:
            if recipient.condition:
                if not frappe.safe_eval(recipient.condition, None, context):
                    continue
            if recipient.email_by_document_field:
                email_ids_value = doc.get(recipient.email_by_document_field)
                if validate_email_add(email_ids_value):
                    email_ids = email_ids_value.replace(",", "\n")
                    recipients = recipients + email_ids.split("\n")

                # else:
                # 	print "invalid email"
            if recipient.cc and "{" in recipient.cc:
                recipient.cc = frappe.render_template(recipient.cc, context)

            if recipient.cc:
                recipient.cc = recipient.cc.replace(",", "\n")
                recipients = recipients + recipient.cc.split("\n")

            #For sending emails to specified role
            if recipient.email_by_role:
                emails = get_emails_from_role(recipient.email_by_role)

                for email in emails:
                    recipients = recipients + email.split("\n")

        if not recipients:
            return

        return list(set(recipients))
Example #3
0
 def assign_to_role(role, reviewer=False):
     emails = get_emails_from_role(role)
     print "####### role = {} emails = {}".format(role, emails)
     name = ""
     for email in emails:
         if email == "*****@*****.**":
             continue
         print "email = {}".format(email)
         print "role[-2] = {}".format(role[:-2])
         if (reviewer):
             name = role
         else:
             name = role[:-2]
         add({
             "assign_to":
             email,
             "doctype":
             "Task",
             "name":
             doc.project + " - " + name,
             "description":
             "New Task : " + doc.project + " - " + name + "<br><br>" +
             "<a href='" + get_url_to_form("Task", doc.project + " - " +
                                           name) +
             "' target='_self'>&nbsp; Click Hear To open Task</a>"
         })
Example #4
0
    def send(self, doc):
        '''Build recipients and send email alert'''
        context = get_context(doc)

        recipients = []
        for recipient in self.recipients:
            if recipient.condition:
                if not frappe.safe_eval(recipient.condition, None, context):
                    continue
            if recipient.email_by_document_field:
                if validate_email_add(
                        doc.get(recipient.email_by_document_field)):
                    recipient.email_by_document_field = doc.get(
                        recipient.email_by_document_field).replace(",", "\n")
                    recipients = recipients + recipient.email_by_document_field.split(
                        "\n")

                # else:
                # 	print "invalid email"
            if recipient.cc:
                recipient.cc = recipient.cc.replace(",", "\n")
                recipients = recipients + recipient.cc.split("\n")

            #For sending emails to specified role
            if recipient.email_by_role:
                emails = get_emails_from_role(recipient.email_by_role)

                for email in emails:
                    recipients = recipients + email.split("\n")

        if not recipients:
            return

        recipients = list(set(recipients))
        subject = self.subject

        context = {"doc": doc, "alert": self, "comments": None}

        if self.is_standard:
            self.load_standard_properties(context)

        if doc.get("_comments"):
            context["comments"] = json.loads(doc.get("_comments"))

        if "{" in subject:
            subject = frappe.render_template(self.subject, context)

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

		for recipient in self.recipients:
			recipients = []
			if recipient.condition:
				if not eval(recipient.condition, context):
					continue
			if recipient.email_by_document_field:
				if validate_email_add(doc.get(recipient.email_by_document_field)):
					recipients.append(doc.get(recipient.email_by_document_field))
				# else:
				# 	print "invalid email"
			if recipient.cc:
				recipient.cc = recipient.cc.replace(",", "\n")
				recipients = recipients + recipient.cc.split("\n")

			#For sending emails to specified role
			if recipient.email_by_role:
				emails = get_emails_from_role(recipient.email_by_role)

		for email in emails:
			recipients = recipients + email.split("\n")

		if not recipients:
			return

		subject = self.subject

		context = {"doc": doc, "alert": self, "comments": None}

		if self.is_standard:
			self.load_standard_properties(context)

		if doc.get("_comments"):
			context["comments"] = json.loads(doc.get("_comments"))

		if "{" in subject:
			subject = frappe.render_template(self.subject, context)

		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)
Example #6
0
	def get_list_of_recipients(self, doc, context):
		recipients = []
		cc = []
		bcc = []
		for recipient in self.recipients:
			if recipient.condition:
				if not frappe.safe_eval(recipient.condition, None, context):
					continue
			if recipient.email_by_document_field:
				email_ids_value = doc.get(recipient.email_by_document_field)
				if validate_email_add(email_ids_value):
					email_ids = email_ids_value.replace(",", "\n")
					recipients = recipients + email_ids.split("\n")

				# else:
				# 	print "invalid email"
			if recipient.cc and "{" in recipient.cc:
				recipient.cc = frappe.render_template(recipient.cc, context)

			if recipient.cc:
				recipient.cc = recipient.cc.replace(",", "\n")
				cc = cc + recipient.cc.split("\n")

			if recipient.bcc and "{" in recipient.bcc:
				recipient.bcc = frappe.render_template(recipient.bcc, context)

			if recipient.bcc:
				recipient.bcc = recipient.bcc.replace(",", "\n")
				bcc = bcc + recipient.bcc.split("\n")

			#For sending emails to specified role
			if recipient.email_by_role:
				emails = get_emails_from_role(recipient.email_by_role)

				for email in emails:
					recipients = recipients + email.split("\n")

		if not recipients and not cc and not bcc:
			return None, None, None
		return list(set(recipients)), list(set(cc)), list(set(bcc))
Example #7
0
    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)),
                             title=_("Error in Email Alert"))
            else:
                return [frappe.attach_print(doc.doctype, doc.name)]

        context = get_context(doc)
        recipients = []

        for recipient in self.recipients:
            if recipient.condition:
                if not frappe.safe_eval(recipient.condition, None, context):
                    continue
            if recipient.email_by_document_field:
                if validate_email_add(
                        doc.get(recipient.email_by_document_field)):
                    recipient.email_by_document_field = doc.get(
                        recipient.email_by_document_field).replace(",", "\n")
                    recipients = recipients + recipient.email_by_document_field.split(
                        "\n")

                # else:
                # 	print "invalid email"
            if recipient.cc:
                recipient.cc = recipient.cc.replace(",", "\n")
                recipients = recipients + recipient.cc.split("\n")

            #For sending emails to specified role
            if recipient.email_by_role:
                emails = get_emails_from_role(recipient.email_by_role)

                for email in emails:
                    recipients = recipients + email.split("\n")

        if not recipients:
            return

        recipients = list(set(recipients))
        subject = self.subject

        context = {"doc": doc, "alert": self, "comments": None}

        if self.is_standard:
            self.load_standard_properties(context)

        if doc.get("_comments"):
            context["comments"] = json.loads(doc.get("_comments"))

        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=attachments)
Example #8
0
	def send(self, doc):
		'''Build recipients and send email alert'''
		from email.utils import formataddr

		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)),
					title=_("Error in Email Alert"))
			else:
				return [{"print_format_attachment":1, "doctype":doc.doctype, "name": doc.name,
					"print_format":self.print_format, "print_letterhead": print_settings.with_letterhead}]

		context = get_context(doc)
		recipients = []
		sender = ""

		for recipient in self.recipients:
			if recipient.condition:
				if not frappe.safe_eval(recipient.condition, None, context):
					continue
			if recipient.email_by_document_field:
				email_ids_value = doc.get(recipient.email_by_document_field)
				if validate_email_add(email_ids_value):
					email_ids = email_ids_value.replace(",", "\n")
					recipients = recipients + email_ids.split("\n")

				# else:
				# 	print "invalid email"
			if recipient.cc:
				recipient.cc = recipient.cc.replace(",", "\n")
				recipients = recipients + recipient.cc.split("\n")

			#For sending emails to specified role
			if recipient.email_by_role:
				emails = get_emails_from_role(recipient.email_by_role)

				for email in emails:
					recipients = recipients + email.split("\n")

		if not recipients:
			return

		recipients = list(set(recipients))
		subject = self.subject

		context = {"doc": doc, "alert": self, "comments": None}

		if self.sender:
			sender = formataddr((self.sender, self.sender_email))

		if self.is_standard:
			self.load_standard_properties(context)

		if doc.get("_comments"):
			context["comments"] = json.loads(doc.get("_comments"))

		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),
			sender = sender,
			reference_doctype = doc.doctype,
			reference_name = doc.name,
			attachments = attachments,
			print_letterhead = ((attachments
				and attachments[0].get('print_letterhead')) or False))

		if self.set_property_after_alert:
			frappe.db.set_value(doc.doctype, doc.name, self.set_property_after_alert,
				self.property_value, update_modified = False)
			doc.set(self.set_property_after_alert, self.property_value)
Example #9
0
    def send(self, doc):
        '''Build recipients and send email alert'''
        from email.utils import formataddr

        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)),
                             title=_("Error in Email Alert"))
            else:
                return [{
                    "print_format_attachment": 1,
                    "doctype": doc.doctype,
                    "name": doc.name,
                    "print_format": self.print_format,
                    "print_letterhead": print_settings.with_letterhead
                }]

        context = get_context(doc)
        recipients = []
        sender = ""

        for recipient in self.recipients:
            if recipient.condition:
                if not frappe.safe_eval(recipient.condition, None, context):
                    continue
            if recipient.email_by_document_field:
                email_ids_value = doc.get(recipient.email_by_document_field)
                if validate_email_add(email_ids_value):
                    email_ids = email_ids_value.replace(",", "\n")
                    recipients = recipients + email_ids.split("\n")

                # else:
                # 	print "invalid email"
            if recipient.cc:
                recipient.cc = recipient.cc.replace(",", "\n")
                recipients = recipients + recipient.cc.split("\n")

            #For sending emails to specified role
            if recipient.email_by_role:
                emails = get_emails_from_role(recipient.email_by_role)

                for email in emails:
                    recipients = recipients + email.split("\n")

        if not recipients:
            return

        recipients = list(set(recipients))
        subject = self.subject

        context = {"doc": doc, "alert": self, "comments": None}

        if self.sender:
            sender = formataddr((self.sender, self.sender_email))

        if self.is_standard:
            self.load_standard_properties(context)

        if doc.get("_comments"):
            context["comments"] = json.loads(doc.get("_comments"))

        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),
            sender=sender,
            reference_doctype=doc.doctype,
            reference_name=doc.name,
            attachments=attachments,
            print_letterhead=((attachments
                               and attachments[0].get('print_letterhead'))
                              or False))

        if self.set_property_after_alert:
            frappe.db.set_value(doc.doctype,
                                doc.name,
                                self.set_property_after_alert,
                                self.property_value,
                                update_modified=False)
            doc.set(self.set_property_after_alert, self.property_value)