58 lines
No EOL
2.5 KiB
Python
58 lines
No EOL
2.5 KiB
Python
import frappe
|
|
from custom_ui.services import AddressService, ClientService
|
|
from datetime import timedelta
|
|
|
|
def after_insert(doc, method):
|
|
print("DEBUG: After Insert Triggered for Project")
|
|
print("DEBUG: Linking Project to address and Customer")
|
|
AddressService.append_link_v2(
|
|
doc.job_address, "projects", {"project": doc.name, "project_template": doc.project_template}
|
|
)
|
|
AddressService.append_link_v2(
|
|
doc.job_address, "links", {"link_doctype": "Project", "link_name": doc.name}
|
|
)
|
|
ClientService.append_link_v2(
|
|
doc.customer, "projects", {"project": doc.name, "project_template": doc.project_template}
|
|
)
|
|
if doc.project_template == "SNW Install":
|
|
print("DEBUG: Project template is SNW Install, updating Address status to In Progress")
|
|
AddressService.update_value(
|
|
doc.job_address,
|
|
"job_status",
|
|
"In Progress"
|
|
)
|
|
|
|
|
|
def before_insert(doc, method):
|
|
# This is where we will add logic to set tasks and other properties of a job based on it's project_template
|
|
pass
|
|
|
|
def before_save(doc, method):
|
|
print("DEBUG: Before Save Triggered for Project:", doc.name)
|
|
if doc.expected_start_date and doc.expected_end_date:
|
|
print("DEBUG: Project has expected start and end dates, marking as scheduled")
|
|
doc.is_scheduled = 1
|
|
while frappe.db.exists("Holiday", {"holiday_date": doc.expected_end_date}):
|
|
print("DEBUG: Expected end date falls on a holiday, extending end date by 1 day")
|
|
doc.expected_end_date += timedelta(days=1)
|
|
elif not doc.expected_start_date or not doc.expected_end_date:
|
|
print("DEBUG: Project missing expected start or end date, marking as unscheduled")
|
|
doc.is_scheduled = 0
|
|
|
|
def after_save(doc, method):
|
|
print("DEBUG: After Save Triggered for Project:", doc.name)
|
|
if doc.project_template == "SNW Install":
|
|
print("DEBUG: Project template is SNW Install, updating Address Job Status based on Project status")
|
|
status_mapping = {
|
|
"Open": "In Progress",
|
|
"Completed": "Completed",
|
|
"Closed": "Completed"
|
|
}
|
|
new_status = status_mapping.get(doc.status, "In Progress")
|
|
if frappe.db.get_value("Address", doc.job_address, "job_status") != new_status:
|
|
print("DEBUG: Updating Address job_status to:", new_status)
|
|
AddressService.update_value(
|
|
doc.job_address,
|
|
"job_status",
|
|
new_status
|
|
) |