From 1894dc8197c568936d839ef50fa65879c7ce9ac7 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Fri, 23 Jun 2023 21:53:34 +0530 Subject: [PATCH] fix: Test case and code cleanup --- .../payment_reconciliation.js | 1 + .../purchase_invoice_advance.json | 12 +-- .../doctype/sales_invoice/sales_invoice.py | 3 +- .../sales_invoice_advance.json | 12 +-- erpnext/accounts/utils.py | 6 +- erpnext/controllers/accounts_controller.py | 78 ------------------- 6 files changed, 11 insertions(+), 101 deletions(-) diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js index bd931f1a2b..16e3f95ee6 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js @@ -34,6 +34,7 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo filters: { "company": this.frm.doc.company, "is_group": 0, + "account_type": this.frm.doc.party_type == 'Customer' ? "Receivable": "Payable", "root_type": this.frm.doc.party_type == 'Customer' ? "Liability": "Asset" } }; diff --git a/erpnext/accounts/doctype/purchase_invoice_advance/purchase_invoice_advance.json b/erpnext/accounts/doctype/purchase_invoice_advance/purchase_invoice_advance.json index 9082115f23..4db531eac9 100644 --- a/erpnext/accounts/doctype/purchase_invoice_advance/purchase_invoice_advance.json +++ b/erpnext/accounts/doctype/purchase_invoice_advance/purchase_invoice_advance.json @@ -14,8 +14,7 @@ "advance_amount", "allocated_amount", "exchange_gain_loss", - "ref_exchange_rate", - "account" + "ref_exchange_rate" ], "fields": [ { @@ -112,20 +111,13 @@ "label": "Reference Exchange Rate", "non_negative": 1, "read_only": 1 - }, - { - "fieldname": "account", - "fieldtype": "Link", - "label": "Account", - "options": "Account", - "read_only": 1 } ], "idx": 1, "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2023-06-01 16:56:48.530169", + "modified": "2023-06-23 21:13:18.013816", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice Advance", diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 25553cff0c..7ab1c89397 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1052,12 +1052,13 @@ class SalesInvoice(SellingController): elif self.docstatus == 2 and cint(self.update_stock) and cint(auto_accounting_for_stock): make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name) - def get_gl_entries(self): + def get_gl_entries(self, warehouse_account=None): from erpnext.accounts.general_ledger import merge_similar_entries gl_entries = [] self.make_customer_gl_entry(gl_entries) + self.make_tax_gl_entries(gl_entries) self.make_exchange_gain_loss_gl_entries(gl_entries) self.make_internal_transfer_gl_entries(gl_entries) diff --git a/erpnext/accounts/doctype/sales_invoice_advance/sales_invoice_advance.json b/erpnext/accounts/doctype/sales_invoice_advance/sales_invoice_advance.json index aa52b1cac2..0ae85d9000 100644 --- a/erpnext/accounts/doctype/sales_invoice_advance/sales_invoice_advance.json +++ b/erpnext/accounts/doctype/sales_invoice_advance/sales_invoice_advance.json @@ -14,8 +14,7 @@ "advance_amount", "allocated_amount", "exchange_gain_loss", - "ref_exchange_rate", - "account" + "ref_exchange_rate" ], "fields": [ { @@ -113,20 +112,13 @@ "label": "Reference Exchange Rate", "non_negative": 1, "read_only": 1 - }, - { - "fieldname": "account", - "fieldtype": "Link", - "label": "Account", - "options": "Account", - "read_only": 1 } ], "idx": 1, "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2023-05-31 11:47:00.191681", + "modified": "2023-06-23 21:12:57.557731", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice Advance", diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 5c256b730f..046711532f 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -474,7 +474,9 @@ def reconcile_against_document(args, skip_ref_details_update_for_pe=False): # n doc = frappe.get_doc(entry.voucher_type, entry.voucher_no) gl_map = doc.build_gl_map() create_payment_ledger_entry(gl_map, update_outstanding="No", cancel=0, adv_adj=1) - doc.make_advance_gl_entries(entry.against_voucher_type, entry.against_voucher) + + if voucher_type == "Payment Entry": + doc.make_advance_gl_entries(entry.against_voucher_type, entry.against_voucher) # Only update outstanding for newly linked vouchers for entry in entries: @@ -732,7 +734,7 @@ def remove_ref_doc_link_from_pe(ref_type, ref_no): for pe in linked_pe: try: - pe_doc = frappe.get_doc("Payment Entry", pe, cache=True) + 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) pe_doc.clear_unallocated_reference_document_rows() diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 0d9ab6498d..4193b5327d 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -2916,84 +2916,6 @@ def update_child_qty_rate(parent_doctype, trans_items, parent_doctype_name, chil parent.create_stock_reservation_entries() -# def make_advance_liability_entry( -# gl_entries, pe, allocated_amount, invoice, party_type -# ): -# pe = frappe.get_doc("Payment Entry", pe) -# if party_type == "Customer": -# invoice = frappe.get_doc("Sales Invoice", invoice) -# account = pe.paid_from -# dr_or_cr = "debit" -# rev = "credit" -# against = invoice.debit_to -# party = invoice.customer -# else: -# invoice = frappe.get_doc("Purchase Invoice", invoice) -# account = pe.paid_to -# dr_or_cr = "credit" -# rev = "debit" -# against = invoice.credit_to -# party = invoice.supplier -# gl_entries.append( -# pe.get_gl_dict( -# { -# "account": account, -# "party_type": party_type, -# "party": party, -# "due_date": invoice.due_date, -# "against": against, -# dr_or_cr: allocated_amount, -# dr_or_cr + "_in_account_currency": allocated_amount, -# rev: 0, -# rev + "_in_account_currency": 0, -# "cost_center": invoice.cost_center, -# "project": invoice.project, -# "against_voucher_type": "Payment Entry", -# "against_voucher": pe.name, -# }, -# invoice.party_account_currency, -# item=pe, -# ) -# ) - -# (dr_or_cr, rev) = ("credit", "debit") if party_type == "Customer" else ("debit", "credit") -# gl_entries.append( -# pe.get_gl_dict( -# { -# "account": against, -# "party_type": party_type, -# "party": party, -# "due_date": invoice.due_date, -# dr_or_cr: allocated_amount, -# dr_or_cr + "_in_account_currency": allocated_amount, -# rev: 0, -# rev + "_in_account_currency": 0, -# "cost_center": invoice.cost_center, -# "project": invoice.project, -# "against_voucher_type": invoice.doctype, -# "against_voucher": invoice.name, -# }, -# invoice.party_account_currency, -# item=pe, -# ) -# ) - - -# def check_advance_liability_entry(gl_entries, company, advances, invoice, party_type): -# advance_payments_as_liability = frappe.db.get_value( -# "Company", {"company_name": company}, "book_advance_payments_as_liability" -# ) -# if advance_payments_as_liability: -# for advance_entry in advances: -# make_advance_liability_entry( -# gl_entries, -# advance_entry.reference_name, -# advance_entry.allocated_amount, -# invoice=invoice, -# party_type=party_type, -# ) - - @erpnext.allow_regional def validate_regional(doc): pass