Skip to content

Commit 5235f28

Browse files
hitesh-erpharborjans23
authored andcommitted
[18.0][MIG] mass_mailing_double_opt_in_nitrokey: Migration to v18.0 (#251)
* [18.0][MIG] mass_mailing_double_opt_in_nitrokey: Migration to v18.0 * [18.0][IMP] mass_mailing_double_opt_in_nitrokey: Renamed module name to website_mass_mailing_double_opt_in_nitrokey * [18.0][IMP] website_mass_mailing_double_opt_in_nitrokey: Implemented email translated values * [REM] Removed old module mass_mailing_double_opt_in_nitrokey
1 parent 35dfcee commit 5235f28

12 files changed

Lines changed: 567 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
===================================
2+
Nitrokey Mass Mailing Double opt-in
3+
===================================
4+
5+
Usage
6+
=====
7+
8+
Mass Mailing Double opt-in module subscribe the newsletter at the time of
9+
payment processing also checks if user has already subscribed or not,
10+
Added only nitrokey related custom code into this module from
11+
"website_mass_mailing_double_opt_in"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
2+
3+
from . import controllers, models
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
2+
{
3+
"name": "Website Mass Mailing Double opt-in Nitrokey",
4+
"version": "18.0.1.0.0",
5+
"author": "Nitrokey GmbH",
6+
"license": "AGPL-3",
7+
"website": "http://www.nitrokey.com",
8+
"summary": """
9+
Mass Mailing Double opt-in module subscribe the newsletter at the time of
10+
payment processing also checks if user has already subscribed or not,
11+
Added only nitrokey related custom code into this module from
12+
"website_mass_mailing_double_opt_in"
13+
""",
14+
"depends": [
15+
"website_sale_mass_mailing",
16+
"website_mass_mailing_double_opt_in",
17+
"website_payment",
18+
"nitrokey_setup",
19+
"nitrokey_reports",
20+
],
21+
"data": [
22+
"security/ir.model.access.csv",
23+
"data/mail_template.xml",
24+
],
25+
"installable": True,
26+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
2+
3+
from . import main
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
2+
import logging
3+
4+
from odoo import _, http
5+
from odoo.http import request
6+
7+
from odoo.addons.website_mass_mailing_double_opt_in.controllers.main import (
8+
ConsentController,
9+
)
10+
from odoo.addons.website_sale.controllers.main import WebsiteSale
11+
from odoo.addons.website_sale.controllers.payment import PaymentPortal
12+
13+
_logger = logging.getLogger(__name__)
14+
15+
16+
class ConsentControllerExt(ConsentController):
17+
def consent_success(self):
18+
return request.redirect("https://www.nitrokey.com/subscribed")
19+
20+
def _prepare_mail_content(self, mailing_list_contact, language):
21+
"""Newsletter Subscribed email template content"""
22+
res = super()._prepare_mail_content(mailing_list_contact, language)
23+
# Get company information
24+
user = request.env.user
25+
company = user.company_id or request.env.company
26+
if language == "de_DE":
27+
# Update subject
28+
res["subject"] = "Sie haben den Nitrokey Newsletter abonniert"
29+
# Get translated strings for body header
30+
greeting = "Hallo,"
31+
thank_you = "Vielen Dank, dass Sie den Nitrokey Newsletter abonniert haben."
32+
best_regards = "Viele Grüße,"
33+
team = "Ihr Team"
34+
elif language == "en_US":
35+
# Update subject
36+
res["subject"] = "You Have Subscribed to the Nitrokey Newsletter"
37+
# Get translated strings for body header
38+
greeting = "Hi!"
39+
thank_you = "Thank you for subscribing the Nitrokey newsletter."
40+
best_regards = "Best regards,"
41+
team = "your Nitrokey team"
42+
else:
43+
# Update subject
44+
res["subject"] = _("You Have Subscribed to the Nitrokey Newsletter")
45+
# Get translated strings for body header
46+
greeting = _("Hi!")
47+
thank_you = _("Thank you for subscribing the Nitrokey newsletter.")
48+
best_regards = _("Best regards,")
49+
team = _("your Nitrokey team")
50+
# Build complete HTML with a single f-string
51+
res["body_html"] = f"""
52+
<div>
53+
<p>{greeting}</p>
54+
<p>{thank_you}</p>
55+
<br />
56+
<p>{best_regards}<br />{team}</p>
57+
</div>
58+
59+
<div>
60+
<div style="max-width: 532px; background-color: #14212D;">
61+
<table style="margin-left: 15px;">
62+
<tr>
63+
<td colspan="2"
64+
style="color: #FFFFFF;
65+
font-family: Arial;
66+
font-size: 13px;
67+
line-height: 17px;">
68+
<br />
69+
<strong>{company.name or ''}</strong><br />
70+
71+
{company.street or ''} {company.street2 or ''}<br />
72+
{company.zip or ''} {company.city or ''}<br />
73+
{company.state_id.name if company.state_id else ''}
74+
{company.country_id.name if company.country_id else ''}
75+
76+
<br /><br />
77+
<strong>CEO:</strong>
78+
{company.ceo or ''}<br />
79+
<strong>Company register:</strong>
80+
{company.company_registry or ''}<br />
81+
<strong>VAT ID:</strong>
82+
{company.vat or ''}
83+
</td>
84+
</tr>
85+
</table>
86+
</div>
87+
</div>
88+
"""
89+
return res
90+
91+
92+
class PaymentPortalExt(PaymentPortal):
93+
@http.route(
94+
"/shop/payment/transaction/<int:order_id>",
95+
type="json",
96+
auth="public",
97+
website=True,
98+
)
99+
def shop_payment_transaction(self, *args, **kwargs):
100+
"""Payment transaction override to double check cart quantities before
101+
placing the order
102+
"""
103+
order = request.website.sale_get_order()
104+
is_subscribed = order.partner_id.newsletter_subscribed
105+
if not is_subscribed or not order.partner_id.email:
106+
return super().shop_payment_transaction(*args, **kwargs)
107+
108+
# Automatically subscribe the newsletter if the option
109+
# Stay informed about the project progress, new products and firmware updates.
110+
# is selected by the customer.
111+
newsletter = request.env.ref("mass_mailing.mailing_list_data")
112+
subscription = request.env["mailing.subscription"].sudo()
113+
request.session["mass_mailing_email"] = subscription.double_opt_in_subscribe(
114+
newsletter.id,
115+
order.partner_id.email,
116+
language=request.lang.code,
117+
)
118+
return super().shop_payment_transaction(*args, **kwargs)
119+
120+
121+
class WebsiteSaleExt(WebsiteSale):
122+
def _prepare_checkout_page_values(self, order_sudo, **_kwargs):
123+
res = super()._prepare_checkout_page_values(order_sudo, **_kwargs)
124+
if res and res.get("checkout"):
125+
res["checkout"]["newsletter"] = res.get("newsletter") == "on"
126+
return res
127+
128+
def _handle_extra_form_data(self, extra_form_data, address_values):
129+
res = super()._handle_extra_form_data(extra_form_data, address_values)
130+
if extra_form_data.get("newsletter") and address_values.get("email"):
131+
subscription = request.env["mailing.subscription"].sudo()
132+
subscription.double_opt_in_subscribe(
133+
request.website.newsletter_id.id,
134+
address_values.get("email"),
135+
language=request.lang.code,
136+
)
137+
return res
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<odoo>
2+
<!-- Newsletter Subscription template -->
3+
<record
4+
id="nitrokey_newsletter_confirmation_request_template"
5+
model="mail.template"
6+
>
7+
<field name="name">[Nitrokey Shop] Newsletter Subscription</field>
8+
<field name="subject">Confirm your newsletter subscription</field>
9+
<field name="model_id" ref="mass_mailing.model_mailing_subscription" />
10+
<field name="email_to">{{ object.contact_id.email }}</field>
11+
<field name="body_html" type="html">
12+
<div style="margin: -10px -10px; padding:50px 30px 50px 30px; height:100%;">
13+
<div style="margin:0 auto; max-width:660px;">
14+
<div
15+
style="float: left; background-color: #FFFFFF; padding:10px 30px 10px 30px; border: 1px solid #DDDDDD;"
16+
>
17+
<div style="float: left; max-width:470px;">
18+
<p
19+
style="line-height: 21px; font-family: Helvetica, Verdana, Arial, sans-serif; font-size: 12px;"
20+
>
21+
<strong
22+
style="line-height: 21px; font-family: Helvetica, Verdana, Arial, sans-serif; font-size: 18px;"
23+
>Confirm your newsletter subscription
24+
</strong>
25+
</p>
26+
<div
27+
style="line-height: 21px; min-height: 100px; font-family: Helvetica, Verdana, Arial, sans-serif; font-size: 12px;"
28+
>
29+
<p
30+
style="line-height: 21px; font-family: Helvetica, Verdana, Arial, sans-serif; font-size: 12px;"
31+
>Thanks for subscribing to our email list.
32+
</p>
33+
<p
34+
style="line-height: 21px; font-family: Helvetica, Verdana, Arial, sans-serif; font-size: 12px;"
35+
>You allow Nitrokey to be in touch with you via email for the purpose of news, updates
36+
and product information. If you wish to withdraw your consent and stop hearing from
37+
us, simply click the unsubscribe link at the bottom of every email. By subscribing,
38+
you agree that we may process your information in accordance with our <a
39+
href="https://www.nitrokey.com/data-privacy-policy"
40+
>policy</a>.
41+
</p>
42+
<p
43+
style="line-height: 21px; font-family: Helvetica, Verdana, Arial, sans-serif; font-size: 12px;"
44+
>Please confirm your subscription by clicking the button below:
45+
</p>
46+
<p
47+
style="line-height: 21px; font-family: Helvetica, Verdana, Arial, sans-serif; font-size: 12px; margin-bottom: 25px; padding: 15px; text-align: center;"
48+
>
49+
<a
50+
t-attf-href="/newsletter/confirmation/{{ object.access_token }}"
51+
style="background-color: #449d44; padding: 12px; font-weight: 12px; text-decoration: none; color: #fff; border-radius: 5px; font-size:16px;"
52+
>Confirm
53+
</a>
54+
</p>
55+
<p
56+
style="line-height: 21px; font-family: Helvetica, Verdana, Arial, sans-serif; font-size: 12px;"
57+
>Thank you,<br />Nitrokey
58+
</p>
59+
</div>
60+
</div>
61+
</div>
62+
<div style="max-width: 532px; background-color: #14212D;">
63+
<table style="margin-left: 15px;">
64+
<tr>
65+
<td
66+
class="text"
67+
colspan="2"
68+
style="color: #FFFFFF;font-family: Arial;font-size: 13px;letter-spacing: 0;line-height: 17px;"
69+
>
70+
<br />
71+
<strong t-out="user.company_id.name" />
72+
<br />
73+
74+
<t t-if="user.company_id.street">
75+
<t t-out="user.company_id.street" />,
76+
</t>
77+
<t t-if="user.company_id.street2">
78+
<t t-out="user.company_id.street2" />,
79+
</t>
80+
<t
81+
t-if="user.company_id.city or user.company_id.zip"
82+
>
83+
<t t-out="user.company_id.zip" />
84+
<t t-out="user.company_id.city" />,
85+
</t>
86+
<t t-if="user.company_id.country_id">
87+
<t
88+
t-out="user.company_id.state_id.name or ''"
89+
/>
90+
<t
91+
t-out="user.company_id.country_id.name or ''"
92+
/>
93+
</t>
94+
<br />
95+
<br />
96+
<strong>CEO:</strong>
97+
<t t-out="user.company_id.ceo or ''" />
98+
<br />
99+
<strong>Company register:</strong>
100+
<t t-out="user.company_id.company_registry or ''" />
101+
<br />
102+
<strong>VAT ID:</strong>
103+
<t t-out="user.company_id.vat or ''" />
104+
</td>
105+
</tr>
106+
</table>
107+
</div>
108+
</div>
109+
</div>
110+
</field>
111+
</record>
112+
</odoo>

0 commit comments

Comments
 (0)