Merge pull request #26044 from GangaManoj/account-multiselect-gl

feat(General Ledger): Implement multi-account selection
This commit is contained in:
Deepesh Garg 2021-06-16 22:33:50 +05:30 committed by GitHub
commit 913e92c29f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 15 deletions

View File

@ -36,16 +36,12 @@ frappe.query_reports["General Ledger"] = {
{ {
"fieldname":"account", "fieldname":"account",
"label": __("Account"), "label": __("Account"),
"fieldtype": "Link", "fieldtype": "MultiSelectList",
"options": "Account", "options": "Account",
"get_query": function() { get_data: function(txt) {
var company = frappe.query_report.get_filter_value('company'); return frappe.db.get_link_options('Account', txt, {
return { company: frappe.query_report.get_filter_value("company")
"doctype": "Account", });
"filters": {
"company": company,
}
}
} }
}, },
{ {

View File

@ -49,8 +49,12 @@ def validate_filters(filters, account_details):
if not filters.get("from_date") and not filters.get("to_date"): if not filters.get("from_date") and not filters.get("to_date"):
frappe.throw(_("{0} and {1} are mandatory").format(frappe.bold(_("From Date")), frappe.bold(_("To Date")))) frappe.throw(_("{0} and {1} are mandatory").format(frappe.bold(_("From Date")), frappe.bold(_("To Date"))))
if filters.get("account") and not account_details.get(filters.account): for account in filters.account:
frappe.throw(_("Account {0} does not exists").format(filters.account)) if not account_details.get(account):
frappe.throw(_("Account {0} does not exists").format(account))
if filters.get('account'):
filters.account = frappe.parse_json(filters.get('account'))
if (filters.get("account") and filters.get("group_by") == _('Group by Account') if (filters.get("account") and filters.get("group_by") == _('Group by Account')
and account_details[filters.account].is_group == 0): and account_details[filters.account].is_group == 0):
@ -87,7 +91,19 @@ def set_account_currency(filters):
account_currency = None account_currency = None
if filters.get("account"): if filters.get("account"):
account_currency = get_account_currency(filters.account) if len(filters.get("account")) == 1:
account_currency = get_account_currency(filters.account[0])
else:
currency = get_account_currency(filters.account[0])
is_same_account_currency = True
for account in filters.get("account"):
if get_account_currency(account) != currency:
is_same_account_currency = False
break
if is_same_account_currency:
account_currency = currency
elif filters.get("party"): elif filters.get("party"):
gle_currency = frappe.db.get_value( gle_currency = frappe.db.get_value(
"GL Entry", { "GL Entry", {
@ -205,10 +221,10 @@ def get_gl_entries(filters, accounting_dimensions):
def get_conditions(filters): def get_conditions(filters):
conditions = [] conditions = []
if filters.get("account") and not filters.get("include_dimensions"): if filters.get("account") and not filters.get("include_dimensions"):
lft, rgt = frappe.db.get_value("Account", filters["account"], ["lft", "rgt"]) filters.account = get_accounts_with_children(filters.account)
conditions.append("""account in (select name from tabAccount conditions.append("account in %(account)s")
where lft>=%s and rgt<=%s and docstatus<2)""" % (lft, rgt))
if filters.get("cost_center"): if filters.get("cost_center"):
filters.cost_center = get_cost_centers_with_children(filters.cost_center) filters.cost_center = get_cost_centers_with_children(filters.cost_center)
@ -266,6 +282,20 @@ def get_conditions(filters):
return "and {}".format(" and ".join(conditions)) if conditions else "" return "and {}".format(" and ".join(conditions)) if conditions else ""
def get_accounts_with_children(accounts):
if not isinstance(accounts, list):
accounts = [d.strip() for d in accounts.strip().split(',') if d]
all_accounts = []
for d in accounts:
if frappe.db.exists("Account", d):
lft, rgt = frappe.db.get_value("Account", d, ["lft", "rgt"])
children = frappe.get_all("Account", filters={"lft": [">=", lft], "rgt": ["<=", rgt]})
all_accounts += [c.name for c in children]
else:
frappe.throw(_("Account: {0} does not exist").format(d))
return list(set(all_accounts))
def get_data_with_opening_closing(filters, account_details, accounting_dimensions, gl_entries): def get_data_with_opening_closing(filters, account_details, accounting_dimensions, gl_entries):
data = [] data = []