fix: add get_field_meta function to get doctype field metadata

This commit is contained in:
raizasafeel
2026-03-05 02:03:24 +05:30
parent 22fb96a00f
commit 5683fd5d7a
2 changed files with 66 additions and 1 deletions

View File

@@ -37,6 +37,7 @@ from lms.lms.utils import (
get_average_rating, get_average_rating,
get_batch_details, get_batch_details,
get_course_details, get_course_details,
get_field_meta,
get_instructors, get_instructors,
get_lesson_count, get_lesson_count,
get_lms_route, get_lms_route,
@@ -103,7 +104,54 @@ def validate_billing_access(billing_type: str, name: str):
as_dict=1, as_dict=1,
) )
return {"access": access, "message": message, "address": address} payment_fields = get_payment_field_meta()
address_fields = get_field_meta(
"Address",
[
"address_line1",
"address_line2",
"city",
"state",
"country",
"pincode",
"phone",
],
)
billing_field_meta = {**payment_fields, **address_fields}
return {
"access": access,
"message": message,
"address": address,
"billing_field_meta": billing_field_meta,
}
@frappe.whitelist()
def get_payment_field_meta():
return get_field_meta(
"LMS Payment",
[
"member",
"billing_name",
"source",
"payment_for_document_type",
"payment_for_document",
"currency",
"amount",
"amount_with_gst",
"original_amount",
"discount_amount",
"coupon",
"coupon_code",
"address",
"gstin",
"pan",
"payment_id",
"order_id",
"member_consent",
],
)
def verify_billing_access(doctype, name, billing_type): def verify_billing_access(doctype, name, billing_type):

View File

@@ -2328,3 +2328,20 @@ def recalculate_course_progress(course: str, member: str):
) )
frappe.db.set_value("LMS Enrollment", membership, "progress", progress) frappe.db.set_value("LMS Enrollment", membership, "progress", progress)
update_program_progress(member) update_program_progress(member)
def get_field_meta(doctype, fieldnames):
"""Returns field metadata for 'fieldnames' from 'doctype'"""
meta = frappe.get_meta(doctype)
fieldnames_meta = {}
for fieldname in fieldnames:
field = meta.get_field(fieldname)
if field:
fieldnames_meta[fieldname] = {
"reqd": field.reqd,
"default": field.default,
"description": field.description,
}
return fieldnames_meta