def process_message(self, mail): if mail.from_email == self.settings.email_id: return name = frappe.db.get_value("Job Applicant", {"email_id": mail.from_email}, "name") if name: applicant = frappe.get_doc("Job Applicant", name) if applicant.status != "Rejected": applicant.status = "Open" applicant.ignore_permissions = True applicant.save() else: name = (mail.from_real_name and (mail.from_real_name + " - ") or "") \ + mail.from_email applicant = frappe.get_doc({ "creation": mail.date, "doctype": "Job Applicant", "applicant_name": name, "email_id": mail.from_email, "status": "Open" }) applicant.ignore_permissions = True applicant.ignore_mandatory = True applicant.insert() mail.save_attachments_in_doc(applicant) _make(content=mail.content, sender=mail.from_email, subject=mail.subject or "No Subject", doctype="Job Applicant", name=applicant.name, sent_or_received="Received")
def process_message(self, mail): if mail.from_email == self.settings.email_id: return name = frappe.db.get_value("Job Applicant", {"email_id": mail.from_email}, "name") if name: applicant = frappe.get_doc("Job Applicant", name) if applicant.status!="Rejected": applicant.status = "Open" applicant.ignore_permissions = True applicant.save() else: name = (mail.from_real_name and (mail.from_real_name + " - ") or "") \ + mail.from_email applicant = frappe.get_doc({ "creation": mail.date, "doctype":"Job Applicant", "applicant_name": name, "email_id": mail.from_email, "status": "Open" }) applicant.ignore_permissions = True applicant.ignore_mandatory = True applicant.insert() mail.save_attachments_in_doc(applicant) _make(content=mail.content, sender=mail.from_email, subject=mail.subject or "No Subject", doctype="Job Applicant", name=applicant.name, sent_or_received="Received")
def add_support_communication(subject, content, sender, docname=None, mail=None): if docname: ticket = frappe.get_doc("Support Ticket", docname) ticket.status = 'Open' ticket.ignore_permissions = True ticket.save() else: ticket = frappe.get_doc(decode_dict({ "doctype":"Support Ticket", "description": content, "subject": subject, "raised_by": sender, "content_type": mail.content_type if mail else None, "status": "Open", })) ticket.ignore_permissions = True ticket.ignore_mandatory = True ticket.insert() _make(content=content, sender=sender, subject = subject, doctype="Support Ticket", name=ticket.name, date=mail.date if mail else today(), sent_or_received="Received") if mail: mail.save_attachments_in_doc(ticket) return ticket
def add_support_communication(subject, content, sender, docname=None, mail=None): if docname: ticket = frappe.get_doc("Support Ticket", docname) ticket.status = 'Open' ticket.ignore_permissions = True ticket.save() else: ticket = frappe.get_doc(decode_dict({ "doctype":"Support Ticket", "description": content, "subject": subject, "raised_by": sender, "content_type": mail.content_type if mail else None, "status": "Open", })) ticket.ignore_permissions = True ticket.ignore_mandatory = True ticket.insert() _make(content=content, sender=sender, subject = subject, doctype="Support Ticket", name=ticket.name, date=mail.date if mail else today(), sent_or_received="Received") if mail: mail.save_attachments_in_doc(ticket) return ticket
def add_reply(ticket, message): if not message: raise frappe.throw(_("Please write something")) bean = frappe.bean("Support Ticket", ticket) if bean.doc.raised_by != frappe.session.user: raise frappe.throw(_("You are not allowed to reply to this ticket."), frappe.PermissionError) from frappe.core.doctype.communication.communication import _make _make(content=message, sender=bean.doc.raised_by, subject = bean.doc.subject, doctype="Support Ticket", name=bean.doc.name, date=today())
def add_sales_communication(subject, content, sender, real_name, mail=None, status="Open", date=None): lead_name = frappe.db.get_value("Lead", {"email_id": sender}) contact_name = frappe.db.get_value("Contact", {"email_id": sender}) if not (lead_name or contact_name): # none, create a new Lead lead = frappe.get_doc({ "doctype":"Lead", "lead_name": real_name or sender, "email_id": sender, "status": status, "source": "Email" }) lead.ignore_permissions = True lead.ignore_mandatory = True lead.insert() lead_name = lead.name parent_doctype = "Contact" if contact_name else "Lead" parent_name = contact_name or lead_name message = _make(content=content, sender=sender, subject=subject, doctype = parent_doctype, name = parent_name, date=date, sent_or_received="Received") if mail: # save attachments to parent if from mail doc = frappe.get_doc(parent_doctype, parent_name) mail.save_attachments_in_doc(doc)
def add_reply(ticket, message): if not message: raise frappe.throw(_("Please write something")) doc = frappe.get_doc("Support Ticket", ticket) if doc.raised_by != frappe.session.user: raise frappe.throw(_("You are not allowed to reply to this ticket."), frappe.PermissionError) from frappe.core.doctype.communication.communication import _make _make(content=message, sender=doc.raised_by, subject=doc.subject, doctype="Support Ticket", name=doc.name, date=today())
def add_sales_communication(subject, content, sender, real_name, mail=None, status="Open", date=None): lead_name = frappe.db.get_value("Lead", {"email_id": sender}) contact_name = frappe.db.get_value("Contact", {"email_id": sender}) if not (lead_name or contact_name): # none, create a new Lead lead = frappe.get_doc({ "doctype": "Lead", "lead_name": real_name or sender, "email_id": sender, "status": status, "source": "Email" }) lead.ignore_permissions = True lead.ignore_mandatory = True lead.insert() lead_name = lead.name parent_doctype = "Contact" if contact_name else "Lead" parent_name = contact_name or lead_name message = _make(content=content, sender=sender, subject=subject, doctype=parent_doctype, name=parent_name, date=date, sent_or_received="Received") if mail: # save attachments to parent if from mail doc = frappe.get_doc(parent_doctype, parent_name) mail.save_attachments_in_doc(doc)