diff --git a/erpnext/accounts/report/purchase_register/purchase_register.py b/erpnext/accounts/report/purchase_register/purchase_register.py index 1f25a05155..00f6527fa0 100644 --- a/erpnext/accounts/report/purchase_register/purchase_register.py +++ b/erpnext/accounts/report/purchase_register/purchase_register.py @@ -35,7 +35,7 @@ def _execute(filters=None, additional_table_columns=None): frappe.throw(_("Please select a supplier for fetching payments.")) invoice_list = get_invoices(filters, get_query_columns(additional_table_columns)) if filters.get("include_payments"): - invoice_list += get_payments(filters, additional_table_columns) + invoice_list += get_payments(filters) columns, expense_accounts, tax_accounts, unrealized_profit_loss_accounts = get_columns( invoice_list, additional_table_columns, include_payments @@ -156,7 +156,7 @@ def get_columns(invoice_list, additional_table_columns, include_payments=False): _("Supplier Name") + "::120", ] - if additional_table_columns: + if additional_table_columns and not include_payments: columns += additional_table_columns if not include_payments: @@ -279,6 +279,9 @@ def get_invoices(filters, additional_query_columns): .where((pi.docstatus == 1)) .orderby(pi.posting_date, pi.name, order=Order.desc) ) + if additional_query_columns: + for col in additional_query_columns: + query = query.select(col) if filters.get("supplier"): query = query.where(pi.supplier == filters.supplier) query = get_conditions(filters, query, [pi, invoice_item]) @@ -291,10 +294,7 @@ def get_invoices(filters, additional_query_columns): return invoices -def get_payments(filters, additional_query_columns): - if additional_query_columns: - additional_query_columns = ", " + ", ".join(additional_query_columns) - +def get_payments(filters): args = frappe._dict( account="credit_to", party="supplier", @@ -302,7 +302,6 @@ def get_payments(filters, additional_query_columns): party_account=get_party_account( "Supplier", filters.supplier, filters.company, include_advance=True ), - additional_query_columns="" if not additional_query_columns else additional_query_columns, ) payment_entries = get_payment_entries(filters, args) journal_entries = get_journal_entries(filters, args) diff --git a/erpnext/accounts/report/sales_register/sales_register.py b/erpnext/accounts/report/sales_register/sales_register.py index 94a7bee4fd..32f25bd81a 100644 --- a/erpnext/accounts/report/sales_register/sales_register.py +++ b/erpnext/accounts/report/sales_register/sales_register.py @@ -36,7 +36,7 @@ def _execute(filters, additional_table_columns=None): frappe.throw(_("Please select a customer for fetching payments.")) invoice_list = get_invoices(filters, get_query_columns(additional_table_columns)) if filters.get("include_payments"): - invoice_list += get_payments(filters, additional_table_columns) + invoice_list += get_payments(filters) columns, income_accounts, tax_accounts, unrealized_profit_loss_accounts = get_columns( invoice_list, additional_table_columns, include_payments @@ -187,7 +187,7 @@ def get_columns(invoice_list, additional_table_columns, include_payments=False): {"label": _("Customer Name"), "fieldname": "customer_name", "fieldtype": "Data", "width": 120}, ] - if additional_table_columns: + if additional_table_columns and not include_payments: columns += additional_table_columns if not include_payments: @@ -437,6 +437,9 @@ def get_invoices(filters, additional_query_columns): .where((si.docstatus == 1)) .orderby(si.posting_date, si.name, order=Order.desc) ) + if additional_query_columns: + for col in additional_query_columns: + query = query.select(col) if filters.get("customer"): query = query.where(si.customer == filters.customer) query = get_conditions(filters, query, [si, invoice_item, invoice_payment]) @@ -444,10 +447,7 @@ def get_invoices(filters, additional_query_columns): return invoices -def get_payments(filters, additional_query_columns): - if additional_query_columns: - additional_query_columns = ", " + ", ".join(additional_query_columns) - +def get_payments(filters): args = frappe._dict( account="debit_to", party="customer", @@ -455,7 +455,6 @@ def get_payments(filters, additional_query_columns): party_account=get_party_account( "Customer", filters.customer, filters.company, include_advance=True ), - additional_query_columns="" if not additional_query_columns else additional_query_columns, ) payment_entries = get_payment_entries(filters, args) journal_entries = get_journal_entries(filters, args) diff --git a/erpnext/accounts/report/utils.py b/erpnext/accounts/report/utils.py index 462ef21c82..91a6e7fd9f 100644 --- a/erpnext/accounts/report/utils.py +++ b/erpnext/accounts/report/utils.py @@ -173,7 +173,7 @@ def get_query_columns(report_columns): else: columns.append(fieldname) - return ", " + ", ".join(columns) + return columns def get_values_for_columns(report_columns, report_row):