update calendar
This commit is contained in:
parent
7395d3e048
commit
e67805c01f
10 changed files with 848 additions and 325 deletions
|
|
@ -404,7 +404,7 @@ def upsert_estimate(data):
|
|||
# estimate.custom_job_address = data.get("address_name")
|
||||
# estimate.party_name = data.get("customer")
|
||||
# estimate.contact_person = data.get("contact_name")
|
||||
estimate.custom_requires_half_payment = data.get("requires_half_payment", 0)
|
||||
estimate.requires_half_payment = data.get("requires_half_payment", 0)
|
||||
estimate.custom_project_template = project_template
|
||||
estimate.custom_quotation_template = data.get("quotation_template", None)
|
||||
# estimate.company = data.get("company")
|
||||
|
|
@ -427,6 +427,7 @@ def upsert_estimate(data):
|
|||
})
|
||||
|
||||
estimate.save()
|
||||
frappe.db.commit()
|
||||
estimate_dict = estimate.as_dict()
|
||||
estimate_dict["history"] = get_doc_history("Quotation", estimate_name)
|
||||
print(f"DEBUG: Estimate updated: {estimate.name}")
|
||||
|
|
@ -444,7 +445,7 @@ def upsert_estimate(data):
|
|||
# print("DEBUG: No billing address found for client:", client_doc.name)
|
||||
new_estimate = frappe.get_doc({
|
||||
"doctype": "Quotation",
|
||||
"custom_requires_half_payment": data.get("requires_half_payment", 0),
|
||||
"requires_half_payment": data.get("requires_half_payment", 0),
|
||||
"custom_job_address": data.get("address_name"),
|
||||
"custom_current_status": "Draft",
|
||||
"contact_email": data.get("contact_email"),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import frappe, json
|
||||
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.services import AddressService, ClientService
|
||||
from frappe.utils import getdate
|
||||
|
||||
# ===============================================================================
|
||||
# JOB MANAGEMENT API METHODS
|
||||
|
|
@ -177,21 +178,26 @@ def upsert_job(data):
|
|||
return {"status": "error", "message": str(e)}
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_projects_for_calendar(date, company=None, project_templates=[]):
|
||||
def get_projects_for_calendar(start_date, end_date, company=None, project_templates=[]):
|
||||
"""Get install projects for the calendar."""
|
||||
# Parse project_templates if it's a JSON string
|
||||
if isinstance(project_templates, str):
|
||||
project_templates = json.loads(project_templates)
|
||||
|
||||
# put some emojis in the print to make it stand out
|
||||
print("📅📅📅", date, "company:", company, "project_templates:", project_templates, "type:", type(project_templates))
|
||||
print("📅📅📅", start_date, end_date, " company:", company, "project_templates:", project_templates, "type:", type(project_templates))
|
||||
try:
|
||||
filters = {"company": company} if company else {}
|
||||
filters = {
|
||||
"company": company
|
||||
} if company else {}
|
||||
if project_templates and len(project_templates) > 0:
|
||||
filters["project_template"] = ["in", project_templates]
|
||||
unscheduled_filters = filters.copy()
|
||||
unscheduled_filters["is_scheduled"] = 0
|
||||
filters["expected_start_date"] = date
|
||||
|
||||
# add to filter for if expected_start_date is between start_date and end_date OR expected_end_date is between start_date and end_date
|
||||
filters["expected_start_date"] = ["<=", getdate(end_date)]
|
||||
filters["expected_end_date"] = [">=", getdate(start_date)]
|
||||
# If date range provided, we could filter, but for now let's fetch all open/active ones
|
||||
# or maybe filter by status not Closed/Completed if we want active ones.
|
||||
# The user said "unscheduled" are those with status "Open" (and no date).
|
||||
|
|
@ -206,3 +212,22 @@ def get_projects_for_calendar(date, company=None, project_templates=[]):
|
|||
return build_success_response({ "projects": projects, "unscheduled_projects": unscheduled_projects })
|
||||
except Exception as e:
|
||||
return build_error_response(str(e), 500)
|
||||
|
||||
@frappe.whitelist()
|
||||
def update_job_scheduled_dates(job_name: str, new_start_date: str = None, new_end_date: str = None, foreman_name: str = None):
|
||||
"""Update job (project) schedule dates."""
|
||||
print("DEBUG: Updating job schedule:", job_name, new_start_date, new_end_date, foreman_name)
|
||||
try:
|
||||
project = frappe.get_doc("Project", job_name)
|
||||
project.expected_start_date = getdate(new_start_date) if new_start_date else None
|
||||
project.expected_end_date = getdate(new_end_date) if new_end_date else None
|
||||
if new_start_date and new_end_date:
|
||||
project.is_scheduled = 1
|
||||
else:
|
||||
project.is_scheduled = 0
|
||||
if foreman_name:
|
||||
project.custom_foreman = foreman_name
|
||||
project.save()
|
||||
return build_success_response(project.as_dict())
|
||||
except Exception as e:
|
||||
return build_error_response(str(e), 500)
|
||||
Loading…
Add table
Add a link
Reference in a new issue