diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 2c2efc0645..8a894e29d1 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() @@ -1060,6 +1058,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": @@ -1128,7 +1128,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 ): @@ -1164,6 +1164,13 @@ class PaymentEntry(AccountsController): "voucher_detail_no": invoice.name, } + posting_date = frappe.db.get_value( + 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 @@ -1172,6 +1179,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/doctype/payment_reconciliation/payment_reconciliation.js b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js index 7b7ce7a892..d9f00befa9 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/accounts/utils.py b/erpnext/accounts/utils.py index bbfe3d26d0..6a80f20ec9 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -491,14 +491,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 diff --git a/erpnext/buying/doctype/supplier/supplier.js b/erpnext/buying/doctype/supplier/supplier.js index 372ca56b86..08dc44c71b 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 60f0941559..e274a52690 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 fa207ecdd1..4973dab505 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 49a90f959d..3c81b0283c 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 b2acfd7355..33629297ff 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