From c47adcfdd9c63b4e99adb775dbb6d1a85cf0c151 Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Mon, 21 Aug 2023 15:12:11 +0530 Subject: [PATCH 1/3] fix: advance in seperate account --- erpnext/accounts/doctype/payment_entry/payment_entry.py | 7 ++++++- erpnext/accounts/utils.py | 5 ++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index ac31e8a1dbe..1f5fba52a68 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1123,7 +1123,7 @@ class PaymentEntry(AccountsController): if self.book_advance_payments_in_separate_party_account: gl_entries = [] for d in self.get("references"): - if d.reference_doctype in ("Sales Invoice", "Purchase Invoice"): + if d.reference_doctype in ("Sales Invoice", "Purchase Invoice", "Journal Entry"): if not (against_voucher_type and against_voucher) or ( d.reference_doctype == against_voucher_type and d.reference_name == against_voucher ): @@ -1159,6 +1159,10 @@ class PaymentEntry(AccountsController): "voucher_detail_no": invoice.name, } + posting_date = frappe.db.get_value( + invoice.reference_doctype, invoice.reference_name, "posting_date" + ) + dr_or_cr = "credit" if invoice.reference_doctype == "Sales Invoice" else "debit" args_dict["account"] = invoice.account args_dict[dr_or_cr] = invoice.allocated_amount @@ -1167,6 +1171,7 @@ class PaymentEntry(AccountsController): { "against_voucher_type": invoice.reference_doctype, "against_voucher": invoice.reference_name, + "posting_date": posting_date, } ) gle = self.get_gl_dict( diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index bccf6f10b63..5c3c486deba 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -489,14 +489,13 @@ def reconcile_against_document(args, skip_ref_details_update_for_pe=False): # n gl_map = doc.build_gl_map() create_payment_ledger_entry(gl_map, update_outstanding="No", cancel=0, adv_adj=1) - if voucher_type == "Payment Entry": - doc.make_advance_gl_entries() - # Only update outstanding for newly linked vouchers for entry in entries: update_voucher_outstanding( entry.against_voucher_type, entry.against_voucher, entry.account, entry.party_type, entry.party ) + if voucher_type == "Payment Entry": + doc.make_advance_gl_entries(entry.against_voucher_type, entry.against_voucher) frappe.flags.ignore_party_validation = False From 43061f4416f4c04cbd4442cd128ff504d3ecfc04 Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Mon, 11 Sep 2023 19:16:25 +0530 Subject: [PATCH 2/3] fix: correct set_query filters --- .../doctype/payment_reconciliation/payment_reconciliation.js | 3 ++- erpnext/buying/doctype/supplier/supplier.js | 1 + erpnext/selling/doctype/customer/customer.js | 1 + erpnext/setup/doctype/company/company.js | 4 ++-- erpnext/setup/doctype/customer_group/customer_group.js | 1 + erpnext/setup/doctype/supplier_group/supplier_group.js | 1 + 6 files changed, 8 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js index 2adc1238b70..9072ce4561e 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js @@ -24,7 +24,8 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo filters: { "company": this.frm.doc.company, "is_group": 0, - "account_type": frappe.boot.party_account_types[this.frm.doc.party_type] + "account_type": frappe.boot.party_account_types[this.frm.doc.party_type], + "root_type": this.frm.doc.party_type == 'Customer' ? "Asset" : "Liability" } }; }); diff --git a/erpnext/buying/doctype/supplier/supplier.js b/erpnext/buying/doctype/supplier/supplier.js index 372ca56b86b..08dc44c71b4 100644 --- a/erpnext/buying/doctype/supplier/supplier.js +++ b/erpnext/buying/doctype/supplier/supplier.js @@ -12,6 +12,7 @@ frappe.ui.form.on("Supplier", { return { filters: { 'account_type': 'Payable', + 'root_type': 'Liability', 'company': d.company, "is_group": 0 } diff --git a/erpnext/selling/doctype/customer/customer.js b/erpnext/selling/doctype/customer/customer.js index 60f0941559a..e274a52690b 100644 --- a/erpnext/selling/doctype/customer/customer.js +++ b/erpnext/selling/doctype/customer/customer.js @@ -23,6 +23,7 @@ frappe.ui.form.on("Customer", { let d = locals[cdt][cdn]; let filters = { 'account_type': 'Receivable', + 'root_type': 'Asset', 'company': d.company, "is_group": 0 }; diff --git a/erpnext/setup/doctype/company/company.js b/erpnext/setup/doctype/company/company.js index fa207ecdd1c..4973dab505e 100644 --- a/erpnext/setup/doctype/company/company.js +++ b/erpnext/setup/doctype/company/company.js @@ -200,8 +200,8 @@ erpnext.company.setup_queries = function(frm) { $.each([ ["default_bank_account", {"account_type": "Bank"}], ["default_cash_account", {"account_type": "Cash"}], - ["default_receivable_account", {"account_type": "Receivable"}], - ["default_payable_account", {"account_type": "Payable"}], + ["default_receivable_account", { "root_type": "Asset", "account_type": "Receivable" }], + ["default_payable_account", { "root_type": "Liability", "account_type": "Payable" }], ["default_expense_account", {"root_type": "Expense"}], ["default_income_account", {"root_type": "Income"}], ["round_off_account", {"root_type": "Expense"}], diff --git a/erpnext/setup/doctype/customer_group/customer_group.js b/erpnext/setup/doctype/customer_group/customer_group.js index 49a90f959d0..3c81b0283ca 100644 --- a/erpnext/setup/doctype/customer_group/customer_group.js +++ b/erpnext/setup/doctype/customer_group/customer_group.js @@ -30,6 +30,7 @@ frappe.ui.form.on("Customer Group", { frm.set_query('account', 'accounts', function (doc, cdt, cdn) { return { filters: { + 'root_type': 'Asset', "account_type": 'Receivable', "company": locals[cdt][cdn].company, "is_group": 0 diff --git a/erpnext/setup/doctype/supplier_group/supplier_group.js b/erpnext/setup/doctype/supplier_group/supplier_group.js index b2acfd73559..33629297ffd 100644 --- a/erpnext/setup/doctype/supplier_group/supplier_group.js +++ b/erpnext/setup/doctype/supplier_group/supplier_group.js @@ -30,6 +30,7 @@ frappe.ui.form.on("Supplier Group", { frm.set_query('account', 'accounts', function (doc, cdt, cdn) { return { filters: { + 'root_type': 'Liability', 'account_type': 'Payable', 'company': locals[cdt][cdn].company, "is_group": 0 From c09807845f4142207da75e1061a8561cdf0d6af6 Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Tue, 12 Sep 2023 13:25:51 +0530 Subject: [PATCH 3/3] fix: ensure correct preview and set latest transaction date --- erpnext/accounts/doctype/payment_entry/payment_entry.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 1f5fba52a68..3b3c78f3b24 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -98,7 +98,6 @@ class PaymentEntry(AccountsController): if self.difference_amount: frappe.throw(_("Difference Amount must be zero")) self.make_gl_entries() - self.make_advance_gl_entries() self.update_outstanding_amounts() self.update_advance_paid() self.update_payment_schedule() @@ -152,7 +151,6 @@ class PaymentEntry(AccountsController): ) super(PaymentEntry, self).on_cancel() self.make_gl_entries(cancel=1) - self.make_advance_gl_entries(cancel=1) self.update_outstanding_amounts() self.update_advance_paid() self.delink_advance_entry_references() @@ -1055,6 +1053,8 @@ class PaymentEntry(AccountsController): else: self.make_exchange_gain_loss_journal() + self.make_advance_gl_entries(cancel=cancel) + def add_party_gl_entries(self, gl_entries): if self.party_account: if self.payment_type == "Receive": @@ -1163,6 +1163,9 @@ class PaymentEntry(AccountsController): invoice.reference_doctype, invoice.reference_name, "posting_date" ) + if getdate(posting_date) < getdate(self.posting_date): + posting_date = self.posting_date + dr_or_cr = "credit" if invoice.reference_doctype == "Sales Invoice" else "debit" args_dict["account"] = invoice.account args_dict[dr_or_cr] = invoice.allocated_amount