Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] event: access issue for event admin to event templates #117089

Draft
wants to merge 1 commit into
base: 15.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions addons/event/models/event_mail.py
Expand Up @@ -11,6 +11,8 @@
from odoo import api, fields, models, tools
from odoo.tools import exception_to_unicode
from odoo.tools.translate import _
from odoo.exceptions import UserError


_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -67,6 +69,19 @@ def _prepare_event_mail_values(self):
'template_ref': '%s,%i' % (self.template_ref._name, self.template_ref.id)
}

@api.onchange('notification_type')
def set_template_ref_model(self):
notification_model = self.template_model_id.model
Copy link
Author

@joanna350 joanna350 Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, tested this to work..do correct me if I'm wrong

model = self.env[notification_model]
try:
model.search_count([('model', '=', 'event.registration')])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nle-odoo if you agree this is better than hardcoded parts in previous PRs, will update on the newly raised PRs

exists = model.search([('model', '=', 'event.registration')], limit=1)
if exists:
self.template_ref = "{},{}".format(notification_model, exists.id)
except:
raise UserError(
_("There is no template data relevant to the notification type."))


class EventMailScheduler(models.Model):
""" Event automated mailing. This model replaces all existing fields and
Expand Down
2 changes: 1 addition & 1 deletion addons/event/views/event_views.xml
Expand Up @@ -55,7 +55,7 @@
<tree string="Communication" editable="bottom">
<field name="notification_type"/>
<field name="template_model_id" invisible="1"/>
<field name="template_ref" options="{'model_field': 'template_model_id', 'no_quick_create': True}" context="{'filter_template_on_event': True, 'default_model': 'event.registration'}"/>
<field name="template_ref" options="{'hide_model': True, 'no_quick_create': True}" context="{'filter_template_on_event': True, 'default_model': 'event.registration'}"/>
<field name="interval_nbr" attrs="{'readonly':[('interval_unit', '=', 'now')]}"/>
<field name="interval_unit"/>
<field name="interval_type"/>
Expand Down