[email] changes in email_account api

This commit is contained in:
Rushabh Mehta 2015-05-04 18:17:22 +05:30
parent e991c9e075
commit 82ee5fdba6
4 changed files with 28 additions and 30 deletions

View File

@ -11,14 +11,12 @@ from frappe.model.mapper import get_mapped_doc
from erpnext.controllers.selling_controller import SellingController
from erpnext.utilities.address_and_contact import load_address_and_contact
sender_field = "email_id"
class Lead(SellingController):
def get_feed(self):
return '{0}: {1}'.format(_(self.status), self.lead_name)
def set_sender(self, sender):
"""Will be called by **Communication** when a Lead is created from an incoming email."""
self.email_id = sender
def onload(self):
customer = frappe.db.get_value("Customer", {"lead_name": self.name})
self.get("__onload").is_customer = customer

View File

@ -9,25 +9,10 @@ from frappe.model.mapper import get_mapped_doc
from erpnext.utilities.transaction_base import TransactionBase
subject_field = "title"
sender_field = "contact_email"
class Opportunity(TransactionBase):
def set_sender(self, email_id):
"""Set lead against new opportunity"""
lead_name = frappe.db.get_value("Lead", {"email_id": email_id})
if not lead_name:
lead = frappe.get_doc({
"doctype": "Lead",
"email_id": email_id,
"lead_name": email_id
})
lead.insert(ignore_permissions=True)
lead_name = lead.name
self.enquiry_from = "Lead"
self.lead = lead_name
def set_subject(self, subject):
self.title = subject
def after_insert(self):
if self.lead:
frappe.get_doc("Lead", self.lead).set_status(update=True)
@ -40,6 +25,8 @@ class Opportunity(TransactionBase):
(not cint(self.get("__islocal"))) else None,
})
self.make_new_lead_if_required()
if not self.enquiry_from:
frappe.throw(_("Opportunity From field is mandatory"))
@ -55,6 +42,22 @@ class Opportunity(TransactionBase):
from erpnext.accounts.utils import validate_fiscal_year
validate_fiscal_year(self.transaction_date, self.fiscal_year, _("Opportunity Date"), self)
def make_new_lead_if_required(self):
"""Set lead against new opportunity"""
if not self.lead or self.customer:
lead_name = frappe.db.get_value("Lead", {"email_id": self.contact_email})
if not lead_name:
lead = frappe.get_doc({
"doctype": "Lead",
"email_id": self.contact_email,
"lead_name": self.contact_email
})
lead.insert(ignore_permissions=True)
lead_name = lead.name
self.enquiry_from = "Lead"
self.lead = lead_name
def declare_enquiry_lost(self,arg):
if not self.has_quotation():
frappe.db.set(self, 'status', 'Lost')

View File

@ -9,12 +9,14 @@ import frappe
from frappe import _
from frappe.utils import comma_and
sender_field = "email_id"
class JobApplicant(Document):
def onload(self):
offer_letter = frappe.get_all("Offer Letter", filters={"job_applicant": self.name})
if offer_letter:
self.get("__onload").offer_letter = offer_letter[0].name
def autoname(self):
keys = filter(None, (self.applicant_name, self.email_id))
if not keys:
@ -31,6 +33,3 @@ class JobApplicant(Document):
if names:
frappe.throw(_("Email id must be unique, already exists for {0}").format(comma_and(names)), frappe.DuplicateEntryError)
def set_sender(self, sender):
self.email_id = sender

View File

@ -10,14 +10,12 @@ from frappe.model.document import Document
from frappe.utils import now
from frappe.utils.user import is_website_user
sender_field = "raised_by"
class Issue(Document):
def get_feed(self):
return "{0}: {1}".format(_(self.status), self.subject)
def set_sender(self, sender):
"""Will be called by **Communication** when the Issue is created from an incoming email."""
self.raised_by = sender
def validate(self):
self.update_status()
self.set_lead_contact(self.raised_by)