RemiFr82
1 year ago
5 changed files with 148 additions and 1 deletions
-
1event_type_description/__manifest__.py
-
81event_type_description/models/event_event.py
-
2event_type_description/models/event_type.py
-
39event_type_description/views/event_event.xml
-
26event_type_description/views/event_type.xml
@ -0,0 +1,81 @@ |
|||
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 |
|||
|
|||
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): |
|||
self.ensure_one() |
|||
if self.can_pull: |
|||
self.write({"description": self.event_type_id.description}) |
|||
|
|||
# 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_description_type(self): |
|||
self.ensure_one() |
|||
event_type = self.event_type_id |
|||
if self.can_push: |
|||
event_type.write({"description": self.description}) |
|||
else: |
|||
raise UserError( |
|||
_( |
|||
"The web description of this event is 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)." |
|||
# ) |
|||
# ) |
@ -0,0 +1,39 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
|
|||
<record id="view_event_form_inherit_event_type_description" model="ir.ui.view"> |
|||
<field name="name">event.event.view.form.inherit</field> |
|||
<field name="model">event.event</field> |
|||
<field name="inherit_id" ref="event.view_event_form" /> |
|||
<field name="arch" type="xml"> |
|||
<field name="event_type_id" position="after"> |
|||
<button type="object" name="pull_description_type" colspan="2" |
|||
string="Update this event description from template" |
|||
class="btn-secondary btn-sm" icon="fa-download" |
|||
attrs="{'invisible': [('can_pull','=',False)]}" /> |
|||
</field> |
|||
<field name="active" position="after"> |
|||
<field name="can_pull" invisible="1" /> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
|
|||
<record id="event_event_action_server_type_description" model="ir.actions.server"> |
|||
<field name="name">Push Template 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_type()</field> |
|||
</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> |
@ -0,0 +1,26 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
|
|||
<record id="view_event_type_form_inherit" model="ir.ui.view"> |
|||
<field name="name">event.type.view.form.inherit</field> |
|||
<field name="model">event.type</field> |
|||
<field name="inherit_id" ref="event.view_event_type_form" /> |
|||
<field name="arch" type="xml"> |
|||
<notebook position="inside"> |
|||
<page string="Website description" groups="base.group_no_one"> |
|||
<field name="description" /> |
|||
</page> |
|||
</notebook> |
|||
</field> |
|||
</record> |
|||
|
|||
<!-- <record id="event_type_action_server_default_description" model="ir.actions.server"> |
|||
<field name="name">Push Default descritpion</field> |
|||
<field name="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="state">code</field> |
|||
<field name="code">record.push_description_default()</field> |
|||
</record> --> |
|||
|
|||
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue