From f37316a266f28dc3d26b5bd11729c65613ce75c5 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 22 Mar 2022 11:44:53 +0530 Subject: [PATCH] refactor: use `get_value` instead of `exists` --- erpnext/accounts/doctype/pos_invoice/pos_invoice.py | 5 ++--- erpnext/crm/doctype/appointment/appointment.py | 4 +--- erpnext/crm/doctype/appointment/test_appointment.py | 11 +---------- .../leave_application/test_leave_application.py | 5 +---- 4 files changed, 5 insertions(+), 20 deletions(-) diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py index 2b88fe7e54..d782cc295c 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py @@ -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) diff --git a/erpnext/crm/doctype/appointment/appointment.py b/erpnext/crm/doctype/appointment/appointment.py index c36faaf79b..88a9c10131 100644 --- a/erpnext/crm/doctype/appointment/appointment.py +++ b/erpnext/crm/doctype/appointment/appointment.py @@ -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 diff --git a/erpnext/crm/doctype/appointment/test_appointment.py b/erpnext/crm/doctype/appointment/test_appointment.py index 7183737bea..776e604333 100644 --- a/erpnext/crm/doctype/appointment/test_appointment.py +++ b/erpnext/crm/doctype/appointment/test_appointment.py @@ -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", diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py index e01bdf6e84..db4cbb7aae 100644 --- a/erpnext/hr/doctype/leave_application/test_leave_application.py +++ b/erpnext/hr/doctype/leave_application/test_leave_application.py @@ -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: