Merge lp:~domsense/domsense-agilebg-addons/adding_email_notifications into lp:domsense-agilebg-addons/6.0

Proposed by Lorenzo Battistini
Status: Merged
Merged at revision: 20
Proposed branch: lp:~domsense/domsense-agilebg-addons/adding_email_notifications
Merge into: lp:domsense-agilebg-addons/6.0
Diff against target: 381 lines (+340/-0)
8 files modified
email_notifications/AUTHORS.txt (+1/-0)
email_notifications/__init__.py (+24/-0)
email_notifications/__openerp__.py (+39/-0)
email_notifications/email_notifications.py (+61/-0)
email_notifications/email_template.py (+61/-0)
email_notifications/email_template_view.xml (+22/-0)
email_notifications/i18n/email_notifications.pot (+66/-0)
email_notifications/i18n/it.po (+66/-0)
To merge this branch: bzr merge lp:~domsense/domsense-agilebg-addons/adding_email_notifications
Reviewer Review Type Date Requested Status
Agile Business Group Pending
Review via email: mp+75856@code.launchpad.net
To post a comment you must log in.
23. By Lorenzo Battistini

[FIX] multiple templates

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'email_notifications'
2=== added file 'email_notifications/AUTHORS.txt'
3--- email_notifications/AUTHORS.txt 1970-01-01 00:00:00 +0000
4+++ email_notifications/AUTHORS.txt 2011-09-19 06:47:25 +0000
5@@ -0,0 +1,1 @@
6+Lorenzo Battistini <lorenzo.battistini@agilebg.com>
7
8=== added file 'email_notifications/__init__.py'
9--- email_notifications/__init__.py 1970-01-01 00:00:00 +0000
10+++ email_notifications/__init__.py 2011-09-19 06:47:25 +0000
11@@ -0,0 +1,24 @@
12+# -*- encoding: utf-8 -*-
13+##############################################################################
14+#
15+# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
16+# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
17+# All Rights Reserved
18+# $Id$
19+#
20+# This program is free software: you can redistribute it and/or modify
21+# it under the terms of the GNU Affero General Public License as published
22+# by the Free Software Foundation, either version 3 of the License, or
23+# (at your option) any later version.
24+#
25+# This program is distributed in the hope that it will be useful,
26+# but WITHOUT ANY WARRANTY; without even the implied warranty of
27+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28+# GNU General Public License for more details.
29+#
30+# You should have received a copy of the GNU General Public License
31+# along with this program. If not, see <http://www.gnu.org/licenses/>.
32+#
33+##############################################################################
34+import email_notifications
35+import email_template
36
37=== added file 'email_notifications/__openerp__.py'
38--- email_notifications/__openerp__.py 1970-01-01 00:00:00 +0000
39+++ email_notifications/__openerp__.py 2011-09-19 06:47:25 +0000
40@@ -0,0 +1,39 @@
41+# -*- encoding: utf-8 -*-
42+##############################################################################
43+#
44+# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
45+# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
46+# All Rights Reserved
47+# $Id$
48+#
49+# This program is free software: you can redistribute it and/or modify
50+# it under the terms of the GNU Affero General Public License as published
51+# by the Free Software Foundation, either version 3 of the License, or
52+# (at your option) any later version.
53+#
54+# This program is distributed in the hope that it will be useful,
55+# but WITHOUT ANY WARRANTY; without even the implied warranty of
56+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57+# GNU General Public License for more details.
58+#
59+# You should have received a copy of the GNU General Public License
60+# along with this program. If not, see <http://www.gnu.org/licenses/>.
61+#
62+##############################################################################
63+{
64+ 'name': "Email notifications",
65+ 'version': '0.1',
66+ 'category': 'Generic Modules/Base',
67+ 'description': """This modules allows to configure automatic email notifications on creating or writing objects. You just have to create an email template, associate to a model and specify whether that email has to be used as change notification""",
68+ 'author': 'Agile Business Group & Domsense',
69+ 'website': 'http://www.agilebg.com',
70+ 'license': 'AGPL-3',
71+ "depends" : ['email_template'],
72+ "init_xml" : [],
73+ "update_xml" : [
74+ 'email_template_view.xml',
75+ ],
76+ "demo_xml" : [],
77+ "active": False,
78+ "installable": True
79+}
80
81=== added file 'email_notifications/email_notifications.py'
82--- email_notifications/email_notifications.py 1970-01-01 00:00:00 +0000
83+++ email_notifications/email_notifications.py 2011-09-19 06:47:25 +0000
84@@ -0,0 +1,61 @@
85+# -*- coding: utf-8 -*-
86+##############################################################################
87+#
88+# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
89+# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
90+# All Rights Reserved
91+# $Id$
92+#
93+# This program is free software: you can redistribute it and/or modify
94+# it under the terms of the GNU Affero General Public License as published
95+# by the Free Software Foundation, either version 3 of the License, or
96+# (at your option) any later version.
97+#
98+# This program is distributed in the hope that it will be useful,
99+# but WITHOUT ANY WARRANTY; without even the implied warranty of
100+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
101+# GNU General Public License for more details.
102+#
103+# You should have received a copy of the GNU General Public License
104+# along with this program. If not, see <http://www.gnu.org/licenses/>.
105+#
106+##############################################################################
107+
108+from osv import fields,osv
109+from osv.orm import orm
110+
111+class email_notifications(osv.osv):
112+
113+ _name = "email.notifications"
114+
115+ def notifications_create(self, cr, uid, vals, context=None):
116+ res = self.orig_create(cr, uid, vals, context)
117+ model_pool = self.pool.get('ir.model')
118+ model_ids = model_pool.search(cr, uid, [('model', '=', self._name)])
119+ if model_ids:
120+ template_pool = self.pool.get('email.template')
121+ template_ids = template_pool.search(cr, uid, [('object_name', '=', model_ids[0]), ('is_notification', '=', True)])
122+ for template_id in template_ids:
123+ template_pool.generate_mail(cr, uid, template_id, [res], context)
124+ return res
125+
126+ orig_create = orm.create
127+ orm.create = notifications_create
128+ orm.orig_create = orig_create
129+
130+ def notifications_write(self, cr, uid, ids, vals, context=None):
131+ res = self.orig_write(cr, uid, ids, vals, context)
132+ model_pool = self.pool.get('ir.model')
133+ model_ids = model_pool.search(cr, uid, [('model', '=', self._name)])
134+ if model_ids:
135+ template_pool = self.pool.get('email.template')
136+ template_ids = template_pool.search(cr, uid, [('object_name', '=', model_ids[0]), ('is_notification', '=', True)])
137+ for template_id in template_ids:
138+ template_pool.generate_mail(cr, uid, template_id, ids, context)
139+ return res
140+
141+ orig_write = orm.write
142+ orm.write = notifications_write
143+ orm.orig_write = orig_write
144+
145+email_notifications()
146
147=== added file 'email_notifications/email_template.py'
148--- email_notifications/email_template.py 1970-01-01 00:00:00 +0000
149+++ email_notifications/email_template.py 2011-09-19 06:47:25 +0000
150@@ -0,0 +1,61 @@
151+# -*- coding: utf-8 -*-
152+##############################################################################
153+#
154+# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>)
155+# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>)
156+# All Rights Reserved
157+# $Id$
158+#
159+# This program is free software: you can redistribute it and/or modify
160+# it under the terms of the GNU Affero General Public License as published
161+# by the Free Software Foundation, either version 3 of the License, or
162+# (at your option) any later version.
163+#
164+# This program is distributed in the hope that it will be useful,
165+# but WITHOUT ANY WARRANTY; without even the implied warranty of
166+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
167+# GNU General Public License for more details.
168+#
169+# You should have received a copy of the GNU General Public License
170+# along with this program. If not, see <http://www.gnu.org/licenses/>.
171+#
172+##############################################################################
173+
174+from osv import osv, fields
175+from tools.translate import _
176+
177+class email_template(osv.osv):
178+
179+ _inherit = "email.template"
180+
181+ '''
182+ def _too_many_notifications(self, cr, uid, template_id):
183+ template = self.browse(cr, uid, template_id)
184+ template_ids = self.search(cr, uid, [('object_name', '=', template.object_name.id), ('is_notification', '=', True)])
185+ if len(template_ids) > 1:
186+ return True
187+ return False
188+
189+ def create(self, cr, uid, vals, context=None):
190+ res = super(email_template, self).create(cr, uid, vals, context)
191+ if self._too_many_notifications(cr, uid, res):
192+ raise osv.except_osv(_('Error'), _('The model associated to template %s has too many notifications') % res)
193+ return res
194+
195+ def write(self, cr, uid, ids, vals, context=None):
196+ if isinstance(ids, (long,int)):
197+ ids = [ids]
198+ res = super(email_template, self).write(cr, uid, ids, vals, context)
199+ for template_id in ids:
200+ if self._too_many_notifications(cr, uid, template_id):
201+ raise osv.except_osv(_('Error'),
202+ _('The model associated to template %s has too many notifications') % template_id)
203+ return res
204+ '''
205+
206+ _columns = {
207+ 'is_notification' : fields.boolean('Is change notification', help="Check this if you want to send this email every time that the related object is modified or created"),
208+ }
209+
210+email_template()
211+
212
213=== added file 'email_notifications/email_template_view.xml'
214--- email_notifications/email_template_view.xml 1970-01-01 00:00:00 +0000
215+++ email_notifications/email_template_view.xml 2011-09-19 06:47:25 +0000
216@@ -0,0 +1,22 @@
217+<?xml version="1.0" encoding="UTF-8"?>
218+<openerp>
219+ <data>
220+
221+ <record model="ir.ui.view" id="email_template_form">
222+ <field name="name">email.template.form</field>
223+ <field name="model">email.template</field>
224+ <field name="type">form</field>
225+ <field name="inherit_id" ref="email_template.email_template_form"></field>
226+ <field name="arch" type="xml">
227+ <field name="track_campaign_item" position="after">
228+ <field name="is_notification" />
229+ </field>
230+ </field>
231+ </record>
232+ </data>
233+</openerp>
234+
235+
236+
237+
238+
239
240=== added directory 'email_notifications/i18n'
241=== added file 'email_notifications/i18n/email_notifications.pot'
242--- email_notifications/i18n/email_notifications.pot 1970-01-01 00:00:00 +0000
243+++ email_notifications/i18n/email_notifications.pot 2011-09-19 06:47:25 +0000
244@@ -0,0 +1,66 @@
245+# Translation of OpenERP Server.
246+# This file contains the translation of the following modules:
247+# * email_notifications
248+#
249+msgid ""
250+msgstr ""
251+"Project-Id-Version: OpenERP Server 6.0.3\n"
252+"Report-Msgid-Bugs-To: support@openerp.com\n"
253+"POT-Creation-Date: 2011-09-17 12:50+0000\n"
254+"PO-Revision-Date: 2011-09-17 12:50+0000\n"
255+"Last-Translator: <>\n"
256+"Language-Team: \n"
257+"MIME-Version: 1.0\n"
258+"Content-Type: text/plain; charset=UTF-8\n"
259+"Content-Transfer-Encoding: \n"
260+"Plural-Forms: \n"
261+
262+#. module: email_notifications
263+#: model:ir.model,name:email_notifications.model_email_notifications
264+msgid "email.notifications"
265+msgstr ""
266+
267+#. module: email_notifications
268+#: code:addons/email_notifications/email_template.py:42
269+#: code:addons/email_notifications/email_template.py:52
270+#, python-format
271+msgid "The model associated to template %s has too many notifications"
272+msgstr ""
273+
274+#. module: email_notifications
275+#: field:email.template,is_notification:0
276+msgid "Is change notification"
277+msgstr ""
278+
279+#. module: email_notifications
280+#: model:ir.module.module,description:email_notifications.module_meta_information
281+msgid "This modules allows to configure automatic email notifications on creating or writing objects. You just have to create an email template, associate to a model and specify whether that email has to be used as change notification"
282+msgstr ""
283+
284+#. module: email_notifications
285+#: help:email.template,is_notification:0
286+msgid "Check this if you want to send this email every time that the related object is modified or created"
287+msgstr ""
288+
289+#. module: email_notifications
290+#: model:ir.module.module,shortdesc:email_notifications.module_meta_information
291+msgid "Email notifications"
292+msgstr ""
293+
294+#. module: email_notifications
295+#: sql_constraint:email.template:0
296+msgid "The template name must be unique !"
297+msgstr ""
298+
299+#. module: email_notifications
300+#: code:addons/email_notifications/email_template.py:42
301+#: code:addons/email_notifications/email_template.py:51
302+#, python-format
303+msgid "Error"
304+msgstr ""
305+
306+#. module: email_notifications
307+#: model:ir.model,name:email_notifications.model_email_template
308+msgid "Email Templates for Models"
309+msgstr ""
310+
311
312=== added file 'email_notifications/i18n/it.po'
313--- email_notifications/i18n/it.po 1970-01-01 00:00:00 +0000
314+++ email_notifications/i18n/it.po 2011-09-19 06:47:25 +0000
315@@ -0,0 +1,66 @@
316+# Translation of OpenERP Server.
317+# This file contains the translation of the following modules:
318+# * email_notifications
319+#
320+msgid ""
321+msgstr ""
322+"Project-Id-Version: OpenERP Server 6.0.3\n"
323+"Report-Msgid-Bugs-To: support@openerp.com\n"
324+"POT-Creation-Date: 2011-09-17 12:50+0000\n"
325+"PO-Revision-Date: 2011-09-17 14:53+0100\n"
326+"Last-Translator: Lorenzo Battistini <lorenzo.battistini@agilebg.com>\n"
327+"Language-Team: \n"
328+"MIME-Version: 1.0\n"
329+"Content-Type: text/plain; charset=UTF-8\n"
330+"Content-Transfer-Encoding: 8bit\n"
331+"Plural-Forms: \n"
332+
333+#. module: email_notifications
334+#: model:ir.model,name:email_notifications.model_email_notifications
335+msgid "email.notifications"
336+msgstr "email.notifications"
337+
338+#. module: email_notifications
339+#: code:addons/email_notifications/email_template.py:42
340+#: code:addons/email_notifications/email_template.py:52
341+#, python-format
342+msgid "The model associated to template %s has too many notifications"
343+msgstr "Il model associato al template %s ha troppe notifiche"
344+
345+#. module: email_notifications
346+#: field:email.template,is_notification:0
347+msgid "Is change notification"
348+msgstr "E' una notifica di modifica"
349+
350+#. module: email_notifications
351+#: model:ir.module.module,description:email_notifications.module_meta_information
352+msgid "This modules allows to configure automatic email notifications on creating or writing objects. You just have to create an email template, associate to a model and specify whether that email has to be used as change notification"
353+msgstr "Questo modulo permette di configurare notifiche via email sulla creazione o scrittura di oggetti. E' solamente necessario creare un template email, associarlo ad un model e specificare se quella email debba essere usata come una notifica di cambiamento"
354+
355+#. module: email_notifications
356+#: help:email.template,is_notification:0
357+msgid "Check this if you want to send this email every time that the related object is modified or created"
358+msgstr "Selezionare questo campo se si vuole inviare questa email ogni volta che l'oggetto collegato viene modificato o creato"
359+
360+#. module: email_notifications
361+#: model:ir.module.module,shortdesc:email_notifications.module_meta_information
362+msgid "Email notifications"
363+msgstr "Notifiche Email"
364+
365+#. module: email_notifications
366+#: sql_constraint:email.template:0
367+msgid "The template name must be unique !"
368+msgstr "Il nome template deve essere unico!"
369+
370+#. module: email_notifications
371+#: code:addons/email_notifications/email_template.py:42
372+#: code:addons/email_notifications/email_template.py:51
373+#, python-format
374+msgid "Error"
375+msgstr "Errore"
376+
377+#. module: email_notifications
378+#: model:ir.model,name:email_notifications.model_email_template
379+msgid "Email Templates for Models"
380+msgstr "Template email per modelli"
381+

Subscribers

People subscribed via source and target branches

to status/vote changes: