|
|
@@ -5,21 +5,14 @@ |
|
|
|
|
|
|
|
from __future__ import unicode_literals |
|
|
|
import webnotes |
|
|
|
try: |
|
|
|
from erpnext.startup.open_count import for_doctype, for_module, for_module_doctypes |
|
|
|
all_doctypes = for_doctype.keys() + for_module_doctypes.keys() |
|
|
|
except ImportError: |
|
|
|
for_doctype = {} |
|
|
|
for_module = {} |
|
|
|
for_module_doctypes = [] |
|
|
|
all_doctypes = [] |
|
|
|
|
|
|
|
class DocType: |
|
|
|
def __init__(self, d, dl): |
|
|
|
self.doc, self.doclist = d, dl |
|
|
|
|
|
|
|
@webnotes.whitelist() |
|
|
|
def get(): |
|
|
|
def get_notifications(): |
|
|
|
config = get_notification_config() |
|
|
|
can_read = webnotes.user.get_can_read() |
|
|
|
open_count_doctype = {} |
|
|
|
open_count_module = {} |
|
|
@@ -27,12 +20,11 @@ def get(): |
|
|
|
notification_count = dict(webnotes.conn.sql("""select for_doctype, open_count |
|
|
|
from `tabNotification Count` where owner=%s""", webnotes.session.user)) |
|
|
|
|
|
|
|
for d in for_doctype: |
|
|
|
for d in config.for_doctype: |
|
|
|
if d in can_read: |
|
|
|
condition = for_doctype[d] |
|
|
|
condition = config.for_doctype[d] |
|
|
|
key = condition.keys()[0] |
|
|
|
|
|
|
|
|
|
|
|
if d in notification_count: |
|
|
|
open_count_doctype[d] = notification_count[d] |
|
|
|
else: |
|
|
@@ -44,11 +36,11 @@ def get(): |
|
|
|
|
|
|
|
open_count_doctype[d] = result |
|
|
|
|
|
|
|
for m in for_module: |
|
|
|
for m in config.for_module: |
|
|
|
if m in notification_count: |
|
|
|
open_count_module[m] = notification_count[m] |
|
|
|
else: |
|
|
|
open_count_module[m] = for_module[m]() |
|
|
|
open_count_module[m] = webnotes.get_attr(config.for_module[m])() |
|
|
|
webnotes.doc({"doctype":"Notification Count", "for_doctype":m, |
|
|
|
"open_count":open_count_module[m]}).insert() |
|
|
|
|
|
|
@@ -58,33 +50,35 @@ def get(): |
|
|
|
} |
|
|
|
|
|
|
|
def delete_notification_count_for(doctype): |
|
|
|
try: |
|
|
|
webnotes.conn.sql("""delete from `tabNotification Count` where for_doctype = %s""", doctype) |
|
|
|
except webnotes.SQLError: |
|
|
|
pass # during install |
|
|
|
webnotes.conn.sql("""delete from `tabNotification Count` where for_doctype = %s""", doctype) |
|
|
|
|
|
|
|
def clear_doctype_notifications(controller, method=None): |
|
|
|
if webnotes.flags.in_import: |
|
|
|
return |
|
|
|
|
|
|
|
config = get_notification_config() |
|
|
|
doctype = controller.doc.doctype |
|
|
|
if doctype in all_doctypes: |
|
|
|
delete_notification_count_for(for_module_doctypes[doctype] if doctype in \ |
|
|
|
for_module_doctypes else doctype) |
|
|
|
|
|
|
|
if doctype in config.for_doctype: |
|
|
|
delete_notification_count_for(doctype) |
|
|
|
return |
|
|
|
|
|
|
|
if doctype in config.for_module_doctypes: |
|
|
|
delete_notification_count_for(config.for_module_doctypes[doctype]) |
|
|
|
|
|
|
|
def get_notification_info_for_boot(): |
|
|
|
out = get() |
|
|
|
out = get_notifications() |
|
|
|
|
|
|
|
config = get_notification_config() |
|
|
|
|
|
|
|
can_read = webnotes.user.get_can_read() |
|
|
|
conditions = {} |
|
|
|
module_doctypes = {} |
|
|
|
doctype_info = dict(webnotes.conn.sql("""select name, module from tabDocType""")) |
|
|
|
|
|
|
|
try: |
|
|
|
from erpnext.startup.open_count import for_doctype |
|
|
|
except ImportError: |
|
|
|
for_doctype = {} |
|
|
|
|
|
|
|
for d in list(set(can_read + for_doctype.keys())): |
|
|
|
if d in for_doctype: |
|
|
|
conditions[d] = for_doctype[d] |
|
|
|
for d in list(set(can_read + config.for_doctype.keys())): |
|
|
|
if d in config.for_doctype: |
|
|
|
conditions[d] = config.for_doctype[d] |
|
|
|
|
|
|
|
if d in doctype_info: |
|
|
|
module_doctypes.setdefault(doctype_info[d], []).append(d) |
|
|
@@ -95,7 +89,16 @@ def get_notification_info_for_boot(): |
|
|
|
}) |
|
|
|
|
|
|
|
return out |
|
|
|
|
|
|
|
|
|
|
|
def get_notification_config(): |
|
|
|
config = webnotes._dict() |
|
|
|
for notification_config in webnotes.get_hooks().notification_config: |
|
|
|
nc = webnotes.get_attr(notification_config)() |
|
|
|
for key in ("for_doctype", "for_module", "for_module_doctypes"): |
|
|
|
config.setdefault(key, {}) |
|
|
|
config[key].update(nc.get(key, {})) |
|
|
|
return config |
|
|
|
|
|
|
|
def on_doctype_update(): |
|
|
|
if not webnotes.conn.sql("""show index from `tabNotification Count` |
|
|
|
where Key_name="notification_count_owner_index" """): |
|
|
|