Skip to content

Commit

Permalink
refactor: don't split based on reference while reconciling advance
Browse files Browse the repository at this point in the history
  • Loading branch information
ruthra-kumar committed Sep 29, 2023
1 parent ad23938 commit 1f53f2c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
69 changes: 40 additions & 29 deletions erpnext/accounts/doctype/payment_entry/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,46 +1085,57 @@ def add_party_gl_entries(self, gl_entries):
"credit" if erpnext.get_party_account_type(self.party_type) == "Receivable" else "debit"
)

for d in self.get("references"):
cost_center = self.cost_center
if d.reference_doctype == "Sales Invoice" and not cost_center:
cost_center = frappe.db.get_value(d.reference_doctype, d.reference_name, "cost_center")

if self.book_advance_payments_in_separate_party_account:
gle = party_gl_dict.copy()

allocated_amount_in_company_currency = self.calculate_base_allocated_amount_for_reference(d)

if self.book_advance_payments_in_separate_party_account:
against_voucher_type = "Payment Entry"
against_voucher = self.name
if self.payment_type == "Receive":
amount = self.base_paid_amount
else:
against_voucher_type = d.reference_doctype
against_voucher = d.reference_name
amount = self.base_received_amount

gle.update(
{
dr_or_cr: allocated_amount_in_company_currency,
dr_or_cr + "_in_account_currency": d.allocated_amount,
"against_voucher_type": against_voucher_type,
"against_voucher": against_voucher,
"cost_center": cost_center,
dr_or_cr: amount,
dr_or_cr + "_in_account_currency": amount,
"against_voucher_type": "Payment Entry",
"against_voucher": self.name,
"cost_center": self.cost_center,
}
)
gl_entries.append(gle)
else:
for d in self.get("references"):
cost_center = self.cost_center
if d.reference_doctype == "Sales Invoice" and not cost_center:
cost_center = frappe.db.get_value(d.reference_doctype, d.reference_name, "cost_center")

if self.unallocated_amount:
exchange_rate = self.get_exchange_rate()
base_unallocated_amount = self.unallocated_amount * exchange_rate
gle = party_gl_dict.copy()

gle = party_gl_dict.copy()
gle.update(
{
dr_or_cr + "_in_account_currency": self.unallocated_amount,
dr_or_cr: base_unallocated_amount,
}
)
allocated_amount_in_company_currency = self.calculate_base_allocated_amount_for_reference(d)

gl_entries.append(gle)
gle.update(
{
dr_or_cr: allocated_amount_in_company_currency,
dr_or_cr + "_in_account_currency": d.allocated_amount,
"against_voucher_type": d.reference_doctype,
"against_voucher": d.reference_name,
"cost_center": cost_center,
}
)
gl_entries.append(gle)

if self.unallocated_amount:
exchange_rate = self.get_exchange_rate()
base_unallocated_amount = self.unallocated_amount * exchange_rate

gle = party_gl_dict.copy()
gle.update(
{
dr_or_cr + "_in_account_currency": self.unallocated_amount,
dr_or_cr: base_unallocated_amount,
}
)

gl_entries.append(gle)

def make_advance_gl_entries(self, against_voucher_type=None, against_voucher=None, cancel=0):
if self.book_advance_payments_in_separate_party_account:
Expand Down
8 changes: 3 additions & 5 deletions erpnext/accounts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,8 @@ def reconcile_against_document(args, skip_ref_details_update_for_pe=False): # n
# cancel advance entry
doc = frappe.get_doc(voucher_type, voucher_no)
frappe.flags.ignore_party_validation = True
_delete_pl_entries(voucher_type, voucher_no)

if voucher_type == "Payment Entry" and doc.book_advance_payments_in_separate_party_account:
_delete_gl_entries(voucher_type, voucher_no)
if not (voucher_type == "Payment Entry" and doc.book_advance_payments_in_separate_party_account):
_delete_pl_entries(voucher_type, voucher_no)

for entry in entries:
check_if_advance_entry_modified(entry)
Expand All @@ -494,7 +492,7 @@ def reconcile_against_document(args, skip_ref_details_update_for_pe=False): # n

if voucher_type == "Payment Entry" and doc.book_advance_payments_in_separate_party_account:
# both ledgers must be posted to for `Advance as Liability`
doc.make_gl_entries()
doc.make_advance_gl_entries()
else:
gl_map = doc.build_gl_map()
create_payment_ledger_entry(gl_map, update_outstanding="No", cancel=0, adv_adj=1)
Expand Down

0 comments on commit 1f53f2c

Please sign in to comment.