I have an Appointment doctype where i need to verify if the Seller already has an appointment when trying to add another one for the same seller, but i have no idea how to do that. I am using a appointment_calendar.js and a appointment.py files.
appointment_calendar.js
frappe.views.calendar["Appointment"] = {
field_map: {
start: "start_date",
end: "end_date",
id: "name",
allDay: 0,
title: "client_name",
status: "status",
},
order_by: "start_date",
get_events_method: "scheduling_system.scheduling_system.doctype.appointment.appointment.get_appointments"};
appointment.py:
from frappe.model.document import Document
from datetime import datetime, timedelta
from frappe.utils import get_datetime
import frappe
class Appointment(Document):
pass
@frappe.whitelist()
def get_appointments(start, end):
appointments = frappe.get_all(
"Appointment",
filters={"start_date": ["between", [start, end]]},
fields=["name", "start_date", "duration", "client_name", "status"]
)
for app in appointments:
if not app["start_date"]:
continue # Pula registros inválidos
if isinstance(app["start_date"], str):
start_date = datetime.strptime(app["start_date"], "%Y-%m-%d %H:%M:%S")
else:
start_date = app["start_date"]
duration = app.get("duration", "00:00:00") # Evita erro caso `duration` seja None
if isinstance(duration, str):
h, m, s = map(int, duration.split(":"))
duration = timedelta(hours=h, minutes=m, seconds=s)
end_date = start_date + duration
app["start_date"] = start_date.strftime("%Y-%m-%d %H:%M:%S")
app["end_date"] = end_date.strftime("%Y-%m-%d %H:%M:%S")
return appointments
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745212574a4616931.html
评论列表(0条)