예제 #1
0
    def test_get_notifications_for_targets(self):
        '''
                Test notification config entries for targets as percentages
        '''

        company = frappe.get_all("Company")[0]
        frappe.db.set_value("Company", company.name, "monthly_sales_target",
                            10000)
        frappe.db.set_value("Company", company.name, "total_monthly_sales",
                            1000)

        config = notifications.get_notification_config()
        doc_target_percents = notifications.get_notifications_for_targets(
            config, {})

        self.assertEqual(doc_target_percents['Company'][company.name], 10)

        frappe.db.set_value("Company", company.name, "monthly_sales_target",
                            2000)
        frappe.db.set_value("Company", company.name, "total_monthly_sales", 0)

        config = notifications.get_notification_config()
        doc_target_percents = notifications.get_notifications_for_targets(
            config, {})

        self.assertEqual(doc_target_percents['Company'][company.name], 0)
	def test_get_notifications_for_targets(self):
		'''
			Test notification config entries for targets as percentages
		'''

		config = notifications.get_notification_config()
		doc_target_percents = notifications.get_notifications_for_targets(config, {})
		self.assertEquals(doc_target_percents['Company']['_Test Company 7'], 10)
		self.assertEquals(doc_target_percents['Company']['_Test Company 6'], 0)
예제 #3
0
def get_notifications():

    if frappe.flags.in_install:
        return

    # if user has no permission
    if frappe.session.user == "Guest":
        return {
            "open_count_doctype": 0,
            "open_count_module": 0,
            "open_count_other": 0,
            "targets": 0,
            "new_messages": 0,
        }

    from frappe.desk.notifications import get_notification_config
    config = get_notification_config()

    groups = list(config.get("for_doctype").keys()) + list(
        config.get("for_module").keys())
    cache = frappe.cache()

    notification_count = {}
    notification_percent = {}

    for name in groups:
        count = cache.hget("notification_count:" + name, frappe.session.user)
        if count is not None:
            notification_count[name] = count

    from frappe.desk.notifications import get_notifications_for_doctypes
    from frappe.desk.notifications import get_notifications_for_modules
    from frappe.desk.notifications import get_notifications_for_other
    from frappe.desk.notifications import get_notifications_for_targets
    from frappe.desk.notifications import get_new_messages

    return {
        "open_count_doctype":
        get_notifications_for_doctypes(config, notification_count),
        "open_count_module":
        get_notifications_for_modules(config, notification_count),
        "open_count_other":
        get_notifications_for_other(config, notification_count),
        "targets":
        get_notifications_for_targets(config, notification_percent),
        "new_messages":
        get_new_messages()
    }