mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-05 21:29:11 +00:00
Merge pull request #32061 from resilient-tech/fix-appointment-creation
fix(Appointment): create lead notes as child table
This commit is contained in:
@@ -7,7 +7,7 @@ from collections import Counter
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils import get_url, getdate
|
from frappe.utils import get_url, getdate, now
|
||||||
from frappe.utils.verified_command import get_signed_params
|
from frappe.utils.verified_command import get_signed_params
|
||||||
|
|
||||||
|
|
||||||
@@ -104,16 +104,28 @@ class Appointment(Document):
|
|||||||
# Return if already linked
|
# Return if already linked
|
||||||
if self.party:
|
if self.party:
|
||||||
return
|
return
|
||||||
|
|
||||||
lead = frappe.get_doc(
|
lead = frappe.get_doc(
|
||||||
{
|
{
|
||||||
"doctype": "Lead",
|
"doctype": "Lead",
|
||||||
"lead_name": self.customer_name,
|
"lead_name": self.customer_name,
|
||||||
"email_id": self.customer_email,
|
"email_id": self.customer_email,
|
||||||
"notes": self.customer_details,
|
|
||||||
"phone": self.customer_phone_number,
|
"phone": self.customer_phone_number,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if self.customer_details:
|
||||||
|
lead.append(
|
||||||
|
"notes",
|
||||||
|
{
|
||||||
|
"note": self.customer_details,
|
||||||
|
"added_by": frappe.session.user,
|
||||||
|
"added_on": now(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
lead.insert(ignore_permissions=True)
|
lead.insert(ignore_permissions=True)
|
||||||
|
|
||||||
# Link lead
|
# Link lead
|
||||||
self.party = lead.name
|
self.party = lead.name
|
||||||
|
|
||||||
|
|||||||
@@ -6,29 +6,20 @@ import unittest
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
|
|
||||||
|
LEAD_EMAIL = "test_appointment_lead@example.com"
|
||||||
def create_test_lead():
|
|
||||||
test_lead = frappe.db.get_value("Lead", {"email_id": "test@example.com"})
|
|
||||||
if test_lead:
|
|
||||||
return frappe.get_doc("Lead", test_lead)
|
|
||||||
test_lead = frappe.get_doc(
|
|
||||||
{"doctype": "Lead", "lead_name": "Test Lead", "email_id": "test@example.com"}
|
|
||||||
)
|
|
||||||
test_lead.insert(ignore_permissions=True)
|
|
||||||
return test_lead
|
|
||||||
|
|
||||||
|
|
||||||
def create_test_appointments():
|
def create_test_appointment():
|
||||||
test_appointment = frappe.get_doc(
|
test_appointment = frappe.get_doc(
|
||||||
{
|
{
|
||||||
"doctype": "Appointment",
|
"doctype": "Appointment",
|
||||||
"email": "test@example.com",
|
|
||||||
"status": "Open",
|
"status": "Open",
|
||||||
"customer_name": "Test Lead",
|
"customer_name": "Test Lead",
|
||||||
"customer_phone_number": "666",
|
"customer_phone_number": "666",
|
||||||
"customer_skype": "test",
|
"customer_skype": "test",
|
||||||
"customer_email": "test@example.com",
|
"customer_email": LEAD_EMAIL,
|
||||||
"scheduled_time": datetime.datetime.now(),
|
"scheduled_time": datetime.datetime.now(),
|
||||||
|
"customer_details": "Hello, Friend!",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
test_appointment.insert()
|
test_appointment.insert()
|
||||||
@@ -36,16 +27,16 @@ def create_test_appointments():
|
|||||||
|
|
||||||
|
|
||||||
class TestAppointment(unittest.TestCase):
|
class TestAppointment(unittest.TestCase):
|
||||||
test_appointment = test_lead = None
|
def setUpClass():
|
||||||
|
frappe.db.delete("Lead", {"email_id": LEAD_EMAIL})
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.test_lead = create_test_lead()
|
self.test_appointment = create_test_appointment()
|
||||||
self.test_appointment = create_test_appointments()
|
self.test_appointment.set_verified(self.test_appointment.customer_email)
|
||||||
|
|
||||||
def test_calendar_event_created(self):
|
def test_calendar_event_created(self):
|
||||||
cal_event = frappe.get_doc("Event", self.test_appointment.calendar_event)
|
cal_event = frappe.get_doc("Event", self.test_appointment.calendar_event)
|
||||||
self.assertEqual(cal_event.starts_on, self.test_appointment.scheduled_time)
|
self.assertEqual(cal_event.starts_on, self.test_appointment.scheduled_time)
|
||||||
|
|
||||||
def test_lead_linked(self):
|
def test_lead_linked(self):
|
||||||
lead = frappe.get_doc("Lead", self.test_lead.name)
|
self.assertTrue(self.test_appointment.party)
|
||||||
self.assertIsNotNone(lead)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user