Skip to content

Commit

Permalink
fix: cancel common party advance jv while canceling the invoice
Browse files Browse the repository at this point in the history
(cherry picked from commit 6a928b9)
  • Loading branch information
venkat102 authored and mergify[bot] committed Sep 6, 2024
1 parent f4032b6 commit f506952
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
40 changes: 40 additions & 0 deletions erpnext/accounts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,46 @@ def cancel_exchange_gain_loss_journal(
gain_loss_je.cancel()


def cancel_common_party_journal(self):
if self.doctype not in ["Sales Invoice", "Purchase Invoice"]:
return

if not frappe.db.get_single_value("Accounts Settings", "enable_common_party_accounting"):
return

party_link = self.get_common_party_link()
if not party_link:
return

journal_entry = frappe.db.get_value(
"Journal Entry Account",
filters={
"reference_type": self.doctype,
"reference_name": self.name,
"docstatus": 1,
},
fieldname="parent",
)

if not journal_entry:
return

common_party_journal = frappe.db.get_value(
"Journal Entry",
filters={
"name": journal_entry,
"is_system_generated": True,
"docstatus": 1,
},
)

if not common_party_journal:
return

common_party_je = frappe.get_doc("Journal Entry", common_party_journal)
common_party_je.cancel()


def update_accounting_ledgers_after_reference_removal(
ref_type: str | None = None, ref_no: str | None = None, payment_name: str | None = None
):
Expand Down
3 changes: 3 additions & 0 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,7 @@ def on_cancel(self):
remove_from_bank_transaction,
)
from erpnext.accounts.utils import (
cancel_common_party_journal,
cancel_exchange_gain_loss_journal,
unlink_ref_doc_from_payment_entries,
)
Expand All @@ -1474,6 +1475,7 @@ def on_cancel(self):

# Cancel Exchange Gain/Loss Journal before unlinking
cancel_exchange_gain_loss_journal(self)
cancel_common_party_journal(self)

if frappe.db.get_single_value("Accounts Settings", "unlink_payment_on_cancellation_of_invoice"):
unlink_ref_doc_from_payment_entries(self)
Expand Down Expand Up @@ -2302,6 +2304,7 @@ def create_advance_and_reconcile(self, party_link):
jv.posting_date = self.posting_date
jv.company = self.company
jv.remark = f"Adjustment for {self.doctype} {self.name}"
jv.is_system_generated = True

reconcilation_entry = frappe._dict()
advance_entry = frappe._dict()
Expand Down

0 comments on commit f506952

Please sign in to comment.