Child table controllers; module3 hook no longer writes standard DocTypes
This commit is contained in:
+5
@@ -0,0 +1,5 @@
|
||||
from frappe.model.document import Document
|
||||
|
||||
|
||||
class CriticalAcceptanceRequirement(Document):
|
||||
pass
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
from frappe.model.document import Document
|
||||
|
||||
|
||||
class MaterialStructure(Document):
|
||||
pass
|
||||
|
||||
@@ -1,27 +1,10 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import frappe
|
||||
|
||||
|
||||
ROOT = Path(__file__).parent
|
||||
SOURCE_DIR = ROOT / "schema_sources"
|
||||
|
||||
|
||||
def ensure_module3_child_tables():
|
||||
for filename in ("material_structure.json", "critical_acceptance_requirement.json"):
|
||||
data = json.loads((SOURCE_DIR / filename).read_text(encoding="utf-8"))
|
||||
name = data["name"]
|
||||
|
||||
if frappe.db.exists("DocType", name):
|
||||
existing = frappe.get_doc("DocType", name)
|
||||
existing.update(data)
|
||||
existing.save(ignore_permissions=True)
|
||||
else:
|
||||
frappe.get_doc(data).insert(ignore_permissions=True)
|
||||
|
||||
frappe.db.commit()
|
||||
return ["Material Structure", "Critical Acceptance Requirement"]
|
||||
CHILD_TABLES = ["Material Structure", "Critical Acceptance Requirement"]
|
||||
|
||||
|
||||
def ensure_makap_backend_module():
|
||||
@@ -39,18 +22,11 @@ def ensure_makap_backend_module():
|
||||
|
||||
|
||||
def ensure_module3_child_tables():
|
||||
for filename in ("material_structure.json", "critical_acceptance_requirement.json"):
|
||||
data = json.loads((SOURCE_DIR / filename).read_text(encoding="utf-8"))
|
||||
data["module"] = "makap_backend"
|
||||
name = data["name"]
|
||||
|
||||
if frappe.db.exists("DocType", name):
|
||||
existing = frappe.get_doc("DocType", name)
|
||||
existing.update(data)
|
||||
existing.module = "makap_backend"
|
||||
existing.save(ignore_permissions=True)
|
||||
else:
|
||||
frappe.get_doc(data).insert(ignore_permissions=True)
|
||||
|
||||
frappe.db.commit()
|
||||
return ["Material Structure", "Critical Acceptance Requirement"]
|
||||
"""The child tables ship as files under doctype/ and `bench migrate` syncs them.
|
||||
Standard DocTypes can't be created or saved at runtime outside developer mode,
|
||||
so this only checks that they exist."""
|
||||
missing = [n for n in CHILD_TABLES if not frappe.db.exists("DocType", n)]
|
||||
if missing:
|
||||
frappe.log_error(title="MAKAP child tables missing", message=", ".join(missing))
|
||||
print("WARNING: missing DocTypes: " + ", ".join(missing))
|
||||
return CHILD_TABLES
|
||||
|
||||
Reference in New Issue
Block a user