fix: usage of frappe.db.exists
diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py
index 91c07ad..2b88fe7 100644
--- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py
+++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py
@@ -494,7 +494,7 @@
}
pr = frappe.db.exists(args)
if pr:
- return frappe.get_doc('Payment Request', pr[0][0])
+ return frappe.get_doc('Payment Request', pr)
@frappe.whitelist()
def get_stock_availability(item_code, warehouse):
diff --git a/erpnext/crm/doctype/appointment/appointment.py b/erpnext/crm/doctype/appointment/appointment.py
index 20fb987..c36faaf 100644
--- a/erpnext/crm/doctype/appointment/appointment.py
+++ b/erpnext/crm/doctype/appointment/appointment.py
@@ -229,5 +229,5 @@
{'doctype': 'Employee', 'user_id': user})
if employee_docname:
# frappe.db.exists returns a tuple of a tuple
- return frappe.get_doc('Employee', employee_docname[0][0])
+ return frappe.get_doc('Employee', employee_docname)
return None
diff --git a/erpnext/crm/doctype/appointment/test_appointment.py b/erpnext/crm/doctype/appointment/test_appointment.py
index f4086dc..7183737 100644
--- a/erpnext/crm/doctype/appointment/test_appointment.py
+++ b/erpnext/crm/doctype/appointment/test_appointment.py
@@ -8,50 +8,53 @@
def create_test_lead():
- test_lead = frappe.db.exists({'doctype': 'Lead', 'email_id':'test@example.com'})
- if test_lead:
- return frappe.get_doc('Lead', test_lead[0][0])
- 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
+ test_lead = frappe.db.exists({"doctype": "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():
- test_appointment = frappe.db.exists(
- {'doctype': 'Appointment', 'scheduled_time':datetime.datetime.now(),'email':'test@example.com'})
- if test_appointment:
- return frappe.get_doc('Appointment', test_appointment[0][0])
- test_appointment = frappe.get_doc({
- 'doctype': 'Appointment',
- 'email': 'test@example.com',
- 'status': 'Open',
- 'customer_name': 'Test Lead',
- 'customer_phone_number': '666',
- 'customer_skype': 'test',
- 'customer_email': 'test@example.com',
- 'scheduled_time': datetime.datetime.now()
- })
- test_appointment.insert()
- return test_appointment
+ test_appointment = frappe.db.exists(
+ {
+ "doctype": "Appointment",
+ "scheduled_time": datetime.datetime.now(),
+ "email": "test@example.com",
+ }
+ )
+ if test_appointment:
+ return frappe.get_doc("Appointment", test_appointment)
+ test_appointment = frappe.get_doc(
+ {
+ "doctype": "Appointment",
+ "email": "test@example.com",
+ "status": "Open",
+ "customer_name": "Test Lead",
+ "customer_phone_number": "666",
+ "customer_skype": "test",
+ "customer_email": "test@example.com",
+ "scheduled_time": datetime.datetime.now(),
+ }
+ )
+ test_appointment.insert()
+ return test_appointment
class TestAppointment(unittest.TestCase):
- test_appointment = test_lead = None
+ test_appointment = test_lead = None
- def setUp(self):
- self.test_lead = create_test_lead()
- self.test_appointment = create_test_appointments()
+ def setUp(self):
+ self.test_lead = create_test_lead()
+ self.test_appointment = create_test_appointments()
- def test_calendar_event_created(self):
- cal_event = frappe.get_doc(
- 'Event', self.test_appointment.calendar_event)
- self.assertEqual(cal_event.starts_on,
- self.test_appointment.scheduled_time)
+ def test_calendar_event_created(self):
+ cal_event = frappe.get_doc("Event", self.test_appointment.calendar_event)
+ self.assertEqual(cal_event.starts_on, self.test_appointment.scheduled_time)
- def test_lead_linked(self):
- lead = frappe.get_doc('Lead', self.test_lead.name)
- self.assertIsNotNone(lead)
+ def test_lead_linked(self):
+ lead = frappe.get_doc("Lead", self.test_lead.name)
+ self.assertIsNotNone(lead)
diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py
index 7d32fd8..e01bdf6 100644
--- a/erpnext/hr/doctype/leave_application/test_leave_application.py
+++ b/erpnext/hr/doctype/leave_application/test_leave_application.py
@@ -936,7 +936,7 @@
"company": "_Test Company"
})
if leave_period_name:
- return frappe.get_doc("Leave Period", leave_period_name[0][0])
+ return frappe.get_doc("Leave Period", leave_period_name)
else:
return frappe.get_doc(dict(
name = 'Test Leave Period',