Browse Source

[IMP] event_type_description

16.0
RemiFr82 10 months ago
parent
commit
7529337828
  1. 44
      event_type_description/models/event_event.py
  2. 8
      event_type_description/models/event_type.py
  3. 20
      event_type_description/views/event_event.xml
  4. 14
      event_type_description/views/event_type.xml

44
event_type_description/models/event_event.py

@ -31,15 +31,22 @@ class EventEvent(models.Model):
# Pull from template # Pull from template
@api.depends("event_type_id", "event_type_id.description")
def _get_can_pull(self): def _get_can_pull(self):
for event in self: for event in self:
event_type = event.event_type_id event_type = event.event_type_id
event.can_pull = event_type and not is_html_empty(event_type.description) 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() self.ensure_one()
if self.can_pull: 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 # Push to template
@ -49,33 +56,18 @@ class EventEvent(models.Model):
event.description 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: if self.can_push:
event_type.write({"description": self.description})
self.event_type_id.write({"description": self.description})
else: else:
raise UserError( 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": '<t name="Event default description" t-name="event.event_default_descripton">\n'
# + self.description
# + "\n</t>"
# }
# )
# 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)."
# )
# )

8
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 from odoo.tools.translate import html_translate
@ -10,5 +11,8 @@ class EventType(models.Model):
translate=html_translate, translate=html_translate,
sanitize_attributes=False, sanitize_attributes=False,
sanitize_form=False, sanitize_form=False,
default=lambda self: self.env["event.event"]._default_description(),
default="",
) )
def clear_description(self):
self.write({"description": ""})

20
event_type_description/views/event_event.xml

@ -7,7 +7,7 @@
<field name="inherit_id" ref="event.view_event_form" /> <field name="inherit_id" ref="event.view_event_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="event_type_id" position="after"> <field name="event_type_id" position="after">
<button type="object" name="pull_description_type" colspan="2"
<button type="object" name="pull_type_description" colspan="2"
string="Update this event description from template" string="Update this event description from template"
class="btn-secondary btn-sm" icon="fa-download" class="btn-secondary btn-sm" icon="fa-download"
attrs="{'invisible': [('can_pull','=',False)]}" /> attrs="{'invisible': [('can_pull','=',False)]}" />
@ -15,25 +15,21 @@
<field name="active" position="after"> <field name="active" position="after">
<field name="can_pull" invisible="1" /> <field name="can_pull" invisible="1" />
</field> </field>
<notebook position="inside">
<page name="description" string="Website description">
<field name="description" />
</page>
</notebook>
</field> </field>
</record> </record>
<record id="event_event_action_server_type_description" model="ir.actions.server"> <record id="event_event_action_server_type_description" model="ir.actions.server">
<field name="name">Push Template descritpion</field>
<field name="name">Push template description</field>
<field name="model_id" ref="event.model_event_event" /> <field name="model_id" ref="event.model_event_event" />
<field name="binding_model_id" ref="event.model_event_event" /> <field name="binding_model_id" ref="event.model_event_event" />
<field name="groups_id" eval="[(6, 0, [ref('event.group_event_manager')])]" /> <field name="groups_id" eval="[(6, 0, [ref('event.group_event_manager')])]" />
<field name="state">code</field> <field name="state">code</field>
<field name="code">record.push_description_type()</field>
<field name="code">record.push_type_description()</field>
</record> </record>
<!-- <record id="event_event_action_server_default_description" model="ir.actions.server">
<field name="name">Push Default descritpion</field>
<field name="model_id" ref="event.model_event_event" />
<field name="binding_model_id" ref="event.model_event_event" />
<field name="groups_id" eval="[(6, 0, [ref('event.group_event_manager')])]" />
<field name="state">code</field>
<field name="code">record.push_description_default()</field>
</record> -->
</odoo> </odoo>

14
event_type_description/views/event_type.xml

@ -7,20 +7,20 @@
<field name="inherit_id" ref="event.view_event_type_form" /> <field name="inherit_id" ref="event.view_event_type_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<notebook position="inside"> <notebook position="inside">
<page string="Website description" groups="base.group_no_one">
<field name="description" />
<page string="Website description">
<field name="description" readonly="1" />
</page> </page>
</notebook> </notebook>
</field> </field>
</record> </record>
<!-- <record id="event_type_action_server_default_description" model="ir.actions.server">
<field name="name">Push Default descritpion</field>
<record id="event_type_action_server_type_description" model="ir.actions.server">
<field name="name">Clear template description</field>
<field name="model_id" ref="event.model_event_type" /> <field name="model_id" ref="event.model_event_type" />
<field name="binding_model_id" ref="event.model_event_type" /> <field name="binding_model_id" ref="event.model_event_type" />
<field name="groups_id" eval="[(6, 0, [ref('event.group_event_manager')])]" />
<field name="groups_id" eval="[(6, 0, [ref('event.group_event_manager' )])]" />
<field name="state">code</field> <field name="state">code</field>
<field name="code">record.push_description_default()</field>
</record> -->
<field name="code">records.clear_description()</field>
</record>
</odoo> </odoo>
Loading…
Cancel
Save