ai*
This commit is contained in:
1
ai_product/models/__init__.py
Normal file
1
ai_product/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import ai_composer
|
||||
29
ai_product/models/ai_composer.py
Normal file
29
ai_product/models/ai_composer.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import json
|
||||
|
||||
from odoo import models
|
||||
from odoo.exceptions import MissingError
|
||||
from odoo.addons.ai.utils.ai_image_tools import retrieve_image_parts_from_path
|
||||
|
||||
|
||||
class AIComposer(models.Model):
|
||||
_inherit = 'ai.composer'
|
||||
|
||||
def _get_initial_context(self, res_model=None, res_id=None, text_selection=None, text_of_editable=None, reference_image_path=None):
|
||||
parts = super()._get_initial_context(res_model, res_id, text_selection, text_of_editable, reference_image_path)
|
||||
if self.interface_key != "chatter_ai_button" or (res_model != 'product.template' and res_model != 'product.product'):
|
||||
return parts
|
||||
|
||||
if not (record := self.env[res_model].browse(res_id)).exists():
|
||||
raise MissingError(self.env._("The record linked to this session has not been found."))
|
||||
|
||||
parts += retrieve_image_parts_from_path(self.env, f'/web/image/{record._name}/{record.id}/image_1024')
|
||||
parts.append({
|
||||
'type': 'text',
|
||||
'text': json.dumps({
|
||||
'product_name': record.name,
|
||||
'product_description': record.description,
|
||||
'product_description_sale': record.description_sale,
|
||||
'product_type': record.type,
|
||||
})
|
||||
})
|
||||
return parts
|
||||
Reference in New Issue
Block a user