@@ -1537,35 +1537,46 @@ def get_payment_entry(ref_doc, args):
15371537
15381538@frappe .whitelist ()
15391539@frappe .validate_and_sanitize_search_inputs
1540+ < << << << HEAD
15401541def get_against_jv (doctype , txt , searchfield , start , page_len , filters ):
1542+ == == == =
1543+ def get_against_jv (
1544+ doctype : str ,
1545+ txt : str ,
1546+ searchfield : str ,
1547+ start : int ,
1548+ page_len : int ,
1549+ filters : dict ,
1550+ ):
1551+ > >> >> >> c133f7156d (fix : replace raw SQL with qb in get_against_jv to prevent SQL injection )
15411552 if not frappe .db .has_column ("Journal Entry" , searchfield ):
15421553 return []
15431554
1544- return frappe .db .sql (
1545- f"""
1546- SELECT jv.name, jv.posting_date, jv.user_remark
1547- FROM `tabJournal Entry` jv, `tabJournal Entry Account` jv_detail
1548- WHERE jv_detail.parent = jv.name
1549- AND jv_detail.account = %(account)s
1550- AND IFNULL(jv_detail.party, '') = %(party)s
1551- AND (
1552- jv_detail.reference_type IS NULL
1553- OR jv_detail.reference_type = ''
1554- )
1555- AND jv.docstatus = 1
1556- AND jv.`{ searchfield } ` LIKE %(txt)s
1557- ORDER BY jv.name DESC
1558- LIMIT %(limit)s offset %(offset)s
1559- """ ,
1560- dict (
1561- account = filters .get ("account" ),
1562- party = cstr (filters .get ("party" )),
1563- txt = f"%{ txt } %" ,
1564- offset = start ,
1565- limit = page_len ,
1566- ),
1555+ JournalEntry = frappe .qb .DocType ("Journal Entry" )
1556+ JournalEntryAccount = frappe .qb .DocType ("Journal Entry Account" )
1557+
1558+ query = (
1559+ frappe .qb .from_ (JournalEntry )
1560+ .join (JournalEntryAccount )
1561+ .on (JournalEntryAccount .parent == JournalEntry .name )
1562+ .select (JournalEntry .name , JournalEntry .posting_date , JournalEntry .user_remark )
1563+ .where (JournalEntryAccount .account == filters .get ("account" ))
1564+ .where (JournalEntryAccount .reference_type .isnull () | (JournalEntryAccount .reference_type == "" ))
1565+ .where (JournalEntry .docstatus == 1 )
1566+ .where (JournalEntry [searchfield ].like (f"%{ txt } %" ))
1567+ .orderby (JournalEntry .name , order = frappe .qb .desc )
1568+ .limit (page_len )
1569+ .offset (start )
15671570 )
15681571
1572+ party = filters .get ("party" )
1573+ if party :
1574+ query = query .where (JournalEntryAccount .party == party )
1575+ else :
1576+ query = query .where (JournalEntryAccount .party .isnull () | (JournalEntryAccount .party == "" ))
1577+
1578+ return query .run ()
1579+
15691580
15701581@frappe .whitelist ()
15711582def get_outstanding (args ):
0 commit comments