fix: Migrate color fields to color doctype (#20011)

This commit is contained in:
Ankush Menat 2023-02-13 16:17:34 +05:30 committed by GitHub
parent 29be4a544e
commit 91e0d1a439
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 13 deletions

View file

@ -12,7 +12,6 @@ def execute():
for theme in themes:
doc = frappe.get_doc("Website Theme", theme.name)
try:
doc.generate_bootstrap_theme()
doc.save()
except Exception:
print("Ignoring....")

View file

@ -8,21 +8,31 @@ def execute():
for theme in frappe.get_all("Website Theme"):
doc = frappe.get_doc("Website Theme", theme.name)
setup_color_record(doc)
if not doc.get("custom_scss") and doc.theme_scss:
# move old theme to new theme
doc.custom_scss = doc.theme_scss
if doc.background_color:
setup_color_record(doc.background_color)
doc.save()
def setup_color_record(color):
frappe.get_doc(
{
"doctype": "Color",
"__newname": color,
"color": color,
}
).save()
def setup_color_record(doc):
color_fields = [
"primary_color",
"text_color",
"light_color",
"dark_color",
"background_color",
]
for color_field in color_fields:
color_code = doc.get(color_field)
if not color_code or frappe.db.exists("Color", color_code):
continue
frappe.get_doc(
{
"doctype": "Color",
"__newname": color_code,
"color": color_code,
}
).insert()