fix: overallocation on Payment with PO/SO

(cherry picked from commit 23df4205f8)

# Conflicts:
#	erpnext/accounts/utils.py
This commit is contained in:
ruthra kumar
2023-10-19 11:32:21 +05:30
committed by Mergify
parent f413530493
commit d71b885fb8

View File

@@ -624,7 +624,12 @@ def update_reference_in_payment_entry(
"outstanding_amount": d.outstanding_amount, "outstanding_amount": d.outstanding_amount,
"allocated_amount": d.allocated_amount, "allocated_amount": d.allocated_amount,
"exchange_rate": d.exchange_rate if d.exchange_gain_loss else payment_entry.get_exchange_rate(), "exchange_rate": d.exchange_rate if d.exchange_gain_loss else payment_entry.get_exchange_rate(),
<<<<<<< HEAD
"exchange_gain_loss": d.exchange_gain_loss, # only populated from invoice in case of advance allocation "exchange_gain_loss": d.exchange_gain_loss, # only populated from invoice in case of advance allocation
=======
"exchange_gain_loss": d.exchange_gain_loss,
"account": d.account,
>>>>>>> 23df4205f8 (fix: overallocation on Payment with PO/SO)
} }
if d.voucher_detail_no: if d.voucher_detail_no:
@@ -636,22 +641,21 @@ def update_reference_in_payment_entry(
existing_row.reference_doctype, existing_row.reference_name existing_row.reference_doctype, existing_row.reference_name
).set_total_advance_paid() ).set_total_advance_paid()
original_row = existing_row.as_dict().copy() if d.allocated_amount <= existing_row.allocated_amount:
existing_row.update(reference_details) existing_row.allocated_amount -= d.allocated_amount
if d.allocated_amount < original_row.allocated_amount:
new_row = payment_entry.append("references") new_row = payment_entry.append("references")
new_row.docstatus = 1 new_row.docstatus = 1
for field in list(reference_details): for field in list(reference_details):
new_row.set(field, original_row[field]) new_row.set(field, reference_details[field])
new_row.allocated_amount = original_row.allocated_amount - d.allocated_amount
else: else:
new_row = payment_entry.append("references") new_row = payment_entry.append("references")
new_row.docstatus = 1 new_row.docstatus = 1
new_row.update(reference_details) new_row.update(reference_details)
payment_entry.flags.ignore_validate_update_after_submit = True payment_entry.flags.ignore_validate_update_after_submit = True
payment_entry.clear_unallocated_reference_document_rows()
payment_entry.setup_party_account_field() payment_entry.setup_party_account_field()
payment_entry.set_missing_values() payment_entry.set_missing_values()
if not skip_ref_details_update_for_pe: if not skip_ref_details_update_for_pe: