Skip to content

Commit

Permalink
fix: broken date fields in a stored query
Browse files Browse the repository at this point in the history
  • Loading branch information
nextchamp-saqib committed Nov 7, 2022
1 parent 0d6ec35 commit 0023c42
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def get_stored_queries(self):
return frappe.get_all("Insights Query", filters={"is_stored": 1}, pluck="name")

def make_columns(self, columns):
set_date_fields_as_string(columns)
return [
frappe._dict(
{
Expand Down Expand Up @@ -91,7 +92,7 @@ def create_temporary_table(self, table):

# create temporary table for an existing insights query
query = frappe.get_doc("Insights Query", table)
columns = query.get_columns()
columns = self.get_table_columns(table)
result = list(query.load_result())
result.pop(0)

Expand Down Expand Up @@ -155,4 +156,14 @@ def get_table_columns(self, table):
return []

query = frappe.get_cached_doc("Insights Query", table)
return query.get_columns()
columns = query.get_columns()
set_date_fields_as_string(columns)
return columns


def set_date_fields_as_string(columns):
for column in columns:
if column.format_option and column.type in ("Date", "Datetime"):
format_option = frappe.parse_json(column.format_option)
if format_option.date_format:
column.type = "String"
2 changes: 1 addition & 1 deletion insights/insights/doctype/insights_table/insights_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def on_update(self):
@frappe.whitelist()
def sync_table(self):
source = frappe.get_doc("Insights Data Source", self.data_source)
source.sync_tables([self.table])
source.sync_tables([self.table], force=True)

@frappe.whitelist()
def update_visiblity(self, hidden):
Expand Down

0 comments on commit 0023c42

Please sign in to comment.