Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions beveren_fsm/field_service_management/api/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@
import frappe


@frappe.whitelist()
def get_unassigned_service_orders(limit=50):
filters = {"docstatus": 1}
assigned_orders = frappe.get_all(
"Service Appointment",
filters={"service_order": ["is", "set"], "docstatus": ["!=", 2]},
pluck="service_order",
limit_page_length=0,
)
if assigned_orders:
filters["name"] = ["not in", assigned_orders]

orders = frappe.get_all(
"Service Order",
fields=["name", "customer", "priority", "posting_date", "status", "type"],
filters=filters,
order_by="posting_date desc",
limit_page_length=limit,
)
return orders


@frappe.whitelist()
def create_appointment_from_api(
posting_date,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_appointments(
"Service Appointment",
filters=filters,
fields=requested_fields,
order_by="scheduled_start_datetime asc",
order_by="scheduled_start_datetime desc",
limit_page_length=limit_page_length if limit_page_length > 0 else None,
)

Expand Down
77 changes: 77 additions & 0 deletions beveren_fsm/field_service_management/api/service_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import frappe
from frappe.utils import getdate


@frappe.whitelist()
def get_service_requests(
status=None,
start_date=None,
end_date=None,
search=None,
limit_page_length: int | None = 50,
):
filters = {"docstatus": ["!=", 2]}

if status and status != "all":
filters["status"] = status

if start_date and end_date:
filters["posting_date"] = ["between", [getdate(start_date), getdate(end_date)]]
elif start_date:
filters["posting_date"] = [">=", getdate(start_date)]
elif end_date:
filters["posting_date"] = ["<=", getdate(end_date)]

or_filters = []
if search:
search_term = f"%{search.strip()}%"
or_filters = [
["Service Request", "name", "like", search_term],
["Service Request", "customer", "like", search_term],
["Service Request", "serial_no", "like", search_term],
["Service Request", "item_code", "like", search_term],
]

fields = [
"name",
"subject",
"customer",
"status",
"posting_date",
"due_date",
"serial_no",
"item_code",
"item_name",
"current_product_location",
"description",
]

limit = int(limit_page_length) if limit_page_length else None

requests = frappe.get_all(
"Service Request",
filters=filters,
or_filters=or_filters,
fields=fields,
order_by="posting_date desc",
limit_page_length=limit,
)

results = []
for req in requests:
doc = frappe.get_doc("Service Request", req.name)
req["product_movement"] = [
{
"name": movement.name,
"movement_type": movement.movement_type,
"destination": movement.destination,
"movement_date": movement.movement_date,
"linked_document_type": movement.linked_document_type,
"linked_document": movement.linked_document,
"handled_by": movement.handled_by,
}
for movement in doc.product_movement
]
results.append(req)

return results
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@
"fetch_from": "movement_type.destination",
"fieldname": "destination",
"fieldtype": "Data",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Destination"
}
],
"grid_page_length": 50,
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2025-11-12 04:12:53.341700",
"modified": "2025-11-17 04:21:43.163670",
"modified_by": "Administrator",
"module": "Field Service Management",
"name": "Product Movement",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,8 @@
{
"fieldname": "service_total",
"fieldtype": "Currency",
"label": "Service Total"
"label": "Service Total",
"read_only": 1
},
{
"default": "0",
Expand All @@ -796,7 +797,8 @@
{
"fieldname": "spareparts_total",
"fieldtype": "Currency",
"label": "SpareParts Total"
"label": "SpareParts Total",
"read_only": 1
},
{
"allow_on_submit": 1,
Expand All @@ -819,7 +821,7 @@
"link_fieldname": "custom_reference_service_document"
}
],
"modified": "2025-11-12 03:31:42.698792",
"modified": "2025-11-17 04:08:15.600873",
"modified_by": "Administrator",
"module": "Field Service Management",
"name": "Service Order",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from frappe.utils import flt, today

LOCATION_STATUS_MAP = {
"delivered to customer": "Completed",
"deliver to customer": "Completed", # fallback for legacy value
"delivered to customer": "Review",
"deliver to customer": "Review", # fallback for legacy value
"receive from vendor": "In Progress",
"receive from customer": "In Progress",
"received from customer": "In Progress",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
"label": "Warranty Expiry Date"
},
{
"depends_on": "amc_contract",
"fetch_from": "serial_no.amc_expiry_date",
"fetch_if_empty": 1,
"fieldname": "amc_expiry_date",
Expand All @@ -335,6 +336,7 @@
"fieldname": "repair_vendor",
"fieldtype": "Link",
"label": "Repair Vendor",
"no_copy": 1,
"options": "Supplier"
},
{
Expand All @@ -343,6 +345,7 @@
"fieldname": "current_product_location",
"fieldtype": "Link",
"label": "Current Product Location",
"no_copy": 1,
"options": "Product Location"
},
{
Expand All @@ -355,6 +358,7 @@
"fieldname": "product_movement",
"fieldtype": "Table",
"label": "Product Movement",
"no_copy": 1,
"options": "Product Movement",
"read_only": 1
}
Expand All @@ -371,7 +375,7 @@
"link_fieldname": "service_request"
}
],
"modified": "2025-11-17 03:13:18.909917",
"modified": "2025-11-17 04:17:34.797562",
"modified_by": "Administrator",
"module": "Field Service Management",
"name": "Service Request",
Expand Down
Empty file.

This file was deleted.

Loading