Example #1
0
def get_timeline_data(doctype, name):
	'''returns timeline data for the past one year'''
	from frappe.desk.form.load import get_communication_data

	out = {}
	fields = 'date(creation), count(name)'
	after = add_years(None, -1).strftime('%Y-%m-%d')
	group_by='group by date(creation)'

	data = get_communication_data(doctype, name,
		fields=fields, after=after, group_by=group_by, as_dict=False)

	# fetch and append data from Activity Log
	data += frappe.db.sql("""select {fields}
		from `tabActivity Log`
		where reference_doctype="{doctype}" and reference_name="{name}"
		and status!='Success' and creation > {after}
		{group_by} order by creation desc
		""".format(doctype=frappe.db.escape(doctype), name=frappe.db.escape(name), fields=fields,
			group_by=group_by, after=after), as_dict=False)

	timeline_items = dict(data)

	for date, count in iteritems(timeline_items):
		timestamp = get_timestamp(date)
		out.update({ timestamp: count })

	return out
Example #2
0
def get_timeline_data(doctype, name):
	'''returns timeline data for the past one year'''
	from frappe.desk.form.load import get_communication_data

	out = {}
	fields = 'creation, count(*)'
	after = add_years(None, -1).strftime('%Y-%m-%d')
	group_by='group by Date(creation)'

	data = get_communication_data(doctype, name, after=after, group_by='group by creation',
		fields='C.creation as creation, count(C.name)',as_dict=False)

	# fetch and append data from Activity Log
	data += frappe.db.sql("""select {fields}
		from `tabActivity Log`
		where (reference_doctype=%(doctype)s and reference_name=%(name)s)
		or (timeline_doctype in (%(doctype)s) and timeline_name=%(name)s)
		or (reference_doctype in ("Quotation", "Opportunity") and timeline_name=%(name)s)
		and status!='Success' and creation > {after}
		{group_by} order by creation desc
		""".format(fields=fields, group_by=group_by, after=after), {
			"doctype": doctype,
			"name": name
		}, as_dict=False)

	timeline_items = dict(data)

	for date, count in iteritems(timeline_items):
		timestamp = get_timestamp(date)
		out.update({ timestamp: count })

	return out
Example #3
0
def get_timeline_data(doctype, name):
	'''returns timeline data for the past one year'''
	from frappe.desk.form.load import get_communication_data
	data = get_communication_data(doctype, name,
		fields = 'unix_timestamp(date(creation)), count(name)',
		after = add_years(None, -1).strftime('%Y-%m-%d'),
		group_by='group by date(creation)', as_dict=False)
	return dict(data)
Example #4
0
def get_timeline_data(doctype, name):
    '''returns timeline data for the past one year'''
    from frappe.desk.form.load import get_communication_data
    data = get_communication_data(
        doctype,
        name,
        fields='unix_timestamp(date(creation)), count(name)',
        after=add_years(None, -1).strftime('%Y-%m-%d'),
        group_by='group by date(creation)',
        as_dict=False)
    return dict(data)
Example #5
0
def get_timeline_data(doctype, name):
	'''returns timeline data for the past one year'''
	from frappe.desk.form.load import get_communication_data

	out = {}
	data = get_communication_data(doctype, name,
		fields = 'date(creation), count(name)',
		after = add_years(None, -1).strftime('%Y-%m-%d'),
		group_by='group by date(creation)', as_dict=False)

	timeline_items = dict(data)

	for date, count in timeline_items.iteritems():
		timestamp = get_timestamp(date)
		out.update({ timestamp: count })

	return out
Example #6
0
def get_timeline_data(doctype, name):
	'''returns timeline data for the past one year'''
	from frappe.desk.form.load import get_communication_data

	out = {}
	data = get_communication_data(doctype, name,
		fields = 'date(creation), count(name)',
		after = add_years(None, -1).strftime('%Y-%m-%d'),
		group_by='group by date(creation)', as_dict=False)

	timeline_items = dict(data)

	for date, count in timeline_items.iteritems():
		timestamp = get_timestamp(date)
		out.update({ timestamp: count })

	return out
Example #7
0
    def test_get_communication_data(self):
        from frappe.desk.form.load import get_communication_data

        frappe.delete_doc_if_exists("Note", "get communication data")

        note = frappe.get_doc({
            "doctype": "Note",
            "title": "get communication data",
            "content": "get communication data"
        }).insert(ignore_permissions=True)

        comm_note_1 = frappe.get_doc({
            "doctype": "Communication",
            "communication_type": "Communication",
            "content": "Test Get Communication Data 1",
            "communication_medium": "Email"
        }).insert(ignore_permissions=True)

        comm_note_1.add_link(link_doctype="Note",
                             link_name=note.name,
                             autosave=True)

        comm_note_2 = frappe.get_doc({
            "doctype": "Communication",
            "communication_type": "Communication",
            "content": "Test Get Communication Data 2",
            "communication_medium": "Email"
        }).insert(ignore_permissions=True)

        comm_note_2.add_link(link_doctype="Note",
                             link_name=note.name,
                             autosave=True)

        comms = get_communication_data("Note", note.name, as_dict=True)

        data = []
        for comm in comms:
            data.append(comm.name)

        self.assertIn(comm_note_1.name, data)
        self.assertIn(comm_note_2.name, data)