fix: validate amount and currency for paid courses and batches

This commit is contained in:
Jannat Patel
2024-11-18 16:37:09 +05:30
parent dcf5c72cad
commit 1ecbc2e3f9
3 changed files with 14 additions and 2 deletions

View File

@@ -193,13 +193,15 @@
"depends_on": "paid_batch",
"fieldname": "amount",
"fieldtype": "Currency",
"label": "Amount"
"label": "Amount",
"mandatory_depends_on": "paid_batch"
},
{
"depends_on": "paid_batch",
"fieldname": "currency",
"fieldtype": "Link",
"label": "Currency",
"mandatory_depends_on": "paid_batch",
"options": "Currency"
},
{
@@ -328,7 +330,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-07-18 18:06:37.229885",
"modified": "2024-11-18 16:28:41.336928",
"modified_by": "Administrator",
"module": "LMS",
"name": "LMS Batch",

View File

@@ -28,6 +28,7 @@ class LMSBatch(Document):
self.validate_duplicate_courses()
self.validate_duplicate_students()
self.validate_payments_app()
self.validate_amount_and_currency()
self.validate_duplicate_assessments()
self.validate_membership()
self.validate_timetable()
@@ -64,6 +65,10 @@ class LMSBatch(Document):
if "payments" not in installed_apps:
frappe.throw(_("Please install the Payments app to create a paid batches."))
def validate_amount_and_currency(self):
if self.paid_batch and (not self.amount or not self.currency):
frappe.throw(_("Amount and currency are required for paid batches."))
def validate_duplicate_assessments(self):
assessments = [row.assessment_name for row in self.assessment]
for assessment in self.assessment:

View File

@@ -19,6 +19,7 @@ class LMSCourse(Document):
self.validate_video_link()
self.validate_status()
self.validate_payments_app()
self.validate_amount_and_currency()
self.image = validate_image(self.image)
def validate_published(self):
@@ -51,6 +52,10 @@ class LMSCourse(Document):
if "payments" not in installed_apps:
frappe.throw(_("Please install the Payments app to create a paid courses."))
def validate_amount_and_currency(self):
if self.paid_course and (not self.amount and not self.currency):
frappe.throw(_("Amount and currency are required for paid courses."))
def on_update(self):
if not self.upcoming and self.has_value_changed("upcoming"):
self.send_email_to_interested_users()