Overview
Location:services/sessions.py
This module handles:
- Tattoo session creation and scheduling
- Schedule conflict detection
- Session status management
- Session completion with transaction creation
- Commission calculations
- Session listing and filtering
Session Status Values
Activa
Scheduled and confirmed session
Completada
Finished session with payment recorded
En espera
Tentative or pending confirmation
Cancelada
Cancelled session (includes no-shows)
Payment Methods
Efectivo
Cash payment
Tarjeta
Card payment
Transferencia
Bank transfer
Functions
create_session
Creates a new tattoo session after validating schedule conflicts.Session data dictionary
client_id(int): Client identifierartist_id(int): Artist identifierstart(datetime): Session start timeend(datetime): Session end timeprice(float): Session pricenotes(Optional[str]): Additional notes
int - The ID of the created session
Raises: ValueError - If schedule conflict detected or invalid time range
The function automatically sets the session status to “Activa” upon creation.
update_session
Updates an existing session’s details.ID of the session to update
Dictionary with fields to update
start(datetime): New start timeend(datetime): New end timeprice(float): Updated pricenotes(str): Updated notesstatus(str): New status (except “Completada”)artist_id(int): Reassign to different artistcommission_override(float): Custom commission rate
None
Raises: ValueError - If session not found, invalid status, or schedule conflict
complete_session
Marks a session as complete and creates the associated financial transaction.ID of the session to complete
Payment information dictionary
method(str): Payment method - “Efectivo”, “Tarjeta”, or “Transferencia”
int - The ID of the created transaction
Raises: ValueError - If session not found, already completed, or cancelled
This function automatically calculates the artist’s commission based on their configured rate or a session-specific override.
Commission Calculation
The commission is calculated as follows:- If
commission_overrideis set on the session, use that rate - Otherwise, use the artist’s
rate_commissionfrom their profile - Default to 0.5 (50%) if neither is set
- Commission amount =
session.price * commission_rate
cancel_session
Cancels a session and optionally marks it as a no-show.ID of the session to cancel
Whether to mark this as a client no-show
None
Raises: ValueError - If session not found or already completed
When
as_no_show=True, the function prepends “[No-show]” to the session notes to track client attendance issues.list_sessions
Retrieves sessions with optional filtering.Filter criteria dictionary
from(datetime): Start date filterto(datetime): End date filterartist_id(int): Filter by artiststatus(str | list): Filter by status(es)
list[dict] - List of session dictionaries
Each session dictionary contains:
id(int): Session IDclient_id(int): Client IDartist_id(int): Artist IDstart(datetime): Start timeend(datetime): End timestatus(str): Current statusprice(float): Session pricenotes(str): Notes
Schedule Conflict Detection
The service includes automatic overlap detection to prevent double-booking:Overlap Rules
Two sessions overlap if:Conflict Detection Behavior
- Checks only for the same artist
- Ignores cancelled sessions
- Allows updates to the same session (using
exclude_session_id) - Raises
ValueErrorwith message “Choque de horario” on conflict
Example conflict scenarios
Example conflict scenarios
Existing session: 10:00 - 13:00CONFLICT:
- 09:00 - 11:00 (starts before, ends during)
- 11:00 - 14:00 (starts during, ends after)
- 09:00 - 14:00 (completely overlaps)
- 11:00 - 12:00 (completely inside)
- 08:00 - 10:00 (ends exactly when existing starts)
- 13:00 - 15:00 (starts exactly when existing ends)
- 14:00 - 16:00 (completely after)
Typical Workflows
- New Appointment
- Reschedule
- Complete Session
- No-Show
Best Practices
Session pricing
Session pricing
- Always set the price before completing a session
- If price is not set (None), it defaults to 0.0 on completion
- Consider including deposit information in the notes field
Commission overrides
Commission overrides
- Use
commission_overridefor special pricing arrangements - Values should be between 0.0 and 1.0 (e.g., 0.6 for 60%)
- Override persists if session is updated
Status transitions
Status transitions
Valid transitions:
- “En espera” → “Activa” (confirmation)
- “Activa” → “Completada” (via
complete_session()) - Any → “Cancelada” (via
cancel_session())
- “Completada” → Any other status
- “Cancelada” → “Completada”
Time handling
Time handling
- All datetime objects should be timezone-aware
- Session end time must be after start time
- Consider buffer time between sessions for setup/cleanup
Related
Session Model
TattooSession data model and schema
Transaction Model
Financial transaction tracking
Managing Appointments
User guide for appointment scheduling
Artist Model
Artist data and commission rates