From 4ee163742a705083bd9b00e36aac9099efadaabd Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Thu, 8 Jun 2023 13:15:23 +0530 Subject: [PATCH] fix: Using one field for both advance liability accounts --- .../doctype/party_account/party_account.json | 15 +- .../doctype/payment_entry/payment_entry.js | 54 +--- .../doctype/payment_entry/payment_entry.json | 2 +- .../doctype/payment_entry/payment_entry.py | 116 ++++++-- .../payment_entry_reference.json | 11 +- .../payment_reconciliation.js | 32 +- .../payment_reconciliation.json | 17 +- .../payment_reconciliation.py | 31 +- .../purchase_invoice/purchase_invoice.json | 5 +- .../sales_invoice/test_sales_invoice.py | 4 +- erpnext/accounts/party.py | 18 +- erpnext/accounts/utils.py | 38 ++- erpnext/buying/doctype/supplier/supplier.js | 13 +- erpnext/controllers/accounts_controller.py | 275 +++++++++++------- erpnext/selling/doctype/customer/customer.js | 14 +- .../selling/doctype/customer/customer.json | 14 +- erpnext/setup/doctype/company/company.js | 3 +- erpnext/setup/doctype/company/company.json | 29 +- .../doctype/customer_group/customer_group.js | 13 +- .../doctype/supplier_group/supplier_group.js | 11 + 20 files changed, 385 insertions(+), 330 deletions(-) diff --git a/erpnext/accounts/doctype/party_account/party_account.json b/erpnext/accounts/doctype/party_account/party_account.json index 719b474f1f..6ac6e56086 100644 --- a/erpnext/accounts/doctype/party_account/party_account.json +++ b/erpnext/accounts/doctype/party_account/party_account.json @@ -7,8 +7,7 @@ "field_order": [ "company", "account", - "advances_received_account", - "advances_paid_account" + "advance_account" ], "fields": [ { @@ -28,22 +27,16 @@ "options": "Account" }, { - "fieldname": "advances_received_account", + "fieldname": "advance_account", "fieldtype": "Link", - "label": "Advances Received Account", - "options": "Account" - }, - { - "fieldname": "advances_paid_account", - "fieldtype": "Link", - "label": "Advances Paid Account", + "label": "Advance Account", "options": "Account" } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2023-06-02 13:00:06.885744", + "modified": "2023-06-05 14:15:42.053150", "modified_by": "Administrator", "module": "Accounts", "name": "Party Account", diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index 7bd3bb8710..1f0e45fc11 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -18,20 +18,14 @@ frappe.ui.form.on('Payment Entry', { }, setup: function(frm) { - advance_payments_as_liability = frappe.db.get_value("Company", {"company_name": frm.doc.company}, "book_advance_payments_as_liability"); - - if(advance_payments_as_liability && frm.doc.payment_type == 'Receive'){ - account_type = "Payable"; - } - else{ - account_type = "Receivable"; - } - frm.set_query("paid_from", function() { frm.events.validate_company(frm); + + var account_types = in_list(["Pay", "Internal Transfer"], frm.doc.payment_type) ? + ["Bank", "Cash"] : [frappe.boot.party_account_types[frm.doc.party_type]]; return { filters: { - "account_type": account_type, + "account_type": ["in", account_types], "is_group": 0, "company": frm.doc.company } @@ -80,15 +74,12 @@ frappe.ui.form.on('Payment Entry', { frm.set_query("paid_to", function() { frm.events.validate_company(frm); - if(advance_payments_as_liability && in_list(['Receive', 'Internal Transfer'], cur_frm.doc.payment_type)){ - account_type = ["Bank", "Cash"]; - } - else{ - account_type = "Receivable"; - } + + var account_types = in_list(["Receive", "Internal Transfer"], frm.doc.payment_type) ? + ["Bank", "Cash"] : [frappe.boot.party_account_types[frm.doc.party_type]]; return { filters: { - "account_type": ["in", account_type], + "account_type": ["in", account_types], "is_group": 0, "company": frm.doc.company } @@ -279,25 +270,6 @@ frappe.ui.form.on('Payment Entry', { }, payment_type: function(frm) { - advance_payments_as_liability = frappe.db.get_value("Company", {"company_name": frm.doc.company}, "book_advance_payments_as_liability"); - - if(advance_payments_as_liability && frm.doc.payment_type == 'Receive'){ - account_type = ["Payable"]; - } - else{ - account_type = ["Bank", "Cash"]; - } - - frm.set_query("paid_from", function() { - frm.events.validate_company(frm); - return { - filters: { - "account_type": ["in", account_type], - "is_group": 0, - "company": frm.doc.company - } - } - }); if(frm.doc.payment_type == "Internal Transfer") { $.each(["party", "party_balance", "paid_from", "paid_to", "references", "total_allocated_amount"], function(i, field) { @@ -364,7 +336,7 @@ frappe.ui.form.on('Payment Entry', { frm.set_party_account_based_on_party = true; let company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency; - + return frappe.call({ method: "erpnext.accounts.doctype.payment_entry.payment_entry.get_party_details", args: { @@ -372,8 +344,7 @@ frappe.ui.form.on('Payment Entry', { party_type: frm.doc.party_type, party: frm.doc.party, date: frm.doc.posting_date, - cost_center: frm.doc.cost_center, - is_advance: !(frm.doc.references) + cost_center: frm.doc.cost_center }, callback: function(r, rt) { if(r.message) { @@ -741,7 +712,7 @@ frappe.ui.form.on('Payment Entry', { if(r.message) { var total_positive_outstanding = 0; var total_negative_outstanding = 0; - + console.log(r.message); $.each(r.message, function(i, d) { var c = frm.add_child("references"); c.reference_doctype = d.voucher_type; @@ -752,6 +723,7 @@ frappe.ui.form.on('Payment Entry', { c.bill_no = d.bill_no; c.payment_term = d.payment_term; c.allocated_amount = d.allocated_amount; + c.account = d.account; if(!in_list(frm.events.get_order_doctypes(frm), d.voucher_type)) { if(flt(d.outstanding_amount) > 0) @@ -1467,4 +1439,4 @@ frappe.ui.form.on('Payment Entry', { }); } }, -}) +}) \ No newline at end of file diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.json b/erpnext/accounts/doctype/payment_entry/payment_entry.json index 3927ecae43..1c330b841e 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.json +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.json @@ -733,7 +733,7 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2023-02-14 04:52:30.478523", + "modified": "2023-06-07 14:36:50.521884", "modified_by": "Administrator", "module": "Accounts", "name": "Payment Entry", diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index ed2158a649..291f8e4411 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -86,12 +86,36 @@ class PaymentEntry(AccountsController): def on_submit(self): if self.difference_amount: frappe.throw(_("Difference Amount must be zero")) + book_advance_payments_as_liability = frappe.get_value( + "Company", {"company_name": self.company}, "book_advance_payments_as_liability" + ) + if book_advance_payments_as_liability: + self.get_liability_account() self.make_gl_entries() self.update_outstanding_amounts() self.update_advance_paid() self.update_payment_schedule() self.set_status() + def get_liability_account(self): + liability_account = get_party_account(self.party_type, self.party, self.company, is_advance=True) + if self.party_type == "Customer": + msg = "Book Advance Payments as Liability option is chosen. Paid From account changed from {0} to {1}.".format( + frappe.bold(self.paid_from), + frappe.bold(liability_account), + ) + frappe.db.set_value("Payment Entry", self.name, "paid_from", liability_account) + self.paid_from = liability_account + else: + msg = "Book Advance Payments as Liability option is chosen. Paid To account changed from {0} to {1}.".format( + frappe.bold(self.paid_to), + frappe.bold(liability_account), + ) + frappe.db.set_value("Payment Entry", self.name, "paid_to", liability_account) + self.paid_to = liability_account + frappe.msgprint(_(msg), title="Warning", indicator="orange") + return liability_account + def on_cancel(self): self.ignore_linked_doctypes = ( "GL Entry", @@ -869,10 +893,14 @@ class PaymentEntry(AccountsController): if self.party_account: if self.payment_type == "Receive": against_account = self.paid_to + self.party_account = self.paid_from + dr_or_cr = "credit" else: against_account = self.paid_from + self.party_account = self.paid_to + dr_or_cr = "debit" - party_gl_dict = self.get_gl_dict( + party_dict = self.get_gl_dict( { "account": self.party_account, "party_type": self.party_type, @@ -883,30 +911,24 @@ class PaymentEntry(AccountsController): }, item=self, ) - - dr_or_cr = ( - "credit" if erpnext.get_party_account_type(self.party_type) == "Receivable" else "debit" - ) - for d in self.get("references"): - cost_center = self.cost_center - if d.reference_doctype == "Sales Invoice" and not cost_center: - cost_center = frappe.db.get_value(d.reference_doctype, d.reference_name, "cost_center") - gle = party_gl_dict.copy() - gle.update( - { - "against_voucher_type": d.reference_doctype, - "against_voucher": d.reference_name, - "cost_center": cost_center, - } + book_advance_payments_as_liability = frappe.get_value( + "Company", {"company_name": self.company}, "book_advance_payments_as_liability" ) + if ( + d.reference_doctype in ["Sales Invoice", "Purchase Invoice"] + and book_advance_payments_as_liability + ): + self.make_invoice_liability_entry(gl_entries, d) allocated_amount_in_company_currency = self.calculate_base_allocated_amount_for_reference(d) - + gle = party_dict.copy() gle.update( { - dr_or_cr + "_in_account_currency": d.allocated_amount, dr_or_cr: allocated_amount_in_company_currency, + dr_or_cr + "_in_account_currency": d.allocated_amount, + "against_voucher_type": d.reference_doctype, + "against_voucher": d.reference_name, } ) @@ -916,8 +938,7 @@ class PaymentEntry(AccountsController): exchange_rate = self.get_exchange_rate() base_unallocated_amount = self.unallocated_amount * exchange_rate - gle = party_gl_dict.copy() - + gle = party_dict.copy() gle.update( { dr_or_cr + "_in_account_currency": self.unallocated_amount, @@ -927,6 +948,40 @@ class PaymentEntry(AccountsController): gl_entries.append(gle) + def make_invoice_liability_entry(self, gl_entries, invoice): + args_dict = { + "party_type": self.party_type, + "party": self.party, + "account_currency": self.party_account_currency, + "cost_center": self.cost_center, + "voucher_type": invoice.reference_doctype, + "voucher_no": invoice.reference_name, + "against_voucher_type": invoice.reference_doctype, + "against_voucher": invoice.reference_name, + } + + 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 + args_dict[dr_or_cr + "_in_account_currency"] = invoice.allocated_amount + gle = self.get_gl_dict( + args_dict, + item=self, + ) + gl_entries.append(gle) + + args_dict[dr_or_cr] = 0 + args_dict[dr_or_cr + "_in_account_currency"] = 0 + dr_or_cr = "debit" if dr_or_cr == "credit" else "credit" + args_dict["account"] = self.get_liability_account() + args_dict[dr_or_cr] = invoice.allocated_amount + args_dict[dr_or_cr + "_in_account_currency"] = invoice.allocated_amount + gle = self.get_gl_dict( + args_dict, + item=self, + ) + gl_entries.append(gle) + def add_bank_gl_entries(self, gl_entries): if self.payment_type in ("Pay", "Internal Transfer"): gl_entries.append( @@ -1401,6 +1456,7 @@ def split_invoices_based_on_payment_terms(outstanding_invoices): "outstanding_amount": flt(d.outstanding_amount), "payment_amount": payment_term.payment_amount, "payment_term": payment_term.payment_term, + "account": d.account, } ) ) @@ -1449,7 +1505,7 @@ def get_orders_to_be_billed( if voucher_type: doc = frappe.get_doc({"doctype": voucher_type}) condition = "" - if doc and hasattr(doc, "cost_center"): + if cost_center and doc and hasattr(doc, "cost_center"): condition = " and cost_center='%s'" % cost_center orders = [] @@ -1495,9 +1551,13 @@ def get_orders_to_be_billed( order_list = [] for d in orders: - if not ( - flt(d.outstanding_amount) >= flt(filters.get("outstanding_amt_greater_than")) - and flt(d.outstanding_amount) <= flt(filters.get("outstanding_amt_less_than")) + if filters.get("oustanding_amt_greater_than") and flt(d.outstanding_amount) < flt( + filters.get("outstanding_amt_greater_than") + ): + continue + + if filters.get("oustanding_amt_less_than") and flt(d.outstanding_amount) > flt( + filters.get("outstanding_amt_less_than") ): continue @@ -1519,6 +1579,7 @@ def get_negative_outstanding_invoices( condition=None, ): voucher_type = "Sales Invoice" if party_type == "Customer" else "Purchase Invoice" + account = "debit_to" if voucher_type == "Sales Invoice" else "credit_to" supplier_condition = "" if voucher_type == "Purchase Invoice": supplier_condition = "and (release_date is null or release_date <= CURRENT_DATE)" @@ -1532,7 +1593,7 @@ def get_negative_outstanding_invoices( return frappe.db.sql( """ select - "{voucher_type}" as voucher_type, name as voucher_no, + "{voucher_type}" as voucher_type, name as voucher_no, {account} as account, if({rounded_total_field}, {rounded_total_field}, {grand_total_field}) as invoice_amount, outstanding_amount, posting_date, due_date, conversion_rate as exchange_rate @@ -1555,6 +1616,7 @@ def get_negative_outstanding_invoices( "party_type": scrub(party_type), "party_account": "debit_to" if party_type == "Customer" else "credit_to", "cost_center": cost_center, + "account": account, } ), (party, party_account), @@ -1563,12 +1625,12 @@ def get_negative_outstanding_invoices( @frappe.whitelist() -def get_party_details(company, party_type, party, date, cost_center=None, is_advance=False): +def get_party_details(company, party_type, party, date, cost_center=None): bank_account = "" if not frappe.db.exists(party_type, party): frappe.throw(_("Invalid {0}: {1}").format(party_type, party)) - party_account = get_party_account(party_type, party, company, is_advance) + party_account = get_party_account(party_type, party, company) account_currency = get_account_currency(party_account) account_balance = get_balance_on(party_account, date, cost_center=cost_center) _party_name = "title" if party_type == "Shareholder" else party_type.lower() + "_name" diff --git a/erpnext/accounts/doctype/payment_entry_reference/payment_entry_reference.json b/erpnext/accounts/doctype/payment_entry_reference/payment_entry_reference.json index 3003c68196..c318ea53bd 100644 --- a/erpnext/accounts/doctype/payment_entry_reference/payment_entry_reference.json +++ b/erpnext/accounts/doctype/payment_entry_reference/payment_entry_reference.json @@ -15,7 +15,8 @@ "outstanding_amount", "allocated_amount", "exchange_rate", - "exchange_gain_loss" + "exchange_gain_loss", + "account" ], "fields": [ { @@ -101,12 +102,18 @@ "label": "Exchange Gain/Loss", "options": "Company:company:default_currency", "read_only": 1 + }, + { + "fieldname": "account", + "fieldtype": "Link", + "label": "Account", + "options": "Account" } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2022-12-12 12:31:44.919895", + "modified": "2023-06-07 14:35:06.166907", "modified_by": "Administrator", "module": "Accounts", "name": "Payment Entry Reference", diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js index 2e9628c9f0..d8743bb69e 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js @@ -29,22 +29,12 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo }; }); - this.frm.set_query('default_advances_received_account', () => { + this.frm.set_query('default_advance_account', () => { return { filters: { "company": this.frm.doc.company, "is_group": 0, - "root_type": "Liability" - } - }; - }); - - this.frm.set_query('default_advances_paid_account', () => { - return { - filters: { - "company": this.frm.doc.company, - "is_group": 0, - "root_type": "Asset" + "root_type": (this.frm.party_type == 'Customer') ? "Liability": "Asset" } }; }); @@ -169,23 +159,7 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo }, callback: (r) => { if (!r.exc && r.message) { - this.frm.set_value("default_advances_received_account", r.message); - } - this.frm.refresh(); - } - }); - - frappe.call({ - method: "erpnext.accounts.party.get_party_account", - args: { - company: this.frm.doc.company, - party_type: (this.frm.doc.party_type == 'Customer')?'Supplier':'Customer', - party: this.frm.doc.party, - is_advance: 1 - }, - callback: (r) => { - if (!r.exc && r.message) { - this.frm.set_value("default_advances_paid_account", r.message); + this.frm.set_value("default_advance_account", r.message); } this.frm.refresh(); } diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.json b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.json index 21b8392d60..0e166ffd5d 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.json +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.json @@ -10,8 +10,7 @@ "party", "column_break_4", "receivable_payable_account", - "default_advances_received_account", - "default_advances_paid_account", + "default_advance_account", "col_break1", "from_invoice_date", "from_payment_date", @@ -190,27 +189,19 @@ }, { "depends_on": "eval:doc.party_type", - "fieldname": "default_advances_received_account", + "fieldname": "default_advance_account", "fieldtype": "Link", - "label": "Default Advances Received Account", + "label": "Default Advance Account", "mandatory_depends_on": "doc.party_type", "options": "Account", "reqd": 1 - }, - { - "depends_on": "eval:doc.party_type", - "fieldname": "default_advances_paid_account", - "fieldtype": "Link", - "label": "Default Advances Paid Account", - "mandatory_depends_on": "doc.party_type", - "options": "Account" } ], "hide_toolbar": 1, "icon": "icon-resize-horizontal", "issingle": 1, "links": [], - "modified": "2023-06-02 14:32:27.276083", + "modified": "2023-06-05 20:09:58.925427", "modified_by": "Administrator", "module": "Accounts", "name": "Payment Reconciliation", diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py index 9b03d36a8e..e7d7f2c1e4 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py @@ -13,14 +13,17 @@ import erpnext from erpnext.accounts.doctype.process_payment_reconciliation.process_payment_reconciliation import ( is_any_doc_running, ) +from erpnext.accounts.general_ledger import make_gl_entries from erpnext.accounts.utils import ( QueryPaymentLedger, get_outstanding_invoices, reconcile_against_document, ) -from erpnext.controllers.accounts_controller import get_advance_payment_entries -from erpnext.controllers.accounts_controller import make_advance_liability_entry -from erpnext.accounts.general_ledger import make_gl_entries +from erpnext.controllers.accounts_controller import ( + get_advance_payment_entries, + make_advance_liability_entry, +) + class PaymentReconciliation(Document): def __init__(self, *args, **kwargs): @@ -57,9 +60,17 @@ class PaymentReconciliation(Document): self.add_payment_entries(non_reconciled_payments) def get_payment_entries(self): - receivable_payable_account = self.receivable_payable_account - default_advances_account = self.default_advances_received_account - party_account = [receivable_payable_account, default_advances_account] + advance_accounts = [] + if self.party_type == "Customer": + advance_accounts = frappe.db.get_list( + "Account", filters={"root_type": "Liability", "company": self.company}, pluck="name" + ) + elif self.party_type == "Supplier": + advance_accounts = frappe.db.get_list( + "Account", filters={"root_type": "Asset", "company": self.company}, pluck="name" + ) + party_account = [self.receivable_payable_account] + advance_accounts + order_doctype = "Sales Order" if self.party_type == "Customer" else "Purchase Order" condition = frappe._dict( { @@ -69,12 +80,12 @@ class PaymentReconciliation(Document): "from_payment_date": self.get("from_payment_date"), "to_payment_date": self.get("to_payment_date"), "maximum_payment_amount": self.get("maximum_payment_amount"), - "minimum_payment_amount": self.get("minimum_payment_amount") + "minimum_payment_amount": self.get("minimum_payment_amount"), } ) payment_entries = get_advance_payment_entries( - self.party_type, + self.party_type, self.party, party_account, order_doctype, @@ -336,7 +347,9 @@ class PaymentReconciliation(Document): if row.invoice_number and row.allocated_amount: if row.invoice_type in ["Sales Invoice", "Purchase Invoice"]: gl_entries = [] - make_advance_liability_entry(gl_entries, row.reference_name, row.allocated_amount, row.invoice_number, self.party_type) + make_advance_liability_entry( + gl_entries, row.reference_name, row.allocated_amount, row.invoice_number, self.party_type + ) make_gl_entries(gl_entries) if row.reference_type in ["Sales Invoice", "Purchase Invoice"]: reconciled_entry = dr_or_cr_notes diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json index 60f9d62bf2..f0f1684b4d 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json @@ -1086,6 +1086,7 @@ "fieldtype": "Button", "label": "Get Advances Paid", "oldfieldtype": "Button", + "options": "set_advances", "print_hide": 1 }, { @@ -1364,12 +1365,12 @@ "depends_on": "eval:doc.update_stock && doc.is_internal_supplier", "fieldname": "set_from_warehouse", "fieldtype": "Link", + "ignore_user_permissions": 1, "label": "Set From Warehouse", "no_copy": 1, "options": "Warehouse", "print_hide": 1, "print_width": "50px", - "ignore_user_permissions": 1, "width": "50px" }, { @@ -1573,7 +1574,7 @@ "idx": 204, "is_submittable": 1, "links": [], - "modified": "2023-04-29 12:57:50.832598", + "modified": "2023-06-05 17:40:35.320635", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice", diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 6051c9915d..dbc277044a 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -3353,14 +3353,16 @@ def check_gl_entries(doc, voucher_no, expected_gle, posting_date): gl_entries = frappe.db.sql( """select account, debit, credit, posting_date from `tabGL Entry` - where voucher_type='Sales Invoice' and voucher_no=%s and posting_date > %s + where voucher_type='Sales Invoice' and voucher_no=%s and posting_date >= %s and is_cancelled = 0 order by posting_date asc, account asc""", (voucher_no, posting_date), as_dict=1, + debug=True, ) for i, gle in enumerate(gl_entries): + print(i, gle) doc.assertEqual(expected_gle[i][0], gle.account) doc.assertEqual(expected_gle[i][1], gle.debit) doc.assertEqual(expected_gle[i][2], gle.credit) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index 3be4275888..782c41e529 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -380,9 +380,7 @@ def get_party_account(party_type, party=None, company=None, is_advance=False): return frappe.get_cached_value("Company", company, default_account_name) - advance_payments_as_liability = frappe.db.get_value("Company", {"company_name": company}, "book_advance_payments_as_liability") - - if is_advance and advance_payments_as_liability and party_type in ["Customer", "Supplier"]: + if is_advance and party_type in ["Customer", "Supplier"]: return get_party_advance_account(party_type, party, company) account = frappe.db.get_value( @@ -415,9 +413,10 @@ def get_party_account(party_type, party=None, company=None, is_advance=False): def get_party_advance_account(party_type, party, company): - account_name = 'advances_received_account' if party_type == 'Customer' else 'advances_paid_account' account = frappe.db.get_value( - "Party Account", {"parenttype": party_type, "parent": party, "company": company}, account_name + "Party Account", + {"parenttype": party_type, "parent": party, "company": company}, + "advance_account", ) if not account: @@ -426,14 +425,15 @@ def get_party_advance_account(party_type, party, company): account = frappe.db.get_value( "Party Account", {"parenttype": party_group_doctype, "parent": group, "company": company}, - account_name, + "advance_account", ) - + if not account: - account = frappe.get_cached_value("Company", company, "default_" + account_name) + account = frappe.get_cached_value("Company", company, "default_advance_account") return account - + + @frappe.whitelist() def get_party_bank_account(party_type, party): return frappe.db.get_value( diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 5abc64315c..506279c1e5 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -498,30 +498,36 @@ def check_if_advance_entry_modified(args): journal_entry = frappe.qb.DocType("Journal Entry") journal_acc = frappe.qb.DocType("Journal Entry Account") - q = (frappe.qb.from_(journal_entry) + q = ( + frappe.qb.from_(journal_entry) .innerjoin(journal_acc) .on(journal_entry.name == journal_acc.parent) ) - if args.get("dr_or_cr") == 'debit_in_account_currency': + if args.get("dr_or_cr") == "debit_in_account_currency": q = q.select(journal_acc.debit_in_account_currency) else: q = q.select(journal_acc.credit_in_account_currency) - - q = q.where((journal_acc.account == args.get("account")) - &((journal_acc.party_type == args.get("party_type"))) - &((journal_acc.party == args.get("party"))) - &((journal_acc.reference_type == None) | (journal_acc.reference_type.isin(['', 'Sales Order', 'Purchase Order']))) - &((journal_entry.name == args.get("voucher_no"))) - &((journal_acc.name == args.get("voucher_detail_no"))) - &((journal_entry.docstatus == 1)) + + q = q.where( + (journal_acc.account == args.get("account")) + & ((journal_acc.party_type == args.get("party_type"))) + & ((journal_acc.party == args.get("party"))) + & ( + (journal_acc.reference_type == None) + | (journal_acc.reference_type.isin(["", "Sales Order", "Purchase Order"])) + ) + & ((journal_entry.name == args.get("voucher_no"))) + & ((journal_acc.name == args.get("voucher_detail_no"))) + & ((journal_entry.docstatus == 1)) ) else: payment_entry = frappe.qb.DocType("Payment Entry") payment_ref = frappe.qb.DocType("Payment Entry Reference") - q = (frappe.qb.from_(payment_entry) + q = ( + frappe.qb.from_(payment_entry) .select(payment_entry.name) .where(payment_entry.name == args.get("voucher_no")) .where(payment_entry.docstatus == 1) @@ -530,15 +536,16 @@ def check_if_advance_entry_modified(args): ) if args.voucher_detail_no: - q = ( q.inner_join(payment_ref) + q = ( + q.inner_join(payment_ref) .on(payment_entry.name == payment_ref.parent) .where(payment_ref.name == args.get("voucher_detail_no")) - .where(payment_ref.reference_doctype.isin(('', 'Sales Order', 'Purchase Order'))) + .where(payment_ref.reference_doctype.isin(("", "Sales Order", "Purchase Order"))) .where(payment_ref.allocated_amount == args.get("unreconciled_amount")) - ) + ) else: q = q.where(payment_entry.unallocated_amount == args.get("unreconciled_amount")) - + ret = q.run(as_dict=True) if not ret: @@ -921,6 +928,7 @@ def get_outstanding_invoices( "outstanding_amount": outstanding_amount, "due_date": d.due_date, "currency": d.currency, + "account": d.account, } ) ) diff --git a/erpnext/buying/doctype/supplier/supplier.js b/erpnext/buying/doctype/supplier/supplier.js index 9e217b5113..6da47c5c69 100644 --- a/erpnext/buying/doctype/supplier/supplier.js +++ b/erpnext/buying/doctype/supplier/supplier.js @@ -18,7 +18,7 @@ frappe.ui.form.on("Supplier", { } }); - frm.set_query('advances_received_account', 'accounts', function (doc, cdt, cdn) { + frm.set_query('advance_account', 'accounts', function (doc, cdt, cdn) { var d = locals[cdt][cdn]; return { filters: { @@ -29,17 +29,6 @@ frappe.ui.form.on("Supplier", { } }); - frm.set_query('advances_paid_account', 'accounts', function (doc, cdt, cdn) { - var d = locals[cdt][cdn]; - return { - filters: { - "root_type": 'Liability', - "company": d.company, - "is_group": 0 - } - } - }); - frm.set_query("default_bank_account", function() { return { filters: { diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index ac32fd352c..0589f4a89a 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -7,9 +7,8 @@ import json import frappe from frappe import _, bold, throw from frappe.model.workflow import get_workflow_name, is_transition_condition_satisfied -from frappe.query_builder.functions import Abs, Sum from frappe.query_builder.custom import ConstantColumn - +from frappe.query_builder.functions import Abs, Sum from frappe.utils import ( add_days, add_months, @@ -859,7 +858,6 @@ class AccountsController(TransactionBase): amount = self.get("base_rounded_total") or self.base_grand_total else: amount = self.get("rounded_total") or self.grand_total - allocated_amount = min(amount - advance_allocated, d.amount) advance_allocated += flt(allocated_amount) @@ -887,16 +885,18 @@ class AccountsController(TransactionBase): amount_field = "credit_in_account_currency" order_field = "sales_order" order_doctype = "Sales Order" - party_account = frappe.db.get_values("Company", {"company_name": self.company}, ["default_receivable_account", "default_advances_received_account"]) + party_account = [ + get_party_account(party_type, party=party, company=self.company, is_advance=True) + ] else: party_type = "Supplier" party = self.supplier amount_field = "debit_in_account_currency" order_field = "purchase_order" order_doctype = "Purchase Order" - party_account = frappe.db.get_values("Company", {"company_name": self.company}, ["default_receivable_account", "default_advances_paid_account"]) - - party_account = list(party_account[0]) + party_account = [ + get_party_account(party_type, party=party, company=self.company, is_advance=True) + ] order_list = list(set(d.get(order_field) for d in self.get("items") if d.get(order_field))) @@ -2144,35 +2144,43 @@ def get_advance_journal_entries( order_list, include_unallocated=True, ): - journal_entry = frappe.qb.DocType('Journal Entry') - journal_acc = frappe.qb.DocType('Journal Entry Account') - q = (frappe.qb.from_(journal_entry) + journal_entry = frappe.qb.DocType("Journal Entry") + journal_acc = frappe.qb.DocType("Journal Entry Account") + q = ( + frappe.qb.from_(journal_entry) .inner_join(journal_acc) .on(journal_entry.name == journal_acc.parent) .select( - ConstantColumn('Journal Entry').as_('reference_type'), - (journal_entry.name).as_('reference_name'), - (journal_entry.remark).as_('remarks'), - (journal_acc.debit_in_account_currency if party_type == 'Supplier' else journal_acc.credit_in_account_currency).as_('amount'), - (journal_acc.name).as_('reference_row'), - (journal_acc.reference_name).as_('against_order'), - (journal_acc.exchange_rate) + ConstantColumn("Journal Entry").as_("reference_type"), + (journal_entry.name).as_("reference_name"), + (journal_entry.remark).as_("remarks"), + ( + journal_acc.debit_in_account_currency + if party_type == "Supplier" + else journal_acc.credit_in_account_currency + ).as_("amount"), + (journal_acc.name).as_("reference_row"), + (journal_acc.reference_name).as_("against_order"), + (journal_acc.exchange_rate), ) - .where(journal_acc.account.isin(party_account) - & (journal_acc.party_type == party_type) - & (journal_acc.party == party) - & (journal_acc.is_advance == 'Yes') - & (journal_entry.docstatus == 1) - ) - ) + .where( + journal_acc.account.isin(party_account) + & (journal_acc.party_type == party_type) + & (journal_acc.party == party) + & (journal_acc.is_advance == "Yes") + & (journal_entry.docstatus == 1) + ) + ) if party_type == "Customer": q = q.where(journal_acc.credit_in_account_currency > 0) + else: + q = q.where(journal_acc.debit_in_account_currency > 0) + if order_list: q = q.where(journal_acc.reference_type == order_doctype) if include_unallocated: - q = q.where(journal_acc.reference_name.isin(order_list) - |(journal_acc.reference_name == '')) + q = q.where(journal_acc.reference_name.isin(order_list) | (journal_acc.reference_name == "")) else: q = q.where(journal_acc.reference_name.isin(order_list)) @@ -2194,69 +2202,119 @@ def get_advance_payment_entries( condition=None, ): - q = build_query(party_type, party, party_account, order_doctype, order_list, include_unallocated, against_all_orders, limit, condition) + q = build_query( + party_type, + party, + party_account, + order_doctype, + order_list, + include_unallocated, + against_all_orders, + limit, + condition, + ) payment_entries = q.run(as_dict=True) return list(payment_entries) -def build_query(party_type, party, party_account, order_doctype, order_list, include_unallocated, against_all_orders, limit, condition): - payment_type = "Receive" if party_type == "Customer" else "Pay" - payment_entry = frappe.qb.DocType('Payment Entry') - payment_ref = frappe.qb.DocType('Payment Entry Reference') - q = (frappe.qb.from_(payment_entry) +def build_query( + party_type, + party, + party_account, + order_doctype, + order_list, + include_unallocated, + against_all_orders, + limit, + condition, +): + payment_type = "Receive" if party_type == "Customer" else "Pay" + payment_entry = frappe.qb.DocType("Payment Entry") + payment_ref = frappe.qb.DocType("Payment Entry Reference") + + q = ( + frappe.qb.from_(payment_entry) .select( - ConstantColumn('Payment Entry').as_('reference_type'), - (payment_entry.name).as_('reference_name'), + ConstantColumn("Payment Entry").as_("reference_type"), + (payment_entry.name).as_("reference_name"), payment_entry.posting_date, - (payment_entry.remarks).as_('remarks') + (payment_entry.remarks).as_("remarks"), ) .where(payment_entry.payment_type == payment_type) .where(payment_entry.party_type == party_type) .where(payment_entry.party == party) .where(payment_entry.docstatus == 1) ) - + if party_type == "Customer": - q = q.select(payment_entry.paid_from_account_currency) - q = q.select(payment_entry.paid_from) - q = q.where(payment_entry.paid_from.isin(party_account)) + q = q.select(payment_entry.paid_from_account_currency) + q = q.select(payment_entry.paid_from) + q = q.where(payment_entry.paid_from.isin(party_account)) else: q = q.select(payment_entry.paid_to_account_currency) q = q.select(payment_entry.paid_to) - q = q.where(payment_entry.paid_to.isin(party_account)) + q = q.where(payment_entry.paid_to.isin(party_account)) if payment_type == "Receive": q = q.select(payment_entry.source_exchange_rate) - else: + else: q.select(payment_entry.target_exchange_rate) if include_unallocated: - q = q.select((payment_entry.unallocated_amount).as_('amount')) - q = q.where(payment_entry.unallocated_amount>0) + q = q.select((payment_entry.unallocated_amount).as_("amount")) + q = q.where(payment_entry.unallocated_amount > 0) if condition: q = q.where(payment_entry.company == condition["company"]) - q = q.where(payment_entry.posting_date >= condition["from_payment_date"]) if condition.get("from_payment_date") else q - q = q.where(payment_entry.posting_date <= condition["to_payment_date"]) if condition.get("to_payment_date") else q + q = ( + q.where(payment_entry.posting_date >= condition["from_payment_date"]) + if condition.get("from_payment_date") + else q + ) + q = ( + q.where(payment_entry.posting_date <= condition["to_payment_date"]) + if condition.get("to_payment_date") + else q + ) if condition.get("get_payments") == True: - q = q.where(payment_entry.cost_center == condition["cost_center"]) if condition.get("cost_center") else q - q = q.where(payment_entry.unallocated_amount >= condition["minimum_payment_amount"]) if condition.get("minimum_payment_amount") else q - q = q.where(payment_entry.unallocated_amount <= condition["maximum_payment_amount"]) if condition.get("maximum_payment_amount") else q + q = ( + q.where(payment_entry.cost_center == condition["cost_center"]) + if condition.get("cost_center") + else q + ) + q = ( + q.where(payment_entry.unallocated_amount >= condition["minimum_payment_amount"]) + if condition.get("minimum_payment_amount") + else q + ) + q = ( + q.where(payment_entry.unallocated_amount <= condition["maximum_payment_amount"]) + if condition.get("maximum_payment_amount") + else q + ) else: - q = q.where(payment_entry.total_debit >= condition["minimum_payment_amount"]) if condition.get("minimum_payment_amount") else q - q = q.where(payment_entry.total_debit <= condition["maximum_payment_amount"]) if condition.get("maximum_payment_amount") else q + q = ( + q.where(payment_entry.total_debit >= condition["minimum_payment_amount"]) + if condition.get("minimum_payment_amount") + else q + ) + q = ( + q.where(payment_entry.total_debit <= condition["maximum_payment_amount"]) + if condition.get("maximum_payment_amount") + else q + ) elif order_list or against_all_orders: q = q.inner_join(payment_ref).on(payment_entry.name == payment_ref.parent) q = q.select( - (payment_ref.allocated_amount).as_('amount'), - (payment_ref.name).as_('reference_row'), - (payment_ref.reference_name).as_('against_order'), - payment_ref.reference_doctype == order_doctype + (payment_ref.allocated_amount).as_("amount"), + (payment_ref.name).as_("reference_row"), + (payment_ref.reference_name).as_("against_order"), + payment_ref.reference_doctype == order_doctype, ) - + if order_list: q = q.where(payment_ref.reference_name.isin(order_list)) @@ -2862,9 +2920,12 @@ def validate_regional(doc): def validate_einvoice_fields(doc): pass -def make_advance_liability_entry(gl_entries, pe, allocated_amount, invoice, party_type): + +def make_advance_liability_entry( + gl_entries, pe, allocated_amount, invoice, party_type, references=False +): pe = frappe.get_doc("Payment Entry", pe) - if party_type=="Customer": + if party_type == "Customer": invoice = frappe.get_doc("Sales Invoice", invoice) account = pe.paid_from dr_or_cr = "debit" @@ -2880,53 +2941,55 @@ def make_advance_liability_entry(gl_entries, pe, allocated_amount, invoice, part against = invoice.credit_to party = invoice.supplier voucher_type = "Purchase Invoice" - gl_entries.append(invoice.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, - "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, - "project": invoice.project, - "voucher_type": voucher_type, - "voucher_no": invoice.name - }, - invoice.party_account_currency, - item=invoice, - )) - - (dr_or_cr, rev) = ("credit", "debit") if party_type=="Customer" else ("debit", "credit") - gl_entries.append(invoice.get_gl_dict( - { - "account": against, - "party_type": party_type, - "party": party, - "due_date": invoice.due_date, - "against": account, - dr_or_cr: allocated_amount, - dr_or_cr + "_in_account_currency": allocated_amount, - rev: 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, - "project": invoice.project, - "voucher_type": voucher_type, - "voucher_no": invoice.name - }, - invoice.party_account_currency, - item=invoice, - )) - + gl_entries.append( + invoice.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, + "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, + "project": invoice.project, + "voucher_type": voucher_type, + "voucher_no": invoice.name, + }, + invoice.party_account_currency, + item=invoice, + ) + ) + (dr_or_cr, rev) = ("credit", "debit") if party_type == "Customer" else ("debit", "credit") + gl_entries.append( + invoice.get_gl_dict( + { + "account": against, + "party_type": party_type, + "party": party, + "due_date": invoice.due_date, + "against": account, + dr_or_cr: allocated_amount, + dr_or_cr + "_in_account_currency": allocated_amount, + rev: 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, + "project": invoice.project, + "voucher_type": "Payment Entry" if references else voucher_type, + "voucher_no": pe.name if references else invoice.name, + }, + invoice.party_account_currency, + item=invoice, + ) + ) diff --git a/erpnext/selling/doctype/customer/customer.js b/erpnext/selling/doctype/customer/customer.js index 6dac692747..35cf8c53ee 100644 --- a/erpnext/selling/doctype/customer/customer.js +++ b/erpnext/selling/doctype/customer/customer.js @@ -34,8 +34,8 @@ frappe.ui.form.on("Customer", { filters: filters } }); - - frm.set_query('advances_received_account', 'accounts', function (doc, cdt, cdn) { + + frm.set_query('advance_account', 'accounts', function (doc, cdt, cdn) { var d = locals[cdt][cdn]; return { filters: { @@ -46,16 +46,6 @@ frappe.ui.form.on("Customer", { } }); - frm.set_query('advances_paid_account', 'accounts', function (doc, cdt, cdn) { - var d = locals[cdt][cdn]; - return { - filters: { - "root_type": 'Asset', - "company": d.company, - "is_group": 0 - } - } - }); if (frm.doc.__islocal == 1) { frm.set_value("represents_company", ""); diff --git a/erpnext/selling/doctype/customer/customer.json b/erpnext/selling/doctype/customer/customer.json index 0050279a4b..46b10351fd 100644 --- a/erpnext/selling/doctype/customer/customer.json +++ b/erpnext/selling/doctype/customer/customer.json @@ -337,12 +337,12 @@ "label": "Default Accounts" }, { - "description": "Mention if a non-standard receivable account", - "fieldname": "accounts", - "fieldtype": "Table", - "label": "Accounts", - "options": "Party Account" - }, + "description": "Mention if non-standard Receivable account", + "fieldname": "accounts", + "fieldtype": "Table", + "label": "Accounts", + "options": "Party Account" + }, { "fieldname": "credit_limit_section", "fieldtype": "Section Break", @@ -568,7 +568,7 @@ "link_fieldname": "party" } ], - "modified": "2023-05-29 14:29:17.789578", + "modified": "2023-06-05 13:48:46.152659", "modified_by": "Administrator", "module": "Selling", "name": "Customer", diff --git a/erpnext/setup/doctype/company/company.js b/erpnext/setup/doctype/company/company.js index 81919af4e1..fb0ee7f07a 100644 --- a/erpnext/setup/doctype/company/company.js +++ b/erpnext/setup/doctype/company/company.js @@ -227,8 +227,7 @@ erpnext.company.setup_queries = function(frm) { ["asset_received_but_not_billed", {"account_type": "Asset Received But Not Billed"}], ["unrealized_profit_loss_account", {"root_type": ["in", ["Liability", "Asset"]]}], ["default_provisional_account", {"root_type": ["in", ["Liability", "Asset"]]}], - ["default_advances_received_account", {"root_type": "Liability"}], - ["default_advances_paid_account", {"root_type": "Asset"}], + ["default_advance_account", {"root_type": ["in", ["Liability", "Asset"]]}], ], function(i, v) { erpnext.company.set_custom_query(frm, v); }); diff --git a/erpnext/setup/doctype/company/company.json b/erpnext/setup/doctype/company/company.json index 369e139eef..5b3d3bb086 100644 --- a/erpnext/setup/doctype/company/company.json +++ b/erpnext/setup/doctype/company/company.json @@ -72,9 +72,8 @@ "default_finance_book", "advance_payments_section", "book_advance_payments_as_liability", - "default_advances_received_account", + "default_advance_account", "column_break_cui0", - "default_advances_paid_account", "auto_accounting_for_stock_settings", "enable_perpetual_inventory", "enable_provisional_accounting_for_non_stock_items", @@ -711,25 +710,17 @@ "fieldtype": "Section Break", "label": "Advance Payments" }, - { - "depends_on": "eval:doc.book_advance_payments_as_liability", - "fieldname": "default_advances_received_account", - "fieldtype": "Link", - "label": "Default Advances Received Account", - "mandatory_depends_on": "book_advance_payments_as_liability", - "options": "Account" - }, - { - "depends_on": "eval:doc.book_advance_payments_as_liability", - "fieldname": "default_advances_paid_account", - "fieldtype": "Link", - "label": "Default Advances Paid Account", - "mandatory_depends_on": "book_advance_payments_as_liability", - "options": "Account" - }, { "fieldname": "column_break_cui0", "fieldtype": "Column Break" + }, + { + "depends_on": "eval:doc.book_advance_payments_as_liability", + "fieldname": "default_advance_account", + "fieldtype": "Link", + "label": "Default Account", + "mandatory_depends_on": "book_advance_payments_as_liability", + "options": "Account" } ], "icon": "fa fa-building", @@ -737,7 +728,7 @@ "image_field": "company_logo", "is_tree": 1, "links": [], - "modified": "2023-06-02 13:11:41.939016", + "modified": "2023-06-05 14:12:37.946451", "modified_by": "Administrator", "module": "Setup", "name": "Company", diff --git a/erpnext/setup/doctype/customer_group/customer_group.js b/erpnext/setup/doctype/customer_group/customer_group.js index ef556c774d..3a71b43ee8 100644 --- a/erpnext/setup/doctype/customer_group/customer_group.js +++ b/erpnext/setup/doctype/customer_group/customer_group.js @@ -37,7 +37,7 @@ cur_frm.fields_dict['accounts'].grid.get_field('account').get_query = function(d } } -cur_frm.fields_dict['accounts'].grid.get_field('advances_received_account').get_query = function(doc, cdt, cdn) { +cur_frm.fields_dict['accounts'].grid.get_field('advance_account').get_query = function(doc, cdt, cdn) { var d = locals[cdt][cdn]; return { filters: { @@ -46,15 +46,4 @@ cur_frm.fields_dict['accounts'].grid.get_field('advances_received_account').get_ "is_group": 0 } } -} - -cur_frm.fields_dict['accounts'].grid.get_field('advances_paid_account').get_query = function(doc, cdt, cdn) { - var d = locals[cdt][cdn]; - return { - filters: { - "root_type": 'Asset', - "company": d.company, - "is_group": 0 - } - } } \ No newline at end of file diff --git a/erpnext/setup/doctype/supplier_group/supplier_group.js b/erpnext/setup/doctype/supplier_group/supplier_group.js index e75030d441..58ab7fa928 100644 --- a/erpnext/setup/doctype/supplier_group/supplier_group.js +++ b/erpnext/setup/doctype/supplier_group/supplier_group.js @@ -36,3 +36,14 @@ cur_frm.fields_dict['accounts'].grid.get_field('account').get_query = function(d } }; }; + +cur_frm.fields_dict['accounts'].grid.get_field('advance_account').get_query = function(doc, cdt, cdn) { + var d = locals[cdt][cdn]; + return { + filters: { + "root_type": 'Asset', + "company": d.company, + "is_group": 0 + } + } +}; \ No newline at end of file