[FIX] survey: compute survey attachments
**Current behavior:**
Adding an attachment to a mail template record associated with
the survey invite wizard will not cause the attachment to
populate the relevant field when actually sending a new survey
invite email.
**Expected behavior:**
The attachments linked in the email template which is used by
the survey invite wizard will appear in the form when sending a
survey invite.
**Steps to reproduce:**
1. In settings, go to the email templates management page
2. Select the Survey: Invite template and upload some
attachment
3. Go to the Survey application and click on one of the surveys
listed, observe the lack of attachments despite having the
email template with the attachment selected
**Cause of the issue:**
The survey invite wizard never uses its template's attachments
to modify/update its own attachment_ids field.
**Fix:**
Make the attachment_ids field a stored computed field.
opw-3709830
closes odoo/odoo#162499
X-original-commit: 1fcc11a2ca8e18d10eaac51ce20773596db183e2
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Signed-off-by: Vincent Ethan <etvi@odoo.com>
This commit is contained in:
@@ -318,3 +318,52 @@ class TestSurveyInvite(common.TestSurveyCommon, MailCommon):
|
||||
answers = self.env['survey.user_input'].search([('survey_id', '=', self.survey.id)])
|
||||
self.assertEqual(len(answers), 1)
|
||||
self.assertEqual(answers.partner_id.display_name, first_partner.display_name)
|
||||
|
||||
@users('survey_user')
|
||||
def test_survey_invite_with_template_attachment(self):
|
||||
"""
|
||||
Test that a group_survey_user can send a survey that includes an attachment from the survey invite's
|
||||
email template
|
||||
"""
|
||||
mail_template = self.env['mail.template'].create({
|
||||
'name': 'test mail template',
|
||||
'attachment_ids': [Command.create({
|
||||
'name': 'some_attachment.pdf',
|
||||
'res_model': 'mail.template',
|
||||
'datas': 'test',
|
||||
'type': 'binary',
|
||||
})],
|
||||
})
|
||||
|
||||
user_survey = self.env['survey.survey'].create({
|
||||
'title': 'User Created Survey',
|
||||
'access_mode': 'public',
|
||||
'users_login_required': False,
|
||||
'users_can_go_back': False,
|
||||
'question_and_page_ids': [
|
||||
Command.create({
|
||||
'title': 'First page',
|
||||
'sequence': 1,
|
||||
'is_page': True,
|
||||
'question_type': False,
|
||||
}),
|
||||
Command.create({
|
||||
'title': 'Test Free Text',
|
||||
'sequence': 2,
|
||||
'question_type': 'text_box',
|
||||
}),
|
||||
]
|
||||
})
|
||||
|
||||
action = user_survey.action_send_survey()
|
||||
invite_form = Form(self.env[action['res_model']].with_context(action['context']))
|
||||
invite_form.send_email = True
|
||||
invite_form.template_id = mail_template
|
||||
invite_form.emails = 'test_survey_invite_with_template_attachment@odoo.gov'
|
||||
invite = invite_form.save()
|
||||
with self.mock_mail_gateway():
|
||||
invite.action_invite()
|
||||
|
||||
self.assertEqual(self.env['mail.mail'].sudo().search([
|
||||
('email_to', '=', 'test_survey_invite_with_template_attachment@odoo.gov')
|
||||
]).attachment_ids, mail_template.attachment_ids)
|
||||
|
||||
@@ -25,7 +25,7 @@ class SurveyInvite(models.TransientModel):
|
||||
# composer content
|
||||
attachment_ids = fields.Many2many(
|
||||
'ir.attachment', 'survey_mail_compose_message_ir_attachments_rel', 'wizard_id', 'attachment_id',
|
||||
string='Attachments')
|
||||
string='Attachments', compute='_compute_attachment_ids', store=True, readonly=False)
|
||||
# origin
|
||||
author_id = fields.Many2one(
|
||||
'res.partner', 'Author', index=True,
|
||||
@@ -168,6 +168,18 @@ class SurveyInvite(models.TransientModel):
|
||||
invite = invite.with_context(lang=langs.pop())
|
||||
super(SurveyInvite, invite)._compute_body()
|
||||
|
||||
@api.depends('template_id')
|
||||
def _compute_attachment_ids(self):
|
||||
"""
|
||||
'OnChange-like' behavior used for template selection: not intended to update records when
|
||||
individual attachments get added
|
||||
"""
|
||||
for invite in self:
|
||||
if invite.template_id:
|
||||
invite.attachment_ids = invite.template_id.attachment_ids
|
||||
else:
|
||||
invite.attachment_ids = False
|
||||
|
||||
# ------------------------------------------------------
|
||||
# Wizard validation and send
|
||||
# ------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user