예제 #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)
예제 #2
0
    def get_reply(self):
        if self.startswith('open', 'show open', 'list open', 'get open'):
            if self.tables:
                doctype = self.get_doctype()
                from frappe.desk.notifications import get_notification_config
                filters = get_notification_config().get('for_doctype').get(
                    doctype, None)
                if filters:
                    if isinstance(filters, dict):
                        data = frappe.get_list(doctype, filters=filters)
                    else:
                        data = [{
                            'name': d[0],
                            'title': d[1]
                        } for d in frappe.get_attr(filters)(as_list=True)]

                    return ", ".join(
                        '[{title}](/app/Form/{doctype}/{name})'.format(
                            doctype=doctype,
                            name=d.get('name'),
                            title=d.get('title') or d.get('name'))
                        for d in data)
                else:
                    return _("Can't identify open {0}. Try something else."
                             ).format(doctype)
	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)
예제 #4
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()
    }
예제 #5
0
파일: bot.py 프로젝트: Dattatech/frappetest
	def get_reply(self):
		if self.startswith('open', 'show open', 'list open', 'get open'):
			if self.tables:
				doctype = self.get_doctype()
				from frappe.desk.notifications import get_notification_config
				filters = get_notification_config().get('for_doctype').get(doctype, None)
				if filters:
					if isinstance(filters, dict):
						data = frappe.get_list(doctype, filters=filters)
					else:
						data = [{'name':d[0], 'title':d[1]} for d in frappe.get_attr(filters)(as_list=True)]

					return ", ".join('[{title}](#Form/{doctype}/{name})'.format(doctype=doctype,
						name=d.get('name'), title=d.get('title') or d.get('name')) for d in data)
				else:
					return _("Can't identify open {0}. Try something else.").format(doctype)