Capitalize all Data fields using hooks.py

frappe.get_meta() is the best thing that Frappe brought to the world. This code capitalizes all fields of datatype Data using the str.upper() method.

Step 1: Create a python class in which you add the following methods.
def return_fields_to_capitalize(doc):
meta = meta = frappe.get_meta(doc.get(“doctype”))
fieldnames =[x.get(“fieldname”) for x in meta.get(“fields”)
if x.get(“fieldtype”) in [“Data”]]
return fieldnames
def capitalize_essential_fields(doc , state):
fields_to_capitalize = return_fields_to_capitalize(doc)
if fields_to_capitalize:
for d in fields_to_capitalize:
if doc.get(d):
doc.set(d, str(doc.get(d)).upper())
return

Step 2. Add a before_save hook in your hooks.py to reference it.
Step 3: bench restart