Make Autotask resolve messages dynamic based on time entries
The resolve confirmation dialog and ticket notes now correctly indicate whether the ticket will be closed or remain open based on time entry check. Changes: - Frontend: Updated confirmation message to explain conditional closure - Backend: Check time entries before creating note - Dynamic message in ticket note: * "ticket will be closed in Autotask" (no time entries) * "ticket remains open in Autotask due to existing time entries" (has time entries) - Updated route docstring to reflect conditional status behaviour Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
237ae4f431
commit
cc76068206
@ -1814,8 +1814,12 @@ def api_run_checks_autotask_link_existing_ticket():
|
||||
def api_run_checks_autotask_resolve_note():
|
||||
"""Post a user-visible 'should be resolved' update to an existing Autotask ticket.
|
||||
|
||||
This step does NOT close the ticket in Autotask.
|
||||
Status update behaviour (per API contract section 9):
|
||||
- If NO time entries exist: ticket is closed (status 5 = Complete)
|
||||
- If time entries exist: ticket remains open
|
||||
|
||||
Primary behaviour: create a Ticket note via POST /Tickets/{id}/Notes so the message is clearly visible.
|
||||
Then updates the ticket resolution field which triggers the conditional status update.
|
||||
Fallback behaviour: if TicketNote create is not supported (HTTP 404), append the marker text
|
||||
to the Ticket description via PUT /Tickets and verify persistence.
|
||||
"""
|
||||
@ -1847,6 +1851,19 @@ def api_run_checks_autotask_resolve_note():
|
||||
if ticket_id <= 0:
|
||||
return jsonify({"status": "error", "message": "Run has an invalid Autotask ticket id."}), 400
|
||||
|
||||
try:
|
||||
client = _build_autotask_client_from_settings()
|
||||
except Exception as exc:
|
||||
return jsonify({"status": "error", "message": f"Autotask client setup failed: {exc}"}), 400
|
||||
|
||||
# Check for time entries to determine ticket closure status
|
||||
# Per API contract section 9: ticket closes only if no time entries exist
|
||||
try:
|
||||
time_entries = client.query_time_entries_by_ticket_id(ticket_id)
|
||||
has_time_entries = len(time_entries) > 0
|
||||
except Exception:
|
||||
has_time_entries = False # Assume no time entries if query fails
|
||||
|
||||
tz_name = _get_ui_timezone_name()
|
||||
tz = _get_ui_timezone()
|
||||
now_utc = datetime.utcnow().replace(tzinfo=timezone.utc)
|
||||
@ -1855,19 +1872,20 @@ def api_run_checks_autotask_resolve_note():
|
||||
actor = (getattr(current_user, "email", None) or getattr(current_user, "username", None) or "operator")
|
||||
ticket_number = str(getattr(run, "autotask_ticket_number", "") or "").strip()
|
||||
|
||||
# Build dynamic message based on time entry check
|
||||
marker = "[Backupchecks] Marked as resolved in Backupchecks"
|
||||
if has_time_entries:
|
||||
status_note = "(ticket remains open in Autotask due to existing time entries)"
|
||||
else:
|
||||
status_note = "(ticket will be closed in Autotask)"
|
||||
|
||||
body = (
|
||||
f"{marker} (ticket remains open in Autotask).\n"
|
||||
f"{marker} {status_note}.\n"
|
||||
f"Time: {now} ({tz_name})\n"
|
||||
f"By: {actor}\n"
|
||||
+ (f"Ticket: {ticket_number}\n" if ticket_number else "")
|
||||
)
|
||||
|
||||
try:
|
||||
client = _build_autotask_client_from_settings()
|
||||
except Exception as exc:
|
||||
return jsonify({"status": "error", "message": f"Autotask client setup failed: {exc}"}), 400
|
||||
|
||||
# 1) Preferred: create an explicit TicketNote (user-visible update)
|
||||
try:
|
||||
note_payload = {
|
||||
|
||||
@ -1191,7 +1191,7 @@ table.addEventListener('change', function (e) {
|
||||
btnAutotaskResolveNote.addEventListener('click', function () {
|
||||
if (!currentRunId) { alert('Select a run first.'); return; }
|
||||
clearStatus();
|
||||
if (!confirm('Add an update to the existing Autotask ticket that it should be resolved?\n\nThis will NOT close the ticket in Autotask.')) return;
|
||||
if (!confirm('Add an update to the existing Autotask ticket that it should be resolved?\n\nThe ticket will be closed (status Complete) if there are no time entries.\nIf time entries exist, the ticket will remain open.')) return;
|
||||
if (atStatus) atStatus.textContent = 'Posting update...';
|
||||
btnAutotaskResolveNote.disabled = true;
|
||||
apiJson('/api/run-checks/autotask-resolve-note', {
|
||||
|
||||
@ -4,6 +4,14 @@ This file documents all changes made to this project via Claude Code.
|
||||
|
||||
## [2026-02-05]
|
||||
|
||||
### Changed
|
||||
- Autotask resolve confirmation and note messages now correctly indicate ticket closure status:
|
||||
- Frontend confirmation dialog explains conditional closure based on time entries
|
||||
- Backend route checks time entries before creating note and generates dynamic message:
|
||||
- "ticket will be closed in Autotask" when no time entries exist
|
||||
- "ticket remains open in Autotask due to existing time entries" when time entries exist
|
||||
- Route docstring updated to reflect conditional status update behaviour
|
||||
|
||||
### Added
|
||||
- Autotask conditional ticket status update based on time entries (API contract section 9):
|
||||
- `query_time_entries_by_ticket_id()` - Query time entries for a ticket via POST /TimeEntries/query
|
||||
|
||||
Loading…
Reference in New Issue
Block a user