PURPOSE This commit adds the possibility the create a subscribing form from the form snippet, it creates default inputs automatically. LINKS Task-2672194 Part-of: odoo/odoo#79582
24 lines
896 B
Python
24 lines
896 B
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 = [int(x) for x in kwargs['list_ids'].split(',')]
|
|
private_list_ids = request.env['mailing.list'].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)
|