[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):
|
||||
if not filters: filters ={}
|
||||
data = []
|
||||
|
||||
trans = "Purchase Invoice"
|
||||
tab = ["tabPurchase Invoice","tabPurchase Invoice Item"]
|
||||
conditions = get_columns(filters, trans)
|
||||
data = get_data(filters, conditions)
|
||||
|
||||
details = get_columns(filters, trans)
|
||||
data = get_data(filters, tab, details)
|
||||
|
||||
if not data :
|
||||
webnotes.msgprint("Data not found for selected criterias")
|
||||
|
||||
return details["columns"], data
|
||||
return conditions["columns"], data
|
@ -21,14 +21,8 @@ from controllers.trends import get_columns,get_data
|
||||
def execute(filters=None):
|
||||
if not filters: filters ={}
|
||||
data = []
|
||||
|
||||
trans = "Sales Invoice"
|
||||
tab = ["tabSales Invoice","tabSales Invoice Item"]
|
||||
conditions = get_columns(filters, trans)
|
||||
data = get_data(filters, conditions)
|
||||
|
||||
details = get_columns(filters, trans)
|
||||
data = get_data(filters, tab, details)
|
||||
|
||||
if not data :
|
||||
webnotes.msgprint("Data not found for selected criterias")
|
||||
|
||||
return details["columns"], data
|
||||
return conditions["columns"], data
|
@ -185,21 +185,22 @@ class DocType(BuyingController):
|
||||
if d.fields.has_key(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:
|
||||
msgprint("Item %s does not exist in Item Master." % cstr(d.item_code))
|
||||
raise Exception
|
||||
msgprint("Item %s does not exist in Item Master." % cstr(d.item_code), raise_exception=True)
|
||||
|
||||
from stock.utils import validate_end_of_life
|
||||
validate_end_of_life(d.item_code, item[0][3])
|
||||
|
||||
# validate stock item
|
||||
if item[0][0]=='Yes' and d.qty and not d.warehouse:
|
||||
msgprint("Warehouse is mandatory for %s, since it is a stock item" %
|
||||
d.item_code, raise_exception=1)
|
||||
msgprint("Warehouse is mandatory for %s, since it is a stock item" %
|
||||
d.item_code, raise_exception=1)
|
||||
|
||||
# validate purchase item
|
||||
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))
|
||||
raise Exception
|
||||
|
||||
msgprint("Item %s is not a purchase item or sub-contracted item. Please check" % (d.item_code), raise_exception=True)
|
||||
|
||||
if d.fields.has_key('prevdoc_docname') and d.prevdoc_docname:
|
||||
# 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.
|
||||
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))
|
||||
raise Exception
|
||||
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), raise_exception=True)
|
||||
|
||||
# Check if UOM has been modified.
|
||||
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))
|
||||
raise Exception
|
||||
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), raise_exception=True)
|
||||
|
||||
# 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 '']
|
||||
|
@ -21,14 +21,8 @@ from controllers.trends import get_columns,get_data
|
||||
def execute(filters=None):
|
||||
if not filters: filters ={}
|
||||
data = []
|
||||
|
||||
trans = "Purchase Order"
|
||||
tab = ["tabPurchase Order","tabPurchase Order Item"]
|
||||
conditions = get_columns(filters, trans)
|
||||
data = get_data(filters, conditions)
|
||||
|
||||
details = get_columns(filters, trans)
|
||||
data = get_data(filters, tab, details)
|
||||
|
||||
if not data :
|
||||
webnotes.msgprint("Data not found for selected criterias")
|
||||
|
||||
return details["columns"], data
|
||||
return conditions["columns"], data
|
@ -54,16 +54,7 @@ class BuyingController(StockController):
|
||||
raise_exception=WrongWarehouseCompany)
|
||||
|
||||
def validate_stock_or_nonstock_items(self):
|
||||
items = [d.item_code for d in self.doclist.get({"parentfield": self.fname})]
|
||||
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:
|
||||
if not self.stock_items:
|
||||
tax_for_valuation = [d.account_head for d in
|
||||
self.doclist.get({"parentfield": "purchase_tax_details"})
|
||||
if d.category in ["Valuation", "Valuation and Total"]]
|
||||
|
@ -16,43 +16,47 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
from webnotes.utils import cint, add_days, add_months, cstr
|
||||
from datetime import datetime
|
||||
from webnotes.utils import add_days, add_months, cstr, getdate
|
||||
from webnotes import _
|
||||
|
||||
def get_columns(filters, trans):
|
||||
|
||||
if not (filters.get("period") and filters.get("based_on")):
|
||||
webnotes.msgprint("Value missing in 'Period' or 'Based On'", raise_exception=1)
|
||||
|
||||
elif filters.get("based_on") == filters.get("group_by"):
|
||||
webnotes.msgprint("Plese select different values in 'Based On' and 'Group By'", raise_exception=1)
|
||||
|
||||
else:
|
||||
bonc, query_bon, based, sup_tab = basedon_wise_colums_query(filters.get("based_on"), 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"]
|
||||
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,
|
||||
"grbc": grbc, "sup_tab": sup_tab}
|
||||
|
||||
return details
|
||||
|
||||
def get_data(filters, tab, details):
|
||||
validate_filters(filters)
|
||||
|
||||
# get conditions for based_on filter cond
|
||||
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"))
|
||||
|
||||
columns = based_on_cols + period_cols + ["Total(Qty):Float:120", "Total(Amt):Currency:120"]
|
||||
if group_by_cols:
|
||||
columns = based_on_cols + group_by_cols + period_cols +["Total(Qty):Float:120", "Total(Amt):Currency:120"]
|
||||
|
||||
conditions = {"based_on_select": based_on_select, "period_wise_select": period_select, "columns": columns,
|
||||
"group_by": based_on_group_by, "grbc": group_by_cols, "sup_tab": addl_tables, "trans": trans}
|
||||
|
||||
return conditions
|
||||
|
||||
def validate_filters(filters):
|
||||
for f in ["Fiscal Year", "Based On", "Period", "Company"]:
|
||||
if not filters.get(f.lower().replace(" ", "_")):
|
||||
webnotes.msgprint(f + _(" is mandatory"), raise_exception=1)
|
||||
|
||||
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, conditions):
|
||||
data = []
|
||||
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,"]:
|
||||
cond = 'and '+ details["query_bon"][:-1] +' IS Not NULL'
|
||||
if conditions["based_on_select"] in ["t1.project_name,", "t2.project_name,"]:
|
||||
cond = 'and '+ conditions["based_on_select"][:-1] +' IS Not NULL'
|
||||
|
||||
if filters.get("group_by"):
|
||||
sel_col = ''
|
||||
ind = details["columns"].index(details["grbc"][0])
|
||||
ind = conditions["columns"].index(conditions["grbc"][0])
|
||||
|
||||
if filters.get("group_by") == 'Item':
|
||||
sel_col = 't2.item_code'
|
||||
@ -65,15 +69,14 @@ def get_data(filters, tab, details):
|
||||
inc = 2
|
||||
else :
|
||||
inc = 1
|
||||
|
||||
data1 = webnotes.conn.sql(""" select %s from `%s` t1, `%s` t2 %s
|
||||
data1 = webnotes.conn.sql(""" select %s from `tab%s` t1, `tab%s Item` t2 %s
|
||||
where t2.parent = t1.name and t1.company = %s
|
||||
and t1.fiscal_year = %s and t1.docstatus = 1 %s
|
||||
group by %s
|
||||
""" % (query_details, tab[0], tab[1], details["sup_tab"], "%s",
|
||||
"%s", cond, details["basedon"]), (filters.get("company"),
|
||||
filters["fiscal_year"]),
|
||||
as_list=1)
|
||||
""" % (query_details, conditions["trans"], conditions["trans"], conditions["sup_tab"], "%s",
|
||||
"%s", cond, conditions["group_by"]), (filters.get("company"),
|
||||
filters["fiscal_year"]),as_list=1)
|
||||
|
||||
for d in range(len(data1)):
|
||||
#to add blanck column
|
||||
dt = data1[d]
|
||||
@ -81,119 +84,58 @@ def get_data(filters, tab, details):
|
||||
data.append(dt)
|
||||
|
||||
#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
|
||||
and t1.docstatus = 1 and %s = %s
|
||||
"""%(sel_col, tab[0], tab[1], details["sup_tab"], "%s", "%s", details["basedon"], "%s"),
|
||||
(filters.get("company"), filters.get("fiscal_year"), data1[d][0]),
|
||||
as_list=1)
|
||||
"""%(sel_col, conditions["trans"], conditions["trans"], conditions["sup_tab"], "%s", "%s",
|
||||
conditions["group_by"], "%s"), (filters.get("company"), filters.get("fiscal_year"),
|
||||
data1[d][0]), as_list=1)
|
||||
|
||||
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
|
||||
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
|
||||
and t1.docstatus = 1 and %s = %s and %s = %s
|
||||
"""%(sel_col, details["query_pwc"], tab[0], tab[1], details["sup_tab"],
|
||||
"%s", "%s", sel_col, "%s", details["basedon"], "%s"),
|
||||
(filters.get("company"), filters.get("fiscal_year"), row[i][0], data1[d][0]),
|
||||
as_list=1)
|
||||
""" % (sel_col, conditions["period_wise_select"], conditions["trans"], conditions["trans"],
|
||||
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]), as_list=1)
|
||||
|
||||
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]
|
||||
|
||||
data.append(des)
|
||||
else:
|
||||
|
||||
data = webnotes.conn.sql(""" select %s from `%s` t1, `%s` t2 %s
|
||||
webnotes.errprint(["hii", conditions["sup_tab"]])
|
||||
data = webnotes.conn.sql(""" select %s from `tab%s` t1, `tab%s Item` t2 %s
|
||||
where t2.parent = t1.name and t1.company = %s
|
||||
and t1.fiscal_year = %s and t1.docstatus = 1 %s
|
||||
group by %s
|
||||
"""%(query_details, tab[0], tab[1], details["sup_tab"], "%s",
|
||||
"%s", cond,details["basedon"]), (filters.get("company"),
|
||||
filters.get("fiscal_year")),
|
||||
as_list=1)
|
||||
"""%(query_details, conditions["trans"], conditions["trans"], conditions["sup_tab"], "%s",
|
||||
"%s", cond,conditions["group_by"]), (filters.get("company"),
|
||||
filters.get("fiscal_year")), as_list=1)
|
||||
|
||||
return data
|
||||
|
||||
def get_mon(date):
|
||||
"""convert srting formated date into date and retrieve month abbrevation"""
|
||||
return (datetime.strptime(date, '%Y-%m-%d')).strftime("%b")
|
||||
def get_mon(dt):
|
||||
return getdate(dt).strftime("%b")
|
||||
|
||||
def period_wise_colums_query(filters, trans):
|
||||
|
||||
query_details = ''
|
||||
pwc = []
|
||||
ysd = webnotes.conn.sql("""select year_start_date from `tabFiscal Year` where name = '%s'
|
||||
"""%filters.get("fiscal_year"))[0][0]
|
||||
|
||||
year_start_date = ysd.strftime('%Y-%m-%d')
|
||||
start_month = cint(year_start_date.split('-')[1])
|
||||
bet_dates = get_period_date_ranges(filters.get("period"), filters.get("fiscal_year"))
|
||||
|
||||
if trans in ['Purchase Receipt', 'Delivery Note', 'Purchase Invoice', 'Sales Invoice']:
|
||||
trans_date = 'posting_date'
|
||||
else:
|
||||
trans_date = 'transaction_date'
|
||||
|
||||
if filters.get("period") == "Monthly":
|
||||
month_name = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
|
||||
|
||||
for month in range(start_month-1,len(month_name)):
|
||||
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}
|
||||
|
||||
if filters.get("period") != 'Yearly':
|
||||
for dt in bet_dates:
|
||||
get_period_wise_columns(dt, filters.get("period"), pwc)
|
||||
query_details = get_period_wise_query(dt, trans_date, query_details)
|
||||
else:
|
||||
pwc = [filters.get("fiscal_year")+" (Qty):Float:120", filters.get("fiscal_year")+" (Amt):Currency:120"]
|
||||
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)'
|
||||
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 = ''
|
||||
|
||||
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"]
|
||||
query_details = "t1.supplier, t3.supplier_type,"
|
||||
based = 't1.supplier'
|
||||
sup_tab = '`tabSupplier` t3',
|
||||
sup_tab = ',`tabSupplier` t3'
|
||||
|
||||
elif based_on == 'Supplier Type':
|
||||
bon = ["Supplier Type:Link/Supplier Type:120"]
|
||||
query_details = "t3.supplier_type,"
|
||||
based = 't3.supplier_type'
|
||||
sup_tab ='`tabSupplier` t3',
|
||||
sup_tab =',`tabSupplier` t3'
|
||||
|
||||
elif based_on == "Territory":
|
||||
bon = ["Territory:Link/Territory:120"]
|
||||
@ -242,19 +231,16 @@ def basedon_wise_colums_query(based_on, trans):
|
||||
based = 't1.territory'
|
||||
|
||||
elif based_on == "Project":
|
||||
|
||||
if trans in ['Sales Invoice', 'Delivery Note', 'Sales Order']:
|
||||
bon = ["Project:Link/Project:120"]
|
||||
query_details = "t1.project_name,"
|
||||
based = 't1.project_name'
|
||||
|
||||
elif trans in ['Purchase Order', 'Purchase Invoice', 'Purchase Receipt']:
|
||||
bon = ["Project:Link/Project:120"]
|
||||
query_details = "t2.project_name,"
|
||||
based = 't2.project_name'
|
||||
|
||||
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
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
import webnotes
|
||||
|
||||
def execute():
|
||||
from utilities.transaction_base import delete_events
|
||||
|
||||
# delete orphaned Event User
|
||||
webnotes.conn.sql("""delete from `tabEvent User`
|
||||
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()
|
||||
else:
|
||||
# remove events where ref doc doesn't exist
|
||||
webnotes.delete_doc("Event", webnotes.conn.sql_list("""select name from `tabEvent`
|
||||
where ref_type=%s and ref_name=%s""", (dt, ref_name)))
|
||||
delete_events(dt, ref_name)
|
@ -19,6 +19,7 @@ import webnotes
|
||||
|
||||
from webnotes.utils import flt, getdate
|
||||
from webnotes import msgprint
|
||||
from utilities.transaction_base import delete_events
|
||||
|
||||
class DocType:
|
||||
def __init__(self, doc, doclist=None):
|
||||
@ -69,7 +70,7 @@ class DocType:
|
||||
|
||||
def add_calendar_event(self):
|
||||
# delete any earlier event for this project
|
||||
self.delete_events()
|
||||
delete_events(self.doc.doctype, self.doc.name)
|
||||
|
||||
# add events
|
||||
for milestone in self.doclist.get({"parentfield": "project_milestones"}):
|
||||
@ -87,8 +88,4 @@ class DocType:
|
||||
}).insert()
|
||||
|
||||
def on_trash(self):
|
||||
self.delete_events()
|
||||
|
||||
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)))
|
||||
delete_events(self.doc.doctype, self.doc.name)
|
@ -4,7 +4,7 @@ var get_filters = function(){
|
||||
"fieldname":"period",
|
||||
"label": "Period",
|
||||
"fieldtype": "Select",
|
||||
"options": ["Monthly", "Quarterly", "Half-yearly", "Yearly"].join("\n"),
|
||||
"options": ["Monthly", "Quarterly", "Half-Yearly", "Yearly"].join("\n"),
|
||||
"default": "Monthly"
|
||||
},
|
||||
{
|
||||
|
@ -4,7 +4,7 @@ var get_filters = function(){
|
||||
"fieldname":"period",
|
||||
"label": "Period",
|
||||
"fieldtype": "Select",
|
||||
"options": ["Monthly", "Quarterly", "Half-yearly", "Yearly"].join("\n"),
|
||||
"options": ["Monthly", "Quarterly", "Half-Yearly", "Yearly"].join("\n"),
|
||||
"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);
|
||||
}
|
||||
|
||||
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) {
|
||||
var callback = function(r,rt){
|
||||
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,
|
||||
"modified": "2013-01-29 17:14:58",
|
||||
"modified": "2013-06-18 17:49:11",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@ -32,6 +32,7 @@
|
||||
"parent": "Sales Order",
|
||||
"parentfield": "permissions",
|
||||
"parenttype": "DocType",
|
||||
"permlevel": 0,
|
||||
"read": 1
|
||||
},
|
||||
{
|
||||
@ -202,7 +203,7 @@
|
||||
"label": "Shipping Address Name",
|
||||
"options": "Address",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
"read_only": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
@ -950,104 +951,33 @@
|
||||
"options": "Sales Team",
|
||||
"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,
|
||||
"cancel": 1,
|
||||
"create": 1,
|
||||
"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,
|
||||
"role": "Sales User",
|
||||
"submit": 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,
|
||||
"cancel": 1,
|
||||
"create": 1,
|
||||
"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,
|
||||
"role": "Maintenance User",
|
||||
"submit": 1,
|
||||
"write": 1
|
||||
},
|
||||
{
|
||||
"amend": 0,
|
||||
"cancel": 0,
|
||||
"create": 0,
|
||||
"doctype": "DocPerm",
|
||||
"match": "",
|
||||
"permlevel": 1,
|
||||
"role": "Maintenance User",
|
||||
"submit": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocPerm",
|
||||
"permlevel": 0,
|
||||
"role": "Accounts User"
|
||||
},
|
||||
{
|
||||
"doctype": "DocPerm",
|
||||
"match": "customer",
|
||||
"permlevel": 0,
|
||||
"role": "Customer"
|
||||
}
|
||||
]
|
@ -16,19 +16,13 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
from controllers.trends import get_columns,get_data
|
||||
from controllers.trends import get_columns, get_data
|
||||
|
||||
def execute(filters=None):
|
||||
if not filters: filters ={}
|
||||
data = []
|
||||
|
||||
trans = "Quotation"
|
||||
tab = ["tabQuotation","tabQuotation Item"]
|
||||
conditions = get_columns(filters, trans)
|
||||
data = get_data(filters, conditions)
|
||||
|
||||
details = get_columns(filters, trans)
|
||||
data = get_data(filters, tab, details)
|
||||
|
||||
if not data:
|
||||
webnotes.msgprint("Data not found for selected criterias")
|
||||
|
||||
return details["columns"], data
|
||||
return conditions["columns"], data
|
@ -21,14 +21,8 @@ from controllers.trends import get_columns,get_data
|
||||
def execute(filters=None):
|
||||
if not filters: filters ={}
|
||||
data = []
|
||||
|
||||
trans = "Sales Order"
|
||||
tab = ["tabSales Order","tabSales Order Item"]
|
||||
conditions = get_columns(filters, trans)
|
||||
data = get_data(filters, conditions)
|
||||
|
||||
details = get_columns(filters, trans)
|
||||
data = get_data(filters, tab, details)
|
||||
|
||||
if not data :
|
||||
webnotes.msgprint("Data not found for selected criterias")
|
||||
|
||||
return details["columns"], data
|
||||
return conditions["columns"], data
|
@ -53,7 +53,7 @@ def execute_daily():
|
||||
|
||||
# daily backup
|
||||
from setup.doctype.backup_manager.backup_manager import take_backups_daily
|
||||
take_backups_daily()
|
||||
run_fn(take_backups_daily)
|
||||
|
||||
# check reorder level
|
||||
from stock.utils import reorder_item
|
||||
@ -61,7 +61,7 @@ def execute_daily():
|
||||
|
||||
def execute_weekly():
|
||||
from setup.doctype.backup_manager.backup_manager import take_backups_weekly
|
||||
take_backups_weekly()
|
||||
run_fn(take_backups_weekly)
|
||||
|
||||
def execute_monthly():
|
||||
pass
|
||||
|
@ -1,14 +1,14 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-01-29 19:25:41",
|
||||
"creation": "2013-05-16 10:59:15",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-01-29 16:27:57",
|
||||
"modified": "2013-06-20 11:23:01",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
{
|
||||
"allow_attach": 1,
|
||||
"allow_rename": 1,
|
||||
"allow_rename": 0,
|
||||
"autoname": "field:serial_no",
|
||||
"description": "Distinct unit of an Item",
|
||||
"doctype": "DocType",
|
||||
@ -31,7 +31,9 @@
|
||||
"parent": "Serial No",
|
||||
"parentfield": "permissions",
|
||||
"parenttype": "DocType",
|
||||
"permlevel": 0,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"submit": 0
|
||||
},
|
||||
{
|
||||
@ -43,12 +45,14 @@
|
||||
"fieldname": "details",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Details",
|
||||
"oldfieldtype": "Section Break"
|
||||
"oldfieldtype": "Section Break",
|
||||
"read_only": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "column_break0",
|
||||
"fieldtype": "Column Break"
|
||||
"fieldtype": "Column Break",
|
||||
"read_only": 0
|
||||
},
|
||||
{
|
||||
"default": "In Store",
|
||||
@ -75,6 +79,7 @@
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "serial_no",
|
||||
"oldfieldtype": "Data",
|
||||
"read_only": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 1
|
||||
},
|
||||
@ -88,13 +93,15 @@
|
||||
"oldfieldname": "item_code",
|
||||
"oldfieldtype": "Link",
|
||||
"options": "Item",
|
||||
"read_only": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "column_break1",
|
||||
"fieldtype": "Column Break"
|
||||
"fieldtype": "Column Break",
|
||||
"read_only": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
@ -146,12 +153,14 @@
|
||||
"doctype": "DocField",
|
||||
"fieldname": "purchase_details",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Purchase Details"
|
||||
"label": "Purchase Details",
|
||||
"read_only": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "column_break2",
|
||||
"fieldtype": "Column Break",
|
||||
"read_only": 0,
|
||||
"width": "50%"
|
||||
},
|
||||
{
|
||||
@ -160,7 +169,8 @@
|
||||
"fieldtype": "Select",
|
||||
"label": "Purchase Document Type",
|
||||
"no_copy": 1,
|
||||
"options": "\nPurchase Receipt\nStock Entry"
|
||||
"options": "\nPurchase Receipt\nStock Entry",
|
||||
"read_only": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
@ -168,7 +178,8 @@
|
||||
"fieldtype": "Data",
|
||||
"hidden": 0,
|
||||
"label": "Purchase Document No",
|
||||
"no_copy": 1
|
||||
"no_copy": 1,
|
||||
"read_only": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
@ -179,6 +190,7 @@
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "purchase_date",
|
||||
"oldfieldtype": "Date",
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0
|
||||
},
|
||||
@ -188,6 +200,7 @@
|
||||
"fieldtype": "Time",
|
||||
"label": "Incoming Time",
|
||||
"no_copy": 1,
|
||||
"read_only": 0,
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
@ -200,6 +213,7 @@
|
||||
"oldfieldname": "purchase_rate",
|
||||
"oldfieldtype": "Currency",
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0
|
||||
},
|
||||
@ -207,6 +221,7 @@
|
||||
"doctype": "DocField",
|
||||
"fieldname": "column_break3",
|
||||
"fieldtype": "Column Break",
|
||||
"read_only": 0,
|
||||
"width": "50%"
|
||||
},
|
||||
{
|
||||
@ -220,6 +235,7 @@
|
||||
"oldfieldname": "warehouse",
|
||||
"oldfieldtype": "Link",
|
||||
"options": "Warehouse",
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 1
|
||||
},
|
||||
@ -230,7 +246,8 @@
|
||||
"in_filter": 1,
|
||||
"label": "Supplier",
|
||||
"no_copy": 1,
|
||||
"options": "Supplier"
|
||||
"options": "Supplier",
|
||||
"read_only": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
@ -254,12 +271,14 @@
|
||||
"fieldname": "delivery_details",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Delivery Details",
|
||||
"oldfieldtype": "Column Break"
|
||||
"oldfieldtype": "Column Break",
|
||||
"read_only": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "column_break4",
|
||||
"fieldtype": "Column Break",
|
||||
"read_only": 0,
|
||||
"width": "50%"
|
||||
},
|
||||
{
|
||||
@ -318,12 +337,14 @@
|
||||
"oldfieldname": "is_cancelled",
|
||||
"oldfieldtype": "Select",
|
||||
"options": "\nYes\nNo",
|
||||
"read_only": 0,
|
||||
"report_hide": 1
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "column_break5",
|
||||
"fieldtype": "Column Break",
|
||||
"read_only": 0,
|
||||
"width": "50%"
|
||||
},
|
||||
{
|
||||
@ -378,12 +399,14 @@
|
||||
"doctype": "DocField",
|
||||
"fieldname": "warranty_amc_details",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Warranty / AMC Details"
|
||||
"label": "Warranty / AMC Details",
|
||||
"read_only": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "column_break6",
|
||||
"fieldtype": "Column Break",
|
||||
"read_only": 0,
|
||||
"width": "50%"
|
||||
},
|
||||
{
|
||||
@ -396,6 +419,7 @@
|
||||
"oldfieldname": "maintenance_status",
|
||||
"oldfieldtype": "Select",
|
||||
"options": "\nUnder Warranty\nOut of Warranty\nUnder AMC\nOut of AMC",
|
||||
"read_only": 0,
|
||||
"search_index": 1,
|
||||
"width": "150px"
|
||||
},
|
||||
@ -406,12 +430,14 @@
|
||||
"label": "Warranty Period (Days)",
|
||||
"oldfieldname": "warranty_period",
|
||||
"oldfieldtype": "Int",
|
||||
"read_only": 0,
|
||||
"width": "150px"
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "column_break7",
|
||||
"fieldtype": "Column Break",
|
||||
"read_only": 0,
|
||||
"width": "50%"
|
||||
},
|
||||
{
|
||||
@ -422,6 +448,7 @@
|
||||
"label": "Warranty Expiry Date",
|
||||
"oldfieldname": "warranty_expiry_date",
|
||||
"oldfieldtype": "Date",
|
||||
"read_only": 0,
|
||||
"width": "150px"
|
||||
},
|
||||
{
|
||||
@ -432,6 +459,7 @@
|
||||
"label": "AMC Expiry Date",
|
||||
"oldfieldname": "amc_expiry_date",
|
||||
"oldfieldtype": "Date",
|
||||
"read_only": 0,
|
||||
"search_index": 0,
|
||||
"width": "150px"
|
||||
},
|
||||
@ -439,13 +467,15 @@
|
||||
"doctype": "DocField",
|
||||
"fieldname": "more_info",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "More Info"
|
||||
"label": "More Info",
|
||||
"read_only": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "serial_no_details",
|
||||
"fieldtype": "Text Editor",
|
||||
"label": "Serial No Details"
|
||||
"label": "Serial No Details",
|
||||
"read_only": 0
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
@ -454,6 +484,7 @@
|
||||
"in_filter": 1,
|
||||
"label": "Company",
|
||||
"options": "link:Company",
|
||||
"read_only": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 1
|
||||
},
|
||||
@ -464,6 +495,7 @@
|
||||
"in_filter": 1,
|
||||
"label": "Fiscal Year",
|
||||
"options": "link:Fiscal Year",
|
||||
"read_only": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 1
|
||||
},
|
||||
@ -487,54 +519,10 @@
|
||||
"read_only": 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,
|
||||
"create": 1,
|
||||
"doctype": "DocPerm",
|
||||
"permlevel": 0,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"write": 1
|
||||
},
|
||||
@ -542,8 +530,6 @@
|
||||
"cancel": 1,
|
||||
"create": 1,
|
||||
"doctype": "DocPerm",
|
||||
"permlevel": 0,
|
||||
"report": 1,
|
||||
"role": "Material Master Manager",
|
||||
"write": 1
|
||||
},
|
||||
@ -552,17 +538,15 @@
|
||||
"cancel": 0,
|
||||
"create": 0,
|
||||
"doctype": "DocPerm",
|
||||
"match": "",
|
||||
"permlevel": 1,
|
||||
"role": "System Manager"
|
||||
"role": "Material Manager",
|
||||
"write": 0
|
||||
},
|
||||
{
|
||||
"amend": 0,
|
||||
"cancel": 0,
|
||||
"create": 0,
|
||||
"doctype": "DocPerm",
|
||||
"match": "",
|
||||
"permlevel": 1,
|
||||
"role": "Sales Master Manager"
|
||||
"role": "Material User",
|
||||
"write": 0
|
||||
}
|
||||
]
|
@ -21,6 +21,9 @@ class TestStockEntry(unittest.TestCase):
|
||||
st2.insert()
|
||||
st2.submit()
|
||||
|
||||
from stock.utils import reorder_item
|
||||
reorder_item()
|
||||
|
||||
mr_name = webnotes.conn.sql("""select parent from `tabMaterial Request Item`
|
||||
where item_code='_Test Item'""")
|
||||
|
||||
|
@ -21,14 +21,8 @@ from controllers.trends import get_columns,get_data
|
||||
def execute(filters=None):
|
||||
if not filters: filters ={}
|
||||
data = []
|
||||
|
||||
trans = "Delivery Note"
|
||||
tab = ["tabDelivery Note","tabDelivery Note Item"]
|
||||
conditions = get_columns(filters, trans)
|
||||
data = get_data(filters, conditions)
|
||||
|
||||
details = get_columns(filters, trans)
|
||||
data = get_data(filters, tab, details)
|
||||
|
||||
if not data :
|
||||
webnotes.msgprint("Data not found for selected criterias")
|
||||
|
||||
return details["columns"], data
|
||||
return conditions["columns"], data
|
@ -69,10 +69,11 @@ def get_price_list():
|
||||
from `tabItem Price` where docstatus<2""", as_dict=1)
|
||||
|
||||
for j in price_list:
|
||||
if j.selling:
|
||||
rate.setdefault(j.parent, {}).setdefault("selling", []).append(j.price)
|
||||
if j.buying:
|
||||
rate.setdefault(j.parent, {}).setdefault("buying", []).append(j.price)
|
||||
if j.price:
|
||||
if j.selling:
|
||||
rate.setdefault(j.parent, {}).setdefault("selling", []).append(j.price)
|
||||
if j.buying:
|
||||
rate.setdefault(j.parent, {}).setdefault("buying", []).append(j.price)
|
||||
|
||||
item_rate_map = {}
|
||||
|
||||
|
@ -21,14 +21,11 @@ from controllers.trends import get_columns,get_data
|
||||
def execute(filters=None):
|
||||
if not filters: filters ={}
|
||||
data = []
|
||||
|
||||
trans = "Purchase Receipt"
|
||||
tab = ["tabPurchase Receipt","tabPurchase Receipt Item"]
|
||||
|
||||
details = get_columns(filters, trans)
|
||||
data = get_data(filters, tab, details)
|
||||
conditions = get_columns(filters, trans)
|
||||
data = get_data(filters, tab, conditions)
|
||||
|
||||
if not data :
|
||||
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
|
||||
from webnotes.utils import flt, cstr, nowdate, add_days, cint
|
||||
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):
|
||||
if not end_of_life:
|
||||
end_of_life = webnotes.conn.get_value("Item", item_code, "end_of_life")
|
||||
|
||||
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") + \
|
||||
" %(date)s. " + _("Please check") + ": %(end_of_life_label)s " + \
|
||||
"in Item master") % {
|
||||
@ -205,7 +206,11 @@ def reorder_item():
|
||||
if webnotes.auto_indent:
|
||||
material_requests = {}
|
||||
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)
|
||||
for bin in bin_list:
|
||||
#check if re-order is required
|
||||
@ -220,7 +225,7 @@ def reorder_item():
|
||||
["re_order_level", "re_order_qty"])
|
||||
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):
|
||||
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 """
|
||||
mr_list = []
|
||||
defaults = webnotes.defaults.get_defaults()
|
||||
exceptions_list = []
|
||||
for request_type in material_requests:
|
||||
for company in material_requests[request_type]:
|
||||
items = material_requests[request_type][company]
|
||||
if items:
|
||||
try:
|
||||
items = material_requests[request_type][company]
|
||||
if not items:
|
||||
continue
|
||||
|
||||
mr = [{
|
||||
"doctype": "Material Request",
|
||||
"company": company,
|
||||
@ -257,27 +266,34 @@ def create_material_request(material_requests):
|
||||
quantity reaches re-order level when the following record was created""")
|
||||
}]
|
||||
|
||||
for d in items:
|
||||
item = webnotes.doc("Item", d.item_code)
|
||||
mr.append({
|
||||
"doctype": "Material Request Item",
|
||||
"parenttype": "Material Request",
|
||||
"parentfield": "indent_details",
|
||||
"item_code": d.item_code,
|
||||
"schedule_date": add_days(nowdate(),cint(item.lead_time_days)),
|
||||
"uom": item.stock_uom,
|
||||
"warehouse": d.warehouse,
|
||||
"item_name": item.item_name,
|
||||
"description": item.description,
|
||||
"item_group": item.item_group,
|
||||
"qty": d.reorder_qty,
|
||||
"brand": item.brand,
|
||||
})
|
||||
for d in items:
|
||||
item = webnotes.doc("Item", d.item_code)
|
||||
mr.append({
|
||||
"doctype": "Material Request Item",
|
||||
"parenttype": "Material Request",
|
||||
"parentfield": "indent_details",
|
||||
"item_code": d.item_code,
|
||||
"schedule_date": add_days(nowdate(),cint(item.lead_time_days)),
|
||||
"uom": item.stock_uom,
|
||||
"warehouse": d.warehouse,
|
||||
"item_name": item.item_name,
|
||||
"description": item.description,
|
||||
"item_group": item.item_group,
|
||||
"qty": d.reorder_qty,
|
||||
"brand": item.brand,
|
||||
})
|
||||
|
||||
mr_bean = webnotes.bean(mr)
|
||||
mr_bean.insert()
|
||||
mr_bean.submit()
|
||||
mr_list.append(mr_bean)
|
||||
mr_bean = webnotes.bean(mr)
|
||||
mr_bean.insert()
|
||||
mr_bean.submit()
|
||||
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 not hasattr(webnotes, "reorder_email_notify"):
|
||||
@ -286,11 +302,13 @@ def create_material_request(material_requests):
|
||||
|
||||
if(webnotes.reorder_email_notify):
|
||||
send_email_notification(mr_list)
|
||||
|
||||
if exceptions_list:
|
||||
notify_errors(exceptions_list)
|
||||
|
||||
def send_email_notification(mr_list):
|
||||
""" Notify user about auto creation of indent"""
|
||||
|
||||
from webnotes.utils.email_lib import sendmail
|
||||
email_list = webnotes.conn.sql_list("""select distinct r.parent
|
||||
from tabUserRole r, tabProfile p
|
||||
where p.name = r.parent and p.enabled = 1 and p.docstatus < 2
|
||||
@ -307,4 +325,22 @@ def send_email_notification(mr_list):
|
||||
cstr(item.qty) + "</td><td>" + cstr(item.uom) + "</td></tr>"
|
||||
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
|
||||
|
||||
|
||||
from utilities.transaction_base import TransactionBase
|
||||
from utilities.transaction_base import TransactionBase, delete_events
|
||||
|
||||
class DocType(TransactionBase):
|
||||
def __init__(self, doc, doclist=[]):
|
||||
@ -327,13 +327,7 @@ class DocType(TransactionBase):
|
||||
if d.serial_no:
|
||||
self.update_amc_date(d.serial_no, '')
|
||||
webnotes.conn.set(self.doc, 'status', 'Cancelled')
|
||||
self.delete_events()
|
||||
delete_events(self.doc.doctype, self.doc.name)
|
||||
|
||||
def on_trash(self):
|
||||
self.delete_events()
|
||||
|
||||
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)))
|
||||
|
||||
|
||||
delete_events(self.doc.doctype, self.doc.name)
|
||||
|
@ -303,3 +303,8 @@ class TransactionBase(DocListController):
|
||||
})
|
||||
|
||||
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