From ad6180ef6d325bb6fc09ee9136e3a36e75483f74 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 17 Jun 2013 11:57:04 +0530 Subject: [PATCH 1/6] [material request on re-order level] [fixes] if error occurs, send email to the System Manager --- .../purchase_common/purchase_common.py | 25 +++--- startup/schedule_handlers.py | 4 +- stock/doctype/stock_entry/test_stock_entry.py | 3 + stock/utils.py | 90 +++++++++++++------ 4 files changed, 81 insertions(+), 41 deletions(-) diff --git a/buying/doctype/purchase_common/purchase_common.py b/buying/doctype/purchase_common/purchase_common.py index 2b6ca27acc..7cc5c22ea8 100644 --- a/buying/doctype/purchase_common/purchase_common.py +++ b/buying/doctype/purchase_common/purchase_common.py @@ -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 ''] diff --git a/startup/schedule_handlers.py b/startup/schedule_handlers.py index cc0d1f4fea..99cc05b041 100644 --- a/startup/schedule_handlers.py +++ b/startup/schedule_handlers.py @@ -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 diff --git a/stock/doctype/stock_entry/test_stock_entry.py b/stock/doctype/stock_entry/test_stock_entry.py index c3ce2d7f40..2ab2b1dad8 100644 --- a/stock/doctype/stock_entry/test_stock_entry.py +++ b/stock/doctype/stock_entry/test_stock_entry.py @@ -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'""") diff --git a/stock/utils.py b/stock/utils.py index 5e7e53bb01..53ad69b157 100644 --- a/stock/utils.py +++ b/stock/utils.py @@ -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) + "" + cstr(item.uom) + "" msg += "" - sendmail(email_list, subject='Auto Material Request Generation Notification', msg = msg) \ No newline at end of file + 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) From 11d311376eb4b18572a7ae2dedfe9adb617002a5 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 17 Jun 2013 12:51:36 +0530 Subject: [PATCH 2/6] [event] [fix] commonified delete_events method, which is executed before auto-creation of events. Fixed delete issue --- .../p04_fix_event_for_lead_oppty_project.py | 5 +++-- projects/doctype/project/project.py | 9 +++------ .../maintenance_schedule/maintenance_schedule.py | 12 +++--------- utilities/transaction_base.py | 5 +++++ 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/patches/june_2013/p04_fix_event_for_lead_oppty_project.py b/patches/june_2013/p04_fix_event_for_lead_oppty_project.py index 3f66d8bfbb..971e4c7459 100644 --- a/patches/june_2013/p04_fix_event_for_lead_oppty_project.py +++ b/patches/june_2013/p04_fix_event_for_lead_oppty_project.py @@ -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))) \ No newline at end of file + delete_events(dt, ref_name) \ No newline at end of file diff --git a/projects/doctype/project/project.py b/projects/doctype/project/project.py index 94b6787312..84a216c349 100644 --- a/projects/doctype/project/project.py +++ b/projects/doctype/project/project.py @@ -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))) \ No newline at end of file + delete_events(self.doc.doctype, self.doc.name) \ No newline at end of file diff --git a/support/doctype/maintenance_schedule/maintenance_schedule.py b/support/doctype/maintenance_schedule/maintenance_schedule.py index 06c5a47aff..baed6a9dbd 100644 --- a/support/doctype/maintenance_schedule/maintenance_schedule.py +++ b/support/doctype/maintenance_schedule/maintenance_schedule.py @@ -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) diff --git a/utilities/transaction_base.py b/utilities/transaction_base.py index f9af912737..03321853a7 100644 --- a/utilities/transaction_base.py +++ b/utilities/transaction_base.py @@ -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) \ No newline at end of file From 3c6c3cf5ee902124f3a7e576a4865b206d4749c4 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 18 Jun 2013 18:26:30 +0530 Subject: [PATCH 3/6] [sales order] [shipping address] allow to edit shipping address --- selling/doctype/sales_order/sales_order.js | 23 ++++++ selling/doctype/sales_order/sales_order.txt | 78 ++------------------- 2 files changed, 27 insertions(+), 74 deletions(-) diff --git a/selling/doctype/sales_order/sales_order.js b/selling/doctype/sales_order/sales_order.js index b792754384..f272b2e378 100644 --- a/selling/doctype/sales_order/sales_order.js +++ b/selling/doctype/sales_order/sales_order.js @@ -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]; diff --git a/selling/doctype/sales_order/sales_order.txt b/selling/doctype/sales_order/sales_order.txt index ba0b1de07c..a8989701e7 100644 --- a/selling/doctype/sales_order/sales_order.txt +++ b/selling/doctype/sales_order/sales_order.txt @@ -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" } ] \ No newline at end of file From 21f7623d2ec814f052a2d17226389b5b98288d9c Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 19 Jun 2013 14:13:01 +0530 Subject: [PATCH 4/6] [fix][report] in item prices --- stock/report/item_prices/item_prices.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/stock/report/item_prices/item_prices.py b/stock/report/item_prices/item_prices.py index ea0be477df..86ae085ce7 100644 --- a/stock/report/item_prices/item_prices.py +++ b/stock/report/item_prices/item_prices.py @@ -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 = {} From bc2d9e89a78ccd38f0bc067ccbadcf3b181d429e Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 19 Jun 2013 14:58:01 +0530 Subject: [PATCH 5/6] [validation][buying] stock and non-stock items are now allowed in same document --- controllers/buying_controller.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/controllers/buying_controller.py b/controllers/buying_controller.py index 3deda0284b..f02e8482f4 100644 --- a/controllers/buying_controller.py +++ b/controllers/buying_controller.py @@ -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"]] From b8ebbcafa997de794ac296d4130e26f8207c59ff Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 20 Jun 2013 13:03:10 +0530 Subject: [PATCH 6/6] [trend analyzer] cleanup --- controllers/trends.py | 105 ++++++++-------- .../quotation_trends/quotation_trends.py | 5 +- stock/doctype/serial_no/serial_no.txt | 116 ++++++++---------- 3 files changed, 100 insertions(+), 126 deletions(-) diff --git a/controllers/trends.py b/controllers/trends.py index 4edb7845ce..c0636cba45 100644 --- a/controllers/trends.py +++ b/controllers/trends.py @@ -16,33 +16,39 @@ 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): + validate_filters(filters) + + # based_on_cols, based_on_select, based_on_group_by, addl_tables + bonc, query_bon, based, sup_tab = basedon_wise_colums_query(filters.get("based_on"), trans) + # period_cols, period_select + pwc, query_pwc = period_wise_colums_query(filters, trans) + + # group_by_cols + grbc = group_wise_column(filters.get("group_by")) - if not (filters.get("period") and filters.get("based_on")): - webnotes.msgprint("Value missing in 'Period' or 'Based On'", raise_exception=1) + 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"] - 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} + # conditions + 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): +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, tab, details): data = [] inc, cond= '','' query_details = details["query_bon"] + details["query_pwc"] @@ -96,17 +102,17 @@ def get_data(filters, tab, details): row1 = webnotes.conn.sql(""" select %s , %s from `%s` t1, `%s` 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"], + """ % (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) + (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): des[j+inc] = row1[0][j] + data.append(des) else: - data = webnotes.conn.sql(""" select %s from `%s` t1, `%s` t2 %s where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s and t1.docstatus = 1 %s @@ -118,20 +124,13 @@ def get_data(filters, tab, details): 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): - from datetime import datetime - 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]) + ysd = webnotes.conn.get_value("Fiscal year", filters.get("fiscal_year"), "year_start_date") if trans in ['Purchase Receipt', 'Delivery Note', 'Purchase Invoice', 'Sales Invoice']: trans_date = 'posting_date' @@ -141,27 +140,13 @@ def period_wise_colums_query(filters, trans): 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)} + for month_idx in range(ysd.month-1,len(month_name)) + range(0, ysd.month-1): + query_details = get_monthly_conditions(month_name, month_idx, trans_date, + pwc, query_details) elif filters.get("period") == "Quarterly": - first_qsd, second_qsd, third_qsd, fourth_qsd = year_start_date, add_months(year_start_date,3), add_months(year_start_date,6), add_months(year_start_date,9) + first_qsd, second_qsd, third_qsd, fourth_qsd = ysd, add_months(ysd,3), add_months(ysd,6), add_months(ysd,9) first_qed, second_qed, third_qed, fourth_qed = add_days(add_months(first_qsd,3),-1), add_days(add_months(second_qsd,3),-1), 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]] @@ -178,7 +163,7 @@ def period_wise_colums_query(filters, trans): elif filters.get("period") == "Half-yearly": - first_half_start = year_start_date + first_half_start = ysd 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) @@ -200,6 +185,17 @@ def period_wise_colums_query(filters, trans): query_details += 'SUM(t2.qty), SUM(t1.grand_total)' return pwc, query_details + +def get_monthly_conditions(month_list, month_idx, trans_date, pwc, query_details): + pwc += [month_list[month_idx] + ' (Qty):Float:120', + month_list[month_idx] + ' (Amt):Currency:120'] + + query_details += """ + Sum(IF(MONTH(t1.%(trans_date)s)= %(mon_num)s, t2.qty, NULL)), + SUM(IF(MONTH(t1.%(trans_date)s)= %(mon_num)s, t1.grand_total, NULL)), + """ % {"trans_date": trans_date, "mon_num": cstr(month_idx+1)} + + return query_details def basedon_wise_colums_query(based_on, trans): sup_tab = '' @@ -242,19 +238,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 diff --git a/selling/report/quotation_trends/quotation_trends.py b/selling/report/quotation_trends/quotation_trends.py index e341752cd0..c6a54c7588 100644 --- a/selling/report/quotation_trends/quotation_trends.py +++ b/selling/report/quotation_trends/quotation_trends.py @@ -16,7 +16,7 @@ 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 ={} @@ -27,8 +27,5 @@ def execute(filters=None): 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 \ No newline at end of file diff --git a/stock/doctype/serial_no/serial_no.txt b/stock/doctype/serial_no/serial_no.txt index 8e891b8172..33160c785f 100644 --- a/stock/doctype/serial_no/serial_no.txt +++ b/stock/doctype/serial_no/serial_no.txt @@ -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 } ] \ No newline at end of file