fix: changed account types in controller method
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index dd34909..7c813eb 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -99,11 +99,11 @@
)
if not book_advance_payments_as_liability:
return
- root_type = frappe.get_value(
- "Account", {"name": self.party_account, "company": self.company}, "root_type"
+ account_type = frappe.get_value(
+ "Account", {"name": self.party_account, "company": self.company}, "account_type"
)
- if (root_type == "Liability" and self.party_type == "Customer") or (
- root_type == "Asset" and self.party_type == "Supplier"
+ if (account_type == "Payable" and self.party_type == "Customer") or (
+ account_type == "Receivable" and self.party_type == "Supplier"
):
return
if self.unallocated_amount == 0:
@@ -908,6 +908,8 @@
},
item=self,
)
+ is_advance = self.get_advance_flag()
+
for d in self.get("references"):
gle = party_dict.copy()
book_advance_payments_as_liability = frappe.get_value(
@@ -916,13 +918,14 @@
if (
d.reference_doctype in ["Sales Invoice", "Purchase Invoice"]
and book_advance_payments_as_liability
+ and is_advance
):
if not is_reconcile:
self.make_invoice_liability_entry(gl_entries, d)
gle.update(
{
- "against_voucher_type": "Payment Entry",
- "against_voucher": self.name,
+ "voucher_type": "Payment Entry",
+ "voucher_no": self.name,
}
)
@@ -940,7 +943,6 @@
"against_voucher": d.reference_name,
}
)
-
gl_entries.append(gle)
if self.unallocated_amount:
@@ -952,13 +954,19 @@
{
dr_or_cr + "_in_account_currency": self.unallocated_amount,
dr_or_cr: base_unallocated_amount,
- "against_voucher_type": "Payment Entry",
- "against_voucher": self.name,
}
)
gl_entries.append(gle)
+ def get_advance_flag(self):
+ for d in self.get("references"):
+ if d.reference_doctype == "Sales Order":
+ return True
+ if self.unallocated_amount > 0:
+ return True
+ return False
+
def make_invoice_liability_entry(self, gl_entries, invoice):
args_dict = {
"party_type": self.party_type,
@@ -967,8 +975,6 @@
"cost_center": self.cost_center,
"voucher_type": invoice.reference_doctype,
"voucher_no": invoice.reference_name,
- "against_voucher_type": invoice.reference_doctype,
- "against_voucher": invoice.reference_name,
}
dr_or_cr = "credit" if invoice.reference_doctype == "Sales Invoice" else "debit"
@@ -987,6 +993,12 @@
args_dict["account"] = self.party_account
args_dict[dr_or_cr] = invoice.allocated_amount
args_dict[dr_or_cr + "_in_account_currency"] = invoice.allocated_amount
+ args_dict.update(
+ {
+ "against_voucher_type": "Payment Entry",
+ "against_voucher": self.name,
+ }
+ )
gle = self.get_gl_dict(
args_dict,
item=self,
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 728a6d7..abf9b5e 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -436,7 +436,9 @@
return cc.name
-def reconcile_against_document(args, skip_ref_details_update_for_pe=False): # nosemgrep
+def reconcile_against_document(
+ args, skip_ref_details_update_for_pe=False, is_reconcile=False
+): # nosemgrep
"""
Cancel PE or JV, Update against document, split if required and resubmit
"""
@@ -472,7 +474,7 @@
doc.save(ignore_permissions=True)
# re-submit advance entry
doc = frappe.get_doc(entry.voucher_type, entry.voucher_no)
- gl_map = doc.build_gl_map(is_reconcile=True)
+ gl_map = doc.build_gl_map(is_reconcile)
create_payment_ledger_entry(gl_map, update_outstanding="No", cancel=0, adv_adj=1)
# Only update outstanding for newly linked vouchers
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 7b2039d..578b26a 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -1078,7 +1078,7 @@
if lst:
from erpnext.accounts.utils import reconcile_against_document
- reconcile_against_document(lst)
+ reconcile_against_document(lst, is_reconcile=True)
def on_cancel(self):
from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries