Methods Reference
Public API methods for controlling workflows, generating content, and managing AI operations.
On This Page
Workflow Control
action_start_workflow()
Initiates workflow execution for a project.
Python
def action_start_workflow(self):
"""
Start the AI workflow for this project.
Requires:
- ai_template_id must be set
- ai_state must be 'draft'
Returns:
bool: True if started successfully
Raises:
UserError: If prerequisites not met
"""
# Usage
project = env['project.project'].browse(1)
project.action_start_workflow()
action_next_stage()
Advances the project to the next workflow stage.
Python
def action_next_stage(self):
"""
Move project to the next stage in sequence.
The next stage is determined by:
1. Explicit next_stage_id on current stage
2. Next stage by sequence number
3. Final stage if none remaining
Returns:
ai.project.stage: The new current stage
"""
# Usage
next_stage = project.action_next_stage()
action_pause_workflow()
Pauses workflow execution.
Python
def action_pause_workflow(self):
"""
Pause the workflow execution.
- Sets ai_state to 'paused'
- Preserves current stage position
- Can be resumed with action_resume_workflow()
"""
project.action_pause_workflow()
Content Generation
generate_content(template, context)
Generate content using an AI template.
Python
def generate_content(self, template, context=None):
"""
Generate content using AI provider and template.
Args:
template (ai.template): The prompt template to use
context (dict): Variables for template substitution
Returns:
str: Generated content
Example:
template = env.ref('ai_workflow_website.page_template')
content = project.generate_content(template, {
'page_type': 'about',
'company_name': 'Acme Inc',
})
"""
process_task(task)
Process a single task through AI generation.
Python
def process_task(self, task):
"""
Process a task using the stage's AI template.
Args:
task (project.task): Task to process
Effects:
- Sets task.ai_state to 'processing'
- Calls AI provider
- Stores result in task.ai_content
- Sets task.ai_state to 'done' or 'failed'
Returns:
bool: True if successful
"""
Approval Methods
action_approve_stage()
Approve the current stage and continue.
Python
def action_approve_stage(self):
"""
Approve the current stage content.
Requirements:
- Current stage must have requires_approval=True
- ai_state must be 'approval_pending'
Effects:
- Records approval timestamp
- Advances to next stage
- Continues workflow execution
"""
project.action_approve_stage()
action_request_changes(feedback)
Request changes with feedback for regeneration.
Python
def action_request_changes(self, feedback):
"""
Request changes to the current stage output.
Args:
feedback (str): Instructions for what to change
Effects:
- Stores feedback
- Re-runs the previous AI stage with feedback context
- Returns to approval_pending when complete
"""
project.action_request_changes(
feedback="Make the headline more compelling and add a testimonial section"
)
Utilities
get_workflow_progress()
Get workflow completion percentage.
Python
@api.depends('stage_id', 'ai_template_id')
def _compute_ai_progress(self):
"""
Compute workflow progress as percentage.
Returns:
int: Progress 0-100 based on stage position
"""
# Access via field
progress = project.ai_progress # e.g., 45
get_stage_history()
Get the history of stage transitions.
Python
def get_stage_history(self):
"""
Get chronological list of stage transitions.
Returns:
list: [{
'stage_id': int,
'stage_name': str,
'entered_at': datetime,
'exited_at': datetime,
'duration_seconds': int,
'outcome': 'completed' | 'skipped' | 'failed'
}]
"""
history = project.get_stage_history()