details: https://code.tryton.org/tryton/commit/8337403b5d2e
branch: default
user: Cédric Krier <[email protected]>
date: Fri Apr 03 15:56:14 2026 +0200
description:
Add button to mark notifications as read
Closes #14744
diffstat:
trytond/CHANGELOG | 1 +
trytond/trytond/res/notification.py | 26 +++++++++++++++-----------
trytond/trytond/res/notification.xml | 8 +++++++-
trytond/trytond/res/view/notification_form.xml | 2 ++
trytond/trytond/res/view/notification_list.xml | 1 +
5 files changed, 26 insertions(+), 12 deletions(-)
diffs (119 lines):
diff -r 7ac4b470f9e3 -r 8337403b5d2e trytond/CHANGELOG
--- a/trytond/CHANGELOG Wed May 06 09:23:35 2026 +0200
+++ b/trytond/CHANGELOG Fri Apr 03 15:56:14 2026 +0200
@@ -1,3 +1,4 @@
+* Add button to mark notification as read
Version 8.0.0 - 2026-04-20
--------------------------
diff -r 7ac4b470f9e3 -r 8337403b5d2e trytond/trytond/res/notification.py
--- a/trytond/trytond/res/notification.py Wed May 06 09:23:35 2026 +0200
+++ b/trytond/trytond/res/notification.py Fri Apr 03 15:56:14 2026 +0200
@@ -25,31 +25,37 @@
ModelSQL, ModelView):
__name__ = 'res.notification'
+ _states = {
+ 'readonly': Eval('id', 0) >= 0,
+ }
+
user = fields.Many2One(
'res.user', "User", required=True, ondelete='CASCADE',
- states={
- 'readonly': Eval('id', 0) > 0,
- })
- label = fields.Char("Label")
- description = fields.Char("Description")
- icon = fields.Selection('list_icons', 'Icon', translate=False)
+ states=_states)
+ label = fields.Char("Label", states=_states)
+ description = fields.Char("Description", states=_states)
+ icon = fields.Selection(
+ 'list_icons', "Icon", translate=False, states=_states)
unread = fields.Boolean("Unread")
model = fields.Char(
"Model",
states={
+ 'readonly': _states['readonly'],
'required': Bool(Eval('records')),
})
records = fields.Char(
"Records",
states={
+ 'readonly': _states['readonly'],
'required': Bool(Eval('model')),
})
action = fields.Many2One(
'ir.action', "Action", ondelete='CASCADE',
states={
+ 'readonly': _states['readonly'],
'required': Bool(Eval('action_value')),
})
- action_value = fields.Char("Action Value")
+ action_value = fields.Char("Action Value", states=_states)
@classmethod
def __setup__(cls):
@@ -58,9 +64,8 @@
cls.__rpc__.update({
'get': RPC(),
'get_count': RPC(),
- 'mark_read': RPC(
- readonly=False, instantiate=0, check_access=False),
})
+ cls._buttons.update(mark_read={})
table = cls.__table__()
cls._sql_indexes.update({
@@ -168,7 +173,6 @@
return cursor.fetchone()[0]
@classmethod
+ @ModelView.button
def mark_read(cls, notifications):
- current_user = Transaction().user
- notifications = [n for n in notifications if n.user.id == current_user]
cls.write(notifications, {'unread': False})
diff -r 7ac4b470f9e3 -r 8337403b5d2e trytond/trytond/res/notification.xml
--- a/trytond/trytond/res/notification.xml Wed May 06 09:23:35 2026 +0200
+++ b/trytond/trytond/res/notification.xml Fri Apr 03 15:56:14 2026 +0200
@@ -42,7 +42,7 @@
<record model="ir.model.access" id="access_notification">
<field name="model">res.notification</field>
<field name="perm_read" eval="True"/>
- <field name="perm_write" eval="False"/>
+ <field name="perm_write" eval="True"/>
<field name="perm_create" eval="False"/>
<field name="perm_delete" eval="False"/>
</record>
@@ -81,5 +81,11 @@
<field name="rule_group" ref="rule_group_notification_admin"/>
<field name="group" ref="group_admin"/>
</record>
+
+ <record model="ir.model.button" id="notification_mark_read_button">
+ <field name="model">res.notification</field>
+ <field name="name">mark_read</field>
+ <field name="string">Mark as Read</field>
+ </record>
</data>
</tryton>
diff -r 7ac4b470f9e3 -r 8337403b5d2e
trytond/trytond/res/view/notification_form.xml
--- a/trytond/trytond/res/view/notification_form.xml Wed May 06 09:23:35
2026 +0200
+++ b/trytond/trytond/res/view/notification_form.xml Fri Apr 03 15:56:14
2026 +0200
@@ -10,4 +10,6 @@
<field name="description"/>
<label name="unread"/>
<field name="unread"/>
+
+ <button name="mark_read" colspan="2"/>
</form>
diff -r 7ac4b470f9e3 -r 8337403b5d2e
trytond/trytond/res/view/notification_list.xml
--- a/trytond/trytond/res/view/notification_list.xml Wed May 06 09:23:35
2026 +0200
+++ b/trytond/trytond/res/view/notification_list.xml Fri Apr 03 15:56:14
2026 +0200
@@ -6,4 +6,5 @@
<field name="label" icon="icon" expand="1"/>
<field name="description" expand="2"/>
<field name="unread" optional="0"/>
+ <button name="mark_read" multiple="1"/>
</tree>