Odoo modules related to events management
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.1 KiB

from odoo import models, fields, api, _
from odoo.tools import is_html_empty
from odoo.exceptions import UserError
class EventEvent(models.Model):
_inherit = "event.event"
description = fields.Html(
compute="_compute_description",
store=True,
readonly=False,
# default="",
)
can_push = fields.Boolean(
"Can push description",
compute="_get_can_push",
)
can_pull = fields.Boolean(
"Can pull description",
compute="_get_can_pull",
)
@api.depends("event_type_id")
def _compute_description(self):
for event in self:
if event.event_type_id and not is_html_empty(
event.event_type_id.description
):
event.description = event.event_type_id.description
# Pull from template
@api.depends("event_type_id", "event_type_id.description")
def _get_can_pull(self):
for event in self:
event_type = event.event_type_id
event.can_pull = event_type and not is_html_empty(event_type.description)
def pull_type_description(self):
self.ensure_one()
if self.can_pull:
self._compute_description()
else:
raise UserError(
_(
"The web description of this event template seems to be empty, you cannot pull it."
)
)
# Push to template
def _get_can_push(self):
for event in self:
event.can_push = event.event_type_id and not is_html_empty(
event.description
)
def push_type_description(self):
if len(self) > 1:
raise UserError(
_(
"You can only push one event web description at once, to prevent bad actions..."
)
)
if self.can_push:
self.event_type_id.write({"description": self.description})
else:
raise UserError(
_(
"The web description of this event seems to be empty, you cannot push it to the template."
)
)