mirror of
https://github.com/frappe/lms.git
synced 2026-04-19 22:52:29 +03:00
fix: add get_field_meta function to get doctype field metadata
This commit is contained in:
@@ -37,6 +37,7 @@ from lms.lms.utils import (
|
||||
get_average_rating,
|
||||
get_batch_details,
|
||||
get_course_details,
|
||||
get_field_meta,
|
||||
get_instructors,
|
||||
get_lesson_count,
|
||||
get_lms_route,
|
||||
@@ -103,7 +104,54 @@ def validate_billing_access(billing_type: str, name: str):
|
||||
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):
|
||||
|
||||
@@ -2328,3 +2328,20 @@ def recalculate_course_progress(course: str, member: str):
|
||||
)
|
||||
frappe.db.set_value("LMS Enrollment", membership, "progress", progress)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user