fix: moved erpnext related methods from frappe to erpnext
This commit is contained in:
parent
733ff48d51
commit
270d4e9f4e
@ -10,6 +10,7 @@ from frappe.model.mapper import get_mapped_doc
|
||||
from erpnext.controllers.selling_controller import SellingController
|
||||
from frappe.contacts.address_and_contact import load_address_and_contact
|
||||
from erpnext.accounts.party import set_taxes
|
||||
from frappe.email.inbox import link_communication_to_document
|
||||
|
||||
sender_field = "email_id"
|
||||
|
||||
@ -199,3 +200,29 @@ def get_lead_details(lead, posting_date=None, company=None):
|
||||
out['taxes_and_charges'] = taxes_and_charges
|
||||
|
||||
return out
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_lead_from_communication(communication, ignore_communication_links=False):
|
||||
""" raise a issue from email """
|
||||
|
||||
doc = frappe.get_doc("Communication", communication)
|
||||
lead_name = None
|
||||
if doc.sender:
|
||||
lead_name = frappe.db.get_value("Lead", {"email_id": doc.sender})
|
||||
if not lead_name and doc.phone_no:
|
||||
lead_name = frappe.db.get_value("Lead", {"mobile_no": doc.phone_no})
|
||||
if not lead_name:
|
||||
lead = frappe.get_doc({
|
||||
"doctype": "Lead",
|
||||
"lead_name": doc.sender_full_name,
|
||||
"email_id": doc.sender,
|
||||
"mobile_no": doc.phone_no
|
||||
})
|
||||
lead.flags.ignore_mandatory = True
|
||||
lead.flags.ignore_permissions = True
|
||||
lead.insert()
|
||||
|
||||
lead_name = lead.name
|
||||
|
||||
link_communication_to_document(doc, "Lead", lead_name, ignore_communication_links)
|
||||
return lead_name
|
@ -10,6 +10,7 @@ from erpnext.setup.utils import get_exchange_rate
|
||||
from erpnext.utilities.transaction_base import TransactionBase
|
||||
from erpnext.accounts.party import get_party_account_currency
|
||||
from frappe.desk.form import assign_to
|
||||
from frappe.email.inbox import link_communication_to_document
|
||||
|
||||
subject_field = "title"
|
||||
sender_field = "contact_email"
|
||||
@ -349,3 +350,23 @@ def assign_to_user(doc, subject_field):
|
||||
"name": doc.name,
|
||||
"description": doc.get(subject_field)
|
||||
})
|
||||
@frappe.whitelist()
|
||||
def make_opportunity_from_communication(communication, ignore_communication_links=False):
|
||||
from erpnext.crm.doctype.lead.lead import make_lead_from_communication
|
||||
doc = frappe.get_doc("Communication", communication)
|
||||
|
||||
lead = doc.reference_name if doc.reference_doctype == "Lead" else None
|
||||
if not lead:
|
||||
lead = make_lead_from_communication(communication, ignore_communication_links=True)
|
||||
|
||||
enquiry_from = "Lead"
|
||||
|
||||
opportunity = frappe.get_doc({
|
||||
"doctype": "Opportunity",
|
||||
"enquiry_from": enquiry_from,
|
||||
"lead": lead
|
||||
}).insert(ignore_permissions=True)
|
||||
|
||||
link_communication_to_document(doc, "Opportunity", opportunity.name, ignore_communication_links)
|
||||
|
||||
return opportunity.name
|
||||
|
@ -33,7 +33,7 @@ frappe.ui.form.on("Communication", {
|
||||
|
||||
make_lead_from_communication: (frm) => {
|
||||
return frappe.call({
|
||||
method: "frappe.email.inbox.make_lead_from_communication",
|
||||
method: "erpnext.crm.doctype.lead.lead.make_lead_from_communication",
|
||||
args: {
|
||||
communication: frm.doc.name
|
||||
},
|
||||
@ -48,7 +48,7 @@ frappe.ui.form.on("Communication", {
|
||||
|
||||
make_issue_from_communication: (frm) => {
|
||||
return frappe.call({
|
||||
method: "frappe.email.inbox.make_issue_from_communication",
|
||||
method: "erpnext.support.doctype.issue.issue.make_issue_from_communication",
|
||||
args: {
|
||||
communication: frm.doc.name
|
||||
},
|
||||
@ -63,7 +63,7 @@ frappe.ui.form.on("Communication", {
|
||||
|
||||
make_opportunity_from_communication: (frm) => {
|
||||
return frappe.call({
|
||||
method: "frappe.email.inbox.make_opportunity_from_communication",
|
||||
method: "erpnext.crm.doctype.opportunity.opportunity.make_opportunity_from_communication",
|
||||
args: {
|
||||
communication: frm.doc.name
|
||||
},
|
||||
|
@ -13,6 +13,7 @@ from frappe.model.mapper import get_mapped_doc
|
||||
from frappe.utils.user import is_website_user
|
||||
from ..service_level_agreement.service_level_agreement import get_active_service_level_agreement_for
|
||||
from erpnext.crm.doctype.opportunity.opportunity import assign_to_user
|
||||
from frappe.email.inbox import link_communication_to_document
|
||||
|
||||
sender_field = "raised_by"
|
||||
|
||||
@ -294,3 +295,19 @@ def make_task(source_name, target_doc=None):
|
||||
"doctype": "Task"
|
||||
}
|
||||
}, target_doc)
|
||||
@frappe.whitelist()
|
||||
def make_issue_from_communication(communication, ignore_communication_links=False):
|
||||
""" raise a issue from email """
|
||||
|
||||
doc = frappe.get_doc("Communication", communication)
|
||||
issue = frappe.get_doc({
|
||||
"doctype": "Issue",
|
||||
"subject": doc.subject,
|
||||
"communication_medium": doc.communication_medium,
|
||||
"raised_by": doc.sender or "",
|
||||
"raised_by_phone": doc.phone_no or ""
|
||||
}).insert(ignore_permissions=True)
|
||||
|
||||
link_communication_to_document(doc, "Issue", issue.name, ignore_communication_links)
|
||||
|
||||
return issue.name
|
||||
|
Loading…
x
Reference in New Issue
Block a user