update calendar functionality and holidays
This commit is contained in:
parent
0620060066
commit
7395d3e048
9 changed files with 859 additions and 440 deletions
49
custom_ui/api/db/employees.py
Normal file
49
custom_ui/api/db/employees.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import frappe, json
|
||||
from custom_ui.db_utils import build_success_response, build_error_response
|
||||
# ===============================================================================
|
||||
# EMPLOYEE API METHODS
|
||||
# ===============================================================================
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_employees(company: str, roles=[]):
|
||||
"""Get a list of employees for a given company. Can be filtered by role."""
|
||||
roles = json.loads(roles) if isinstance(roles, str) else roles
|
||||
filters = {"company": company}
|
||||
if roles:
|
||||
filters["designation"] = ["in", roles]
|
||||
try:
|
||||
employee_names = frappe.get_all(
|
||||
"Employee",
|
||||
filters=filters,
|
||||
pluck="name"
|
||||
)
|
||||
employees = [frappe.get_doc("Employee", name).as_dict() for name in employee_names]
|
||||
return build_success_response(employees)
|
||||
except Exception as e:
|
||||
return build_error_response(str(e), 500)
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_employees_organized(company: str, roles=[]):
|
||||
"""Get all employees for a company organized by designation."""
|
||||
roles = json.loads(roles) if isinstance(roles, str) else roles
|
||||
try:
|
||||
filters = {"company": company}
|
||||
if roles:
|
||||
filters["designation"] = ["in", roles]
|
||||
employee_names = frappe.get_all(
|
||||
"Employee",
|
||||
filters=filters,
|
||||
pluck="name"
|
||||
)
|
||||
employees = [frappe.get_doc("Employee", name).as_dict() for name in employee_names]
|
||||
|
||||
organized = {}
|
||||
for emp in employees:
|
||||
designation = emp.get("designation", "Unassigned")
|
||||
if designation not in organized:
|
||||
organized[designation] = []
|
||||
organized[designation].append(emp)
|
||||
|
||||
return build_success_response(organized)
|
||||
except Exception as e:
|
||||
return build_error_response(str(e), 500)
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import frappe, json
|
||||
from frappe.utils.pdf import get_pdf
|
||||
from custom_ui.api.db.general import get_doc_history
|
||||
from custom_ui.db_utils import process_query_conditions, build_datatable_dict, get_count_or_filters, build_success_response, build_error_response
|
||||
from custom_ui.db_utils import DbUtils, process_query_conditions, build_datatable_dict, get_count_or_filters, build_success_response, build_error_response
|
||||
from werkzeug.wrappers import Response
|
||||
from custom_ui.api.db.clients import check_if_customer, convert_lead_to_customer
|
||||
from custom_ui.services import DbService, ClientService, AddressService, ContactService
|
||||
|
|
@ -10,6 +10,12 @@ from custom_ui.services import DbService, ClientService, AddressService, Contact
|
|||
# ESTIMATES & INVOICES API METHODS
|
||||
# ===============================================================================
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_estimate_table_data_v2(filters={}, sortings=[], page=1, page_size=10):
|
||||
"""Get paginated estimate table data with filtering and sorting."""
|
||||
print("DEBUG: Raw estimate options received:", filters, sortings, page, page_size)
|
||||
filters, sortings, page, page_size = DbUtils.process_query_conditions(filters, sortings, page, page_size)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_estimate_table_data(filters={}, sortings=[], page=1, page_size=10):
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import frappe
|
||||
from custom_ui.db_utils import build_history_entries
|
||||
from custom_ui.db_utils import build_history_entries, build_success_response, build_error_response
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
def get_doc_history(doctype, docname):
|
||||
"""Get the history of changes for a specific document."""
|
||||
|
|
@ -56,4 +57,23 @@ def search_any_field(doctype, text):
|
|||
query,
|
||||
[like] * len(conditions),
|
||||
as_dict=True
|
||||
)
|
||||
)
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_week_holidays(week_start_date: str):
|
||||
"""Get holidays within a week starting from the given date."""
|
||||
|
||||
start_date = datetime.strptime(week_start_date, "%Y-%m-%d").date()
|
||||
end_date = start_date + timedelta(days=6)
|
||||
|
||||
holidays = frappe.get_all(
|
||||
"Holiday",
|
||||
filters={
|
||||
"holiday_date": ["between", (start_date, end_date)]
|
||||
},
|
||||
fields=["holiday_date", "description"],
|
||||
order_by="holiday_date asc"
|
||||
)
|
||||
|
||||
print(f"DEBUG: Retrieved holidays from {start_date} to {end_date}: {holidays}")
|
||||
return build_success_response(holidays)
|
||||
Loading…
Add table
Add a link
Reference in a new issue