From 04cc5155f759b605327bdfbeb315a77e46f0d2f1 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 18 Nov 2013 13:22:07 +0530 Subject: [PATCH] Added Notification Control for caching notifications probably causing the freezing problem --- .../doctype/purchase_common/purchase_common.py | 2 +- .../p03_buying_selling_for_price_list.py | 3 +-- .../september_2013/p01_update_communication.py | 3 +-- startup/bean_handlers.py | 17 +++++++++++++++++ startup/observers.py | 9 --------- startup/open_count.py | 6 ++++++ startup/schedule_handlers.py | 4 ++++ .../material_request/material_request.py | 2 +- 8 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 startup/bean_handlers.py delete mode 100644 startup/observers.py diff --git a/buying/doctype/purchase_common/purchase_common.py b/buying/doctype/purchase_common/purchase_common.py index 4d2bc00e0d..90b91031e1 100644 --- a/buying/doctype/purchase_common/purchase_common.py +++ b/buying/doctype/purchase_common/purchase_common.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import webnotes from webnotes.utils import cstr, flt -from webnotes.model.bean import getlist +from webnotes.model.utils import getlist from webnotes import msgprint, _ from buying.utils import get_last_purchase_details diff --git a/patches/june_2013/p03_buying_selling_for_price_list.py b/patches/june_2013/p03_buying_selling_for_price_list.py index 58096c5c14..27bf21999f 100644 --- a/patches/june_2013/p03_buying_selling_for_price_list.py +++ b/patches/june_2013/p03_buying_selling_for_price_list.py @@ -4,7 +4,6 @@ from __future__ import unicode_literals import webnotes from webnotes.utils import cint -import MySQLdb def execute(): webnotes.reload_doc("stock", "doctype", "price_list") @@ -20,7 +19,7 @@ def execute(): buying_or_selling = "Selling" if selling else "Buying" webnotes.conn.set_value("Price List", price_list, "buying_or_selling", buying_or_selling) - except MySQLdb.OperationalError, e: + except webnotes.SQLError, e: if e.args[0] == 1054: webnotes.conn.sql("""update `tabPrice List` set buying_or_selling='Selling' where ifnull(buying_or_selling, '')='' """) diff --git a/patches/september_2013/p01_update_communication.py b/patches/september_2013/p01_update_communication.py index 4b9cac28dc..7fe6f9c9a9 100644 --- a/patches/september_2013/p01_update_communication.py +++ b/patches/september_2013/p01_update_communication.py @@ -3,7 +3,6 @@ from __future__ import unicode_literals import webnotes -import MySQLdb def execute(): webnotes.reload_doc("core", "doctype", "communication") @@ -17,6 +16,6 @@ def execute(): set parenttype=%s, parentfield='communications', parent=`%s` where ifnull(`%s`, '')!=''""" % ("%s", fieldname, fieldname), doctype) - except MySQLdb.OperationalError, e: + except webnotes.SQLError, e: if e.args[0] != 1054: raise diff --git a/startup/bean_handlers.py b/startup/bean_handlers.py new file mode 100644 index 0000000000..b121861d25 --- /dev/null +++ b/startup/bean_handlers.py @@ -0,0 +1,17 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. +# License: GNU General Public License v3. See license.txt + +from home import update_feed +from core.doctype.notification_count.notification_count import clear_doctype_notifications +from stock.doctype.material_request.material_request import update_completed_qty + +def on_method(bean, method): + print method + if method in ("on_update", "on_submit"): + update_feed(bean.controller, method) + + if method in ("on_update", "on_cancel", "on_trash"): + clear_doctype_notifications(bean.controller, method) + + if bean.doc.doctype=="Stock Entry" and method in ("on_submit", "on_cancel"): + update_completed_qty(bean.controller, method) \ No newline at end of file diff --git a/startup/observers.py b/startup/observers.py deleted file mode 100644 index df827daf9d..0000000000 --- a/startup/observers.py +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. -# License: GNU General Public License v3. See license.txt - -observer_map = { - "*:on_update": "home.update_feed", - "*:on_submit": "home.update_feed", - "Stock Entry:on_submit": "stock.doctype.material_request.material_request.update_completed_qty", - "Stock Entry:on_cancel": "stock.doctype.material_request.material_request.update_completed_qty", -} \ No newline at end of file diff --git a/startup/open_count.py b/startup/open_count.py index 431ced95e1..bf29a3219a 100644 --- a/startup/open_count.py +++ b/startup/open_count.py @@ -56,6 +56,12 @@ def get_unread_messages(): AND ifnull(docstatus,0)=0 """, webnotes.user.name)[0][0] +for_module_doctypes = { + "ToDo": "To Do", + "Event": "Calendar", + "Comment": "Messages" +} + for_module = { "To Do": get_things_todo, "Calendar": get_todays_events, diff --git a/startup/schedule_handlers.py b/startup/schedule_handlers.py index 2ff7b6d97b..c2401ef7f0 100644 --- a/startup/schedule_handlers.py +++ b/startup/schedule_handlers.py @@ -30,6 +30,10 @@ def execute_daily(): from core.doctype.event.event import send_event_digest run_fn(send_event_digest) + # clear daily event notifications + from core.doctype.notification_count.notification_count import delete_notification_count_for + delete_notification_count_for("Event") + # email digest from setup.doctype.email_digest.email_digest import send run_fn(send) diff --git a/stock/doctype/material_request/material_request.py b/stock/doctype/material_request/material_request.py index 4af86dac69..dde4ac54b2 100644 --- a/stock/doctype/material_request/material_request.py +++ b/stock/doctype/material_request/material_request.py @@ -8,7 +8,7 @@ from __future__ import unicode_literals import webnotes from webnotes.utils import cstr, flt -from webnotes.model.bean import getlist +from webnotes.model.utils import getlist from webnotes.model.code import get_obj from webnotes import msgprint, _