fix: update outstanding amount and unpaid status on cancellation of payment entry

This commit is contained in:
Gursheen Anand 2023-06-16 13:38:47 +05:30
parent 033e4e84f5
commit 442e3f2aa2
5 changed files with 33 additions and 39 deletions

View File

@ -872,7 +872,7 @@ class PaymentEntry(AccountsController):
self.set("remarks", "\n".join(remarks)) self.set("remarks", "\n".join(remarks))
def build_gl_map(self, is_reconcile=False): def build_gl_map(self, is_reconcile=True):
if self.payment_type in ("Receive", "Pay") and not self.get("party_account_field"): if self.payment_type in ("Receive", "Pay") and not self.get("party_account_field"):
self.setup_party_account_field() self.setup_party_account_field()
@ -918,16 +918,15 @@ class PaymentEntry(AccountsController):
if ( if (
d.reference_doctype in ["Sales Invoice", "Purchase Invoice"] d.reference_doctype in ["Sales Invoice", "Purchase Invoice"]
and book_advance_payments_as_liability and book_advance_payments_as_liability
and is_advance and (is_advance or is_reconcile)
): ):
if not is_reconcile: self.make_invoice_liability_entry(gl_entries, d)
self.make_invoice_liability_entry(gl_entries, d) gle.update(
gle.update( {
{ "against_voucher_type": "Payment Entry",
"against_voucher_type": "Payment Entry", "against_voucher": self.name,
"against_voucher": self.name, }
} )
)
allocated_amount_in_company_currency = self.calculate_base_allocated_amount_for_reference(d) allocated_amount_in_company_currency = self.calculate_base_allocated_amount_for_reference(d)
gle.update( gle.update(
@ -939,8 +938,8 @@ class PaymentEntry(AccountsController):
if not gle.get("against_voucher_type"): if not gle.get("against_voucher_type"):
gle.update( gle.update(
{ {
"against_voucher_type": d.reference_doctype, "against_voucher_type": d.reference_doctype if is_advance else "Payment Entry",
"against_voucher": d.reference_name, "against_voucher": d.reference_name if is_advance else self.name,
} }
) )
gl_entries.append(gle) gl_entries.append(gle)
@ -954,6 +953,8 @@ class PaymentEntry(AccountsController):
{ {
dr_or_cr + "_in_account_currency": self.unallocated_amount, dr_or_cr + "_in_account_currency": self.unallocated_amount,
dr_or_cr: base_unallocated_amount, dr_or_cr: base_unallocated_amount,
"against_voucher_type": "Payment Entry",
"against_voucher": self.name,
} }
) )

View File

@ -223,6 +223,7 @@ def check_if_in_list(gle, gl_map, dimensions=None):
"party_type", "party_type",
"project", "project",
"finance_book", "finance_book",
"voucher_no",
] ]
if dimensions: if dimensions:

View File

@ -437,7 +437,7 @@ def add_cc(args=None):
def reconcile_against_document( def reconcile_against_document(
args, skip_ref_details_update_for_pe=False, is_reconcile=False args, skip_ref_details_update_for_pe=False, is_reconcile=True
): # nosemgrep ): # nosemgrep
""" """
Cancel PE or JV, Update against document, split if required and resubmit Cancel PE or JV, Update against document, split if required and resubmit

View File

@ -1021,7 +1021,7 @@ class AccountsController(TransactionBase):
) )
) )
def update_against_document_in_jv(self): def update_against_document_in_jv(self, is_reconcile=True):
""" """
Links invoice and advance voucher: Links invoice and advance voucher:
1. cancel advance voucher 1. cancel advance voucher
@ -1078,7 +1078,7 @@ class AccountsController(TransactionBase):
if lst: if lst:
from erpnext.accounts.utils import reconcile_against_document from erpnext.accounts.utils import reconcile_against_document
reconcile_against_document(lst, is_reconcile=True) reconcile_against_document(lst, is_reconcile)
def on_cancel(self): def on_cancel(self):
from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries from erpnext.accounts.utils import unlink_ref_doc_from_payment_entries
@ -2919,7 +2919,6 @@ def make_advance_liability_entry(
rev = "credit" rev = "credit"
against = invoice.debit_to against = invoice.debit_to
party = invoice.customer party = invoice.customer
voucher_type = "Sales Invoice"
else: else:
invoice = frappe.get_doc("Purchase Invoice", invoice) invoice = frappe.get_doc("Purchase Invoice", invoice)
account = pe.paid_to account = pe.paid_to
@ -2927,9 +2926,8 @@ def make_advance_liability_entry(
rev = "debit" rev = "debit"
against = invoice.credit_to against = invoice.credit_to
party = invoice.supplier party = invoice.supplier
voucher_type = "Purchase Invoice"
gl_entries.append( gl_entries.append(
invoice.get_gl_dict( pe.get_gl_dict(
{ {
"account": account, "account": account,
"party_type": party_type, "party_type": party_type,
@ -2940,42 +2938,35 @@ def make_advance_liability_entry(
dr_or_cr + "_in_account_currency": allocated_amount, dr_or_cr + "_in_account_currency": allocated_amount,
rev: 0, rev: 0,
rev + "_in_account_currency": 0, rev + "_in_account_currency": 0,
"against_voucher": pe.name,
"against_voucher_type": "Payment Entry",
"cost_center": invoice.cost_center, "cost_center": invoice.cost_center,
"project": invoice.project, "project": invoice.project,
"voucher_type": voucher_type, "against_voucher_type": "Payment Entry",
"voucher_no": invoice.name, "against_voucher": pe.name,
}, },
invoice.party_account_currency, invoice.party_account_currency,
item=invoice, item=pe,
) )
) )
(dr_or_cr, rev) = ("credit", "debit") if party_type == "Customer" else ("debit", "credit") (dr_or_cr, rev) = ("credit", "debit") if party_type == "Customer" else ("debit", "credit")
gl_entries.append( gl_entries.append(
invoice.get_gl_dict( pe.get_gl_dict(
{ {
"account": against, "account": against,
"party_type": party_type, "party_type": party_type,
"party": party, "party": party,
"due_date": invoice.due_date, "due_date": invoice.due_date,
"against": account,
dr_or_cr: allocated_amount, dr_or_cr: allocated_amount,
dr_or_cr + "_in_account_currency": allocated_amount, dr_or_cr + "_in_account_currency": allocated_amount,
rev: 0, rev: 0,
rev + "_in_account_currency": 0, rev + "_in_account_currency": 0,
"against_voucher": invoice.return_against
if cint(invoice.is_return) and invoice.return_against
else invoice.name,
"against_voucher_type": invoice.doctype,
"cost_center": invoice.cost_center, "cost_center": invoice.cost_center,
"project": invoice.project, "project": invoice.project,
"voucher_type": "Payment Entry" if references else voucher_type, "against_voucher_type": invoice.doctype,
"voucher_no": pe.name if references else invoice.name, "against_voucher": invoice.name,
}, },
invoice.party_account_currency, invoice.party_account_currency,
item=invoice, item=pe,
) )
) )

View File

@ -72,9 +72,9 @@
"default_finance_book", "default_finance_book",
"advance_payments_section", "advance_payments_section",
"book_advance_payments_as_liability", "book_advance_payments_as_liability",
"column_break_fwcf",
"default_advance_received_account", "default_advance_received_account",
"default_advance_paid_account", "default_advance_paid_account",
"column_break_cui0",
"auto_accounting_for_stock_settings", "auto_accounting_for_stock_settings",
"enable_perpetual_inventory", "enable_perpetual_inventory",
"enable_provisional_accounting_for_non_stock_items", "enable_provisional_accounting_for_non_stock_items",
@ -702,19 +702,16 @@
}, },
{ {
"default": "0", "default": "0",
"description": "Enabling this option will allow you to record - <br><br> 1. Advances Received in a <b>Liability Account</b> instead of the <b>Receivable Account</b><br><br>2. Advances Paid in an <b>Asset Account</b> instead of the <b> Payable Account</b>",
"fieldname": "book_advance_payments_as_liability", "fieldname": "book_advance_payments_as_liability",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Book Advance Payments as Liability" "label": "Book Advance Payments in Separate Party Account"
}, },
{ {
"fieldname": "advance_payments_section", "fieldname": "advance_payments_section",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "Advance Payments" "label": "Advance Payments"
}, },
{
"fieldname": "column_break_cui0",
"fieldtype": "Column Break"
},
{ {
"depends_on": "eval:doc.book_advance_payments_as_liability", "depends_on": "eval:doc.book_advance_payments_as_liability",
"fieldname": "default_advance_received_account", "fieldname": "default_advance_received_account",
@ -730,6 +727,10 @@
"label": "Default Advance Paid Account", "label": "Default Advance Paid Account",
"mandatory_depends_on": "book_advance_payments_as_liability", "mandatory_depends_on": "book_advance_payments_as_liability",
"options": "Account" "options": "Account"
},
{
"fieldname": "column_break_fwcf",
"fieldtype": "Column Break"
} }
], ],
"icon": "fa fa-building", "icon": "fa fa-building",
@ -737,7 +738,7 @@
"image_field": "company_logo", "image_field": "company_logo",
"is_tree": 1, "is_tree": 1,
"links": [], "links": [],
"modified": "2023-06-12 12:51:12.007410", "modified": "2023-06-16 13:32:48.790947",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Setup", "module": "Setup",
"name": "Company", "name": "Company",