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
|
from pathlib import Path
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
|
|
||||||
|
|
||||||
ROOT = Path(__file__).parent
|
ROOT = Path(__file__).parent
|
||||||
SOURCE_DIR = ROOT / "schema_sources"
|
SOURCE_DIR = ROOT / "schema_sources"
|
||||||
|
CHILD_TABLES = ["Material Structure", "Critical Acceptance Requirement"]
|
||||||
|
|
||||||
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"]
|
|
||||||
|
|
||||||
|
|
||||||
def ensure_makap_backend_module():
|
def ensure_makap_backend_module():
|
||||||
@@ -39,18 +22,11 @@ def ensure_makap_backend_module():
|
|||||||
|
|
||||||
|
|
||||||
def ensure_module3_child_tables():
|
def ensure_module3_child_tables():
|
||||||
for filename in ("material_structure.json", "critical_acceptance_requirement.json"):
|
"""The child tables ship as files under doctype/ and `bench migrate` syncs them.
|
||||||
data = json.loads((SOURCE_DIR / filename).read_text(encoding="utf-8"))
|
Standard DocTypes can't be created or saved at runtime outside developer mode,
|
||||||
data["module"] = "makap_backend"
|
so this only checks that they exist."""
|
||||||
name = data["name"]
|
missing = [n for n in CHILD_TABLES if not frappe.db.exists("DocType", n)]
|
||||||
|
if missing:
|
||||||
if frappe.db.exists("DocType", name):
|
frappe.log_error(title="MAKAP child tables missing", message=", ".join(missing))
|
||||||
existing = frappe.get_doc("DocType", name)
|
print("WARNING: missing DocTypes: " + ", ".join(missing))
|
||||||
existing.update(data)
|
return CHILD_TABLES
|
||||||
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"]
|
|
||||||
|
|||||||
Reference in New Issue
Block a user