Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validate amount and currency for paid courses and batches #1139

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lms/lms/doctype/lms_batch/lms_batch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
{
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions lms/lms/doctype/lms_batch/lms_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def validate(self):
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()
Expand Down Expand Up @@ -64,6 +65,10 @@ def validate_payments_app(self):
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:
Expand Down
5 changes: 5 additions & 0 deletions lms/lms/doctype/lms_course/lms_course.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def validate(self):
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):
Expand Down Expand Up @@ -51,6 +52,10 @@ def validate_payments_app(self):
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()
Expand Down
Loading