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
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
def get_all_transactions_annual_history(company): out = {} items = frappe.db.sql( """ select transaction_date, count(*) as count from ( select name, transaction_date, company from `tabQuotation` UNION ALL select name, transaction_date, company from `tabSales Order` UNION ALL select name, posting_date as transaction_date, company from `tabDelivery Note` UNION ALL select name, posting_date as transaction_date, company from `tabSales Invoice` UNION ALL select name, creation as transaction_date, company from `tabIssue` UNION ALL select name, creation as transaction_date, company from `tabProject` ) t where company=%s and transaction_date > date_sub(curdate(), interval 1 year) group by transaction_date """, (company), as_dict=True, ) for d in items: timestamp = get_timestamp(d["transaction_date"]) out.update({timestamp: d["count"]}) return out
def get_timeline_data(doctype, name): '''returns timeline data based on stock ledger entry''' out = {} items = dict(frappe.db.sql('''select posting_date, count(*) from `tabStock Ledger Entry` where item_code=%s and posting_date > date_sub(curdate(), interval 1 year) group by posting_date''', name)) for date, count in items.iteritems(): timestamp = get_timestamp(date) out.update({ timestamp: count }) return out
def get_timeline_data(doctype, name): '''returns timeline data based on stock ledger entry''' out = {} items = dict(frappe.db.sql('''select posting_date, count(*) from `tabStock Ledger Entry` where item_code=%s and posting_date > date_sub(curdate(), interval 1 year) group by posting_date''', name)) for date, count in iteritems(items): timestamp = get_timestamp(date) out.update({timestamp: count}) return out
def get_all_transactions_annual_history(company): out = {} items = frappe.db.sql(''' select transaction_date, count(*) as count from ( select name, transaction_date, company from `tabQuotation` UNION ALL select name, transaction_date, company from `tabSales Order` UNION ALL select name, posting_date as transaction_date, company from `tabDelivery Note` UNION ALL select name, posting_date as transaction_date, company from `tabSales Invoice` UNION ALL select name, creation as transaction_date, company from `tabIssue` UNION ALL select name, creation as transaction_date, company from `tabProject` ) t where company=%s and transaction_date > date_sub(curdate(), interval 1 year) group by transaction_date ''', (company), as_dict=True) for d in items: timestamp = get_timestamp(d["transaction_date"]) out.update({ timestamp: d["count"] }) return out
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
def get_timeline_data(doctype, name): '''returns timeline data based on notary sales invoice''' from six import iteritems from frappe.utils import (cint, cstr, flt, formatdate, get_timestamp, getdate, now_datetime, random_string, strip) out = {} '''notary sales invoice''' items = dict(frappe.db.sql('''select a.posting_date, count(*) from `tabNotary Sales Invoice` a, `tabNotary Sales Invoice Items` b where item_code=%s and a.posting_date > date_sub(curdate(), interval 1 year) group by a.posting_date''', name)) for date, count in iteritems(items): timestamp = get_timestamp(date) out.update({timestamp: count}) return out
def setup_subscription(self, settings, **kwargs): start_date = (get_timestamp( kwargs.get("subscription_details").get("start_date")) if kwargs.get("subscription_details").get("start_date") else None) subscription_details = { "plan_id": kwargs.get("subscription_details").get("plan_id"), "total_count": kwargs.get("subscription_details").get("billing_frequency"), "customer_notify": kwargs.get("subscription_details").get("customer_notify"), } if start_date: subscription_details["start_at"] = cint(start_date) if kwargs.get("addons"): convert_rupee_to_paisa(**kwargs) subscription_details.update({"addons": kwargs.get("addons")}) try: resp = make_post_request( "https://api.razorpay.com/v1/subscriptions", auth=(settings.api_key, settings.api_secret), data=json.dumps(subscription_details), headers={"content-type": "application/json"}, ) if resp.get("status") == "created": kwargs["subscription_id"] = resp.get("id") frappe.flags.status = "created" return kwargs else: frappe.log_error( str(resp), "Razorpay Failed while creating subscription") except: frappe.log_error(frappe.get_traceback()) # failed pass
def setup_subscription(self, settings, **kwargs): start_date = get_timestamp(kwargs.get('subscription_details').get("start_date")) \ if kwargs.get('subscription_details').get("start_date") else None subscription_details = { "plan_id": kwargs.get('subscription_details').get("plan_id"), "total_count": kwargs.get('subscription_details').get("billing_frequency"), "customer_notify": kwargs.get('subscription_details').get("customer_notify") } if start_date: subscription_details['start_at'] = cint(start_date) if kwargs.get('addons'): convert_rupee_to_paisa(**kwargs) subscription_details.update({ "addons": kwargs.get('addons') }) try: resp = make_post_request( "https://api.midtrans.com/v1/subscriptions", auth=(settings.client_key, settings.server_key), data=json.dumps(subscription_details), headers={ "content-type": "application/json" } ) if resp.get('status') == 'created': kwargs['subscription_id'] = resp.get('id') frappe.flags.status = 'created' return kwargs else: frappe.log_error(str(resp), 'midtrans Failed while creating subscription') except: frappe.log_error(frappe.get_traceback()) # failed pass
def setup_subscription(self, settings, **kwargs): start_date = get_timestamp(kwargs.get('subscription_details').get("start_date")) \ if kwargs.get('subscription_details').get("start_date") else None subscription_details = { "plan_id": kwargs.get('subscription_details').get("plan_id"), "start_at": cint(start_date), "total_count": kwargs.get('subscription_details').get("billing_frequency"), "customer_notify": kwargs.get('subscription_details').get("customer_notify") } if kwargs.get('addons'): convert_rupee_to_paisa(**kwargs) subscription_details.update({ "addons": kwargs.get('addons') }) try: resp = make_post_request( "https://api.razorpay.com/v1/subscriptions", auth=(settings.api_key, settings.api_secret), data=json.dumps(subscription_details), headers={ "content-type": "application/json" } ) if resp.get('status') == 'created': kwargs['subscription_id'] = resp.get('id') frappe.flags.status = 'created' return kwargs else: frappe.log_error(str(resp), 'Razorpay Failed while creating subscription') except: frappe.log_error(frappe.get_traceback()) # failed pass