diff --git a/models/survey_survey.py b/models/survey_survey.py index e5e0fcae85cf17258657d71d85d7fc1400d2ed75..05616a16d4b2f1093bfdd0377637ba1f59ab76f0 100644 --- a/models/survey_survey.py +++ b/models/survey_survey.py @@ -31,6 +31,10 @@ class Survey(models.Model): stage_id = fields.Many2one('survey.stage', track_visibility='onchange') is_button_display = fields.Boolean("Afficher le bouton enregistrer") is_mail_auto = fields.Boolean("Envoi du mail automatique") + question_mail_id = fields.Many2one('survey.question', string="Question pour le Mail d'envoi") + template_id = fields.Many2one( + 'mail.template', 'Template de mail', index=True, + domain="[('model', '=', 'survey.survey')]") def _track_subtype(self, init_values): self.ensure_one() @@ -56,17 +60,10 @@ class SurveyLabel(models.Model): class SurveyUserInputLine(models.Model): - _inherit = "survey.user_input" + _inherit = "survey.user_input_line" stage_id = fields.Many2one('survey.stage', string="Etape du sondage", related='survey_id.stage_id', store=True, readonly=False) - @api.onchange('state') - def on_change_state(self): - if self.state == 'done': - if self.survey_id.is_mail_auto: - return - # Envoi du mail automatique - class SurveyUserInput(models.Model): _inherit = "survey.user_input" @@ -92,3 +89,28 @@ class SurveyUserInput(models.Model): 'target': 'new', 'url': '/survey/%s/%s/%s' % (url_tag, self.survey_id.id, self.token) } + + @api.onchange('state') + def on_change_state(self): + # At the end of the survey, send a mail if survey is configured for that + if self.state == 'done': + if self.survey_id.is_mail_auto: + self.action_send_mail() + + @api.multi + def action_send_mail(self): + self.ensure_one() + if self.survey_id.question_mail_id: + # Get the mail to send in answers + mail = self.env['survey.user_input_line'].search([ + ('survey_id', '=', self.survey_id.id), + ('user_input_id', '=', self.id), + ('question_id', '=', self.survey_id.question_mail_id.id), + ('value_text', '!=', False) + ], limit=1).value_text + if mail: + template = self.survey_id.template_id + if template: + template.email_to = mail + template.with_context( + dbname=self._cr.dbname).send_mail(self.survey_id.id, force_send=True) diff --git a/templates/layout.xml b/templates/layout.xml index 3c98d7f24d7d02228e5d1e33131402d804aeb106..a774069deab5a972f43960218c8dbd73f3b6443c 100644 --- a/templates/layout.xml +++ b/templates/layout.xml @@ -235,5 +235,12 @@ </xpath> </template> + <template id="numerical_box" inherit_id="survey.numerical_box"> +<!-- <input type="number" step="any" class="form-control" t-att-name="prefix"/>--> + <xpath expr="//input" position="replace"> + <input type="range" min="1" max="100" class="form-control slider" t-att-name="prefix"/> + </xpath> + </template> + </data> </odoo> diff --git a/views/survey_views.xml b/views/survey_views.xml index 030cc1f9c31beb91a882c1f1e64f9d1079cddc0b..f2961f56c84e885da44ab10544537349094ee51e 100644 --- a/views/survey_views.xml +++ b/views/survey_views.xml @@ -39,6 +39,8 @@ <xpath expr="//notebook//page//group//field[@name='users_can_go_back']" position="after"> <field name="is_button_display" /> <field name="is_mail_auto" /> + <field name="question_mail_id" attrs="{'invisible': [('is_mail_auto', '=', False)]}"/> + <field name="template_id" attrs="{'invisible': [('is_mail_auto', '=', False)]}"/> </xpath> <xpath expr="//div[hasclass('oe_title')]" position="after">