Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refine GLE deletion with against voucher check #43194

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from frappe.model.workflow import get_workflow_name, is_transition_condition_satisfied
from frappe.query_builder import Criterion
from frappe.query_builder.custom import ConstantColumn
from frappe.query_builder.functions import Abs, Sum
from frappe.query_builder.functions import Abs, IfNull, Sum
from frappe.utils import (
add_days,
add_months,
Expand Down Expand Up @@ -362,13 +362,20 @@ 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),
)

gl_entry = frappe.qb.DocType("GL Entry")
frappe.qb.from_(gl_entry).delete().where(
((gl_entry.voucher_type == self.doctype) & (gl_entry.voucher_no == self.name))
| (
(IfNull(gl_entry.against_voucher_type, "") == self.doctype)
& (IfNull(gl_entry.against_voucher, "") == self.name)
)
).where(gl_entry.is_cancelled == 1).run()

sle = frappe.qb.DocType("Stock Ledger Entry")
frappe.qb.from_(sle).delete().where(
(sle.voucher_type == self.doctype) & (sle.voucher_no == self.name) & (sle.is_cancelled == 1)
).run()

def remove_serial_and_batch_bundle(self):
bundles = frappe.get_all(
Expand Down
Loading