From 40f7dd4e774ac56776e7b7a42061a1fa0c4d074f Mon Sep 17 00:00:00 2001 From: Khushal Trivedi Date: Tue, 26 Nov 2019 18:31:40 +0530 Subject: [PATCH 01/14] fix: date validation on inpatient record, else condition removing on clinical prcd templ which is not req --- .../clinical_procedure_template.py | 5 +++-- .../doctype/inpatient_record/inpatient_record.py | 11 ++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.py b/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.py index 141329b3db1..7cec3622001 100644 --- a/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.py +++ b/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.py @@ -63,10 +63,11 @@ def updating_rate(self): item_code=%s""",(self.template, self.rate, self.item)) def create_item_from_template(doc): + disabled = 1 + if(doc.is_billable == 1): disabled = 0 - else: - disabled = 1 + #insert item item = frappe.get_doc({ "doctype": "Item", diff --git a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py index c107cd73350..835b38bedf8 100644 --- a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py +++ b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import frappe from frappe import _ -from frappe.utils import today, now_datetime +from frappe.utils import today, now_datetime, getdate from frappe.model.document import Document from frappe.desk.reportview import get_match_cond @@ -15,11 +15,20 @@ class InpatientRecord(Document): frappe.db.set_value("Patient", self.patient, "inpatient_record", self.name) def validate(self): + self.validate_dates() self.validate_already_scheduled_or_admitted() if self.status == "Discharged": frappe.db.set_value("Patient", self.patient, "inpatient_status", None) frappe.db.set_value("Patient", self.patient, "inpatient_record", None) + def validate_dates(self): + if (getdate(self.scheduled_date) < getdate(today())) or \ + (getdate(self.admitted_datetime) < getdate(today())): + frappe.throw(_("Scheduled and Admitted dates can not be less than today")) + if (getdate(self.expected_discharge) < getdate(self.scheduled_date)) or \ + (getdate(self.discharge_date) < getdate(self.scheduled_date)): + frappe.throw(_("Expected and Discharge dates cannot be less than Admission Schedule date")) + def validate_already_scheduled_or_admitted(self): query = """ select name, status From 213e071b214893ac951f313a84ffada18a145358 Mon Sep 17 00:00:00 2001 From: Khushal Trivedi Date: Mon, 2 Dec 2019 15:08:52 +0530 Subject: [PATCH 02/14] fix:Pricing Rule error AttributeError: 'str' object has no attribute 'get' #19770 --- erpnext/accounts/doctype/pricing_rule/pricing_rule.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index 430dce7ddbb..e81d186c73f 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -33,9 +33,9 @@ class PricingRule(Document): if not self.margin_type: self.margin_rate_or_amount = 0.0 def validate_duplicate_apply_on(self): + print("##############",self.apply_on) field = apply_on_dict.get(self.apply_on) - values = [d.get(frappe.scrub(self.apply_on)) for d in self.get(field)] - + values = [d.get(frappe.scrub(self.apply_on)) for d in self.get(field) if field] if len(values) != len(set(values)): frappe.throw(_("Duplicate {0} found in the table").format(self.apply_on)) From db8911b05d79c98b10d1ff6b0dd723216961dc3d Mon Sep 17 00:00:00 2001 From: Khushal Trivedi Date: Mon, 2 Dec 2019 15:14:11 +0530 Subject: [PATCH 03/14] fix:Pricing Rule error AttributeError: 'str' object has no attribute 'get' #19770 --- erpnext/accounts/doctype/pricing_rule/pricing_rule.py | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index e81d186c73f..e871d98af6a 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -33,7 +33,6 @@ class PricingRule(Document): if not self.margin_type: self.margin_rate_or_amount = 0.0 def validate_duplicate_apply_on(self): - print("##############",self.apply_on) field = apply_on_dict.get(self.apply_on) values = [d.get(frappe.scrub(self.apply_on)) for d in self.get(field) if field] if len(values) != len(set(values)): From 8af51e1f900ce49361b5766ef0468ab8e7c16433 Mon Sep 17 00:00:00 2001 From: Khushal Trivedi Date: Tue, 3 Dec 2019 19:28:16 +0530 Subject: [PATCH 04/14] fix: joining and relieving Date can be on same date as valid use case --- erpnext/hr/doctype/employee/employee.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/hr/doctype/employee/employee.py b/erpnext/hr/doctype/employee/employee.py index 2f88e1e3631..6f4e0eaac87 100755 --- a/erpnext/hr/doctype/employee/employee.py +++ b/erpnext/hr/doctype/employee/employee.py @@ -152,7 +152,7 @@ class Employee(NestedSet): elif self.date_of_retirement and self.date_of_joining and (getdate(self.date_of_retirement) <= getdate(self.date_of_joining)): throw(_("Date Of Retirement must be greater than Date of Joining")) - elif self.relieving_date and self.date_of_joining and (getdate(self.relieving_date) <= getdate(self.date_of_joining)): + elif self.relieving_date and self.date_of_joining and (getdate(self.relieving_date) < getdate(self.date_of_joining)): throw(_("Relieving Date must be greater than Date of Joining")) elif self.contract_end_date and self.date_of_joining and (getdate(self.contract_end_date) <= getdate(self.date_of_joining)): From 9f0699f7e310df03c0a6417feb671855f8ca7112 Mon Sep 17 00:00:00 2001 From: Khushal Trivedi Date: Mon, 9 Dec 2019 18:02:06 +0530 Subject: [PATCH 05/14] fix-education: date of birth validation --- erpnext/education/doctype/student/student.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/erpnext/education/doctype/student/student.py b/erpnext/education/doctype/student/student.py index 76825cec1b2..8e4b4e16f9a 100644 --- a/erpnext/education/doctype/student/student.py +++ b/erpnext/education/doctype/student/student.py @@ -5,12 +5,14 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document +from frappe.utils import getdate,today from frappe import _ from frappe.desk.form.linked_with import get_linked_doctypes from erpnext.education.utils import check_content_completion, check_quiz_completion class Student(Document): def validate(self): self.title = " ".join(filter(None, [self.first_name, self.middle_name, self.last_name])) + self.validate_dates() if self.student_applicant: self.check_unique() @@ -19,6 +21,10 @@ class Student(Document): if frappe.get_value("Student", self.name, "title") != self.title: self.update_student_name_in_linked_doctype() + def validate_dates(self): + if self.date_of_birth and getdate(self.date_of_birth) >= getdate(today()): + frappe.throw(_("Date of Birth cannot be greater than today.")) + def update_student_name_in_linked_doctype(self): linked_doctypes = get_linked_doctypes("Student") for d in linked_doctypes: From e89d521848d91dac8d11b8eccabdd3c2f2c39196 Mon Sep 17 00:00:00 2001 From: Khushal Trivedi Date: Wed, 11 Dec 2019 14:02:07 +0530 Subject: [PATCH 06/14] fix:Sibling child table filtering for duplacacy on student form --- erpnext/education/doctype/student/student.js | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/erpnext/education/doctype/student/student.js b/erpnext/education/doctype/student/student.js index b6e741c4da6..66df6b977e4 100644 --- a/erpnext/education/doctype/student/student.js +++ b/erpnext/education/doctype/student/student.js @@ -31,8 +31,9 @@ frappe.ui.form.on('Student', { frappe.ui.form.on('Student Guardian', { guardians_add: function(frm){ frm.fields_dict['guardians'].grid.get_field('guardian').get_query = function(doc){ - var guardian_list = []; + let guardian_list = []; if(!doc.__islocal) guardian_list.push(doc.guardian); + $.each(doc.guardians, function(idx, val){ if (val.guardian) guardian_list.push(val.guardian); }); @@ -40,3 +41,21 @@ frappe.ui.form.on('Student Guardian', { }; } }); + + +frappe.ui.form.on('Student Sibling', { + siblings_add: function(frm){ + frm.fields_dict['siblings'].grid.get_field('student').get_query = function(doc){ + let sibling_list = [frm.doc.name]; + if(!doc.__islocal) sibling_list.push(doc.student); + + $.each(doc.siblings, function(idx, val){ + if (val.student && val.studying_in_same_institute == 'YES') { + sibling_list.push(val.student); + } + + }); + return { filters: [['Student', 'name', 'not in', sibling_list]] }; + }; + } +}); \ No newline at end of file From 4c24fb1efc6a2e3111f8a7d7e03fa1717dc73aa8 Mon Sep 17 00:00:00 2001 From: Khushal Trivedi Date: Wed, 11 Dec 2019 15:16:56 +0530 Subject: [PATCH 07/14] fix:Sibling child table filtering for duplacacy on student form --- erpnext/education/doctype/student/student.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/erpnext/education/doctype/student/student.js b/erpnext/education/doctype/student/student.js index 66df6b977e4..ea01b5ded2a 100644 --- a/erpnext/education/doctype/student/student.js +++ b/erpnext/education/doctype/student/student.js @@ -33,7 +33,6 @@ frappe.ui.form.on('Student Guardian', { frm.fields_dict['guardians'].grid.get_field('guardian').get_query = function(doc){ let guardian_list = []; if(!doc.__islocal) guardian_list.push(doc.guardian); - $.each(doc.guardians, function(idx, val){ if (val.guardian) guardian_list.push(val.guardian); }); @@ -48,12 +47,10 @@ frappe.ui.form.on('Student Sibling', { frm.fields_dict['siblings'].grid.get_field('student').get_query = function(doc){ let sibling_list = [frm.doc.name]; if(!doc.__islocal) sibling_list.push(doc.student); - $.each(doc.siblings, function(idx, val){ if (val.student && val.studying_in_same_institute == 'YES') { sibling_list.push(val.student); - } - + } }); return { filters: [['Student', 'name', 'not in', sibling_list]] }; }; From 03e770782a30bb6ffa9ba010f2d642c1573aece3 Mon Sep 17 00:00:00 2001 From: Khushal Trivedi Date: Wed, 11 Dec 2019 15:24:39 +0530 Subject: [PATCH 08/14] fix:Sibling child table filtering for duplacacy on student form --- erpnext/education/doctype/student/student.js | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/education/doctype/student/student.js b/erpnext/education/doctype/student/student.js index ea01b5ded2a..1936dcbd3e0 100644 --- a/erpnext/education/doctype/student/student.js +++ b/erpnext/education/doctype/student/student.js @@ -46,7 +46,6 @@ frappe.ui.form.on('Student Sibling', { siblings_add: function(frm){ frm.fields_dict['siblings'].grid.get_field('student').get_query = function(doc){ let sibling_list = [frm.doc.name]; - if(!doc.__islocal) sibling_list.push(doc.student); $.each(doc.siblings, function(idx, val){ if (val.student && val.studying_in_same_institute == 'YES') { sibling_list.push(val.student); From ee9aea4febee1dfa0113809053df526395ea02fe Mon Sep 17 00:00:00 2001 From: Khushal Trivedi Date: Tue, 24 Dec 2019 13:37:10 +0530 Subject: [PATCH 09/14] fix: date validation on student form, instructor duplicacy fix on student grp, instructor with same employee id fix --- erpnext/education/doctype/instructor/instructor.py | 9 +++++++++ erpnext/education/doctype/student/student.py | 3 +++ .../education/doctype/student_group/student_group.js | 12 ++++++++++++ 3 files changed, 24 insertions(+) diff --git a/erpnext/education/doctype/instructor/instructor.py b/erpnext/education/doctype/instructor/instructor.py index 0756b5f01a4..058d476f5b6 100644 --- a/erpnext/education/doctype/instructor/instructor.py +++ b/erpnext/education/doctype/instructor/instructor.py @@ -22,3 +22,12 @@ class Instructor(Document): self.name = self.employee elif naming_method == 'Full Name': self.name = self.instructor_name + + def validate(self): + self.validate_duplicate_employee() + + def validate_duplicate_employee(self): + if self.employee and frappe.db.get_value("Instructor", {'employee': self.employee}, 'name'): + frappe.throw(_("Employee ID is linked with another instructor")) + + diff --git a/erpnext/education/doctype/student/student.py b/erpnext/education/doctype/student/student.py index 8e4b4e16f9a..99c4c0e9089 100644 --- a/erpnext/education/doctype/student/student.py +++ b/erpnext/education/doctype/student/student.py @@ -25,6 +25,9 @@ class Student(Document): if self.date_of_birth and getdate(self.date_of_birth) >= getdate(today()): frappe.throw(_("Date of Birth cannot be greater than today.")) + if self.joining_date and self.date_of_leaving and getdate(self.joining_date) > getdate(self.date_of_leaving): + frappe.throw(_("Joining Date can not be greater than Leaving Date")) + def update_student_name_in_linked_doctype(self): linked_doctypes = get_linked_doctypes("Student") for d in linked_doctypes: diff --git a/erpnext/education/doctype/student_group/student_group.js b/erpnext/education/doctype/student_group/student_group.js index c29c134843e..372e190af90 100644 --- a/erpnext/education/doctype/student_group/student_group.js +++ b/erpnext/education/doctype/student_group/student_group.js @@ -122,3 +122,15 @@ frappe.ui.form.on("Student Group", { } } }); + +frappe.ui.form.on('Student Group Instructor', { + instructors_add: function(frm){ + frm.fields_dict['instructors'].grid.get_field('instructor').get_query = function(doc){ + let instructor_list = []; + $.each(doc.instructors, function(idx, val){ + instructor_list.push(val.instructor); + }); + return { filters: [['Instructor', 'name', 'not in', instructor_list]] }; + }; + } +}); \ No newline at end of file From e57f1c995d1e0c35788eb1b4d437cb5b03d96f04 Mon Sep 17 00:00:00 2001 From: Khushal Trivedi Date: Tue, 24 Dec 2019 14:02:31 +0530 Subject: [PATCH 10/14] fix: date validation on student form, instructor duplicacy fix on student grp, instructor with same employee id fix --- erpnext/education/doctype/student_group/student_group.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/education/doctype/student_group/student_group.js b/erpnext/education/doctype/student_group/student_group.js index 372e190af90..4165ce0f2e7 100644 --- a/erpnext/education/doctype/student_group/student_group.js +++ b/erpnext/education/doctype/student_group/student_group.js @@ -128,7 +128,7 @@ frappe.ui.form.on('Student Group Instructor', { frm.fields_dict['instructors'].grid.get_field('instructor').get_query = function(doc){ let instructor_list = []; $.each(doc.instructors, function(idx, val){ - instructor_list.push(val.instructor); + instructor_list.push(val.instructor); }); return { filters: [['Instructor', 'name', 'not in', instructor_list]] }; }; From 0d9c151d9f61d03e57f815d99158e1b90c9dca5e Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 24 Dec 2019 18:06:49 +0530 Subject: [PATCH 11/14] fix: Exclude current record while validating duplicate employee --- erpnext/education/doctype/instructor/instructor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/education/doctype/instructor/instructor.py b/erpnext/education/doctype/instructor/instructor.py index 058d476f5b6..28df2fcdc11 100644 --- a/erpnext/education/doctype/instructor/instructor.py +++ b/erpnext/education/doctype/instructor/instructor.py @@ -27,7 +27,7 @@ class Instructor(Document): self.validate_duplicate_employee() def validate_duplicate_employee(self): - if self.employee and frappe.db.get_value("Instructor", {'employee': self.employee}, 'name'): + if self.employee and frappe.db.get_value("Instructor", {'employee': self.employee, 'name': ['!=', self.name]}, 'name'): frappe.throw(_("Employee ID is linked with another instructor")) From dc39b4ba130024f7c246e2110bd9b93a29ca8360 Mon Sep 17 00:00:00 2001 From: Khushal Trivedi Date: Sat, 15 Feb 2020 15:38:16 +0530 Subject: [PATCH 12/14] fix: validation on max group strength student group form --- erpnext/education/doctype/student_group/student_group.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/erpnext/education/doctype/student_group/student_group.py b/erpnext/education/doctype/student_group/student_group.py index aa542ddfbfd..9ec94384d58 100644 --- a/erpnext/education/doctype/student_group/student_group.py +++ b/erpnext/education/doctype/student_group/student_group.py @@ -26,6 +26,8 @@ class StudentGroup(Document): frappe.throw(_("Please select Program")) def validate_strength(self): + if self.max_strength < 0: + frappe.throw(_("""Cannot enroll less than 0 students for this student group.""")) if self.max_strength and len(self.students) > self.max_strength: frappe.throw(_("""Cannot enroll more than {0} students for this student group.""").format(self.max_strength)) From 8773dc3ffeee8b3e3d258d0b34a842bd328a88b7 Mon Sep 17 00:00:00 2001 From: Khushal Trivedi Date: Tue, 18 Feb 2020 19:37:21 +0530 Subject: [PATCH 13/14] fix: student max gropu cannot be zero or less than zero --- erpnext/education/doctype/student_group/student_group.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/education/doctype/student_group/student_group.py b/erpnext/education/doctype/student_group/student_group.py index 9ec94384d58..c92c69b6b41 100644 --- a/erpnext/education/doctype/student_group/student_group.py +++ b/erpnext/education/doctype/student_group/student_group.py @@ -26,8 +26,8 @@ class StudentGroup(Document): frappe.throw(_("Please select Program")) def validate_strength(self): - if self.max_strength < 0: - frappe.throw(_("""Cannot enroll less than 0 students for this student group.""")) + if self.max_strength <= 0: + frappe.throw(_("""Cannot enroll less than or equal to 0 students for this student group.""")) if self.max_strength and len(self.students) > self.max_strength: frappe.throw(_("""Cannot enroll more than {0} students for this student group.""").format(self.max_strength)) From a0021969ad4a403443a6103b94ff1e55aae791a6 Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Thu, 20 Feb 2020 13:22:28 +0530 Subject: [PATCH 14/14] fix: Validation message --- erpnext/education/doctype/student_group/student_group.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/education/doctype/student_group/student_group.py b/erpnext/education/doctype/student_group/student_group.py index c92c69b6b41..2925469312d 100644 --- a/erpnext/education/doctype/student_group/student_group.py +++ b/erpnext/education/doctype/student_group/student_group.py @@ -27,7 +27,7 @@ class StudentGroup(Document): def validate_strength(self): if self.max_strength <= 0: - frappe.throw(_("""Cannot enroll less than or equal to 0 students for this student group.""")) + frappe.throw(_("""Max strength must be greater than zero.""")) if self.max_strength and len(self.students) > self.max_strength: frappe.throw(_("""Cannot enroll more than {0} students for this student group.""").format(self.max_strength))