Odoo modules related to surveys
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.

46 lines
1.6 KiB

from odoo import models, fields, api, _
from odoo.exceptions import UserError
class SurveySurvey(models.Model):
_inherit = 'survey.survey'
is_template = fields.Boolean(string="Is a template", default=False, copy=False)
@api.multi
def copy_data(self, default=None):
data = super(SurveySurvey, self).copy_data(default)[0]
title = isinstance(default, dict) and default.get('title', False) or False
if title:
data['title'] = title
elif _(" (Template)") in data['title']:
data['title'] = data['title'].replace(_(" (Template)"), "")
return [data]
# ACTIONS
@api.multi
def create_survey_from_template(self, default=None):
self.ensure_one()
if not self.is_template:
raise UserError(_("You should use the \"Copy\" secondary action to duplicate a non-template survey."))
return self.copy(default=default)
@api.multi
def action_send_survey(self):
self.ensure_one()
if self.is_template:
raise UserError(_("You cannot send a template survey, create a new survey from this template and you'll be able to share it."))
return super(SurveySurvey, self).action_send_survey()
# ONCHANGES
@api.onchange('is_template')
def onchange_is_template(self):
if self.title:
if self.is_template:
if _("(Template)") not in self.title:
self.title = self.title.strip() + _(" (Template)")
else:
if _(" (Template)") in self.title:
self.title = self.title.replace(_(" (Template)"), "")