Skip to content

Commit

Permalink
feat(Appointment): Duplicate appointment against serial no validation
Browse files Browse the repository at this point in the history
  • Loading branch information
SaiFi0102 authored and ebbad18 committed Jun 27, 2024
1 parent c3208e2 commit 2de6435
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
55 changes: 55 additions & 0 deletions erpnext/fixtures/custom_field.json
Original file line number Diff line number Diff line change
Expand Up @@ -2198,5 +2198,60 @@
"translatable": 0,
"unique": 0,
"width": null
},
{
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"collapsible_depends_on": null,
"columns": 0,
"creation": "2024-06-12 18:08:40.448672",
"default": null,
"depends_on": null,
"description": null,
"docstatus": 0,
"doctype": "Custom Field",
"dt": "Appointment Type",
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "validate_duplicate_appointment",
"fieldtype": "Check",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_preview": 0,
"in_standard_filter": 0,
"insert_after": "auto_assign_agent",
"is_system_generated": 1,
"is_virtual": 0,
"label": "Validate Duplicate Appointment against Serial/Vehicle",
"length": 0,
"mandatory_depends_on": null,
"modified": "2024-06-16 21:12:01.448504",
"module": null,
"name": "Appointment Type-validate_duplicate_appointment",
"no_copy": 0,
"non_negative": 0,
"options": null,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": null,
"read_only": 0,
"read_only_depends_on": null,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"sort_options": 0,
"translatable": 0,
"unique": 0,
"width": null
}
]
1 change: 1 addition & 0 deletions erpnext/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"Appointment-applies_to_item_name",
"Appointment-project_template",
"Appointment-project_template_name",
"Appointment Type-validate_duplicate_appointment",

"Customer Feedback-applies_to_variant_of",
"Customer Feedback-applies_to_variant_of_name",
Expand Down
24 changes: 24 additions & 0 deletions erpnext/overrides/appointment/appointment_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def onload(self):
self.get('applies_to_vehicle')
))

def validate(self):
self.validate_duplicate_appointment()
super().validate()

@classmethod
def get_allowed_party_types(cls):
return super().get_allowed_party_types() + ["Customer"]
Expand All @@ -36,6 +40,26 @@ def set_missing_values_after_submit(self):
super().set_missing_values_after_submit()
self.set_applies_to_details()

def validate_duplicate_appointment(self):
if not frappe.get_cached_value("Appointment Type", self.appointment_type, "validate_duplicate_appointment"):
return

existing_appointment = frappe.db.get_value("Appointment", {
'scheduled_date': self.scheduled_date,
'appointment_type': self.appointment_type,
'applies_to_serial_no': self.applies_to_serial_no,
'docstatus': ['=', 1],
'name': ['!=', self.name]
})
if existing_appointment:
frappe.throw(_("{0} {1} already scheduled for {2} against {3} {4}").format(
self.appointment_type,
frappe.get_desk_link("Appointment", existing_appointment),
self.get_formatted("scheduled_date"),
_("Vehicle") if self.applies_to_vehicle else _("Serial No"),
self.applies_to_serial_no,
))

def validate_next_document_on_cancel(self):
super().validate_next_document_on_cancel()
project = self.get_linked_project()
Expand Down

0 comments on commit 2de6435

Please sign in to comment.