Skip to content

Commit

Permalink
fix: partial cancel of gle and ple (backport #35609)
Browse files Browse the repository at this point in the history
  • Loading branch information
vorasmit committed Nov 20, 2023
1 parent 5afb8b5 commit 80bc235
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
16 changes: 13 additions & 3 deletions erpnext/accounts/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,12 @@ def get_round_off_account_and_cost_center(


def make_reverse_gl_entries(
gl_entries=None, voucher_type=None, voucher_no=None, adv_adj=False, update_outstanding="Yes"
gl_entries=None,
voucher_type=None,
voucher_no=None,
adv_adj=False,
update_outstanding="Yes",
partial_cancel=False,
):
"""
Get original gl entries of the voucher
Expand All @@ -576,14 +581,19 @@ def make_reverse_gl_entries(

if gl_entries:
create_payment_ledger_entry(
gl_entries, cancel=1, adv_adj=adv_adj, update_outstanding=update_outstanding
gl_entries,
cancel=1,
adv_adj=adv_adj,
update_outstanding=update_outstanding,
partial_cancel=partial_cancel,
)
validate_accounting_period(gl_entries)
check_freezing_date(gl_entries[0]["posting_date"], adv_adj)

is_opening = any(d.get("is_opening") == "Yes" for d in gl_entries)
validate_against_pcv(is_opening, gl_entries[0]["posting_date"], gl_entries[0]["company"])
set_as_cancel(gl_entries[0]["voucher_type"], gl_entries[0]["voucher_no"])
if not partial_cancel:
set_as_cancel(gl_entries[0]["voucher_type"], gl_entries[0]["voucher_no"])

for entry in gl_entries:
new_gle = copy.deepcopy(entry)
Expand Down
11 changes: 8 additions & 3 deletions erpnext/accounts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,7 @@ def get_account_type(account):
due_date=gle.due_date,
voucher_type=gle.voucher_type,
voucher_no=gle.voucher_no,
voucher_detail_no=gle.voucher_detail_no,
against_voucher_type=gle.against_voucher_type
if gle.against_voucher_type
else gle.voucher_type,
Expand All @@ -1638,7 +1639,7 @@ def get_account_type(account):


def create_payment_ledger_entry(
gl_entries, cancel=0, adv_adj=0, update_outstanding="Yes", from_repost=0
gl_entries, cancel=0, adv_adj=0, update_outstanding="Yes", from_repost=0, partial_cancel=False
):
if gl_entries:
ple_map = get_payment_ledger_entries(gl_entries, cancel=cancel)
Expand All @@ -1648,7 +1649,7 @@ def create_payment_ledger_entry(
ple = frappe.get_doc(entry)

if cancel:
delink_original_entry(ple)
delink_original_entry(ple, partial_cancel=partial_cancel)

ple.flags.ignore_permissions = 1
ple.flags.adv_adj = adv_adj
Expand Down Expand Up @@ -1695,7 +1696,7 @@ def update_voucher_outstanding(voucher_type, voucher_no, account, party_type, pa
ref_doc.set_status(update=True)


def delink_original_entry(pl_entry):
def delink_original_entry(pl_entry, partial_cancel=False):
if pl_entry:
ple = qb.DocType("Payment Ledger Entry")
query = (
Expand All @@ -1715,6 +1716,10 @@ def delink_original_entry(pl_entry):
& (ple.against_voucher_no == pl_entry.against_voucher_no)
)
)

if partial_cancel:
query = query.where(ple.voucher_detail_no == pl_entry.voucher_detail_no)

query.run()


Expand Down

0 comments on commit 80bc235

Please sign in to comment.