Browse Source

fix: Reset any creation datetimes if inconsistencies exist

version-14
Gavin D'souza 3 years ago
parent
commit
22df3e73ca
2 changed files with 42 additions and 0 deletions
  1. +1
    -0
      frappe/patches.txt
  2. +41
    -0
      frappe/patches/v14_0/reset_creation_datetime.py

+ 1
- 0
frappe/patches.txt View File

@@ -189,6 +189,7 @@ frappe.patches.v14_0.update_workspace2 # 20.09.2021
frappe.patches.v14_0.save_ratings_in_fraction #23-12-2021
frappe.patches.v14_0.transform_todo_schema
frappe.patches.v14_0.remove_post_and_post_comment
frappe.patches.v14_0.reset_creation_datetime

[post_model_sync]
frappe.patches.v14_0.drop_data_import_legacy


+ 41
- 0
frappe/patches/v14_0/reset_creation_datetime.py View File

@@ -0,0 +1,41 @@
import glob
import json
import frappe
import os
from frappe.query_builder import DocType as _DocType


def execute():
"""Resetting creation datetimes for DocTypes"""
DocType = _DocType("DocType")
doctype_jsons = glob.glob(
os.path.join("..", "apps", "frappe", "frappe", "**", "doctype", "**", "*.json")
)

frappe_modules = frappe.get_all(
"Module Def", filters={"app_name": "frappe"}, pluck="name"
)
site_doctypes = frappe.get_all(
"DocType",
filters={"module": ("in", frappe_modules), "custom": False},
fields=["name", "creation"],
)

for dt_path in doctype_jsons:
with open(dt_path) as f:
try:
file_schema = frappe._dict(json.load(f))
except Exception:
continue

if not file_schema.name:
continue

_site_schema = [x for x in site_doctypes if x.name == file_schema.name]
if not _site_schema:
continue

if file_schema.creation != _site_schema[0].creation:
frappe.qb.update(DocType).set(
DocType.creation, file_schema.creation
).where(DocType.name == file_schema.name).run()

Loading…
Cancel
Save