refactor: use get_value instead of exists

This commit is contained in:
Ankush Menat 2022-03-22 11:44:53 +05:30 committed by Ankush Menat
parent 5c4eabf075
commit f37316a266
4 changed files with 5 additions and 20 deletions

View File

@ -485,14 +485,13 @@ class POSInvoice(SalesInvoice):
"payment_account": pay.account,
}, ["name"])
args = {
'doctype': 'Payment Request',
filters = {
'reference_doctype': 'POS Invoice',
'reference_name': self.name,
'payment_gateway_account': payment_gateway_account,
'email_to': self.contact_mobile
}
pr = frappe.db.exists(args)
pr = frappe.db.get_value('Payment Request', filters=filters)
if pr:
return frappe.get_doc('Payment Request', pr)

View File

@ -225,9 +225,7 @@ def _check_agent_availability(agent_email, scheduled_time):
def _get_employee_from_user(user):
employee_docname = frappe.db.exists(
{'doctype': 'Employee', 'user_id': user})
employee_docname = frappe.db.get_value('Employee', {'user_id': user})
if employee_docname:
# frappe.db.exists returns a tuple of a tuple
return frappe.get_doc('Employee', employee_docname)
return None

View File

@ -8,7 +8,7 @@ import frappe
def create_test_lead():
test_lead = frappe.db.exists({"doctype": "Lead", "email_id": "test@example.com"})
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(
@ -19,15 +19,6 @@ def create_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)
test_appointment = frappe.get_doc(
{
"doctype": "Appointment",

View File

@ -931,10 +931,7 @@ def set_leave_approver():
dept_doc.save(ignore_permissions=True)
def get_leave_period():
leave_period_name = frappe.db.exists({
"doctype": "Leave Period",
"company": "_Test Company"
})
leave_period_name = frappe.db.get_value("Leave Period", {"company": "_Test Company"})
if leave_period_name:
return frappe.get_doc("Leave Period", leave_period_name)
else: