fix: usage of frappe.db.exists

This commit is contained in:
barredterra 2022-03-21 19:27:42 +01:00 committed by Ankush Menat
parent 3eb5440aa9
commit 5c4eabf075
4 changed files with 44 additions and 41 deletions

View File

@ -494,7 +494,7 @@ class POSInvoice(SalesInvoice):
}
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):

View File

@ -229,5 +229,5 @@ def _get_employee_from_user(user):
{'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

View File

@ -8,50 +8,53 @@ import frappe
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)

View File

@ -936,7 +936,7 @@ def get_leave_period():
"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',