Merge pull request #8015 from rohitwaghchaure/gross_profit_issue
[fix] Gross profit report permission issue
diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py
index 8b8f257..a4fa3cb 100644
--- a/erpnext/accounts/report/gross_profit/gross_profit.py
+++ b/erpnext/accounts/report/gross_profit/gross_profit.py
@@ -5,6 +5,7 @@
import frappe
from frappe import _, scrub
from erpnext.stock.utils import get_incoming_rate
+from erpnext.controllers.queries import get_match_cond
from frappe.utils import flt
@@ -251,28 +252,29 @@
if self.filters.group_by=="Sales Person":
sales_person_cols = ", sales.sales_person, sales.allocated_amount, sales.incentives"
- sales_team_table = "left join `tabSales Team` sales on sales.parent = si.name"
+ sales_team_table = "left join `tabSales Team` sales on sales.parent = `tabSales Invoice`.name"
else:
sales_person_cols = ""
sales_team_table = ""
- self.si_list = frappe.db.sql("""select item.parenttype, item.parent,
- si.posting_date, si.posting_time, si.project, si.update_stock,
- si.customer, si.customer_group, si.territory,
- item.item_code, item.item_name, item.description, item.warehouse,
- item.item_group, item.brand, item.dn_detail, item.delivery_note,
- item.stock_qty as qty, item.base_net_rate, item.base_net_amount, item.name as "item_row"
+ self.si_list = frappe.db.sql("""select `tabSales Invoice Item`.parenttype, `tabSales Invoice Item`.parent,
+ `tabSales Invoice`.posting_date, `tabSales Invoice`.posting_time, `tabSales Invoice`.project, `tabSales Invoice`.update_stock,
+ `tabSales Invoice`.customer, `tabSales Invoice`.customer_group, `tabSales Invoice`.territory,
+ `tabSales Invoice Item`.item_code, `tabSales Invoice Item`.item_name, `tabSales Invoice Item`.description,
+ `tabSales Invoice Item`.warehouse, `tabSales Invoice Item`.item_group, `tabSales Invoice Item`.brand,
+ `tabSales Invoice Item`.dn_detail, `tabSales Invoice Item`.delivery_note, `tabSales Invoice Item`.stock_qty as qty,
+ `tabSales Invoice Item`.base_net_rate, `tabSales Invoice Item`.base_net_amount, `tabSales Invoice Item`.name as "item_row"
{sales_person_cols}
from
- `tabSales Invoice` si
- inner join `tabSales Invoice Item` item on item.parent = si.name
+ `tabSales Invoice`
+ inner join `tabSales Invoice Item` on `tabSales Invoice Item`.parent = `tabSales Invoice`.name
{sales_team_table}
where
- si.docstatus = 1 and si.is_return != 1 {conditions}
+ `tabSales Invoice`.docstatus = 1 and `tabSales Invoice`.is_return != 1 {conditions} {match_cond}
order by
- si.posting_date desc, si.posting_time desc"""
+ `tabSales Invoice`.posting_date desc, `tabSales Invoice`.posting_time desc"""
.format(conditions=conditions, sales_person_cols=sales_person_cols,
- sales_team_table=sales_team_table), self.filters, as_dict=1)
+ sales_team_table=sales_team_table, match_cond = get_match_cond('Sales Invoice')), self.filters, as_dict=1)
def load_stock_ledger_entries(self):
res = frappe.db.sql("""select item_code, voucher_type, voucher_no,