[minor] timestamp fixes for heatmap

This commit is contained in:
mbauskar 2017-02-16 13:12:29 +05:30
parent d5d0b36973
commit e7b87ad071
2 changed files with 21 additions and 5 deletions

View File

@ -7,7 +7,7 @@ import frappe
import datetime import datetime
from frappe import _, msgprint, scrub from frappe import _, msgprint, scrub
from frappe.defaults import get_user_permissions from frappe.defaults import get_user_permissions
from frappe.utils import add_days, getdate, formatdate, get_first_day, date_diff, add_years from frappe.utils import add_days, getdate, formatdate, get_first_day, date_diff, add_years, get_timestamp
from erpnext.utilities.doctype.address.address import get_address_display from erpnext.utilities.doctype.address.address import get_address_display
from erpnext.utilities.doctype.contact.contact import get_contact_details from erpnext.utilities.doctype.contact.contact import get_contact_details
from erpnext.exceptions import PartyFrozen, InvalidCurrency, PartyDisabled, InvalidAccountCurrency from erpnext.exceptions import PartyFrozen, InvalidCurrency, PartyDisabled, InvalidAccountCurrency
@ -351,8 +351,17 @@ def validate_party_frozen_disabled(party_type, party_name):
def get_timeline_data(doctype, name): def get_timeline_data(doctype, name):
'''returns timeline data for the past one year''' '''returns timeline data for the past one year'''
from frappe.desk.form.load import get_communication_data from frappe.desk.form.load import get_communication_data
out = {}
data = get_communication_data(doctype, name, data = get_communication_data(doctype, name,
fields = 'unix_timestamp(date(creation)), count(name)', fields = 'date(creation), count(name)',
after = add_years(None, -1).strftime('%Y-%m-%d'), after = add_years(None, -1).strftime('%Y-%m-%d'),
group_by='group by date(creation)', as_dict=False) group_by='group by date(creation)', as_dict=False)
return dict(data)
timeline_items = dict(data)
for date, count in timeline_items.iteritems():
timestamp = get_timestamp(date)
out.update({ timestamp: count })
return out

View File

@ -7,7 +7,7 @@ import erpnext
import json import json
import itertools import itertools
from frappe import msgprint, _ from frappe import msgprint, _
from frappe.utils import cstr, flt, cint, getdate, now_datetime, formatdate, strip from frappe.utils import cstr, flt, cint, getdate, now_datetime, formatdate, strip, get_timestamp
from frappe.website.website_generator import WebsiteGenerator from frappe.website.website_generator import WebsiteGenerator
from erpnext.setup.doctype.item_group.item_group import invalidate_cache_for, get_parent_item_groups from erpnext.setup.doctype.item_group.item_group import invalidate_cache_for, get_parent_item_groups
from frappe.website.render import clear_cache from frappe.website.render import clear_cache
@ -667,10 +667,17 @@ class Item(WebsiteGenerator):
def get_timeline_data(doctype, name): def get_timeline_data(doctype, name):
'''returns timeline data based on stock ledger entry''' '''returns timeline data based on stock ledger entry'''
return dict(frappe.db.sql('''select unix_timestamp(posting_date), count(*) out = {}
items = dict(frappe.db.sql('''select posting_date, count(*)
from `tabStock Ledger Entry` where item_code=%s from `tabStock Ledger Entry` where item_code=%s
and posting_date > date_sub(curdate(), interval 1 year) and posting_date > date_sub(curdate(), interval 1 year)
group by posting_date''', name)) group by posting_date''', name))
for date, count in items.iteritems():
timestamp = get_timestamp(date)
out.update({ timestamp: count })
return out
def validate_end_of_life(item_code, end_of_life=None, disabled=None, verbose=1): def validate_end_of_life(item_code, end_of_life=None, disabled=None, verbose=1):
if (not end_of_life) or (disabled is None): if (not end_of_life) or (disabled is None):