From 7529337828dc96ad8aa75352b1269a8658191835 Mon Sep 17 00:00:00 2001 From: RemiFr82 Date: Sun, 14 Jan 2024 13:41:03 +0100 Subject: [PATCH] [IMP] event_type_description --- event_type_description/models/event_event.py | 44 ++++++++------------ event_type_description/models/event_type.py | 8 +++- event_type_description/views/event_event.xml | 20 ++++----- event_type_description/views/event_type.xml | 14 +++---- 4 files changed, 39 insertions(+), 47 deletions(-) diff --git a/event_type_description/models/event_event.py b/event_type_description/models/event_event.py index dceca97..d4b445f 100644 --- a/event_type_description/models/event_event.py +++ b/event_type_description/models/event_event.py @@ -31,15 +31,22 @@ class EventEvent(models.Model): # 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_description_type(self): + def pull_type_description(self): self.ensure_one() if self.can_pull: - self.write({"description": self.event_type_id.description}) + self._compute_description() + else: + raise UserError( + _( + "The web description of this event template seems to be empty, you cannot pull it." + ) + ) # Push to template @@ -49,33 +56,18 @@ class EventEvent(models.Model): event.description ) - def push_description_type(self): - self.ensure_one() - event_type = self.event_type_id + 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: - event_type.write({"description": self.description}) + self.event_type_id.write({"description": self.description}) else: raise UserError( _( - "The web description of this event is empty, you cannot push it to the template." + "The web description of this event seems to be empty, you cannot push it to the template." ) ) - - # Push to source - - # def push_description_default(self): - # self.ensure_one() - # if not is_html_empty(self.description): - # self.env.ref("event.event_default_descripton").write( - # { - # "arch_base": '\n' - # + self.description - # + "\n" - # } - # ) - # else: - # raise UserError( - # _( - # "The web description of this event is empty, you cannot push it as the new default description value (for new events and templates)." - # ) - # ) diff --git a/event_type_description/models/event_type.py b/event_type_description/models/event_type.py index d9163fb..43f4be4 100644 --- a/event_type_description/models/event_type.py +++ b/event_type_description/models/event_type.py @@ -1,4 +1,5 @@ -from odoo import models, fields, _ +from odoo import models, fields +from odoo.tools import is_html_empty from odoo.tools.translate import html_translate @@ -10,5 +11,8 @@ class EventType(models.Model): translate=html_translate, sanitize_attributes=False, sanitize_form=False, - default=lambda self: self.env["event.event"]._default_description(), + default="", ) + + def clear_description(self): + self.write({"description": ""}) diff --git a/event_type_description/views/event_event.xml b/event_type_description/views/event_event.xml index 4d03b79..d6f1391 100644 --- a/event_type_description/views/event_event.xml +++ b/event_type_description/views/event_event.xml @@ -7,7 +7,7 @@ -