Skip to content

Commit

Permalink
refactor: convert sql query to query builder
Browse files Browse the repository at this point in the history
  • Loading branch information
rs-rethik committed Dec 20, 2024
1 parent c14a2d7 commit 2d58e84
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,14 @@ def on_trash(self):
== 1
)
).run()
frappe.db.sql(
"delete from `tabGL Entry` where voucher_type=%s and voucher_no=%s", (self.doctype, self.name)
)
frappe.db.sql(
"delete from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s",
(self.doctype, self.name),
)
gle = frappe.qb.DocType("GL Entry")
frappe.qb.from_(gle).delete().where(
(gle.voucher_type == self.doctype) & (gle.voucher_no == self.name)
).run()
sle = frappe.qb.DocType("Stock Ledger Entry")
frappe.qb.from_(gle).delete().where(
(sle.voucher_type == self.doctype) & (sle.voucher_no == self.name)
).run()

def remove_serial_and_batch_bundle(self):
bundles = frappe.get_all(
Expand Down Expand Up @@ -1164,11 +1165,12 @@ def validate_account_currency(self, account, account_currency=None):
def clear_unallocated_advances(self, childtype, parentfield):
self.set(parentfield, self.get(parentfield, {"allocated_amount": ["not in", [0, None, ""]]}))

frappe.db.sql(
"""delete from `tab{}` where parentfield={} and parent = {}
and allocated_amount = 0""".format(childtype, "%s", "%s"),
(parentfield, self.name),
)
doctype = frappe.qb.DocType(childtype)
frappe.qb.from_(doctype).delete().where(
(doctype.parentfield == parentfield)
& (doctype.parent == self.name)
& (doctype.allocated_amount == 0)
).run()

@frappe.whitelist()
def apply_shipping_rule(self):
Expand Down Expand Up @@ -2143,11 +2145,9 @@ def delink_advance_entries(self, linked_doc_name):
for adv in self.advances:
consider_for_total_advance = True
if adv.reference_name == linked_doc_name:
frappe.db.sql(
f"""delete from `tab{self.doctype} Advance`
where name = %s""",
adv.name,
)
doctype = frappe.qb.DocType(self.doctype + " Advance")
frappe.qb.from_(doctype).delete().where(doctype.name == adv.name).run()

consider_for_total_advance = False

if consider_for_total_advance:
Expand Down

0 comments on commit 2d58e84

Please sign in to comment.