If applied, this commit will solve the KeyError of 'list_ids'. Before this commit ======================= When there are no Mailing Lists available and add the snippet 'Newsletter block' in the website with the template 'Form Subscription' and any user tries to Subscribe to that form. It will raise an error like KeyError: 'list_ids'. After this commit ======================== In this commit, checking keyword arguments which have list_ids in this or not if list_ids not in that returns the error like 'Mailing List(s) not found!' see - https://tinyurl.com/2n3o7s58 sentry - 3949183926 closes odoo/odoo#114871 X-original-commit: 360579977634c38c1cd6287c03e7c06796b408b1 Signed-off-by: Romain Derie (rde) <rde@odoo.com>
27 lines
1.0 KiB
Python
27 lines
1.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
import json
|
|
|
|
from odoo import _
|
|
from odoo.http import request
|
|
from odoo.addons.website.controllers.form import WebsiteForm
|
|
|
|
|
|
class WebsiteNewsletterForm(WebsiteForm):
|
|
|
|
def _handle_website_form(self, model_name, **kwargs):
|
|
if model_name == 'mailing.contact':
|
|
list_ids = kwargs.get('list_ids')
|
|
if not list_ids:
|
|
return json.dumps({'error': _('Mailing List(s) not found!')})
|
|
list_ids = [int(x) for x in list_ids.split(',')]
|
|
private_list_ids = request.env['mailing.list'].sudo().search([
|
|
('id', 'in', list_ids), ('is_public', '=', False)])
|
|
if private_list_ids:
|
|
return json.dumps({
|
|
'error': _('You cannot subscribe to the following list anymore : %s',
|
|
', '.join(private_list_ids.mapped('name')))
|
|
})
|
|
return super()._handle_website_form(model_name, **kwargs)
|