ai*
This commit is contained in:
5
ai_marketing_automation/models/__init__.py
Normal file
5
ai_marketing_automation/models/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import ai_composer
|
||||
from . import ai_session
|
||||
from . import ai_tool
|
||||
27
ai_marketing_automation/models/ai_composer.py
Normal file
27
ai_marketing_automation/models/ai_composer.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class AIComposer(models.Model):
|
||||
_inherit = 'ai.composer'
|
||||
|
||||
interface_key = fields.Selection(
|
||||
selection_add=[
|
||||
("campaign_builder_ai", "Create and edit a marketing campaign"),
|
||||
],
|
||||
ondelete={
|
||||
"campaign_builder_ai": "cascade",
|
||||
},
|
||||
)
|
||||
|
||||
@api.depends("interface_key")
|
||||
def _compute_hide_model_selection(self):
|
||||
super()._compute_hide_model_selection()
|
||||
for rule in self:
|
||||
rule.hide_model_selection = rule.hide_model_selection or rule.interface_key in ['campaign_builder_ai']
|
||||
|
||||
@api.depends("interface_key")
|
||||
def _compute_hide_prompt_button_page(self):
|
||||
super()._compute_hide_prompt_button_page()
|
||||
for rule in self:
|
||||
rule.hide_prompt_button_page = rule.hide_prompt_button_page or rule.interface_key in ['campaign_builder_ai']
|
||||
23
ai_marketing_automation/models/ai_session.py
Normal file
23
ai_marketing_automation/models/ai_session.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models
|
||||
|
||||
CAMPAIGN_BUILDER_TIMEOUT = 180
|
||||
|
||||
|
||||
class AiSession(models.Model):
|
||||
_inherit = 'ai.session'
|
||||
|
||||
def _get_model_round_options(self):
|
||||
completion_options = super()._get_model_round_options()
|
||||
if self._is_campaign_builder_session():
|
||||
completion_options['timeout'] = CAMPAIGN_BUILDER_TIMEOUT
|
||||
return completion_options
|
||||
|
||||
def _run_agentic_loop(self, *args, **kwargs):
|
||||
if self._is_campaign_builder_session():
|
||||
kwargs['timeout'] = CAMPAIGN_BUILDER_TIMEOUT
|
||||
yield from super()._run_agentic_loop(*args, **kwargs)
|
||||
|
||||
def _is_campaign_builder_session(self):
|
||||
return len(self) == 1 and self.ai_composer_id.interface_key == 'campaign_builder_ai'
|
||||
48
ai_marketing_automation/models/ai_tool.py
Normal file
48
ai_marketing_automation/models/ai_tool.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class AITool(models.AbstractModel):
|
||||
_inherit = 'ai.tool'
|
||||
|
||||
@api.model
|
||||
def _sort_campaign_steps(self, campaign_id):
|
||||
campaign = self.env['marketing.campaign'].browse(campaign_id).exists()
|
||||
if not campaign:
|
||||
return {'success': False, 'error': f'No campaign with id {campaign_id}.'}
|
||||
campaign.action_sort_steps()
|
||||
return {'success': True, 'campaign_id': campaign.id}
|
||||
|
||||
@api.model
|
||||
def _is_module_installed(self, module_name):
|
||||
return {
|
||||
'module': module_name,
|
||||
'installed': module_name in self.env['ir.module.module']._installed(),
|
||||
}
|
||||
|
||||
@api.model
|
||||
def _delete_campaign_step(self, activity_id, step_type, cascade_delete=False):
|
||||
"""Remove a step from a campaign, repairing the workflow around it."""
|
||||
activity = self.env['marketing.activity'].browse(activity_id).exists()
|
||||
if not activity:
|
||||
return {'success': False, 'error': f'No marketing activity with id {activity_id}.'}
|
||||
|
||||
campaign = activity.campaign_id
|
||||
activity.action_delete_step(step_type)
|
||||
campaign.action_sort_steps()
|
||||
return {
|
||||
'success': True,
|
||||
'campaign_id': campaign.id,
|
||||
'remaining_activity_ids': campaign.marketing_activity_ids.ids,
|
||||
}
|
||||
|
||||
def _is_base_automation_server_action(self, tool_context):
|
||||
if tool_context.get('res_model') == 'marketing.campaign':
|
||||
return False
|
||||
|
||||
return super()._is_base_automation_server_action(tool_context)
|
||||
|
||||
def _is_automation_skill_required(self, tool_context):
|
||||
if tool_context.get('res_model') == 'marketing.campaign':
|
||||
return False
|
||||
|
||||
return super()._is_base_automation_server_action(tool_context)
|
||||
Reference in New Issue
Block a user