fix: advance paid amount and ledger entries against SO/PO
(cherry picked from commit d9a0494fc3)
# Conflicts:
# erpnext/accounts/utils.py
This commit is contained in:
@@ -1213,7 +1213,7 @@ class PaymentEntry(AccountsController):
|
|||||||
if getdate(posting_date) < getdate(self.posting_date):
|
if getdate(posting_date) < getdate(self.posting_date):
|
||||||
posting_date = self.posting_date
|
posting_date = self.posting_date
|
||||||
|
|
||||||
dr_or_cr = "credit" if invoice.reference_doctype == "Sales Invoice" else "debit"
|
dr_or_cr = "credit" if invoice.reference_doctype in ["Sales Invoice", "Sales Order"] else "debit"
|
||||||
args_dict["account"] = invoice.account
|
args_dict["account"] = invoice.account
|
||||||
args_dict[dr_or_cr] = invoice.allocated_amount
|
args_dict[dr_or_cr] = invoice.allocated_amount
|
||||||
args_dict[dr_or_cr + "_in_account_currency"] = invoice.allocated_amount
|
args_dict[dr_or_cr + "_in_account_currency"] = invoice.allocated_amount
|
||||||
|
|||||||
@@ -490,7 +490,9 @@ def reconcile_against_document(
|
|||||||
|
|
||||||
# For payments with `Advance` in separate account feature enabled, only new ledger entries are posted for each reference.
|
# 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
|
# No need to cancel/delete payment ledger entries
|
||||||
if not (voucher_type == "Payment Entry" and doc.book_advance_payments_in_separate_party_account):
|
if voucher_type == "Payment Entry" and doc.book_advance_payments_in_separate_party_account:
|
||||||
|
doc.make_advance_gl_entries(cancel=1)
|
||||||
|
else:
|
||||||
_delete_pl_entries(voucher_type, voucher_no)
|
_delete_pl_entries(voucher_type, voucher_no)
|
||||||
|
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
@@ -501,14 +503,16 @@ def reconcile_against_document(
|
|||||||
|
|
||||||
# update ref in advance entry
|
# update ref in advance entry
|
||||||
if voucher_type == "Journal Entry":
|
if voucher_type == "Journal Entry":
|
||||||
referenced_row = update_reference_in_journal_entry(entry, doc, do_not_save=False)
|
referenced_row, update_advance_paid = update_reference_in_journal_entry(
|
||||||
|
entry, doc, do_not_save=False
|
||||||
|
)
|
||||||
# advance section in sales/purchase invoice and reconciliation tool,both pass on exchange gain/loss
|
# advance section in sales/purchase invoice and reconciliation tool,both pass on exchange gain/loss
|
||||||
# amount and account in args
|
# amount and account in args
|
||||||
# referenced_row is used to deduplicate gain/loss journal
|
# referenced_row is used to deduplicate gain/loss journal
|
||||||
entry.update({"referenced_row": referenced_row})
|
entry.update({"referenced_row": referenced_row})
|
||||||
doc.make_exchange_gain_loss_journal([entry], dimensions_dict)
|
doc.make_exchange_gain_loss_journal([entry], dimensions_dict)
|
||||||
else:
|
else:
|
||||||
referenced_row = update_reference_in_payment_entry(
|
referenced_row, update_advance_paid = update_reference_in_payment_entry(
|
||||||
entry,
|
entry,
|
||||||
doc,
|
doc,
|
||||||
do_not_save=True,
|
do_not_save=True,
|
||||||
@@ -522,7 +526,7 @@ def reconcile_against_document(
|
|||||||
|
|
||||||
if voucher_type == "Payment Entry" and doc.book_advance_payments_in_separate_party_account:
|
if voucher_type == "Payment Entry" and doc.book_advance_payments_in_separate_party_account:
|
||||||
# both ledgers must be posted to for `Advance` in separate account feature
|
# both ledgers must be posted to for `Advance` in separate account feature
|
||||||
doc.make_advance_gl_entries(cancel=1)
|
# TODO: find a more efficient way post only for the new linked vouchers
|
||||||
doc.make_advance_gl_entries()
|
doc.make_advance_gl_entries()
|
||||||
else:
|
else:
|
||||||
gl_map = doc.build_gl_map()
|
gl_map = doc.build_gl_map()
|
||||||
@@ -533,6 +537,10 @@ def reconcile_against_document(
|
|||||||
update_voucher_outstanding(
|
update_voucher_outstanding(
|
||||||
entry.against_voucher_type, entry.against_voucher, entry.account, entry.party_type, entry.party
|
entry.against_voucher_type, entry.against_voucher, entry.account, entry.party_type, entry.party
|
||||||
)
|
)
|
||||||
|
# update advance paid in Advance Receivable/Payable doctypes
|
||||||
|
if update_advance_paid:
|
||||||
|
for t, n in update_advance_paid:
|
||||||
|
frappe.get_doc(t, n).set_total_advance_paid()
|
||||||
|
|
||||||
frappe.flags.ignore_party_validation = False
|
frappe.flags.ignore_party_validation = False
|
||||||
|
|
||||||
@@ -617,8 +625,17 @@ def update_reference_in_journal_entry(d, journal_entry, do_not_save=False):
|
|||||||
jv_detail = journal_entry.get("accounts", {"name": d["voucher_detail_no"]})[0]
|
jv_detail = journal_entry.get("accounts", {"name": d["voucher_detail_no"]})[0]
|
||||||
|
|
||||||
# Update Advance Paid in SO/PO since they might be getting unlinked
|
# Update Advance Paid in SO/PO since they might be getting unlinked
|
||||||
|
<<<<<<< HEAD
|
||||||
if jv_detail.get("reference_type") in ("Sales Order", "Purchase Order"):
|
if jv_detail.get("reference_type") in ("Sales Order", "Purchase Order"):
|
||||||
frappe.get_doc(jv_detail.reference_type, jv_detail.reference_name).set_total_advance_paid()
|
frappe.get_doc(jv_detail.reference_type, jv_detail.reference_name).set_total_advance_paid()
|
||||||
|
=======
|
||||||
|
update_advance_paid = []
|
||||||
|
advance_payment_doctypes = frappe.get_hooks(
|
||||||
|
"advance_payment_receivable_doctypes"
|
||||||
|
) + frappe.get_hooks("advance_payment_payable_doctypes")
|
||||||
|
if jv_detail.get("reference_type") in advance_payment_doctypes:
|
||||||
|
update_advance_paid.append((jv_detail.reference_type, jv_detail.reference_name))
|
||||||
|
>>>>>>> d9a0494fc3 (fix: advance paid amount and ledger entries against SO/PO)
|
||||||
|
|
||||||
if flt(d["unadjusted_amount"]) - flt(d["allocated_amount"]) != 0:
|
if flt(d["unadjusted_amount"]) - flt(d["allocated_amount"]) != 0:
|
||||||
# adjust the unreconciled balance
|
# adjust the unreconciled balance
|
||||||
@@ -667,7 +684,7 @@ def update_reference_in_journal_entry(d, journal_entry, do_not_save=False):
|
|||||||
if not do_not_save:
|
if not do_not_save:
|
||||||
journal_entry.save(ignore_permissions=True)
|
journal_entry.save(ignore_permissions=True)
|
||||||
|
|
||||||
return new_row.name
|
return new_row.name, update_advance_paid
|
||||||
|
|
||||||
|
|
||||||
def update_reference_in_payment_entry(
|
def update_reference_in_payment_entry(
|
||||||
@@ -686,15 +703,24 @@ def update_reference_in_payment_entry(
|
|||||||
"account": d.account,
|
"account": d.account,
|
||||||
"dimensions": d.dimensions,
|
"dimensions": d.dimensions,
|
||||||
}
|
}
|
||||||
|
update_advance_paid = []
|
||||||
|
|
||||||
if d.voucher_detail_no:
|
if d.voucher_detail_no:
|
||||||
existing_row = payment_entry.get("references", {"name": d["voucher_detail_no"]})[0]
|
existing_row = payment_entry.get("references", {"name": d["voucher_detail_no"]})[0]
|
||||||
|
|
||||||
# Update Advance Paid in SO/PO since they are getting unlinked
|
# Update Advance Paid in SO/PO since they are getting unlinked
|
||||||
|
<<<<<<< HEAD
|
||||||
if existing_row.get("reference_doctype") in ("Sales Order", "Purchase Order"):
|
if existing_row.get("reference_doctype") in ("Sales Order", "Purchase Order"):
|
||||||
frappe.get_doc(
|
frappe.get_doc(
|
||||||
existing_row.reference_doctype, existing_row.reference_name
|
existing_row.reference_doctype, existing_row.reference_name
|
||||||
).set_total_advance_paid()
|
).set_total_advance_paid()
|
||||||
|
=======
|
||||||
|
advance_payment_doctypes = frappe.get_hooks(
|
||||||
|
"advance_payment_receivable_doctypes"
|
||||||
|
) + frappe.get_hooks("advance_payment_payable_doctypes")
|
||||||
|
if existing_row.get("reference_doctype") in advance_payment_doctypes:
|
||||||
|
update_advance_paid.append((existing_row.reference_doctype, existing_row.reference_name))
|
||||||
|
>>>>>>> d9a0494fc3 (fix: advance paid amount and ledger entries against SO/PO)
|
||||||
|
|
||||||
if d.allocated_amount <= existing_row.allocated_amount:
|
if d.allocated_amount <= existing_row.allocated_amount:
|
||||||
existing_row.allocated_amount -= d.allocated_amount
|
existing_row.allocated_amount -= d.allocated_amount
|
||||||
@@ -723,7 +749,7 @@ def update_reference_in_payment_entry(
|
|||||||
|
|
||||||
if not do_not_save:
|
if not do_not_save:
|
||||||
payment_entry.save(ignore_permissions=True)
|
payment_entry.save(ignore_permissions=True)
|
||||||
return row
|
return row, update_advance_paid
|
||||||
|
|
||||||
|
|
||||||
def cancel_exchange_gain_loss_journal(
|
def cancel_exchange_gain_loss_journal(
|
||||||
|
|||||||
@@ -1857,7 +1857,7 @@ class AccountsController(TransactionBase):
|
|||||||
(ple.against_voucher_type == self.doctype)
|
(ple.against_voucher_type == self.doctype)
|
||||||
& (ple.against_voucher_no == self.name)
|
& (ple.against_voucher_no == self.name)
|
||||||
& (ple.party == party)
|
& (ple.party == party)
|
||||||
& (ple.docstatus == 1)
|
& (ple.delinked == 0)
|
||||||
& (ple.company == self.company)
|
& (ple.company == self.company)
|
||||||
)
|
)
|
||||||
.run(as_dict=True)
|
.run(as_dict=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user