feat: order type in trr type filter
This commit is contained in:
parent
41721fe1c3
commit
42fe68d065
@ -8,7 +8,7 @@ frappe.query_reports["Sales Analytics"] = {
|
|||||||
fieldname: "tree_type",
|
fieldname: "tree_type",
|
||||||
label: __("Tree Type"),
|
label: __("Tree Type"),
|
||||||
fieldtype: "Select",
|
fieldtype: "Select",
|
||||||
options: ["Customer Group","Customer","Item Group","Item","Territory"],
|
options: ["Customer Group","Customer","Item Group","Item","Territory","Order Type"],
|
||||||
default: "Customer",
|
default: "Customer",
|
||||||
reqd: 1
|
reqd: 1
|
||||||
},
|
},
|
||||||
|
@ -28,10 +28,10 @@ class Analytics(object):
|
|||||||
def get_columns(self):
|
def get_columns(self):
|
||||||
self.columns = [{
|
self.columns = [{
|
||||||
"label": _(self.filters.tree_type + " ID"),
|
"label": _(self.filters.tree_type + " ID"),
|
||||||
"options": self.filters.tree_type,
|
"options": self.filters.tree_type if self.filters.tree_type != "Order Type" else "",
|
||||||
"fieldname": "entity",
|
"fieldname": "entity",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link" if self.filters.tree_type != "Order Type" else "Data",
|
||||||
"width": 140
|
"width": 140 if self.filters.tree_type != "Order Type" else 200
|
||||||
}]
|
}]
|
||||||
if self.filters.tree_type in ["Customer", "Supplier", "Item"]:
|
if self.filters.tree_type in ["Customer", "Supplier", "Item"]:
|
||||||
self.columns.append({
|
self.columns.append({
|
||||||
@ -73,6 +73,28 @@ class Analytics(object):
|
|||||||
self.get_sales_transactions_based_on_item_group()
|
self.get_sales_transactions_based_on_item_group()
|
||||||
self.get_rows_by_group()
|
self.get_rows_by_group()
|
||||||
|
|
||||||
|
elif self.filters.tree_type == "Order Type":
|
||||||
|
if self.filters.doc_type != "Sales Order":
|
||||||
|
self.data = []
|
||||||
|
return
|
||||||
|
self.get_sales_transactions_based_on_order_type()
|
||||||
|
self.get_rows_by_group()
|
||||||
|
|
||||||
|
def get_sales_transactions_based_on_order_type(self):
|
||||||
|
if self.filters["value_quantity"] == 'Value':
|
||||||
|
value_field = "base_net_total"
|
||||||
|
else:
|
||||||
|
value_field = "total_qty"
|
||||||
|
|
||||||
|
self.entries = frappe.db.sql(""" select s.order_type as entity, s.{value_field} as value_field, s.{date_field}
|
||||||
|
from `tab{doctype}` s where s.docstatus = 1 and s.company = %s and s.{date_field} between %s and %s
|
||||||
|
and ifnull(s.order_type, '') != '' order by s.order_type
|
||||||
|
"""
|
||||||
|
.format(date_field=self.date_field, value_field=value_field, doctype=self.filters.doc_type),
|
||||||
|
(self.filters.company, self.filters.from_date, self.filters.to_date), as_dict=1)
|
||||||
|
|
||||||
|
self.get_teams()
|
||||||
|
|
||||||
def get_sales_transactions_based_on_customers_or_suppliers(self):
|
def get_sales_transactions_based_on_customers_or_suppliers(self):
|
||||||
if self.filters["value_quantity"] == 'Value':
|
if self.filters["value_quantity"] == 'Value':
|
||||||
value_field = "base_net_total as value_field"
|
value_field = "base_net_total as value_field"
|
||||||
@ -192,7 +214,7 @@ class Analytics(object):
|
|||||||
period = self.get_period(end_date)
|
period = self.get_period(end_date)
|
||||||
amount = flt(self.entity_periodic_data.get(d.name, {}).get(period, 0.0))
|
amount = flt(self.entity_periodic_data.get(d.name, {}).get(period, 0.0))
|
||||||
row[scrub(period)] = amount
|
row[scrub(period)] = amount
|
||||||
if d.parent:
|
if d.parent and (self.filters.tree_type != "Order Type" or d.parent == "Order Types"):
|
||||||
self.entity_periodic_data.setdefault(d.parent, frappe._dict()).setdefault(period, 0.0)
|
self.entity_periodic_data.setdefault(d.parent, frappe._dict()).setdefault(period, 0.0)
|
||||||
self.entity_periodic_data[d.parent][period] += amount
|
self.entity_periodic_data[d.parent][period] += amount
|
||||||
total += amount
|
total += amount
|
||||||
@ -278,6 +300,21 @@ class Analytics(object):
|
|||||||
else:
|
else:
|
||||||
self.depth_map.setdefault(d.name, 0)
|
self.depth_map.setdefault(d.name, 0)
|
||||||
|
|
||||||
|
def get_teams(self):
|
||||||
|
self.depth_map = frappe._dict()
|
||||||
|
|
||||||
|
self.group_entries = frappe.db.sql(""" select * from (select "Order Types" as name, 0 as lft,
|
||||||
|
2 as rgt, '' as parent union select distinct order_type as name, 1 as lft, 1 as rgt, "Order Types" as parent
|
||||||
|
from `tab{doctype}` where ifnull(order_type, '') != '') as b order by lft, name
|
||||||
|
"""
|
||||||
|
.format(doctype=self.filters.doc_type), as_dict=1)
|
||||||
|
|
||||||
|
for d in self.group_entries:
|
||||||
|
if d.parent:
|
||||||
|
self.depth_map.setdefault(d.name, self.depth_map.get(d.parent) + 1)
|
||||||
|
else:
|
||||||
|
self.depth_map.setdefault(d.name, 0)
|
||||||
|
|
||||||
def get_supplier_parent_child_map(self):
|
def get_supplier_parent_child_map(self):
|
||||||
self.parent_child_map = frappe._dict(frappe.db.sql(""" select name, supplier_group from `tabSupplier`"""))
|
self.parent_child_map = frappe._dict(frappe.db.sql(""" select name, supplier_group from `tabSupplier`"""))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user