Merge pull request #450 from saurabh6790/master
[Reports] [No Sales Order From Customers] and [Item Reorder Level]
This commit is contained in:
commit
eec70e73ba
@ -165,6 +165,12 @@ wn.module_page["Selling"] = [
|
||||
"label":wn._("Item-wise Sales History"),
|
||||
route: "query-report/Item-wise Sales History",
|
||||
},
|
||||
{
|
||||
"label":wn._("Customers Not Buying Since Long Time"),
|
||||
route: "query-report/Customers Not Buying Since Long Time",
|
||||
doctype: "Sales Order"
|
||||
},
|
||||
|
||||
]
|
||||
}
|
||||
]
|
||||
|
@ -0,0 +1,10 @@
|
||||
wn.query_reports["Customers Not Buying Since Long Time"] = {
|
||||
"filters": [
|
||||
{
|
||||
"fieldname":"days_since_last_order",
|
||||
"label": "Days Since Last Order",
|
||||
"fieldtype": "Int",
|
||||
"default": 60
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
# ERPNext - web based ERP (http://erpnext.com)
|
||||
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
from webnotes.utils import getdate, cint
|
||||
|
||||
def execute(filters=None):
|
||||
if not filters: filters ={}
|
||||
|
||||
days_since_last_order = filters.get("days_since_last_order")
|
||||
if cint(days_since_last_order) <= 0:
|
||||
webnotes.msgprint("Please mention positive value in 'Days Since Last Order' field",raise_exception=1)
|
||||
|
||||
columns = get_columns()
|
||||
customers = get_so_details()
|
||||
|
||||
data = []
|
||||
for cust in customers:
|
||||
if cust[8] >= days_since_last_order:
|
||||
cust.insert(7,get_last_so_amt(cust[0]))
|
||||
data.append(cust)
|
||||
return columns, data
|
||||
|
||||
def get_so_details():
|
||||
return webnotes.conn.sql("""select
|
||||
cust.name,
|
||||
cust.customer_name,
|
||||
cust.territory,
|
||||
cust.customer_group,
|
||||
count(distinct(so.name)) as 'num_of_order',
|
||||
sum(net_total) as 'total_order_value',
|
||||
sum(if(so.status = "Stopped",
|
||||
so.net_total * so.per_delivered/100,
|
||||
so.net_total)) as 'total_order_considered',
|
||||
max(so.transaction_date) as 'last_sales_order_date',
|
||||
DATEDIFF(CURDATE(), max(so.transaction_date)) as 'days_since_last_order'
|
||||
from `tabCustomer` cust, `tabSales Order` so
|
||||
where cust.name = so.customer and so.docstatus = 1
|
||||
group by cust.name
|
||||
order by 'days_since_last_order' desc """,as_list=1)
|
||||
|
||||
def get_last_so_amt(customer):
|
||||
res = webnotes.conn.sql("""select net_total from `tabSales Order`
|
||||
where customer ='%(customer)s' and docstatus = 1 order by transaction_date desc
|
||||
limit 1""" % {'customer':customer})
|
||||
|
||||
return res and res[0][0] or 0
|
||||
|
||||
def get_columns():
|
||||
return [
|
||||
"Customer:Link/Customer:120",
|
||||
"Customer Name:Data:120",
|
||||
"Territory::120",
|
||||
"Customer Group::120",
|
||||
"Number of Order::120",
|
||||
"Total Order Value:Currency:120",
|
||||
"Total Order Considered:Currency:160",
|
||||
"Last Order Amount:Currency:160",
|
||||
"Last Sales Order Date:Date:160",
|
||||
"Days Since Last Order::160"
|
||||
]
|
@ -0,0 +1,21 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-06-07 12:27:07",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-06-07 12:27:07",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
{
|
||||
"doctype": "Report",
|
||||
"is_standard": "Yes",
|
||||
"name": "__common__",
|
||||
"ref_doctype": "Sales Order",
|
||||
"report_name": "Customers Not Buying Since Long Time ",
|
||||
"report_type": "Script Report"
|
||||
},
|
||||
{
|
||||
"doctype": "Report",
|
||||
"name": "Customers Not Buying Since Long Time"
|
||||
}
|
||||
]
|
@ -216,6 +216,12 @@ wn.module_page["Stock"] = [
|
||||
{
|
||||
"label":wn._("Item Prices"),
|
||||
route: "query-report/Item Prices",
|
||||
|
||||
},
|
||||
{
|
||||
"label":wn._("Itemwise Recommended Reorder Level"),
|
||||
route: "query-report/Itemwise Recommended Reorder Level",
|
||||
doctype: "Item"
|
||||
},
|
||||
]
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
wn.query_reports["Itemwise Recommended Reorder Level"] = {
|
||||
"filters": [
|
||||
{
|
||||
"fieldname":"from_date",
|
||||
"label": "From Date",
|
||||
"fieldtype": "Date",
|
||||
"default": sys_defaults.year_start_date
|
||||
},
|
||||
{
|
||||
"fieldname":"to_date",
|
||||
"label": "To Date",
|
||||
"fieldtype": "Date",
|
||||
"default": get_today()
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
# ERPNext - web based ERP (http://erpnext.com)
|
||||
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import webnotes
|
||||
from webnotes.utils import getdate, flt
|
||||
|
||||
def execute(filters=None):
|
||||
if not filters: filters = {}
|
||||
float_preceision = webnotes.conn.get_default("float_preceision")
|
||||
|
||||
condition =get_condition(filters)
|
||||
|
||||
avg_daily_outgoing = 0
|
||||
diff = ((getdate(filters.get("to_date")) - getdate(filters.get("from_date"))).days)+1
|
||||
if diff <= 0:
|
||||
webnotes.msgprint("To Date should not be less than eual to From Date",raise_exception=1)
|
||||
|
||||
columns = get_columns()
|
||||
items = get_item_info()
|
||||
consumed_item_map = get_consumed_items(condition)
|
||||
delivered_item_map = get_delivered_items(condition)
|
||||
|
||||
data = []
|
||||
for item in items:
|
||||
|
||||
total_outgoing = consumed_item_map.get(item.name, 0)+delivered_item_map.get(item.name,0)
|
||||
avg_daily_outgoing = flt(total_outgoing/diff, float_preceision)
|
||||
reorder_level = (avg_daily_outgoing * flt(item.lead_time_days)) + flt(item.min_order_qty)
|
||||
|
||||
data.append([item.name, item.item_name, item.description, item.min_order_qty, item.lead_time_days,
|
||||
consumed_item_map.get(item.name, 0), delivered_item_map.get(item.name,0), total_outgoing,
|
||||
avg_daily_outgoing, reorder_level])
|
||||
|
||||
return columns , data
|
||||
|
||||
def get_columns():
|
||||
return[
|
||||
"Item:Link/Item:120", "Item name:Data:120", "Description::160",
|
||||
"Minimum Inventory Level:Float:160", "Lead Time Days:Float:120", "Consumed:Float:120",
|
||||
"Delivered:Float:120", "Total Outgoing:Float:120", "Avg Daily Outgoing:Float:160",
|
||||
"Reorder Level:Float:120"
|
||||
]
|
||||
|
||||
def get_item_info():
|
||||
return webnotes.conn.sql("""select name, item_name, description, min_order_qty,
|
||||
lead_time_days from tabItem""", as_dict=1)
|
||||
|
||||
def get_consumed_items(condition):
|
||||
|
||||
cn_items = webnotes.conn.sql("""select se_item.item_code,
|
||||
sum(se_item.actual_qty) as 'consume_qty'
|
||||
from `tabStock Entry` se, `tabStock Entry Detail` se_item
|
||||
where se.name = se_item.parent and se.docstatus = 1
|
||||
and ifnull(se_item.t_warehouse, '') = '' %s
|
||||
group by se_item.item_code""" % (condition), as_dict=1)
|
||||
|
||||
cn_items_map = {}
|
||||
for item in cn_items:
|
||||
cn_items_map.setdefault(item.item_code, item.consume_qty)
|
||||
|
||||
return cn_items_map
|
||||
|
||||
def get_delivered_items(condition):
|
||||
|
||||
dn_items = webnotes.conn.sql("""select dn_item.item_code, sum(dn_item.qty) as dn_qty
|
||||
from `tabDelivery Note` dn, `tabDelivery Note Item` dn_item
|
||||
where dn.name = dn_item.parent and dn.docstatus = 1 %s
|
||||
group by dn_item.item_code""" % (condition), as_dict=1)
|
||||
|
||||
si_items = webnotes.conn.sql("""select si_item.item_name, sum(si_item.qty) as si_qty
|
||||
from `tabSales Invoice` si, `tabSales Invoice Item` si_item
|
||||
where si.name = si_item.parent and si.docstatus = 1 and
|
||||
ifnull(si.update_stock, 0) = 1 and ifnull(si.is_pos, 0) = 1 %s
|
||||
group by si_item.item_name""" % (condition), as_dict=1)
|
||||
|
||||
dn_item_map = {}
|
||||
for item in dn_items:
|
||||
dn_item_map.setdefault(item.item_code, item.dn_qty)
|
||||
|
||||
for item in si_items:
|
||||
dn_item_map.setdefault(item.item_code, item.si_qty)
|
||||
|
||||
return dn_item_map
|
||||
|
||||
def get_condition(filters):
|
||||
conditions = ""
|
||||
if filters.get("from_date") and filters.get("to_date"):
|
||||
conditions += " and posting_date between '%s' and '%s'" % (filters["from_date"],filters["to_date"])
|
||||
else:
|
||||
webnotes.msgprint("Please set date in from date field",raise_exception=1)
|
||||
return conditions
|
@ -0,0 +1,21 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-06-07 12:47:22",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-06-07 13:03:54",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
{
|
||||
"doctype": "Report",
|
||||
"is_standard": "Yes",
|
||||
"name": "__common__",
|
||||
"ref_doctype": "Item",
|
||||
"report_name": "Itemwise Recommended Reorder Level",
|
||||
"report_type": "Script Report"
|
||||
},
|
||||
{
|
||||
"doctype": "Report",
|
||||
"name": "Itemwise Recommended Reorder Level"
|
||||
}
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user