refactor: return the newly added reference upon reconciliation

This commit is contained in:
ruthra kumar 2023-11-28 17:04:07 +05:30
parent 5fc19dab54
commit ecb533c4d1

View File

@ -473,6 +473,8 @@ def reconcile_against_document(args, skip_ref_details_update_for_pe=False): # n
doc = frappe.get_doc(voucher_type, voucher_no)
frappe.flags.ignore_party_validation = True
# For payments with `Advance` in separate account feature enabled, only new ledger entries are posted for each reference.
# No need to cancel/delete payment ledger entries
if not (voucher_type == "Payment Entry" and doc.book_advance_payments_in_separate_party_account):
_delete_pl_entries(voucher_type, voucher_no)
@ -489,7 +491,7 @@ def reconcile_against_document(args, skip_ref_details_update_for_pe=False): # n
entry.update({"referenced_row": referenced_row})
doc.make_exchange_gain_loss_journal([entry])
else:
update_reference_in_payment_entry(
referenced_row = update_reference_in_payment_entry(
entry, doc, do_not_save=True, skip_ref_details_update_for_pe=skip_ref_details_update_for_pe
)
@ -498,8 +500,8 @@ def reconcile_against_document(args, skip_ref_details_update_for_pe=False): # n
doc = frappe.get_doc(entry.voucher_type, entry.voucher_no)
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_advance_gl_entries()
# both ledgers must be posted to for `Advance` in separate account feature
doc.make_advance_gl_entries(referenced_row, update_outstanding="No")
else:
gl_map = doc.build_gl_map()
create_payment_ledger_entry(gl_map, update_outstanding="No", cancel=0, adv_adj=1)
@ -681,11 +683,12 @@ def update_reference_in_payment_entry(
new_row.docstatus = 1
for field in list(reference_details):
new_row.set(field, reference_details[field])
row = new_row
else:
new_row = payment_entry.append("references")
new_row.docstatus = 1
new_row.update(reference_details)
row = new_row
payment_entry.flags.ignore_validate_update_after_submit = True
payment_entry.clear_unallocated_reference_document_rows()
@ -700,6 +703,7 @@ def update_reference_in_payment_entry(
if not do_not_save:
payment_entry.save(ignore_permissions=True)
return row
def cancel_exchange_gain_loss_journal(
@ -876,7 +880,13 @@ def remove_ref_doc_link_from_pe(
try:
pe_doc = frappe.get_doc("Payment Entry", pe)
pe_doc.set_amounts()
pe_doc.make_advance_gl_entries(against_voucher_type=ref_type, against_voucher=ref_no, cancel=1)
# Call cancel on only removed reference
references = [
x for x in pe_doc.references if x.reference_doctype == ref_type and x.reference_name == ref_no
]
[pe_doc.make_advance_gl_entries(x, cancel=1) for x in references]
pe_doc.clear_unallocated_reference_document_rows()
pe_doc.validate_payment_type_with_outstanding()
except Exception as e: