changeset d059ef42bb9f in modules/notification_email:default
details:
https://hg.tryton.org/modules/notification_email?cmd=changeset;node=d059ef42bb9f
description:
Add resource relate on notification log
We store on the log the record as resource but also the notification to
get
the email subject.
issue9457
review307901002
diffstat:
CHANGELOG | 1 +
notification.py | 42 +++++++++++++++++++++++++++++++++++++++---
notification.xml | 47 +++++++++++++++++++++++++++++++++++------------
view/log_form.xml | 4 ++++
view/log_list.xml | 3 ++-
5 files changed, 81 insertions(+), 16 deletions(-)
diffs (193 lines):
diff -r 87c62dd58c1a -r d059ef42bb9f CHANGELOG
--- a/CHANGELOG Mon Jul 27 16:16:33 2020 +0200
+++ b/CHANGELOG Tue Aug 11 22:00:26 2020 +0200
@@ -1,3 +1,4 @@
+* Add resource relate on notification log
* Add optional subject to notifications
Version 5.6.0 - 2020-05-04
diff -r 87c62dd58c1a -r d059ef42bb9f notification.py
--- a/notification.py Mon Jul 27 16:16:33 2020 +0200
+++ b/notification.py Tue Aug 11 22:00:26 2020 +0200
@@ -8,6 +8,7 @@
from email.mime.nonmultipart import MIMENonMultipart
from email.utils import formataddr, getaddresses
+from sql.operators import Concat
from genshi.template import TextTemplate
from trytond.config import config
@@ -20,6 +21,8 @@
from trytond.transaction import Transaction
from .exceptions import TemplateError
+from trytond.ir.resource import ResourceAccessMixin
+
_EMAIL_MODELS = [
'res.user',
'party.party',
@@ -277,6 +280,8 @@
'recipients': msg['To'],
'recipients_secondary': msg['Cc'],
'recipients_hidden': bcc,
+ 'resource': str(record),
+ 'notification': trigger.notification_email.id,
'trigger': trigger.id,
}
@@ -409,15 +414,17 @@
return msg
-class EmailLog(ModelSQL, ModelView):
+class EmailLog(ResourceAccessMixin, ModelSQL, ModelView):
"Notification Email Log"
__name__ = 'notification.email.log'
date = fields.Function(fields.DateTime('Date'), 'get_date')
recipients = fields.Char("Recipients")
recipients_secondary = fields.Char("Secondary Recipients")
recipients_hidden = fields.Char("Hidden Recipients")
- trigger = fields.Many2One(
- 'ir.trigger', 'Trigger', required=True, ondelete='CASCADE')
+ notification = fields.Many2One(
+ 'notification.email', "Notification",
+ required=True, ondelete='RESTRICT')
+ trigger = fields.Many2One('ir.trigger', "Trigger")
@classmethod
def __setup__(cls):
@@ -427,6 +434,35 @@
('id', 'DESC'),
]
+ @classmethod
+ def __register__(cls, module_name):
+ pool = Pool()
+ Model = pool.get('ir.model')
+ Trigger = pool.get('ir.trigger')
+ model = Model.__table__()
+ trigger = Trigger.__table__()
+ table = cls.__table__()
+ super().__register__(module_name)
+
+ table_h = cls.__table_handler__(module_name)
+ cursor = Transaction().connection.cursor()
+
+ # Migration from 5.6:
+ # fill notification and resource
+ # remove required on trigger
+ notification = trigger.select(
+ trigger.notification_email,
+ where=trigger.id == table.trigger)
+ resource = (trigger
+ .join(model, condition=trigger.model == model.id)
+ .select(
+ Concat(model.model, ',-1'),
+ where=trigger.id == table.trigger))
+ cursor.execute(*table.update(
+ [table.notification, table.resource],
+ [notification, resource]))
+ table_h.not_null_action('trigger', 'remove')
+
def get_date(self, name):
return self.create_date.replace(microsecond=0)
diff -r 87c62dd58c1a -r d059ef42bb9f notification.xml
--- a/notification.xml Mon Jul 27 16:16:33 2020 +0200
+++ b/notification.xml Tue Aug 11 22:00:26 2020 +0200
@@ -66,17 +66,7 @@
</record>
<record model="ir.model.access" id="access_email_log">
- <field name="model"
- search="[('model', '=', 'notification.email.log')]"/>
- <field name="perm_read" eval="False"/>
- <field name="perm_write" eval="False"/>
- <field name="perm_create" eval="False"/>
- <field name="perm_delete" eval="False"/>
- </record>
- <record model="ir.model.access" id="access_email_log_admin">
- <field name="model"
- search="[('model', '=', 'notification.email.log')]"/>
- <field name="group" ref="res.group_admin"/>
+ <field name="model" search="[('model', '=',
'notification.email.log')]"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="False"/>
<field name="perm_create" eval="False"/>
@@ -87,14 +77,47 @@
<field name="name">Logs</field>
<field name="res_model">notification.email.log</field>
<field name="domain"
- eval="[('trigger.notification_email', 'in',
Eval('active_ids'))]"
+ eval="[('notification', 'in', Eval('active_ids'))]"
pyson="1"/>
</record>
+ <record model="ir.action.act_window.view"
id="act_notification_email_log_view1">
+ <field name="sequence" eval="10"/>
+ <field name="view" ref="email_log_view_list"/>
+ <field name="act_window" ref="act_notification_email_log"/>
+ </record>
+ <record model="ir.action.act_window.view"
id="act_notification_email_log_view2">
+ <field name="sequence" eval="20"/>
+ <field name="view" ref="email_log_view_form"/>
+ <field name="act_window" ref="act_notification_email_log"/>
+ </record>
<record model="ir.action.keyword"
id="act_notification_email_log_keyword1">
<field name="keyword">form_relate</field>
<field name="model">notification.email,-1</field>
<field name="action" ref="act_notification_email_log"/>
</record>
+
+ <record model="ir.action.act_window"
id="act_notification_email_log_relate">
+ <field name="name">Notification E-Mails</field>
+ <field name="res_model">notification.email.log</field>
+ <field
+ name="domain"
+ eval="[If(Eval('active_ids', []) == [Eval('active_id')],
('resource', '=', [Eval('active_model'), Eval('active_id')]), ('resource.id',
'in', Eval('active_ids'), Eval('active_model')))]"
+ pyson="1"/>
+ </record>
+ <record model="ir.action.act_window.view"
id="act_notification_email_log_relate_view1">
+ <field name="sequence" eval="10"/>
+ <field name="view" ref="email_log_view_list"/>
+ <field name="act_window" ref="act_notification_email_log_relate"/>
+ </record>
+ <record model="ir.action.act_window.view"
id="act_notification_email_log_relate_view2">
+ <field name="sequence" eval="20"/>
+ <field name="view" ref="email_log_view_form"/>
+ <field name="act_window" ref="act_notification_email_log_relate"/>
+ </record>
+ <record model="ir.action.keyword"
id="act_notification_email_log_relate_keyword1">
+ <field name="keyword">form_relate</field>
+ <field name="action" ref="act_notification_email_log_relate"/>
+ </record>
</data>
</tryton>
diff -r 87c62dd58c1a -r d059ef42bb9f view/log_form.xml
--- a/view/log_form.xml Mon Jul 27 16:16:33 2020 +0200
+++ b/view/log_form.xml Tue Aug 11 22:00:26 2020 +0200
@@ -4,6 +4,10 @@
<form>
<label name="date"/>
<field name="date"/>
+ <label name="resource"/>
+ <field name="resource"/>
+ <label name="notification"/>
+ <field name="notification"/>
<label name="trigger"/>
<field name="trigger"/>
<label name="recipients"/>
diff -r 87c62dd58c1a -r d059ef42bb9f view/log_list.xml
--- a/view/log_list.xml Mon Jul 27 16:16:33 2020 +0200
+++ b/view/log_list.xml Tue Aug 11 22:00:26 2020 +0200
@@ -4,8 +4,9 @@
<tree>
<field name="date" widget="date"/>
<field name="date" widget="time" string="Time"/>
- <field name="trigger" expand="2"/>
+ <field name="notification" expand="2"/>
<field name="recipients" expand="1"/>
<field name="recipients_secondary" expand="1"/>
<field name="recipients_hidden" expand="1"/>
+ <field name="resource" expand="1"/>
</tree>