[trends analyzer] cleanup completed
This commit is contained in:
commit
f8f68c54d9
@ -21,14 +21,8 @@ from controllers.trends import get_columns,get_data
|
|||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
if not filters: filters ={}
|
if not filters: filters ={}
|
||||||
data = []
|
data = []
|
||||||
|
|
||||||
trans = "Purchase Invoice"
|
trans = "Purchase Invoice"
|
||||||
tab = ["tabPurchase Invoice","tabPurchase Invoice Item"]
|
conditions = get_columns(filters, trans)
|
||||||
|
data = get_data(filters, conditions)
|
||||||
|
|
||||||
details = get_columns(filters, trans)
|
return conditions["columns"], data
|
||||||
data = get_data(filters, tab, details)
|
|
||||||
|
|
||||||
if not data :
|
|
||||||
webnotes.msgprint("Data not found for selected criterias")
|
|
||||||
|
|
||||||
return details["columns"], data
|
|
@ -21,14 +21,8 @@ from controllers.trends import get_columns,get_data
|
|||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
if not filters: filters ={}
|
if not filters: filters ={}
|
||||||
data = []
|
data = []
|
||||||
|
|
||||||
trans = "Sales Invoice"
|
trans = "Sales Invoice"
|
||||||
tab = ["tabSales Invoice","tabSales Invoice Item"]
|
conditions = get_columns(filters, trans)
|
||||||
|
data = get_data(filters, conditions)
|
||||||
|
|
||||||
details = get_columns(filters, trans)
|
return conditions["columns"], data
|
||||||
data = get_data(filters, tab, details)
|
|
||||||
|
|
||||||
if not data :
|
|
||||||
webnotes.msgprint("Data not found for selected criterias")
|
|
||||||
|
|
||||||
return details["columns"], data
|
|
@ -185,10 +185,13 @@ class DocType(BuyingController):
|
|||||||
if d.fields.has_key(x):
|
if d.fields.has_key(x):
|
||||||
d.fields[x] = f_lst[x]
|
d.fields[x] = f_lst[x]
|
||||||
|
|
||||||
item = sql("select is_stock_item, is_purchase_item, is_sub_contracted_item from tabItem where name=%s and (ifnull(end_of_life,'')='' or end_of_life = '0000-00-00' or end_of_life > now())", d.item_code)
|
item = sql("select is_stock_item, is_purchase_item, is_sub_contracted_item, end_of_life from tabItem where name=%s",
|
||||||
|
d.item_code)
|
||||||
if not item:
|
if not item:
|
||||||
msgprint("Item %s does not exist in Item Master." % cstr(d.item_code))
|
msgprint("Item %s does not exist in Item Master." % cstr(d.item_code), raise_exception=True)
|
||||||
raise Exception
|
|
||||||
|
from stock.utils import validate_end_of_life
|
||||||
|
validate_end_of_life(d.item_code, item[0][3])
|
||||||
|
|
||||||
# validate stock item
|
# validate stock item
|
||||||
if item[0][0]=='Yes' and d.qty and not d.warehouse:
|
if item[0][0]=='Yes' and d.qty and not d.warehouse:
|
||||||
@ -197,9 +200,7 @@ class DocType(BuyingController):
|
|||||||
|
|
||||||
# validate purchase item
|
# validate purchase item
|
||||||
if item[0][1] != 'Yes' and item[0][2] != 'Yes':
|
if item[0][1] != 'Yes' and item[0][2] != 'Yes':
|
||||||
msgprint("Item %s is not a purchase item or sub-contracted item. Please check" % (d.item_code))
|
msgprint("Item %s is not a purchase item or sub-contracted item. Please check" % (d.item_code), raise_exception=True)
|
||||||
raise Exception
|
|
||||||
|
|
||||||
|
|
||||||
if d.fields.has_key('prevdoc_docname') and d.prevdoc_docname:
|
if d.fields.has_key('prevdoc_docname') and d.prevdoc_docname:
|
||||||
# check warehouse, uom in previous doc and in current doc are same.
|
# check warehouse, uom in previous doc and in current doc are same.
|
||||||
@ -215,13 +216,13 @@ class DocType(BuyingController):
|
|||||||
|
|
||||||
# Check if Warehouse has been modified.
|
# Check if Warehouse has been modified.
|
||||||
if not cstr(data[0]['warehouse']) == cstr(d.warehouse):
|
if not cstr(data[0]['warehouse']) == cstr(d.warehouse):
|
||||||
msgprint("Please check warehouse %s of Item %s which is not present in %s %s ." % (d.warehouse, d.item_code, d.prevdoc_doctype, d.prevdoc_docname))
|
msgprint("Please check warehouse %s of Item %s which is not present in %s %s ." % \
|
||||||
raise Exception
|
(d.warehouse, d.item_code, d.prevdoc_doctype, d.prevdoc_docname), raise_exception=True)
|
||||||
|
|
||||||
# Check if UOM has been modified.
|
# Check if UOM has been modified.
|
||||||
if not cstr(data[0]['uom']) == cstr(d.uom) and not cstr(d.prevdoc_doctype) == 'Material Request':
|
if not cstr(data[0]['uom']) == cstr(d.uom) and not cstr(d.prevdoc_doctype) == 'Material Request':
|
||||||
msgprint("Please check UOM %s of Item %s which is not present in %s %s ." % (d.uom, d.item_code, d.prevdoc_doctype, d.prevdoc_docname))
|
msgprint("Please check UOM %s of Item %s which is not present in %s %s ." % \
|
||||||
raise Exception
|
(d.uom, d.item_code, d.prevdoc_doctype, d.prevdoc_docname), raise_exception=True)
|
||||||
|
|
||||||
# list criteria that should not repeat if item is stock item
|
# list criteria that should not repeat if item is stock item
|
||||||
e = [d.schedule_date, d.item_code, d.description, d.warehouse, d.uom, d.fields.has_key('prevdoc_docname') and d.prevdoc_docname or '', d.fields.has_key('prevdoc_detail_docname') and d.prevdoc_detail_docname or '', d.fields.has_key('batch_no') and d.batch_no or '']
|
e = [d.schedule_date, d.item_code, d.description, d.warehouse, d.uom, d.fields.has_key('prevdoc_docname') and d.prevdoc_docname or '', d.fields.has_key('prevdoc_detail_docname') and d.prevdoc_detail_docname or '', d.fields.has_key('batch_no') and d.batch_no or '']
|
||||||
|
@ -21,14 +21,8 @@ from controllers.trends import get_columns,get_data
|
|||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
if not filters: filters ={}
|
if not filters: filters ={}
|
||||||
data = []
|
data = []
|
||||||
|
|
||||||
trans = "Purchase Order"
|
trans = "Purchase Order"
|
||||||
tab = ["tabPurchase Order","tabPurchase Order Item"]
|
conditions = get_columns(filters, trans)
|
||||||
|
data = get_data(filters, conditions)
|
||||||
|
|
||||||
details = get_columns(filters, trans)
|
return conditions["columns"], data
|
||||||
data = get_data(filters, tab, details)
|
|
||||||
|
|
||||||
if not data :
|
|
||||||
webnotes.msgprint("Data not found for selected criterias")
|
|
||||||
|
|
||||||
return details["columns"], data
|
|
@ -54,16 +54,7 @@ class BuyingController(StockController):
|
|||||||
raise_exception=WrongWarehouseCompany)
|
raise_exception=WrongWarehouseCompany)
|
||||||
|
|
||||||
def validate_stock_or_nonstock_items(self):
|
def validate_stock_or_nonstock_items(self):
|
||||||
items = [d.item_code for d in self.doclist.get({"parentfield": self.fname})]
|
if not self.stock_items:
|
||||||
if self.stock_items:
|
|
||||||
nonstock_items = list(set(items) - set(self.stock_items))
|
|
||||||
if nonstock_items:
|
|
||||||
webnotes.msgprint(_("Stock and non-stock items can not be entered in the same ") +
|
|
||||||
self.doc.doctype + _(""". You should make separate documents for them.
|
|
||||||
Stock Items: """) + ", ".join(self.stock_items) + _("""
|
|
||||||
Non-stock Items: """) + ", ".join(nonstock_items), raise_exception=1)
|
|
||||||
|
|
||||||
elif items and not self.stock_items:
|
|
||||||
tax_for_valuation = [d.account_head for d in
|
tax_for_valuation = [d.account_head for d in
|
||||||
self.doclist.get({"parentfield": "purchase_tax_details"})
|
self.doclist.get({"parentfield": "purchase_tax_details"})
|
||||||
if d.category in ["Valuation", "Valuation and Total"]]
|
if d.category in ["Valuation", "Valuation and Total"]]
|
||||||
|
@ -16,43 +16,47 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import webnotes
|
import webnotes
|
||||||
from webnotes.utils import cint, add_days, add_months, cstr
|
from webnotes.utils import add_days, add_months, cstr, getdate
|
||||||
from datetime import datetime
|
from webnotes import _
|
||||||
|
|
||||||
def get_columns(filters, trans):
|
def get_columns(filters, trans):
|
||||||
|
validate_filters(filters)
|
||||||
|
|
||||||
if not (filters.get("period") and filters.get("based_on")):
|
# get conditions for based_on filter cond
|
||||||
webnotes.msgprint("Value missing in 'Period' or 'Based On'", raise_exception=1)
|
based_on_cols, based_on_select, based_on_group_by, addl_tables = based_wise_colums_query(filters.get("based_on"), trans)
|
||||||
|
# get conditions for periodic filter cond
|
||||||
|
period_cols, period_select = period_wise_colums_query(filters, trans)
|
||||||
|
# get conditions for grouping filter cond
|
||||||
|
group_by_cols = group_wise_column(filters.get("group_by"))
|
||||||
|
|
||||||
elif filters.get("based_on") == filters.get("group_by"):
|
columns = based_on_cols + period_cols + ["Total(Qty):Float:120", "Total(Amt):Currency:120"]
|
||||||
webnotes.msgprint("Plese select different values in 'Based On' and 'Group By'", raise_exception=1)
|
if group_by_cols:
|
||||||
|
columns = based_on_cols + group_by_cols + period_cols +["Total(Qty):Float:120", "Total(Amt):Currency:120"]
|
||||||
|
|
||||||
else:
|
conditions = {"based_on_select": based_on_select, "period_wise_select": period_select, "columns": columns,
|
||||||
bonc, query_bon, based, sup_tab = basedon_wise_colums_query(filters.get("based_on"), trans)
|
"group_by": based_on_group_by, "grbc": group_by_cols, "sup_tab": addl_tables, "trans": trans}
|
||||||
pwc, query_pwc = period_wise_colums_query(filters, trans)
|
|
||||||
grbc = group_wise_column(filters.get("group_by"))
|
|
||||||
|
|
||||||
columns = bonc + pwc + ["TOTAL(Qty):Float:120", "TOTAL(Amt):Currency:120"]
|
return conditions
|
||||||
if grbc:
|
|
||||||
columns = bonc + grbc + pwc +["TOTAL(Qty):Float:120", "TOTAL(Amt):Currency:120"]
|
|
||||||
|
|
||||||
details = {"query_bon": query_bon, "query_pwc": query_pwc, "columns": columns, "basedon": based,
|
def validate_filters(filters):
|
||||||
"grbc": grbc, "sup_tab": sup_tab}
|
for f in ["Fiscal Year", "Based On", "Period", "Company"]:
|
||||||
|
if not filters.get(f.lower().replace(" ", "_")):
|
||||||
|
webnotes.msgprint(f + _(" is mandatory"), raise_exception=1)
|
||||||
|
|
||||||
return details
|
if filters.get("based_on") == filters.get("group_by"):
|
||||||
|
webnotes.msgprint("'Based On' and 'Group By' can not be same", raise_exception=1)
|
||||||
def get_data(filters, tab, details):
|
|
||||||
|
|
||||||
|
def get_data(filters, conditions):
|
||||||
data = []
|
data = []
|
||||||
inc, cond= '',''
|
inc, cond= '',''
|
||||||
query_details = details["query_bon"] + details["query_pwc"]
|
query_details = conditions["based_on_select"] + conditions["period_wise_select"]
|
||||||
|
|
||||||
if details["query_bon"] in ["t1.project_name,", "t2.project_name,"]:
|
if conditions["based_on_select"] in ["t1.project_name,", "t2.project_name,"]:
|
||||||
cond = 'and '+ details["query_bon"][:-1] +' IS Not NULL'
|
cond = 'and '+ conditions["based_on_select"][:-1] +' IS Not NULL'
|
||||||
|
|
||||||
if filters.get("group_by"):
|
if filters.get("group_by"):
|
||||||
sel_col = ''
|
sel_col = ''
|
||||||
ind = details["columns"].index(details["grbc"][0])
|
ind = conditions["columns"].index(conditions["grbc"][0])
|
||||||
|
|
||||||
if filters.get("group_by") == 'Item':
|
if filters.get("group_by") == 'Item':
|
||||||
sel_col = 't2.item_code'
|
sel_col = 't2.item_code'
|
||||||
@ -65,15 +69,14 @@ def get_data(filters, tab, details):
|
|||||||
inc = 2
|
inc = 2
|
||||||
else :
|
else :
|
||||||
inc = 1
|
inc = 1
|
||||||
|
data1 = webnotes.conn.sql(""" select %s from `tab%s` t1, `tab%s Item` t2 %s
|
||||||
data1 = webnotes.conn.sql(""" select %s from `%s` t1, `%s` t2 %s
|
|
||||||
where t2.parent = t1.name and t1.company = %s
|
where t2.parent = t1.name and t1.company = %s
|
||||||
and t1.fiscal_year = %s and t1.docstatus = 1 %s
|
and t1.fiscal_year = %s and t1.docstatus = 1 %s
|
||||||
group by %s
|
group by %s
|
||||||
""" % (query_details, tab[0], tab[1], details["sup_tab"], "%s",
|
""" % (query_details, conditions["trans"], conditions["trans"], conditions["sup_tab"], "%s",
|
||||||
"%s", cond, details["basedon"]), (filters.get("company"),
|
"%s", cond, conditions["group_by"]), (filters.get("company"),
|
||||||
filters["fiscal_year"]),
|
filters["fiscal_year"]),as_list=1)
|
||||||
as_list=1)
|
|
||||||
for d in range(len(data1)):
|
for d in range(len(data1)):
|
||||||
#to add blanck column
|
#to add blanck column
|
||||||
dt = data1[d]
|
dt = data1[d]
|
||||||
@ -81,119 +84,58 @@ def get_data(filters, tab, details):
|
|||||||
data.append(dt)
|
data.append(dt)
|
||||||
|
|
||||||
#to get distinct value of col specified by group_by in filter
|
#to get distinct value of col specified by group_by in filter
|
||||||
row = webnotes.conn.sql("""select DISTINCT(%s) from `%s` t1, `%s` t2 %s
|
row = webnotes.conn.sql("""select DISTINCT(%s) from `tab%s` t1, `tab%s Item` t2 %s
|
||||||
where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s
|
where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s
|
||||||
and t1.docstatus = 1 and %s = %s
|
and t1.docstatus = 1 and %s = %s
|
||||||
"""%(sel_col, tab[0], tab[1], details["sup_tab"], "%s", "%s", details["basedon"], "%s"),
|
"""%(sel_col, conditions["trans"], conditions["trans"], conditions["sup_tab"], "%s", "%s",
|
||||||
(filters.get("company"), filters.get("fiscal_year"), data1[d][0]),
|
conditions["group_by"], "%s"), (filters.get("company"), filters.get("fiscal_year"),
|
||||||
as_list=1)
|
data1[d][0]), as_list=1)
|
||||||
|
|
||||||
for i in range(len(row)):
|
for i in range(len(row)):
|
||||||
des = ['' for q in range(len(details["columns"]))]
|
des = ['' for q in range(len(conditions["columns"]))]
|
||||||
|
|
||||||
#get data for group_by filter
|
#get data for group_by filter
|
||||||
row1 = webnotes.conn.sql(""" select %s , %s from `%s` t1, `%s` t2 %s
|
row1 = webnotes.conn.sql(""" select %s , %s from `tab%s` t1, `tab%s Item` t2 %s
|
||||||
where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s
|
where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s
|
||||||
and t1.docstatus = 1 and %s = %s and %s = %s
|
and t1.docstatus = 1 and %s = %s and %s = %s
|
||||||
"""%(sel_col, details["query_pwc"], tab[0], tab[1], details["sup_tab"],
|
""" % (sel_col, conditions["period_wise_select"], conditions["trans"], conditions["trans"],
|
||||||
"%s", "%s", sel_col, "%s", details["basedon"], "%s"),
|
conditions["sup_tab"], "%s", "%s", sel_col, "%s", conditions["group_by"], "%s"),
|
||||||
(filters.get("company"), filters.get("fiscal_year"), row[i][0], data1[d][0]),
|
(filters.get("company"), filters.get("fiscal_year"), row[i][0], data1[d][0]), as_list=1)
|
||||||
as_list=1)
|
|
||||||
des[ind] = row[i]
|
des[ind] = row[i]
|
||||||
for j in range(1,len(details["columns"])-inc):
|
for j in range(1,len(conditions["columns"])-inc):
|
||||||
des[j+inc] = row1[0][j]
|
des[j+inc] = row1[0][j]
|
||||||
|
|
||||||
data.append(des)
|
data.append(des)
|
||||||
else:
|
else:
|
||||||
|
webnotes.errprint(["hii", conditions["sup_tab"]])
|
||||||
data = webnotes.conn.sql(""" select %s from `%s` t1, `%s` t2 %s
|
data = webnotes.conn.sql(""" select %s from `tab%s` t1, `tab%s Item` t2 %s
|
||||||
where t2.parent = t1.name and t1.company = %s
|
where t2.parent = t1.name and t1.company = %s
|
||||||
and t1.fiscal_year = %s and t1.docstatus = 1 %s
|
and t1.fiscal_year = %s and t1.docstatus = 1 %s
|
||||||
group by %s
|
group by %s
|
||||||
"""%(query_details, tab[0], tab[1], details["sup_tab"], "%s",
|
"""%(query_details, conditions["trans"], conditions["trans"], conditions["sup_tab"], "%s",
|
||||||
"%s", cond,details["basedon"]), (filters.get("company"),
|
"%s", cond,conditions["group_by"]), (filters.get("company"),
|
||||||
filters.get("fiscal_year")),
|
filters.get("fiscal_year")), as_list=1)
|
||||||
as_list=1)
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_mon(date):
|
def get_mon(dt):
|
||||||
"""convert srting formated date into date and retrieve month abbrevation"""
|
return getdate(dt).strftime("%b")
|
||||||
return (datetime.strptime(date, '%Y-%m-%d')).strftime("%b")
|
|
||||||
|
|
||||||
def period_wise_colums_query(filters, trans):
|
def period_wise_colums_query(filters, trans):
|
||||||
|
|
||||||
query_details = ''
|
query_details = ''
|
||||||
pwc = []
|
pwc = []
|
||||||
ysd = webnotes.conn.sql("""select year_start_date from `tabFiscal Year` where name = '%s'
|
bet_dates = get_period_date_ranges(filters.get("period"), filters.get("fiscal_year"))
|
||||||
"""%filters.get("fiscal_year"))[0][0]
|
|
||||||
|
|
||||||
year_start_date = ysd.strftime('%Y-%m-%d')
|
|
||||||
start_month = cint(year_start_date.split('-')[1])
|
|
||||||
|
|
||||||
if trans in ['Purchase Receipt', 'Delivery Note', 'Purchase Invoice', 'Sales Invoice']:
|
if trans in ['Purchase Receipt', 'Delivery Note', 'Purchase Invoice', 'Sales Invoice']:
|
||||||
trans_date = 'posting_date'
|
trans_date = 'posting_date'
|
||||||
else:
|
else:
|
||||||
trans_date = 'transaction_date'
|
trans_date = 'transaction_date'
|
||||||
|
|
||||||
if filters.get("period") == "Monthly":
|
if filters.get("period") != 'Yearly':
|
||||||
month_name = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
|
for dt in bet_dates:
|
||||||
|
get_period_wise_columns(dt, filters.get("period"), pwc)
|
||||||
for month in range(start_month-1,len(month_name)):
|
query_details = get_period_wise_query(dt, trans_date, query_details)
|
||||||
pwc.append(month_name[month]+' (Qty):Float:120')
|
|
||||||
pwc.append(month_name[month]+' (Amt):Currency:120')
|
|
||||||
|
|
||||||
query_details += """
|
|
||||||
Sum(IF(MONTH(t1.%(trans)s)= %(mon_num)s, t2.qty, NULL)),
|
|
||||||
SUM(IF(MONTH(t1.%(trans)s)= %(mon_num)s, t1.grand_total, NULL)),
|
|
||||||
"""%{"trans": trans_date,"mon_num": cstr(month+1)}
|
|
||||||
|
|
||||||
for month in range(0, start_month-1):
|
|
||||||
pwc.append(month_name[month]+' (Qty):Float:120')
|
|
||||||
pwc.append(month_name[month]+' (Amt):Currency:120')
|
|
||||||
|
|
||||||
query_details += """
|
|
||||||
Sum(IF(MONTH(t1.%(trans)s)= %(mon_num)s, t2.qty, NULL)),
|
|
||||||
SUM(IF(MONTH(t1.%(trans)s)= %(mon_num)s, t1.grand_total, NULL)),
|
|
||||||
"""%{"trans": trans_date, "mon_num": cstr(month+1)}
|
|
||||||
|
|
||||||
elif filters.get("period") == "Quarterly":
|
|
||||||
|
|
||||||
first_qsd, second_qsd = year_start_date, add_months(year_start_date,3)
|
|
||||||
third_qsd, fourth_qsd = add_months(year_start_date,6), add_months(year_start_date,9)
|
|
||||||
|
|
||||||
first_qed, second_qed = add_days(add_months(first_qsd,3),-1), add_days(add_months(second_qsd,3),-1)
|
|
||||||
third_qed, fourth_qed = add_days(add_months(third_qsd,3),-1), add_days(add_months(fourth_qsd,3),-1)
|
|
||||||
|
|
||||||
bet_dates = [[first_qsd,first_qed],[second_qsd,second_qed],[third_qsd,third_qed],[fourth_qsd,fourth_qed]]
|
|
||||||
|
|
||||||
pwc = [get_mon(first_qsd)+"-"+get_mon(first_qed)+" (Qty):Float:120", get_mon(first_qsd)+"-"+get_mon(first_qed)+"(Amt):Currency:120",
|
|
||||||
get_mon(second_qsd)+"-"+get_mon(second_qed)+" (Qty):Float:120", get_mon(second_qsd)+"-"+get_mon(second_qed)+" (Amt):Currency:120",
|
|
||||||
get_mon(third_qsd)+"-"+get_mon(third_qed)+" (Qty):Float:120", get_mon(third_qsd)+"-"+get_mon(third_qed)+" (Amt):Currency:120",
|
|
||||||
get_mon(fourth_qsd)+"-"+get_mon(fourth_qed)+" (Qty):Float:120", get_mon(fourth_qsd)+"-"+get_mon(fourth_qed)+" (Amt):Currency:120"]
|
|
||||||
|
|
||||||
for d in bet_dates:
|
|
||||||
query_details += """
|
|
||||||
SUM(IF(t1.%(trans)s BETWEEN '%(sd)s' AND '%(ed)s', t2.qty, NULL)),
|
|
||||||
SUM(IF(t1.%(trans)s BETWEEN '%(sd)s' AND '%(ed)s', t1.grand_total, NULL)),
|
|
||||||
"""%{"trans": trans_date, "sd": d[0],"ed": d[1]}
|
|
||||||
|
|
||||||
elif filters.get("period") == "Half-yearly":
|
|
||||||
|
|
||||||
first_half_start = year_start_date
|
|
||||||
first_half_end = add_days(add_months(first_half_start,6),-1)
|
|
||||||
second_half_start = add_days(first_half_end,1)
|
|
||||||
second_half_end = add_days(add_months(second_half_start,6),-1)
|
|
||||||
|
|
||||||
pwc = [get_mon(first_half_start)+"-"+get_mon(first_half_end)+"(Qty):Float:120", get_mon(first_half_start)+"-"+get_mon(first_half_end)+" (Amt):Currency:120",
|
|
||||||
get_mon(second_half_start)+"-"+get_mon(second_half_end)+" (Qty):Float:120", get_mon(second_half_start)+"-"+get_mon(second_half_end)+" (Amt):Currency:120"]
|
|
||||||
|
|
||||||
query_details = """
|
|
||||||
SUM(IF(t1.%(trans)s BETWEEN '%(fhs)s' AND '%(fhe)s', t2.qty, NULL)),
|
|
||||||
SUM(IF(t1.%(trans)s BETWEEN '%(fhs)s' AND '%(fhe)s', t1.grand_total, NULL)),
|
|
||||||
SUM(IF(t1.%(trans)s BETWEEN '%(shs)s' AND '%(she)s', t2.qty, NULL)),
|
|
||||||
SUM(IF(t1.%(trans)s BETWEEN '%(shs)s' AND '%(she)s', t1.grand_total, NULL)),
|
|
||||||
"""%{"trans": trans_date, "fhs": first_half_start, "fhe": first_half_end,"shs": second_half_start,
|
|
||||||
"she": second_half_end}
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
pwc = [filters.get("fiscal_year")+" (Qty):Float:120", filters.get("fiscal_year")+" (Amt):Currency:120"]
|
pwc = [filters.get("fiscal_year")+" (Qty):Float:120", filters.get("fiscal_year")+" (Amt):Currency:120"]
|
||||||
query_details = " SUM(t2.qty), SUM(t1.grand_total),"
|
query_details = " SUM(t2.qty), SUM(t1.grand_total),"
|
||||||
@ -201,7 +143,54 @@ def period_wise_colums_query(filters, trans):
|
|||||||
query_details += 'SUM(t2.qty), SUM(t1.grand_total)'
|
query_details += 'SUM(t2.qty), SUM(t1.grand_total)'
|
||||||
return pwc, query_details
|
return pwc, query_details
|
||||||
|
|
||||||
def basedon_wise_colums_query(based_on, trans):
|
def get_period_wise_columns(bet_dates, period, pwc):
|
||||||
|
if period == 'Monthly':
|
||||||
|
pwc += [get_mon(bet_dates[0]) + " (Qty):Float:120",
|
||||||
|
get_mon(bet_dates[0]) + " (Amt):Currency:120"]
|
||||||
|
else:
|
||||||
|
pwc += [get_mon(bet_dates[0]) + "-" + get_mon(bet_dates[1]) + " (Qty):Float:120",
|
||||||
|
get_mon(bet_dates[0]) + "-" + get_mon(bet_dates[1]) + " (Amt):Currency:120"]
|
||||||
|
|
||||||
|
def get_period_wise_query(bet_dates, trans_date, query_details):
|
||||||
|
|
||||||
|
query_details += """SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t2.qty, NULL)),
|
||||||
|
SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t1.grand_total, NULL)),
|
||||||
|
"""%{"trans_date": trans_date, "sd": bet_dates[0],"ed": bet_dates[1]}
|
||||||
|
return query_details
|
||||||
|
|
||||||
|
def get_period_date_ranges(period, fiscal_year):
|
||||||
|
from dateutil.relativedelta import relativedelta
|
||||||
|
|
||||||
|
year_start_date = webnotes.conn.get_value("Fiscal Year", fiscal_year, "year_start_date")
|
||||||
|
increment = {
|
||||||
|
"Monthly": 1,
|
||||||
|
"Quarterly": 3,
|
||||||
|
"Half-Yearly": 6,
|
||||||
|
"Yearly": 12
|
||||||
|
}.get(period)
|
||||||
|
|
||||||
|
period_date_ranges = []
|
||||||
|
for i in xrange(1, 13, increment):
|
||||||
|
period_end_date = year_start_date + relativedelta(months=increment, days=-1)
|
||||||
|
period_date_ranges.append([year_start_date, period_end_date])
|
||||||
|
year_start_date = period_end_date + relativedelta(days=1)
|
||||||
|
|
||||||
|
return period_date_ranges
|
||||||
|
|
||||||
|
def get_period_month_ranges(period, fiscal_year):
|
||||||
|
from dateutil.relativedelta import relativedelta
|
||||||
|
period_month_ranges = []
|
||||||
|
|
||||||
|
for start_date, end_date in get_period_date_ranges(period, fiscal_year):
|
||||||
|
months_in_this_period = []
|
||||||
|
while start_date <= end_date:
|
||||||
|
months_in_this_period.append(start_date.strftime("%B"))
|
||||||
|
start_date += relativedelta(months=1)
|
||||||
|
period_month_ranges.append(months_in_this_period)
|
||||||
|
|
||||||
|
return period_month_ranges
|
||||||
|
|
||||||
|
def based_wise_colums_query(based_on, trans):
|
||||||
sup_tab = ''
|
sup_tab = ''
|
||||||
|
|
||||||
if based_on == "Item":
|
if based_on == "Item":
|
||||||
@ -228,13 +217,13 @@ def basedon_wise_colums_query(based_on, trans):
|
|||||||
bon = ["Supplier:Link/Supplier:120", "Supplier Type:Link/Supplier Type:120"]
|
bon = ["Supplier:Link/Supplier:120", "Supplier Type:Link/Supplier Type:120"]
|
||||||
query_details = "t1.supplier, t3.supplier_type,"
|
query_details = "t1.supplier, t3.supplier_type,"
|
||||||
based = 't1.supplier'
|
based = 't1.supplier'
|
||||||
sup_tab = '`tabSupplier` t3',
|
sup_tab = ',`tabSupplier` t3'
|
||||||
|
|
||||||
elif based_on == 'Supplier Type':
|
elif based_on == 'Supplier Type':
|
||||||
bon = ["Supplier Type:Link/Supplier Type:120"]
|
bon = ["Supplier Type:Link/Supplier Type:120"]
|
||||||
query_details = "t3.supplier_type,"
|
query_details = "t3.supplier_type,"
|
||||||
based = 't3.supplier_type'
|
based = 't3.supplier_type'
|
||||||
sup_tab ='`tabSupplier` t3',
|
sup_tab =',`tabSupplier` t3'
|
||||||
|
|
||||||
elif based_on == "Territory":
|
elif based_on == "Territory":
|
||||||
bon = ["Territory:Link/Territory:120"]
|
bon = ["Territory:Link/Territory:120"]
|
||||||
@ -242,19 +231,16 @@ def basedon_wise_colums_query(based_on, trans):
|
|||||||
based = 't1.territory'
|
based = 't1.territory'
|
||||||
|
|
||||||
elif based_on == "Project":
|
elif based_on == "Project":
|
||||||
|
|
||||||
if trans in ['Sales Invoice', 'Delivery Note', 'Sales Order']:
|
if trans in ['Sales Invoice', 'Delivery Note', 'Sales Order']:
|
||||||
bon = ["Project:Link/Project:120"]
|
bon = ["Project:Link/Project:120"]
|
||||||
query_details = "t1.project_name,"
|
query_details = "t1.project_name,"
|
||||||
based = 't1.project_name'
|
based = 't1.project_name'
|
||||||
|
|
||||||
elif trans in ['Purchase Order', 'Purchase Invoice', 'Purchase Receipt']:
|
elif trans in ['Purchase Order', 'Purchase Invoice', 'Purchase Receipt']:
|
||||||
bon = ["Project:Link/Project:120"]
|
bon = ["Project:Link/Project:120"]
|
||||||
query_details = "t2.project_name,"
|
query_details = "t2.project_name,"
|
||||||
based = 't2.project_name'
|
based = 't2.project_name'
|
||||||
|
|
||||||
else:
|
else:
|
||||||
webnotes.msgprint("Information Not Available", raise_exception=1)
|
webnotes.msgprint("Project-wise data is not available for Quotation", raise_exception=1)
|
||||||
|
|
||||||
return bon, query_details, based, sup_tab
|
return bon, query_details, based, sup_tab
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import webnotes
|
import webnotes
|
||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
|
from utilities.transaction_base import delete_events
|
||||||
|
|
||||||
# delete orphaned Event User
|
# delete orphaned Event User
|
||||||
webnotes.conn.sql("""delete from `tabEvent User`
|
webnotes.conn.sql("""delete from `tabEvent User`
|
||||||
where not exists(select name from `tabEvent` where `tabEvent`.name = `tabEvent User`.parent)""")
|
where not exists(select name from `tabEvent` where `tabEvent`.name = `tabEvent User`.parent)""")
|
||||||
@ -15,5 +17,4 @@ def execute():
|
|||||||
webnotes.get_obj(dt, ref_name).add_calendar_event()
|
webnotes.get_obj(dt, ref_name).add_calendar_event()
|
||||||
else:
|
else:
|
||||||
# remove events where ref doc doesn't exist
|
# remove events where ref doc doesn't exist
|
||||||
webnotes.delete_doc("Event", webnotes.conn.sql_list("""select name from `tabEvent`
|
delete_events(dt, ref_name)
|
||||||
where ref_type=%s and ref_name=%s""", (dt, ref_name)))
|
|
@ -19,6 +19,7 @@ import webnotes
|
|||||||
|
|
||||||
from webnotes.utils import flt, getdate
|
from webnotes.utils import flt, getdate
|
||||||
from webnotes import msgprint
|
from webnotes import msgprint
|
||||||
|
from utilities.transaction_base import delete_events
|
||||||
|
|
||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self, doc, doclist=None):
|
def __init__(self, doc, doclist=None):
|
||||||
@ -69,7 +70,7 @@ class DocType:
|
|||||||
|
|
||||||
def add_calendar_event(self):
|
def add_calendar_event(self):
|
||||||
# delete any earlier event for this project
|
# delete any earlier event for this project
|
||||||
self.delete_events()
|
delete_events(self.doc.doctype, self.doc.name)
|
||||||
|
|
||||||
# add events
|
# add events
|
||||||
for milestone in self.doclist.get({"parentfield": "project_milestones"}):
|
for milestone in self.doclist.get({"parentfield": "project_milestones"}):
|
||||||
@ -87,8 +88,4 @@ class DocType:
|
|||||||
}).insert()
|
}).insert()
|
||||||
|
|
||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
self.delete_events()
|
delete_events(self.doc.doctype, self.doc.name)
|
||||||
|
|
||||||
def delete_events(self):
|
|
||||||
webnotes.delete_doc("Event", webnotes.conn.sql_list("""select name from `tabEvent`
|
|
||||||
where ref_type=%s and ref_name=%s""", (self.doc.doctype, self.doc.name)))
|
|
@ -4,7 +4,7 @@ var get_filters = function(){
|
|||||||
"fieldname":"period",
|
"fieldname":"period",
|
||||||
"label": "Period",
|
"label": "Period",
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"options": ["Monthly", "Quarterly", "Half-yearly", "Yearly"].join("\n"),
|
"options": ["Monthly", "Quarterly", "Half-Yearly", "Yearly"].join("\n"),
|
||||||
"default": "Monthly"
|
"default": "Monthly"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -4,7 +4,7 @@ var get_filters = function(){
|
|||||||
"fieldname":"period",
|
"fieldname":"period",
|
||||||
"label": "Period",
|
"label": "Period",
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"options": ["Monthly", "Quarterly", "Half-yearly", "Yearly"].join("\n"),
|
"options": ["Monthly", "Quarterly", "Half-Yearly", "Yearly"].join("\n"),
|
||||||
"default": "Monthly"
|
"default": "Monthly"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -130,6 +130,29 @@ cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc
|
|||||||
if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1);
|
if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cur_frm.fields_dict.shipping_address_name.get_query = cur_frm.fields_dict['customer_address'].get_query;
|
||||||
|
|
||||||
|
cur_frm.cscript.shipping_address_name = function() {
|
||||||
|
if(cur_frm.doc.shipping_address_name) {
|
||||||
|
wn.model.with_doc("Address", cur_frm.doc.shipping_address_name, function(name) {
|
||||||
|
var address = wn.model.get_doc("Address", name);
|
||||||
|
|
||||||
|
var out = $.map(["address_line1", "address_line2", "city"],
|
||||||
|
function(f) { return address[f]; });
|
||||||
|
|
||||||
|
var state_pincode = $.map(["state", "pincode"], function(f) { return address[f]; }).join(" ");
|
||||||
|
if(state_pincode) out.push(state_pincode);
|
||||||
|
|
||||||
|
if(address["country"]) out.push(address["country"]);
|
||||||
|
|
||||||
|
out.concat($.map([["Phone:", address["phone"]], ["Fax:", address["fax"]]],
|
||||||
|
function(val) { return val[1] ? val.join(" ") : null; }));
|
||||||
|
|
||||||
|
cur_frm.set_value("shipping_address", out.join("\n"));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
cur_frm.cscript.pull_quotation_details = function(doc,dt,dn) {
|
cur_frm.cscript.pull_quotation_details = function(doc,dt,dn) {
|
||||||
var callback = function(r,rt){
|
var callback = function(r,rt){
|
||||||
var doc = locals[cur_frm.doctype][cur_frm.docname];
|
var doc = locals[cur_frm.doctype][cur_frm.docname];
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"creation": "2013-03-07 14:48:34",
|
"creation": "2013-06-18 12:39:59",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"modified": "2013-01-29 17:14:58",
|
"modified": "2013-06-18 17:49:11",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
@ -32,6 +32,7 @@
|
|||||||
"parent": "Sales Order",
|
"parent": "Sales Order",
|
||||||
"parentfield": "permissions",
|
"parentfield": "permissions",
|
||||||
"parenttype": "DocType",
|
"parenttype": "DocType",
|
||||||
|
"permlevel": 0,
|
||||||
"read": 1
|
"read": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -202,7 +203,7 @@
|
|||||||
"label": "Shipping Address Name",
|
"label": "Shipping Address Name",
|
||||||
"options": "Address",
|
"options": "Address",
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"read_only": 1
|
"read_only": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
@ -950,104 +951,33 @@
|
|||||||
"options": "Sales Team",
|
"options": "Sales Team",
|
||||||
"print_hide": 1
|
"print_hide": 1
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"amend": 0,
|
|
||||||
"cancel": 0,
|
|
||||||
"create": 0,
|
|
||||||
"doctype": "DocPerm",
|
|
||||||
"match": "",
|
|
||||||
"permlevel": 1,
|
|
||||||
"report": 0,
|
|
||||||
"role": "Sales Manager",
|
|
||||||
"submit": 0,
|
|
||||||
"write": 0
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"amend": 1,
|
"amend": 1,
|
||||||
"cancel": 1,
|
"cancel": 1,
|
||||||
"create": 1,
|
"create": 1,
|
||||||
"doctype": "DocPerm",
|
"doctype": "DocPerm",
|
||||||
"permlevel": 0,
|
|
||||||
"report": 1,
|
|
||||||
"role": "Sales Manager",
|
|
||||||
"submit": 1,
|
|
||||||
"write": 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"amend": 1,
|
|
||||||
"cancel": 1,
|
|
||||||
"create": 1,
|
|
||||||
"doctype": "DocPerm",
|
|
||||||
"match": "",
|
|
||||||
"permlevel": 0,
|
|
||||||
"report": 1,
|
"report": 1,
|
||||||
"role": "Sales User",
|
"role": "Sales User",
|
||||||
"submit": 1,
|
"submit": 1,
|
||||||
"write": 1
|
"write": 1
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"amend": 0,
|
|
||||||
"cancel": 0,
|
|
||||||
"create": 0,
|
|
||||||
"doctype": "DocPerm",
|
|
||||||
"match": "",
|
|
||||||
"permlevel": 1,
|
|
||||||
"report": 0,
|
|
||||||
"role": "Sales User",
|
|
||||||
"submit": 0,
|
|
||||||
"write": 0
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"amend": 1,
|
"amend": 1,
|
||||||
"cancel": 1,
|
"cancel": 1,
|
||||||
"create": 1,
|
"create": 1,
|
||||||
"doctype": "DocPerm",
|
"doctype": "DocPerm",
|
||||||
"permlevel": 0,
|
|
||||||
"report": 1,
|
|
||||||
"role": "Maintenance Manager",
|
|
||||||
"submit": 1,
|
|
||||||
"write": 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"amend": 0,
|
|
||||||
"cancel": 0,
|
|
||||||
"create": 0,
|
|
||||||
"doctype": "DocPerm",
|
|
||||||
"match": "",
|
|
||||||
"permlevel": 1,
|
|
||||||
"role": "Maintenance Manager",
|
|
||||||
"submit": 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"amend": 1,
|
|
||||||
"cancel": 1,
|
|
||||||
"create": 1,
|
|
||||||
"doctype": "DocPerm",
|
|
||||||
"permlevel": 0,
|
|
||||||
"report": 1,
|
"report": 1,
|
||||||
"role": "Maintenance User",
|
"role": "Maintenance User",
|
||||||
"submit": 1,
|
"submit": 1,
|
||||||
"write": 1
|
"write": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"amend": 0,
|
|
||||||
"cancel": 0,
|
|
||||||
"create": 0,
|
|
||||||
"doctype": "DocPerm",
|
"doctype": "DocPerm",
|
||||||
"match": "",
|
|
||||||
"permlevel": 1,
|
|
||||||
"role": "Maintenance User",
|
|
||||||
"submit": 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"doctype": "DocPerm",
|
|
||||||
"permlevel": 0,
|
|
||||||
"role": "Accounts User"
|
"role": "Accounts User"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocPerm",
|
"doctype": "DocPerm",
|
||||||
"match": "customer",
|
"match": "customer",
|
||||||
"permlevel": 0,
|
|
||||||
"role": "Customer"
|
"role": "Customer"
|
||||||
}
|
}
|
||||||
]
|
]
|
@ -16,19 +16,13 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import webnotes
|
import webnotes
|
||||||
from controllers.trends import get_columns,get_data
|
from controllers.trends import get_columns, get_data
|
||||||
|
|
||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
if not filters: filters ={}
|
if not filters: filters ={}
|
||||||
data = []
|
data = []
|
||||||
|
|
||||||
trans = "Quotation"
|
trans = "Quotation"
|
||||||
tab = ["tabQuotation","tabQuotation Item"]
|
conditions = get_columns(filters, trans)
|
||||||
|
data = get_data(filters, conditions)
|
||||||
|
|
||||||
details = get_columns(filters, trans)
|
return conditions["columns"], data
|
||||||
data = get_data(filters, tab, details)
|
|
||||||
|
|
||||||
if not data:
|
|
||||||
webnotes.msgprint("Data not found for selected criterias")
|
|
||||||
|
|
||||||
return details["columns"], data
|
|
@ -21,14 +21,8 @@ from controllers.trends import get_columns,get_data
|
|||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
if not filters: filters ={}
|
if not filters: filters ={}
|
||||||
data = []
|
data = []
|
||||||
|
|
||||||
trans = "Sales Order"
|
trans = "Sales Order"
|
||||||
tab = ["tabSales Order","tabSales Order Item"]
|
conditions = get_columns(filters, trans)
|
||||||
|
data = get_data(filters, conditions)
|
||||||
|
|
||||||
details = get_columns(filters, trans)
|
return conditions["columns"], data
|
||||||
data = get_data(filters, tab, details)
|
|
||||||
|
|
||||||
if not data :
|
|
||||||
webnotes.msgprint("Data not found for selected criterias")
|
|
||||||
|
|
||||||
return details["columns"], data
|
|
@ -53,7 +53,7 @@ def execute_daily():
|
|||||||
|
|
||||||
# daily backup
|
# daily backup
|
||||||
from setup.doctype.backup_manager.backup_manager import take_backups_daily
|
from setup.doctype.backup_manager.backup_manager import take_backups_daily
|
||||||
take_backups_daily()
|
run_fn(take_backups_daily)
|
||||||
|
|
||||||
# check reorder level
|
# check reorder level
|
||||||
from stock.utils import reorder_item
|
from stock.utils import reorder_item
|
||||||
@ -61,7 +61,7 @@ def execute_daily():
|
|||||||
|
|
||||||
def execute_weekly():
|
def execute_weekly():
|
||||||
from setup.doctype.backup_manager.backup_manager import take_backups_weekly
|
from setup.doctype.backup_manager.backup_manager import take_backups_weekly
|
||||||
take_backups_weekly()
|
run_fn(take_backups_weekly)
|
||||||
|
|
||||||
def execute_monthly():
|
def execute_monthly():
|
||||||
pass
|
pass
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"creation": "2013-01-29 19:25:41",
|
"creation": "2013-05-16 10:59:15",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"modified": "2013-01-29 16:27:57",
|
"modified": "2013-06-20 11:23:01",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"allow_attach": 1,
|
"allow_attach": 1,
|
||||||
"allow_rename": 1,
|
"allow_rename": 0,
|
||||||
"autoname": "field:serial_no",
|
"autoname": "field:serial_no",
|
||||||
"description": "Distinct unit of an Item",
|
"description": "Distinct unit of an Item",
|
||||||
"doctype": "DocType",
|
"doctype": "DocType",
|
||||||
@ -31,7 +31,9 @@
|
|||||||
"parent": "Serial No",
|
"parent": "Serial No",
|
||||||
"parentfield": "permissions",
|
"parentfield": "permissions",
|
||||||
"parenttype": "DocType",
|
"parenttype": "DocType",
|
||||||
|
"permlevel": 0,
|
||||||
"read": 1,
|
"read": 1,
|
||||||
|
"report": 1,
|
||||||
"submit": 0
|
"submit": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -43,12 +45,14 @@
|
|||||||
"fieldname": "details",
|
"fieldname": "details",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "Details",
|
"label": "Details",
|
||||||
"oldfieldtype": "Section Break"
|
"oldfieldtype": "Section Break",
|
||||||
|
"read_only": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "column_break0",
|
"fieldname": "column_break0",
|
||||||
"fieldtype": "Column Break"
|
"fieldtype": "Column Break",
|
||||||
|
"read_only": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"default": "In Store",
|
"default": "In Store",
|
||||||
@ -75,6 +79,7 @@
|
|||||||
"no_copy": 1,
|
"no_copy": 1,
|
||||||
"oldfieldname": "serial_no",
|
"oldfieldname": "serial_no",
|
||||||
"oldfieldtype": "Data",
|
"oldfieldtype": "Data",
|
||||||
|
"read_only": 0,
|
||||||
"reqd": 1,
|
"reqd": 1,
|
||||||
"search_index": 1
|
"search_index": 1
|
||||||
},
|
},
|
||||||
@ -88,13 +93,15 @@
|
|||||||
"oldfieldname": "item_code",
|
"oldfieldname": "item_code",
|
||||||
"oldfieldtype": "Link",
|
"oldfieldtype": "Link",
|
||||||
"options": "Item",
|
"options": "Item",
|
||||||
|
"read_only": 0,
|
||||||
"reqd": 1,
|
"reqd": 1,
|
||||||
"search_index": 0
|
"search_index": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "column_break1",
|
"fieldname": "column_break1",
|
||||||
"fieldtype": "Column Break"
|
"fieldtype": "Column Break",
|
||||||
|
"read_only": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
@ -146,12 +153,14 @@
|
|||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "purchase_details",
|
"fieldname": "purchase_details",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "Purchase Details"
|
"label": "Purchase Details",
|
||||||
|
"read_only": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "column_break2",
|
"fieldname": "column_break2",
|
||||||
"fieldtype": "Column Break",
|
"fieldtype": "Column Break",
|
||||||
|
"read_only": 0,
|
||||||
"width": "50%"
|
"width": "50%"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -160,7 +169,8 @@
|
|||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"label": "Purchase Document Type",
|
"label": "Purchase Document Type",
|
||||||
"no_copy": 1,
|
"no_copy": 1,
|
||||||
"options": "\nPurchase Receipt\nStock Entry"
|
"options": "\nPurchase Receipt\nStock Entry",
|
||||||
|
"read_only": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
@ -168,7 +178,8 @@
|
|||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"hidden": 0,
|
"hidden": 0,
|
||||||
"label": "Purchase Document No",
|
"label": "Purchase Document No",
|
||||||
"no_copy": 1
|
"no_copy": 1,
|
||||||
|
"read_only": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
@ -179,6 +190,7 @@
|
|||||||
"no_copy": 1,
|
"no_copy": 1,
|
||||||
"oldfieldname": "purchase_date",
|
"oldfieldname": "purchase_date",
|
||||||
"oldfieldtype": "Date",
|
"oldfieldtype": "Date",
|
||||||
|
"read_only": 0,
|
||||||
"reqd": 0,
|
"reqd": 0,
|
||||||
"search_index": 0
|
"search_index": 0
|
||||||
},
|
},
|
||||||
@ -188,6 +200,7 @@
|
|||||||
"fieldtype": "Time",
|
"fieldtype": "Time",
|
||||||
"label": "Incoming Time",
|
"label": "Incoming Time",
|
||||||
"no_copy": 1,
|
"no_copy": 1,
|
||||||
|
"read_only": 0,
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -200,6 +213,7 @@
|
|||||||
"oldfieldname": "purchase_rate",
|
"oldfieldname": "purchase_rate",
|
||||||
"oldfieldtype": "Currency",
|
"oldfieldtype": "Currency",
|
||||||
"options": "Company:company:default_currency",
|
"options": "Company:company:default_currency",
|
||||||
|
"read_only": 0,
|
||||||
"reqd": 1,
|
"reqd": 1,
|
||||||
"search_index": 0
|
"search_index": 0
|
||||||
},
|
},
|
||||||
@ -207,6 +221,7 @@
|
|||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "column_break3",
|
"fieldname": "column_break3",
|
||||||
"fieldtype": "Column Break",
|
"fieldtype": "Column Break",
|
||||||
|
"read_only": 0,
|
||||||
"width": "50%"
|
"width": "50%"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -220,6 +235,7 @@
|
|||||||
"oldfieldname": "warehouse",
|
"oldfieldname": "warehouse",
|
||||||
"oldfieldtype": "Link",
|
"oldfieldtype": "Link",
|
||||||
"options": "Warehouse",
|
"options": "Warehouse",
|
||||||
|
"read_only": 0,
|
||||||
"reqd": 0,
|
"reqd": 0,
|
||||||
"search_index": 1
|
"search_index": 1
|
||||||
},
|
},
|
||||||
@ -230,7 +246,8 @@
|
|||||||
"in_filter": 1,
|
"in_filter": 1,
|
||||||
"label": "Supplier",
|
"label": "Supplier",
|
||||||
"no_copy": 1,
|
"no_copy": 1,
|
||||||
"options": "Supplier"
|
"options": "Supplier",
|
||||||
|
"read_only": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
@ -254,12 +271,14 @@
|
|||||||
"fieldname": "delivery_details",
|
"fieldname": "delivery_details",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "Delivery Details",
|
"label": "Delivery Details",
|
||||||
"oldfieldtype": "Column Break"
|
"oldfieldtype": "Column Break",
|
||||||
|
"read_only": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "column_break4",
|
"fieldname": "column_break4",
|
||||||
"fieldtype": "Column Break",
|
"fieldtype": "Column Break",
|
||||||
|
"read_only": 0,
|
||||||
"width": "50%"
|
"width": "50%"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -318,12 +337,14 @@
|
|||||||
"oldfieldname": "is_cancelled",
|
"oldfieldname": "is_cancelled",
|
||||||
"oldfieldtype": "Select",
|
"oldfieldtype": "Select",
|
||||||
"options": "\nYes\nNo",
|
"options": "\nYes\nNo",
|
||||||
|
"read_only": 0,
|
||||||
"report_hide": 1
|
"report_hide": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "column_break5",
|
"fieldname": "column_break5",
|
||||||
"fieldtype": "Column Break",
|
"fieldtype": "Column Break",
|
||||||
|
"read_only": 0,
|
||||||
"width": "50%"
|
"width": "50%"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -378,12 +399,14 @@
|
|||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "warranty_amc_details",
|
"fieldname": "warranty_amc_details",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "Warranty / AMC Details"
|
"label": "Warranty / AMC Details",
|
||||||
|
"read_only": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "column_break6",
|
"fieldname": "column_break6",
|
||||||
"fieldtype": "Column Break",
|
"fieldtype": "Column Break",
|
||||||
|
"read_only": 0,
|
||||||
"width": "50%"
|
"width": "50%"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -396,6 +419,7 @@
|
|||||||
"oldfieldname": "maintenance_status",
|
"oldfieldname": "maintenance_status",
|
||||||
"oldfieldtype": "Select",
|
"oldfieldtype": "Select",
|
||||||
"options": "\nUnder Warranty\nOut of Warranty\nUnder AMC\nOut of AMC",
|
"options": "\nUnder Warranty\nOut of Warranty\nUnder AMC\nOut of AMC",
|
||||||
|
"read_only": 0,
|
||||||
"search_index": 1,
|
"search_index": 1,
|
||||||
"width": "150px"
|
"width": "150px"
|
||||||
},
|
},
|
||||||
@ -406,12 +430,14 @@
|
|||||||
"label": "Warranty Period (Days)",
|
"label": "Warranty Period (Days)",
|
||||||
"oldfieldname": "warranty_period",
|
"oldfieldname": "warranty_period",
|
||||||
"oldfieldtype": "Int",
|
"oldfieldtype": "Int",
|
||||||
|
"read_only": 0,
|
||||||
"width": "150px"
|
"width": "150px"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "column_break7",
|
"fieldname": "column_break7",
|
||||||
"fieldtype": "Column Break",
|
"fieldtype": "Column Break",
|
||||||
|
"read_only": 0,
|
||||||
"width": "50%"
|
"width": "50%"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -422,6 +448,7 @@
|
|||||||
"label": "Warranty Expiry Date",
|
"label": "Warranty Expiry Date",
|
||||||
"oldfieldname": "warranty_expiry_date",
|
"oldfieldname": "warranty_expiry_date",
|
||||||
"oldfieldtype": "Date",
|
"oldfieldtype": "Date",
|
||||||
|
"read_only": 0,
|
||||||
"width": "150px"
|
"width": "150px"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -432,6 +459,7 @@
|
|||||||
"label": "AMC Expiry Date",
|
"label": "AMC Expiry Date",
|
||||||
"oldfieldname": "amc_expiry_date",
|
"oldfieldname": "amc_expiry_date",
|
||||||
"oldfieldtype": "Date",
|
"oldfieldtype": "Date",
|
||||||
|
"read_only": 0,
|
||||||
"search_index": 0,
|
"search_index": 0,
|
||||||
"width": "150px"
|
"width": "150px"
|
||||||
},
|
},
|
||||||
@ -439,13 +467,15 @@
|
|||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "more_info",
|
"fieldname": "more_info",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "More Info"
|
"label": "More Info",
|
||||||
|
"read_only": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "serial_no_details",
|
"fieldname": "serial_no_details",
|
||||||
"fieldtype": "Text Editor",
|
"fieldtype": "Text Editor",
|
||||||
"label": "Serial No Details"
|
"label": "Serial No Details",
|
||||||
|
"read_only": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
@ -454,6 +484,7 @@
|
|||||||
"in_filter": 1,
|
"in_filter": 1,
|
||||||
"label": "Company",
|
"label": "Company",
|
||||||
"options": "link:Company",
|
"options": "link:Company",
|
||||||
|
"read_only": 0,
|
||||||
"reqd": 1,
|
"reqd": 1,
|
||||||
"search_index": 1
|
"search_index": 1
|
||||||
},
|
},
|
||||||
@ -464,6 +495,7 @@
|
|||||||
"in_filter": 1,
|
"in_filter": 1,
|
||||||
"label": "Fiscal Year",
|
"label": "Fiscal Year",
|
||||||
"options": "link:Fiscal Year",
|
"options": "link:Fiscal Year",
|
||||||
|
"read_only": 0,
|
||||||
"reqd": 1,
|
"reqd": 1,
|
||||||
"search_index": 1
|
"search_index": 1
|
||||||
},
|
},
|
||||||
@ -487,54 +519,10 @@
|
|||||||
"read_only": 1,
|
"read_only": 1,
|
||||||
"report_hide": 1
|
"report_hide": 1
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"amend": 0,
|
|
||||||
"cancel": 0,
|
|
||||||
"create": 0,
|
|
||||||
"doctype": "DocPerm",
|
|
||||||
"match": "",
|
|
||||||
"permlevel": 1,
|
|
||||||
"report": 0,
|
|
||||||
"role": "Material Manager",
|
|
||||||
"write": 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"amend": 0,
|
|
||||||
"cancel": 0,
|
|
||||||
"create": 0,
|
|
||||||
"doctype": "DocPerm",
|
|
||||||
"permlevel": 0,
|
|
||||||
"report": 1,
|
|
||||||
"role": "Material Manager",
|
|
||||||
"write": 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"amend": 0,
|
|
||||||
"cancel": 0,
|
|
||||||
"create": 0,
|
|
||||||
"doctype": "DocPerm",
|
|
||||||
"match": "",
|
|
||||||
"permlevel": 1,
|
|
||||||
"report": 0,
|
|
||||||
"role": "Material User",
|
|
||||||
"write": 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"amend": 0,
|
|
||||||
"cancel": 0,
|
|
||||||
"create": 0,
|
|
||||||
"doctype": "DocPerm",
|
|
||||||
"permlevel": 0,
|
|
||||||
"report": 1,
|
|
||||||
"role": "Material User",
|
|
||||||
"write": 0
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"cancel": 1,
|
"cancel": 1,
|
||||||
"create": 1,
|
"create": 1,
|
||||||
"doctype": "DocPerm",
|
"doctype": "DocPerm",
|
||||||
"permlevel": 0,
|
|
||||||
"report": 1,
|
|
||||||
"role": "System Manager",
|
"role": "System Manager",
|
||||||
"write": 1
|
"write": 1
|
||||||
},
|
},
|
||||||
@ -542,8 +530,6 @@
|
|||||||
"cancel": 1,
|
"cancel": 1,
|
||||||
"create": 1,
|
"create": 1,
|
||||||
"doctype": "DocPerm",
|
"doctype": "DocPerm",
|
||||||
"permlevel": 0,
|
|
||||||
"report": 1,
|
|
||||||
"role": "Material Master Manager",
|
"role": "Material Master Manager",
|
||||||
"write": 1
|
"write": 1
|
||||||
},
|
},
|
||||||
@ -552,17 +538,15 @@
|
|||||||
"cancel": 0,
|
"cancel": 0,
|
||||||
"create": 0,
|
"create": 0,
|
||||||
"doctype": "DocPerm",
|
"doctype": "DocPerm",
|
||||||
"match": "",
|
"role": "Material Manager",
|
||||||
"permlevel": 1,
|
"write": 0
|
||||||
"role": "System Manager"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"amend": 0,
|
"amend": 0,
|
||||||
"cancel": 0,
|
"cancel": 0,
|
||||||
"create": 0,
|
"create": 0,
|
||||||
"doctype": "DocPerm",
|
"doctype": "DocPerm",
|
||||||
"match": "",
|
"role": "Material User",
|
||||||
"permlevel": 1,
|
"write": 0
|
||||||
"role": "Sales Master Manager"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
@ -21,6 +21,9 @@ class TestStockEntry(unittest.TestCase):
|
|||||||
st2.insert()
|
st2.insert()
|
||||||
st2.submit()
|
st2.submit()
|
||||||
|
|
||||||
|
from stock.utils import reorder_item
|
||||||
|
reorder_item()
|
||||||
|
|
||||||
mr_name = webnotes.conn.sql("""select parent from `tabMaterial Request Item`
|
mr_name = webnotes.conn.sql("""select parent from `tabMaterial Request Item`
|
||||||
where item_code='_Test Item'""")
|
where item_code='_Test Item'""")
|
||||||
|
|
||||||
|
@ -21,14 +21,8 @@ from controllers.trends import get_columns,get_data
|
|||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
if not filters: filters ={}
|
if not filters: filters ={}
|
||||||
data = []
|
data = []
|
||||||
|
|
||||||
trans = "Delivery Note"
|
trans = "Delivery Note"
|
||||||
tab = ["tabDelivery Note","tabDelivery Note Item"]
|
conditions = get_columns(filters, trans)
|
||||||
|
data = get_data(filters, conditions)
|
||||||
|
|
||||||
details = get_columns(filters, trans)
|
return conditions["columns"], data
|
||||||
data = get_data(filters, tab, details)
|
|
||||||
|
|
||||||
if not data :
|
|
||||||
webnotes.msgprint("Data not found for selected criterias")
|
|
||||||
|
|
||||||
return details["columns"], data
|
|
@ -69,6 +69,7 @@ def get_price_list():
|
|||||||
from `tabItem Price` where docstatus<2""", as_dict=1)
|
from `tabItem Price` where docstatus<2""", as_dict=1)
|
||||||
|
|
||||||
for j in price_list:
|
for j in price_list:
|
||||||
|
if j.price:
|
||||||
if j.selling:
|
if j.selling:
|
||||||
rate.setdefault(j.parent, {}).setdefault("selling", []).append(j.price)
|
rate.setdefault(j.parent, {}).setdefault("selling", []).append(j.price)
|
||||||
if j.buying:
|
if j.buying:
|
||||||
|
@ -21,14 +21,11 @@ from controllers.trends import get_columns,get_data
|
|||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
if not filters: filters ={}
|
if not filters: filters ={}
|
||||||
data = []
|
data = []
|
||||||
|
|
||||||
trans = "Purchase Receipt"
|
trans = "Purchase Receipt"
|
||||||
tab = ["tabPurchase Receipt","tabPurchase Receipt Item"]
|
conditions = get_columns(filters, trans)
|
||||||
|
data = get_data(filters, tab, conditions)
|
||||||
details = get_columns(filters, trans)
|
|
||||||
data = get_data(filters, tab, details)
|
|
||||||
|
|
||||||
if not data :
|
if not data :
|
||||||
webnotes.msgprint("Data not found for selected criterias")
|
webnotes.msgprint("Data not found for selected criterias")
|
||||||
|
|
||||||
return details["columns"], data
|
return conditions["columns"], data
|
@ -19,13 +19,14 @@ from webnotes import msgprint, _
|
|||||||
import json
|
import json
|
||||||
from webnotes.utils import flt, cstr, nowdate, add_days, cint
|
from webnotes.utils import flt, cstr, nowdate, add_days, cint
|
||||||
from webnotes.defaults import get_global_default
|
from webnotes.defaults import get_global_default
|
||||||
|
from webnotes.utils.email_lib import sendmail
|
||||||
|
|
||||||
def validate_end_of_life(item_code, end_of_life=None, verbose=1):
|
def validate_end_of_life(item_code, end_of_life=None, verbose=1):
|
||||||
if not end_of_life:
|
if not end_of_life:
|
||||||
end_of_life = webnotes.conn.get_value("Item", item_code, "end_of_life")
|
end_of_life = webnotes.conn.get_value("Item", item_code, "end_of_life")
|
||||||
|
|
||||||
from webnotes.utils import getdate, now_datetime, formatdate
|
from webnotes.utils import getdate, now_datetime, formatdate
|
||||||
if end_of_life and getdate(end_of_life) > now_datetime().date():
|
if end_of_life and getdate(end_of_life) <= now_datetime().date():
|
||||||
msg = (_("Item") + " %(item_code)s: " + _("reached its end of life on") + \
|
msg = (_("Item") + " %(item_code)s: " + _("reached its end of life on") + \
|
||||||
" %(date)s. " + _("Please check") + ": %(end_of_life_label)s " + \
|
" %(date)s. " + _("Please check") + ": %(end_of_life_label)s " + \
|
||||||
"in Item master") % {
|
"in Item master") % {
|
||||||
@ -205,7 +206,11 @@ def reorder_item():
|
|||||||
if webnotes.auto_indent:
|
if webnotes.auto_indent:
|
||||||
material_requests = {}
|
material_requests = {}
|
||||||
bin_list = webnotes.conn.sql("""select item_code, warehouse, projected_qty
|
bin_list = webnotes.conn.sql("""select item_code, warehouse, projected_qty
|
||||||
from tabBin where ifnull(item_code, '') != '' and ifnull(warehouse, '') != ''""",
|
from tabBin where ifnull(item_code, '') != '' and ifnull(warehouse, '') != ''
|
||||||
|
and exists (select name from `tabItem`
|
||||||
|
where `tabItem`.name = `tabBin`.item_code and
|
||||||
|
is_stock_item='Yes' and (is_purchase_item='Yes' or is_sub_contracted_item='Yes') and
|
||||||
|
(ifnull(end_of_life, '')='') or end_of_life > now())""",
|
||||||
as_dict=True)
|
as_dict=True)
|
||||||
for bin in bin_list:
|
for bin in bin_list:
|
||||||
#check if re-order is required
|
#check if re-order is required
|
||||||
@ -220,7 +225,7 @@ def reorder_item():
|
|||||||
["re_order_level", "re_order_qty"])
|
["re_order_level", "re_order_qty"])
|
||||||
material_request_type = "Purchase"
|
material_request_type = "Purchase"
|
||||||
|
|
||||||
if reorder_level and flt(bin.projected_qty) < flt(reorder_level):
|
if flt(reorder_level) and flt(bin.projected_qty) < flt(reorder_level):
|
||||||
if flt(reorder_level) - flt(bin.projected_qty) > flt(reorder_qty):
|
if flt(reorder_level) - flt(bin.projected_qty) > flt(reorder_qty):
|
||||||
reorder_qty = flt(reorder_level) - flt(bin.projected_qty)
|
reorder_qty = flt(reorder_level) - flt(bin.projected_qty)
|
||||||
|
|
||||||
@ -242,10 +247,14 @@ def create_material_request(material_requests):
|
|||||||
""" Create indent on reaching reorder level """
|
""" Create indent on reaching reorder level """
|
||||||
mr_list = []
|
mr_list = []
|
||||||
defaults = webnotes.defaults.get_defaults()
|
defaults = webnotes.defaults.get_defaults()
|
||||||
|
exceptions_list = []
|
||||||
for request_type in material_requests:
|
for request_type in material_requests:
|
||||||
for company in material_requests[request_type]:
|
for company in material_requests[request_type]:
|
||||||
|
try:
|
||||||
items = material_requests[request_type][company]
|
items = material_requests[request_type][company]
|
||||||
if items:
|
if not items:
|
||||||
|
continue
|
||||||
|
|
||||||
mr = [{
|
mr = [{
|
||||||
"doctype": "Material Request",
|
"doctype": "Material Request",
|
||||||
"company": company,
|
"company": company,
|
||||||
@ -279,6 +288,13 @@ def create_material_request(material_requests):
|
|||||||
mr_bean.submit()
|
mr_bean.submit()
|
||||||
mr_list.append(mr_bean)
|
mr_list.append(mr_bean)
|
||||||
|
|
||||||
|
except:
|
||||||
|
if webnotes.message_log:
|
||||||
|
exceptions_list.append([] + webnotes.message_log)
|
||||||
|
webnotes.message_log = []
|
||||||
|
else:
|
||||||
|
exceptions_list.append(webnotes.getTraceback())
|
||||||
|
|
||||||
if mr_list:
|
if mr_list:
|
||||||
if not hasattr(webnotes, "reorder_email_notify"):
|
if not hasattr(webnotes, "reorder_email_notify"):
|
||||||
webnotes.reorder_email_notify = webnotes.conn.get_value('Global Defaults', None,
|
webnotes.reorder_email_notify = webnotes.conn.get_value('Global Defaults', None,
|
||||||
@ -287,10 +303,12 @@ def create_material_request(material_requests):
|
|||||||
if(webnotes.reorder_email_notify):
|
if(webnotes.reorder_email_notify):
|
||||||
send_email_notification(mr_list)
|
send_email_notification(mr_list)
|
||||||
|
|
||||||
|
if exceptions_list:
|
||||||
|
notify_errors(exceptions_list)
|
||||||
|
|
||||||
def send_email_notification(mr_list):
|
def send_email_notification(mr_list):
|
||||||
""" Notify user about auto creation of indent"""
|
""" Notify user about auto creation of indent"""
|
||||||
|
|
||||||
from webnotes.utils.email_lib import sendmail
|
|
||||||
email_list = webnotes.conn.sql_list("""select distinct r.parent
|
email_list = webnotes.conn.sql_list("""select distinct r.parent
|
||||||
from tabUserRole r, tabProfile p
|
from tabUserRole r, tabProfile p
|
||||||
where p.name = r.parent and p.enabled = 1 and p.docstatus < 2
|
where p.name = r.parent and p.enabled = 1 and p.docstatus < 2
|
||||||
@ -308,3 +326,21 @@ def send_email_notification(mr_list):
|
|||||||
msg += "</table>"
|
msg += "</table>"
|
||||||
|
|
||||||
sendmail(email_list, subject='Auto Material Request Generation Notification', msg = msg)
|
sendmail(email_list, subject='Auto Material Request Generation Notification', msg = msg)
|
||||||
|
|
||||||
|
def notify_errors(exceptions_list):
|
||||||
|
subject = "[Important] [ERPNext] Error(s) while creating Material Requests based on Re-order Levels"
|
||||||
|
msg = """Dear System Manager,
|
||||||
|
|
||||||
|
An error occured for certain Items while creating Material Requests based on Re-order level.
|
||||||
|
|
||||||
|
Please rectify these issues:
|
||||||
|
---
|
||||||
|
|
||||||
|
%s
|
||||||
|
|
||||||
|
---
|
||||||
|
Regards,
|
||||||
|
Administrator""" % ("\n\n".join(["\n".join(msg) for msg in exceptions_list]),)
|
||||||
|
|
||||||
|
from webnotes.profile import get_system_managers
|
||||||
|
sendmail(get_system_managers(), subject=subject, msg=msg)
|
||||||
|
@ -26,7 +26,7 @@ from webnotes import msgprint
|
|||||||
sql = webnotes.conn.sql
|
sql = webnotes.conn.sql
|
||||||
|
|
||||||
|
|
||||||
from utilities.transaction_base import TransactionBase
|
from utilities.transaction_base import TransactionBase, delete_events
|
||||||
|
|
||||||
class DocType(TransactionBase):
|
class DocType(TransactionBase):
|
||||||
def __init__(self, doc, doclist=[]):
|
def __init__(self, doc, doclist=[]):
|
||||||
@ -327,13 +327,7 @@ class DocType(TransactionBase):
|
|||||||
if d.serial_no:
|
if d.serial_no:
|
||||||
self.update_amc_date(d.serial_no, '')
|
self.update_amc_date(d.serial_no, '')
|
||||||
webnotes.conn.set(self.doc, 'status', 'Cancelled')
|
webnotes.conn.set(self.doc, 'status', 'Cancelled')
|
||||||
self.delete_events()
|
delete_events(self.doc.doctype, self.doc.name)
|
||||||
|
|
||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
self.delete_events()
|
delete_events(self.doc.doctype, self.doc.name)
|
||||||
|
|
||||||
def delete_events(self):
|
|
||||||
webnotes.delete_doc("Event", webnotes.conn.sql_list("""select name from `tabEvent`
|
|
||||||
where ref_type=%s and ref_name=%s""", (self.doc.doctype, self.doc.name)))
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -303,3 +303,8 @@ class TransactionBase(DocListController):
|
|||||||
})
|
})
|
||||||
|
|
||||||
webnotes.bean(event_doclist).insert()
|
webnotes.bean(event_doclist).insert()
|
||||||
|
|
||||||
|
|
||||||
|
def delete_events(ref_type, ref_name):
|
||||||
|
webnotes.delete_doc("Event", webnotes.conn.sql_list("""select name from `tabEvent`
|
||||||
|
where ref_type=%s and ref_name=%s""", (ref_type, ref_name)), for_reload=True)
|
Loading…
x
Reference in New Issue
Block a user