From 2bb22f5e72afd0b77e417d7104bed7591e0602c7 Mon Sep 17 00:00:00 2001 From: Landry Date: Mon, 3 Jun 2024 22:29:46 +0000 Subject: [PATCH] Service Appointment Doctype Created --- .../doctype/service_appointment/__init__.py | 0 .../service_appointment.js | 8 +++ .../service_appointment.json | 72 +++++++++++++++++++ .../service_appointment.py | 58 +++++++++++++++ .../test_service_appointment.py | 9 +++ 5 files changed, 147 insertions(+) create mode 100644 erpnext/crm/doctype/service_appointment/__init__.py create mode 100644 erpnext/crm/doctype/service_appointment/service_appointment.js create mode 100644 erpnext/crm/doctype/service_appointment/service_appointment.json create mode 100644 erpnext/crm/doctype/service_appointment/service_appointment.py create mode 100644 erpnext/crm/doctype/service_appointment/test_service_appointment.py diff --git a/erpnext/crm/doctype/service_appointment/__init__.py b/erpnext/crm/doctype/service_appointment/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/crm/doctype/service_appointment/service_appointment.js b/erpnext/crm/doctype/service_appointment/service_appointment.js new file mode 100644 index 0000000000..c1e831ed01 --- /dev/null +++ b/erpnext/crm/doctype/service_appointment/service_appointment.js @@ -0,0 +1,8 @@ +// Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +// frappe.ui.form.on("Service Appointment", { +// refresh(frm) { + +// }, +// }); diff --git a/erpnext/crm/doctype/service_appointment/service_appointment.json b/erpnext/crm/doctype/service_appointment/service_appointment.json new file mode 100644 index 0000000000..6a7fd845e9 --- /dev/null +++ b/erpnext/crm/doctype/service_appointment/service_appointment.json @@ -0,0 +1,72 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2024-06-03 01:56:46.671951", + "doctype": "DocType", + "engine": "InnoDB", + "field_order": [ + "section_break_toee", + "contact", + "appointment_date", + "appointment_time", + "service_details", + "status" + ], + "fields": [ + { + "fieldname": "section_break_toee", + "fieldtype": "Section Break" + }, + { + "fieldname": "appointment_date", + "fieldtype": "Date", + "label": "Appointment Date" + }, + { + "fieldname": "appointment_time", + "fieldtype": "Time", + "label": "Appointment Time" + }, + { + "fieldname": "service_details", + "fieldtype": "Long Text", + "label": "Service Details" + }, + { + "fieldname": "status", + "fieldtype": "Select", + "label": "Status", + "options": "Scheduled\nConfirmed\nDeclined" + }, + { + "fieldname": "contact", + "fieldtype": "Link", + "label": "Contact", + "options": "Contact" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2024-06-03 02:13:09.746413", + "modified_by": "Administrator", + "module": "CRM", + "name": "Service Appointment", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "states": [] +} \ No newline at end of file diff --git a/erpnext/crm/doctype/service_appointment/service_appointment.py b/erpnext/crm/doctype/service_appointment/service_appointment.py new file mode 100644 index 0000000000..b9bbf71842 --- /dev/null +++ b/erpnext/crm/doctype/service_appointment/service_appointment.py @@ -0,0 +1,58 @@ +# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +# import frappe +import frappe +from frappe.utils import add_days, nowdate +from frappe.model.document import Document + + +class ServiceAppointment(Document): + # begin: auto-generated types + # This code is auto-generated. Do not modify anything in this block. + + from typing import TYPE_CHECKING + + if TYPE_CHECKING: + from frappe.types import DF + + appointment_date: DF.Date | None + appointment_time: DF.Time | None + contact: DF.Link | None + service_details: DF.LongText | None + status: DF.Literal["Scheduled", "Confirmed", "Declined"] + # end: auto-generated types + pass + +@frappe.whitelist() +def create_service_appointments(appointment_date, appointment_time, service_details): + # Get all contacts + contacts = frappe.get_all('Contact') + + # Loop through contacts + for contact in contacts: + # Fetch contact document + contact_doc = frappe.get_doc('Contact', contact.name) + + # Generate a human-readable name + appointment_name = f"{contact_doc.first_name} {contact_doc.last_name} - {appointment_date} {appointment_time}" + + # Determine appointment date and time + appointment_date = add_days(nowdate(), 30) # Example: appointment set 30 days from now + appointment_time = '10:00:00' # Example time + + # Create a new Service Appointment document + new_appointment = frappe.get_doc({ + 'doctype': 'Service Appointment', + 'contact': contact_doc.name, + 'appointment_date': appointment_date, + 'appointment_time': appointment_time, + 'service_details': service_details, + 'status': 'Scheduled' + }) + + # Insert the new document into the database + new_appointment.insert() + + # Commit the transaction + frappe.db.commit() \ No newline at end of file diff --git a/erpnext/crm/doctype/service_appointment/test_service_appointment.py b/erpnext/crm/doctype/service_appointment/test_service_appointment.py new file mode 100644 index 0000000000..8ff97ebc87 --- /dev/null +++ b/erpnext/crm/doctype/service_appointment/test_service_appointment.py @@ -0,0 +1,9 @@ +# Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt + +# import frappe +from frappe.tests.utils import FrappeTestCase + + +class TestServiceAppointment(FrappeTestCase): + pass