Skip to content

Commit

Permalink
Merge pull request #267 from DigiThinkIT/staging
Browse files Browse the repository at this point in the history
  • Loading branch information
Alchez committed Sep 24, 2020
2 parents 4bdd47f + 22446e2 commit 36aa226
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
27 changes: 12 additions & 15 deletions frappe/modules/utils.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals, print_function
"""
Utilities for using modules
"""
import json
import os

import frappe
import frappe, os, json
import frappe.utils
from frappe import _
from frappe.utils import cint, unique

from frappe.utils import cint

def export_module_json(doc, is_standard, module):
"""Make a folder for the given doc and add its json file (make it a standard
Expand Down Expand Up @@ -107,22 +104,23 @@ def sync_customizations_for_doctype(data, folder):
update_schema = False

def sync(key, custom_doctype, doctype_fieldname):
doctypes = unique([row.get(doctype_fieldname) for row in data[key]])
doctypes = list(set(map(lambda row: row.get(doctype_fieldname), data[key])))

# sync single doctype excluding the child doctype
def sync_doctype(doc_type):
# sync single doctype exculding the child doctype
def sync_single_doctype(doc_type):
def _insert(data):
if data.get(doctype_fieldname) == doc_type:
data['doctype'] = custom_doctype
doc = frappe.get_doc(data)
doc.db_insert()

frappe.db.sql('delete from `tab{0}` where `{1}` = %s'.format(
custom_doctype, doctype_fieldname), doc_type)

if custom_doctype != 'Custom Field':
frappe.db.sql('delete from `tab{0}` where `{1}` =%s'.format(
custom_doctype, doctype_fieldname), doc_type)

for d in data[key]:
_insert(d)

else:
for d in data[key]:
field = frappe.db.get_value("Custom Field", {"dt": doc_type, "fieldname": d["fieldname"]})
Expand All @@ -137,9 +135,8 @@ def _insert(data):

for doc_type in doctypes:
# only sync the parent doctype and child doctype if there isn't any other child table json file
doctype_json_file = os.path.exists(os.path.join(folder, frappe.scrub(doc_type) + ".json"))
if doc_type == doctype or not doctype_json_file:
sync_doctype(doc_type)
if doc_type == doctype or not os.path.exists(os.path.join(folder, frappe.scrub(doc_type)+".json")):
sync_single_doctype(doc_type)

if data['custom_fields']:
sync('custom_fields', 'Custom Field', 'dt')
Expand Down
5 changes: 5 additions & 0 deletions frappe/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ def get_datetime_str(datetime_obj):
datetime_obj = get_datetime(datetime_obj)
return datetime_obj.strftime(DATETIME_FORMAT)

def get_date_str(date_obj):
if isinstance(date_obj, string_types):
date_obj = get_datetime(date_obj)
return date_obj.strftime(DATE_FORMAT)

def get_user_format():
if getattr(frappe.local, "user_format", None) is None:
frappe.local.user_format = frappe.db.get_default("date_format")
Expand Down

0 comments on commit 36aa226

Please sign in to comment.