From c652a6254ff516717a9ca2f500dcbb362db2c15f Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 16 Dec 2013 12:48:22 +0530 Subject: [PATCH] Rewrote hooks for scheduler, notifications, boot, session, login, webpage webnotes/wnframework#351 --- .../doctype/sales_invoice/sales_invoice.py | 2 +- erpnext/home/__init__.py | 11 ++- erpnext/hooks.txt | 46 +++++++++++- .../upload_attendance/upload_attendance.py | 2 +- .../april_2013/p05_update_file_data.py | 2 +- erpnext/portal/templates/includes/cart.js | 2 +- .../doctype/backup_manager/backup_dropbox.py | 2 +- .../doctype/backup_manager/backup_manager.py | 4 +- erpnext/startup/bean_handlers.py | 16 ---- erpnext/startup/boot.py | 1 - erpnext/startup/event_handlers.py | 12 +-- erpnext/startup/schedule_handlers.py | 74 ------------------- erpnext/startup/webutils.py | 2 +- erpnext/stock/utils.py | 2 +- 14 files changed, 65 insertions(+), 113 deletions(-) delete mode 100644 erpnext/startup/bean_handlers.py delete mode 100644 erpnext/startup/schedule_handlers.py diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index d5b4c51f44..f49541b360 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -738,7 +738,7 @@ def manage_recurring_invoices(next_date=None, commit=True): notify_errors(ref_invoice, ref_wrapper.doc.owner) webnotes.conn.commit() - exception_list.append(webnotes.getTraceback()) + exception_list.append(webnotes.get_traceback()) finally: if commit: webnotes.conn.begin() diff --git a/erpnext/home/__init__.py b/erpnext/home/__init__.py index 9667efd212..36d7db57ca 100644 --- a/erpnext/home/__init__.py +++ b/erpnext/home/__init__.py @@ -29,8 +29,9 @@ feed_dict = { 'Sales Order': ['[%(status)s] To %(customer_name)s worth %(currency)s %(grand_total_export)s', '#4169E1'], # Purchase - 'Supplier': ['%(supplier_name)s, %(supplier_type)s', '#6495ED'], - 'Purchase Order': ['[%(status)s] %(name)s To %(supplier_name)s for %(currency)s %(grand_total_import)s', '#4169E1'], + 'Material Request': ['%(supplier_name)s, %(supplier_type)s', '#6495ED'], + 'Supplier': ['%(supplier_name)s, %(supplier_type)s', '#6495ED'], + 'Purchase Order': ['[%(status)s] %(name)s To %(supplier_name)s for %(currency)s %(grand_total_import)s', '#4169E1'], # Stock 'Delivery Note': ['[%(status)s] To %(customer_name)s', '#4169E1'], @@ -89,3 +90,9 @@ def update_feed(controller, method=None): subject, color = feed_dict.get(doc.doctype, [None, None]) if subject: make_feed('', doc.doctype, doc.name, doc.owner, subject % doc.fields, color) + +def make_comment_feed(bean, method): + """add comment to feed""" + doc = bean.doc + make_feed('Comment', doc.comment_doctype, doc.comment_docname, doc.comment_by, + '"' + doc.comment + '"', '#6B24B3') \ No newline at end of file diff --git a/erpnext/hooks.txt b/erpnext/hooks.txt index 32cdcd29df..69d2d8e43f 100644 --- a/erpnext/hooks.txt +++ b/erpnext/hooks.txt @@ -2,13 +2,57 @@ app_name ERPNext app_include_js assets/js/erpnext.min.js app_include_css assets/css/erpnext.css +web_include_js assets/js/erpnext-web.min.js + get_desktop_icons erpnext.manage.get_desktop_icons boot_session erpnext.startup.boot.boot_session notification_config erpnext.startup.notifications.get_notification_config dump_report_map erpnext.startup.report_data_map.data_map +update_website_context erpnext.startup.webutils.update_website_context + +mail_footer erpnext.startup.mail_footer + +on_session_creation erpnext.startup.event_handlers.on_session_creation +on_logout erpnext.startup.event_handlers.on_logut + +# Bean Events +# ----------- + +bean_event *:on_update:erpnext.home.update_feed +bean_event *:on_submit:erpnext.home.update_feed +bean_event Comment:on_update:erpnext.home.make_comment_feed + +bean_event *:on_update:webnotes.core.doctype.notification_count.notification_count.clear_doctype_notifications +bean_event *:on_cancel:webnotes.core.doctype.notification_count.notification_count.clear_doctype_notifications +bean_event *:on_trash:webnotes.core.doctype.notification_count.notification_count.clear_doctype_notifications + +bean_event Stock Entry:on_update:erpnext.stock.doctype.material_request.material_request.update_completed_qty standard_queries Warehouse:erpnext.stock.utils.get_warehouse_list standard_queries Customer:erpnext.selling.utils.get_customer_list -mail_footer erpnext.startup.mail_footer +# Schedulers +# ---------- + +#### Frequently + +scheduler_event all:erpnext.support.doctype.support_ticket.get_support_mails.get_support_mails +scheduler_event all:erpnext.hr.doctype.job_applicant.get_job_applications.get_job_applications +scheduler_event all:erpnext.selling.doctype.lead.get_leads.get_leads +scheduler_event all:webnotes.utils.email_lib.bulk.flush + +#### Daily + +scheduler_event daily:webnotes.core.doctype.event.event.send_event_digest +scheduler_event daily:erpnext.setup.doctype.email_digest.email_digest.send +scheduler_event daily:webnotes.core.doctype.notification_count.notification_count.delete_event_notification_count +scheduler_event daily:webnotes.utils.email_lib.bulk.clear_outbox +scheduler_event daily:erpnext.accounts.doctype.sales_invoice.sales_invoice.manage_recurring_invoices +scheduler_event daily:erpnext.setup.doctype.backup_manager.backup_manager.take_backups_daily +scheduler_event daily:erpnext.stock.utils.reorder_item +scheduler_event daily:webnotes.scheduler.report_errors + +#### Weekly + +scheduler_event weekly:erpnext.setup.doctype.backup_manager.backup_manager.take_backups_weekly diff --git a/erpnext/hr/doctype/upload_attendance/upload_attendance.py b/erpnext/hr/doctype/upload_attendance/upload_attendance.py index 4f1069a1e1..53b88f78c1 100644 --- a/erpnext/hr/doctype/upload_attendance/upload_attendance.py +++ b/erpnext/hr/doctype/upload_attendance/upload_attendance.py @@ -138,7 +138,7 @@ def upload(): error = True ret.append('Error for row (#%d) %s : %s' % (row_idx, len(row)>1 and row[1] or "", cstr(e))) - webnotes.errprint(webnotes.getTraceback()) + webnotes.errprint(webnotes.get_traceback()) if error: webnotes.conn.rollback() diff --git a/erpnext/patches/april_2013/p05_update_file_data.py b/erpnext/patches/april_2013/p05_update_file_data.py index b41019d352..1403dff337 100644 --- a/erpnext/patches/april_2013/p05_update_file_data.py +++ b/erpnext/patches/april_2013/p05_update_file_data.py @@ -35,7 +35,7 @@ def update_file_list(doctype, singles): webnotes.conn.commit() webnotes.conn.sql("""alter table `tab%s` drop column `file_list`""" % doctype) except Exception, e: - print webnotes.getTraceback() + print webnotes.get_traceback() if (e.args and e.args[0]!=1054) or not e.args: raise diff --git a/erpnext/portal/templates/includes/cart.js b/erpnext/portal/templates/includes/cart.js index 0765c60e1f..c521b6cb97 100644 --- a/erpnext/portal/templates/includes/cart.js +++ b/erpnext/portal/templates/includes/cart.js @@ -127,7 +127,7 @@ $.extend(erpnext.cart, { render_item_row: function($cart_items, doc) { doc.image_html = doc.website_image ? '
' : - '{% include "app/stock/doctype/item/templates/includes/product_missing_image.html" %}'; + '{% include "stock/doctype/item/templates/includes/product_missing_image.html" %}'; if(doc.description === doc.item_name) doc.description = ""; diff --git a/erpnext/setup/doctype/backup_manager/backup_dropbox.py b/erpnext/setup/doctype/backup_manager/backup_dropbox.py index bbd33b5e4b..8659b5a5db 100644 --- a/erpnext/setup/doctype/backup_manager/backup_dropbox.py +++ b/erpnext/setup/doctype/backup_manager/backup_dropbox.py @@ -114,7 +114,7 @@ def backup_to_dropbox(): upload_file_to_dropbox(filepath, "/files", dropbox_client) except Exception: did_not_upload.append(filename) - error_log.append(webnotes.getTraceback()) + error_log.append(webnotes.get_traceback()) webnotes.connect() return did_not_upload, list(set(error_log)) diff --git a/erpnext/setup/doctype/backup_manager/backup_manager.py b/erpnext/setup/doctype/backup_manager/backup_manager.py index 332d983f29..339038f649 100644 --- a/erpnext/setup/doctype/backup_manager/backup_manager.py +++ b/erpnext/setup/doctype/backup_manager/backup_manager.py @@ -37,7 +37,7 @@ def take_backups_dropbox(): send_email(True, "Dropbox") except Exception: file_and_error = [" - ".join(f) for f in zip(did_not_upload, error_log)] - error_message = ("\n".join(file_and_error) + "\n" + webnotes.getTraceback()) + error_message = ("\n".join(file_and_error) + "\n" + webnotes.get_traceback()) webnotes.errprint(error_message) if not webnotes.conn: @@ -57,7 +57,7 @@ def take_backups_gdrive(): send_email(True, "Google Drive") except Exception: file_and_error = [" - ".join(f) for f in zip(did_not_upload, error_log)] - error_message = ("\n".join(file_and_error) + "\n" + webnotes.getTraceback()) + error_message = ("\n".join(file_and_error) + "\n" + webnotes.get_traceback()) webnotes.errprint(error_message) send_email(False, "Google Drive", error_message) diff --git a/erpnext/startup/bean_handlers.py b/erpnext/startup/bean_handlers.py deleted file mode 100644 index a427ffc149..0000000000 --- a/erpnext/startup/bean_handlers.py +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors -# License: GNU General Public License v3. See license.txt - -from erpnext.home import update_feed -from webnotes.core.doctype.notification_count.notification_count import clear_doctype_notifications -from erpnext.stock.doctype.material_request.material_request import update_completed_qty - -def on_method(bean, 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/erpnext/startup/boot.py b/erpnext/startup/boot.py index cd565c749f..e28e5baa41 100644 --- a/erpnext/startup/boot.py +++ b/erpnext/startup/boot.py @@ -47,7 +47,6 @@ def load_country_and_currency(bootinfo): where ifnull(enabled,0)=1""", as_dict=1, update={"doctype":":Currency"}) def get_letter_heads(): - """load letter heads with startup""" import webnotes ret = webnotes.conn.sql("""select name, content from `tabLetter Head` where ifnull(disabled,0)=0""") diff --git a/erpnext/startup/event_handlers.py b/erpnext/startup/event_handlers.py index 7d518728b0..262771dd4a 100644 --- a/erpnext/startup/event_handlers.py +++ b/erpnext/startup/event_handlers.py @@ -5,9 +5,7 @@ from __future__ import unicode_literals import webnotes -from erpnext.home import make_feed - -def on_login_post_session(login_manager): +def on_session_creation(login_manager): """ called after login update login_from and delete parallel sessions @@ -63,10 +61,4 @@ def check_if_expired(): webnotes.msgprint(msg) webnotes.response['message'] = 'Account Expired' - raise webnotes.AuthenticationError - -def comment_added(doc): - """add comment to feed""" - make_feed('Comment', doc.comment_doctype, doc.comment_docname, doc.comment_by, - '"' + doc.comment + '"', '#6B24B3') - + raise webnotes.AuthenticationError diff --git a/erpnext/startup/schedule_handlers.py b/erpnext/startup/schedule_handlers.py deleted file mode 100644 index e1b3bb4544..0000000000 --- a/erpnext/startup/schedule_handlers.py +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors -# License: GNU General Public License v3. See license.txt - -from __future__ import unicode_literals -"""will be called by scheduler""" - -import webnotes -from webnotes.utils import scheduler - -def execute_all(): - """ - * get support email - * recurring invoice - """ - # pull emails - from erpnext.support.doctype.support_ticket.get_support_mails import get_support_mails - run_fn(get_support_mails) - - from erpnext.hr.doctype.job_applicant.get_job_applications import get_job_applications - run_fn(get_job_applications) - - from erpnext.selling.doctype.lead.get_leads import get_leads - run_fn(get_leads) - - from webnotes.utils.email_lib.bulk import flush - run_fn(flush) - -def execute_daily(): - # event reminders - from webnotes.core.doctype.event.event import send_event_digest - run_fn(send_event_digest) - - # clear daily event notifications - from webnotes.core.doctype.notification_count.notification_count import delete_notification_count_for - delete_notification_count_for("Event") - - # email digest - from erpnext.setup.doctype.email_digest.email_digest import send - run_fn(send) - - # run recurring invoices - from erpnext.accounts.doctype.sales_invoice.sales_invoice import manage_recurring_invoices - run_fn(manage_recurring_invoices) - - # send bulk emails - from webnotes.utils.email_lib.bulk import clear_outbox - run_fn(clear_outbox) - - # daily backup - from erpnext.setup.doctype.backup_manager.backup_manager import take_backups_daily - run_fn(take_backups_daily) - - # check reorder level - from erpnext.stock.utils import reorder_item - run_fn(reorder_item) - - # scheduler error - scheduler.report_errors() - -def execute_weekly(): - from erpnext.setup.doctype.backup_manager.backup_manager import take_backups_weekly - run_fn(take_backups_weekly) - -def execute_monthly(): - pass - -def execute_hourly(): - pass - -def run_fn(fn): - try: - fn() - except Exception, e: - scheduler.log(fn.func_name) diff --git a/erpnext/startup/webutils.py b/erpnext/startup/webutils.py index 9e18d4eaad..ef8c88b397 100644 --- a/erpnext/startup/webutils.py +++ b/erpnext/startup/webutils.py @@ -4,7 +4,7 @@ import webnotes from webnotes.utils import cint -def get_website_settings(context): +def update_website_context(context): post_login = [] cart_enabled = cint(webnotes.conn.get_default("shopping_cart_enabled")) if cart_enabled: diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py index 1d838c9c40..b748029187 100644 --- a/erpnext/stock/utils.py +++ b/erpnext/stock/utils.py @@ -343,7 +343,7 @@ def create_material_request(material_requests): exceptions_list.append([] + webnotes.local.message_log) webnotes.local.message_log = [] else: - exceptions_list.append(webnotes.getTraceback()) + exceptions_list.append(webnotes.get_traceback()) if mr_list: if getattr(webnotes.local, "reorder_email_notify", None) is None: