feat: two new filters for gross profit

This commit is contained in:
hrzzz 2022-08-15 09:14:23 -03:00
parent 0047e18a9b
commit 27891ecb77
2 changed files with 25 additions and 0 deletions

View File

@ -38,6 +38,18 @@ frappe.query_reports["Gross Profit"] = {
"options": "Invoice\nItem Code\nItem Group\nBrand\nWarehouse\nCustomer\nCustomer Group\nTerritory\nSales Person\nProject\nMonthly\nPayment Term",
"default": "Invoice"
},
{
"fieldname":"item_group",
"label": __("Item Group"),
"fieldtype": "Link",
"options": "Item Group"
},
{
"fieldname":"sales_person",
"label": __("Sales Person"),
"fieldtype": "Link",
"options": "Sales Person"
},
],
"tree": true,
"name_field": "parent",

View File

@ -8,6 +8,7 @@ from frappe.utils import cint, flt, formatdate
from erpnext.controllers.queries import get_match_cond
from erpnext.stock.utils import get_incoming_rate
from erpnext.stock.report.stock_ledger.stock_ledger import get_item_group_condition
def execute(filters=None):
@ -676,6 +677,17 @@ class GrossProfitGenerator(object):
if self.filters.to_date:
conditions += " and posting_date <= %(to_date)s"
if self.filters.item_group:
conditions += " and {0}".format(get_item_group_condition(self.filters.item_group))
if self.filters.sales_person:
conditions += """
and exists(select 1
from `tabSales Team` st
where st.parent = `tabSales Invoice`.name
and st.sales_person = %(sales_person)s)
"""
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 = `tabSales Invoice`.name"
@ -723,6 +735,7 @@ class GrossProfitGenerator(object):
from
`tabSales Invoice` inner join `tabSales Invoice Item`
on `tabSales Invoice Item`.parent = `tabSales Invoice`.name
join `tabItem` item on item.name = `tabSales Invoice Item`.item_code
{sales_team_table}
{payment_term_table}
where