Skip to content

Commit 4400cd3

Browse files
committed
[IMP] util: Announce Release Notes after a migration
The goal is to warn users that have just upgraded and get them curious about the new features. closes #149 Taskid: 3950689 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 937bba3 commit 4400cd3

File tree

4 files changed

+67
-7
lines changed

4 files changed

+67
-7
lines changed

src/mail/0.0.0/pre-report-migration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class MailMessage(models.Model):
2727

2828
@model_cr
2929
def _register_hook(self):
30+
util.announce_release_note(self.env.cr)
3031
if len(util.migration_reports):
3132
util.announce_migration_report(self.env.cr)
3233
return super(MailMessage, self)._register_hook()

src/util/release-note.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0"?>
2+
<t t-name="mail.release_note">
3+
<span>Hello,</span>
4+
<span>Your database has successfully been upgraded to the latest version 🥳.</span>
5+
<br/>
6+
<t t-if="odoo_showcase_video_id">
7+
<br/>
8+
<a t-attf-href="https://www.youtube.com/watch?v={{ odoo_showcase_video_id }}" target="_blank">
9+
<b>Meet Odoo <t t-esc="major_version"/>.<t t-esc="minor_version"/> now !</b>
10+
<div class="card shadow-sm yt-container" style="max-height: 360px; max-width: 640px">
11+
<img t-attf-src="https://img.youtube.com/vi/{{ odoo_showcase_video_id }}/maxresdefault.jpg"/>
12+
</div>
13+
</a>
14+
</t>
15+
<br/>
16+
<p t-if="int(minor_version) == 0">Want to know more? Check out the full <a t-attf-href="https://www.odoo.com/odoo-{{ major_version }}-release-notes">release note</a>.</p>
17+
<p t-elif="int(minor_version) >= 0">Want to know more? Check out the full <a t-attf-href="https://www.odoo.com/odoo-{{ major_version }}-{{ minor_version }}-release-notes">release note</a>.</p>
18+
<p t-else=""></p>
19+
</t>

src/util/report-migration.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<?xml version="1.0"?>
22
<t t-name="mail.report_migration">
3-
<h2> Upgrade report: <t t-esc="major_version" /> </h2>
3+
<h2> Congratulations, you have just upgraded to Odoo <t t-esc="version" /> </h2>
4+
<p> Here are changes that may impact day to day flows in this new version. </p>
5+
<p t-if="int(minor_version) == 0">Want to know more? Check out the full functional <a t-attf-href="https://www.odoo.com/odoo-{{ major_version }}-release-notes">release note</a>.</p>
6+
<p t-elif="int(minor_version) >= 0">Want to know more? Check out the full fonctional <a t-attf-href="https://www.odoo.com/odoo-{{ major_version }}-{{ minor_version }}-release-notes">release note</a>.</p>
7+
<p t-else=""></p>
8+
<br/>
49
<t t-foreach="messages" t-as="category">
510
<h3><t t-esc="category"/></h3>
611
<ul>

src/util/report.py

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ def html_escape(text):
6666
migration_reports = {}
6767
_logger = logging.getLogger(__name__)
6868

69+
ODOO_SHOWCASE_VIDEOS = {
70+
"18.0": "gbE3azm_Io0",
71+
"saas~17.4": "8F4-uDwom8A",
72+
"saas~17.2": "ivjgo_2-wkE",
73+
"17.0": "qxb74CMR748",
74+
"16.0": "RVFZL3D9plg",
75+
}
76+
6977

7078
def add_to_migration_reports(message, category="Other", format="text"):
7179
assert format in {"text", "html", "md", "rst"}
@@ -82,6 +90,25 @@ def add_to_migration_reports(message, category="Other", format="text"):
8290
migration_reports.setdefault(category, []).append((message, raw))
8391

8492

93+
def announce_release_note(cr):
94+
filepath = os.path.join(os.path.dirname(__file__), "release-note.xml")
95+
with open(filepath, "rb") as fp:
96+
contents = fp.read()
97+
report = lxml.etree.fromstring(contents)
98+
e = env(cr)
99+
major_version, minor_version = re.findall(r"\d+", release.major_version)
100+
values = {
101+
"version": release.major_version,
102+
"major_version": major_version,
103+
"minor_version": minor_version,
104+
"odoo_showcase_video_id": ODOO_SHOWCASE_VIDEOS.get(release.major_version, ""),
105+
}
106+
_logger.info("Rendering release note for version %s", release.version)
107+
render = e["ir.qweb"].render if hasattr(e["ir.qweb"], "render") else e["ir.qweb"]._render
108+
message = render(report, values=values)
109+
_announce_to_db(cr, message, to_admin_only=False)
110+
111+
85112
def announce_migration_report(cr):
86113
filepath = os.path.join(os.path.dirname(__file__), "report-migration.xml")
87114
with open(filepath, "rb") as fp:
@@ -90,27 +117,35 @@ def announce_migration_report(cr):
90117
contents = contents.replace(b"t-raw", b"t-out")
91118
report = lxml.etree.fromstring(contents)
92119
e = env(cr)
120+
major_version, minor_version = re.findall(r"\d+", release.major_version)
93121
values = {
94122
"action_view_id": e.ref("base.action_ui_view").id,
95-
"major_version": release.major_version,
123+
"version": release.major_version,
124+
"major_version": major_version,
125+
"minor_version": minor_version,
96126
"messages": migration_reports,
97127
"get_anchor_link_to_record": get_anchor_link_to_record,
98128
}
99129
_logger.info(migration_reports)
100130
render = e["ir.qweb"].render if hasattr(e["ir.qweb"], "render") else e["ir.qweb"]._render
101131
message = render(report, values=values)
132+
_announce_to_db(cr, message)
133+
# To avoid posting multiple time the same messages in case this method is called multiple times.
134+
migration_reports.clear()
135+
136+
137+
def _announce_to_db(cr, message, to_admin_only=True):
138+
"""Send a rendered message to the database via mail channel."""
102139
if not isinstance(message, basestring):
103140
message = message.decode("utf-8")
104141
if message.strip():
105142
message = message.replace("{", "{{").replace("}", "}}")
106143
kw = {}
107144
# If possible, post the migration report message to administrators only.
108-
admin_channel = get_admin_channel(cr)
109-
if admin_channel:
110-
kw["recipient"] = admin_channel
145+
recipient = get_admin_channel(cr) if to_admin_only else None
146+
if recipient:
147+
kw["recipient"] = recipient
111148
announce(cr, release.major_version, message, format="html", header=None, footer=None, **kw)
112-
# To avoid posting multiple time the same messages in case this method is called multiple times.
113-
migration_reports.clear()
114149

115150

116151
def rst2html(rst):

0 commit comments

Comments
 (0)