You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

42 line
1.0 KiB

  1. import glob
  2. import json
  3. import frappe
  4. import os
  5. from frappe.query_builder import DocType as _DocType
  6. def execute():
  7. """Resetting creation datetimes for DocTypes"""
  8. DocType = _DocType("DocType")
  9. doctype_jsons = glob.glob(
  10. os.path.join("..", "apps", "frappe", "frappe", "**", "doctype", "**", "*.json")
  11. )
  12. frappe_modules = frappe.get_all(
  13. "Module Def", filters={"app_name": "frappe"}, pluck="name"
  14. )
  15. site_doctypes = frappe.get_all(
  16. "DocType",
  17. filters={"module": ("in", frappe_modules), "custom": False},
  18. fields=["name", "creation"],
  19. )
  20. for dt_path in doctype_jsons:
  21. with open(dt_path) as f:
  22. try:
  23. file_schema = frappe._dict(json.load(f))
  24. except Exception:
  25. continue
  26. if not file_schema.name:
  27. continue
  28. _site_schema = [x for x in site_doctypes if x.name == file_schema.name]
  29. if not _site_schema:
  30. continue
  31. if file_schema.creation != _site_schema[0].creation:
  32. frappe.qb.update(DocType).set(
  33. DocType.creation, file_schema.creation
  34. ).where(DocType.name == file_schema.name).run()