diff --git a/erpnext/www/payment_setup_certification.py b/erpnext/www/payment_setup_certification.py index 5d62d60f5eb..e8e9d51668c 100644 --- a/erpnext/www/payment_setup_certification.py +++ b/erpnext/www/payment_setup_certification.py @@ -1,4 +1,5 @@ import frappe +from frappe.query_builder.functions import IfNull no_cache = 1 @@ -12,13 +13,15 @@ def get_context(context): def get_all_certifications_of_a_member(): """Returns all certifications""" all_certifications = [] - all_certifications = frappe.db.sql( - """ select cc.name,cc.from_date,cc.to_date,ca.amount,ca.currency - from `tabCertified Consultant` cc - inner join `tabCertification Application` ca - on cc.certification_application = ca.name - where paid = 1 and email = %(user)s order by cc.to_date desc""", - {"user": frappe.session.user}, - as_dict=True, + cc = frappe.qb.DocType("Certified Consultant") + ca = frappe.qb.DocType("Certification Application") + all_certifications = ( + frappe.qb.from_(cc) + .inner_join(ca) + .on(cc.certification_application == ca.name) + .select(cc.name, cc.from_date, cc.to_date, ca.amount, ca.currency) + .where((cc.paid == 1) & (cc.email == frappe.session.user)) + .orderby(IfNull(cc.to_date, "0001-01-01"), order=frappe.qb.desc) + .run(as_dict=True) ) return all_certifications