From 8aeba8a3a34b60f15cb9fe19ad67a49e7882f8ae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?=
Date: Mon, 15 Jul 2013 17:25:16 +0200
Subject: [PATCH 1/9] [ADD] email_template: added support for 'email' server
action. Email server action are now entirely based on templates. Added tests.
bzr revid: tde@openerp.com-20130715152516-69gokja8u0afgfh8
---
addons/email_template/__init__.py | 1 +
addons/email_template/__openerp__.py | 1 +
addons/email_template/ir_actions.py | 73 +++++++++++++++++++
addons/email_template/ir_actions_view.xml | 49 +++++++++++++
addons/email_template/tests/__init__.py | 3 +-
.../email_template/tests/test_ir_actions.py | 55 ++++++++++++++
6 files changed, 181 insertions(+), 1 deletion(-)
create mode 100644 addons/email_template/ir_actions.py
create mode 100644 addons/email_template/ir_actions_view.xml
create mode 100644 addons/email_template/tests/test_ir_actions.py
diff --git a/addons/email_template/__init__.py b/addons/email_template/__init__.py
index d1cf5b28431..3f091fd8645 100644
--- a/addons/email_template/__init__.py
+++ b/addons/email_template/__init__.py
@@ -22,5 +22,6 @@
import email_template
import wizard
import res_partner
+import ir_actions
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/email_template/__openerp__.py b/addons/email_template/__openerp__.py
index 1dc3baaf63c..b7977660134 100644
--- a/addons/email_template/__openerp__.py
+++ b/addons/email_template/__openerp__.py
@@ -59,6 +59,7 @@ campaigns on any OpenERP document.
'wizard/email_template_preview_view.xml',
'email_template_view.xml',
'res_partner_view.xml',
+ 'ir_actions_view.xml',
'wizard/mail_compose_message_view.xml',
'security/ir.model.access.csv'
],
diff --git a/addons/email_template/ir_actions.py b/addons/email_template/ir_actions.py
new file mode 100644
index 00000000000..ae2ce4f2f82
--- /dev/null
+++ b/addons/email_template/ir_actions.py
@@ -0,0 +1,73 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Business Applications
+# Copyright (c) 2014 OpenERP S.A.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+from openerp.osv import fields, osv
+
+
+class actions_server(osv.Model):
+ """ Add email option in server actions. """
+ _name = 'ir.actions.server'
+ _inherit = ['ir.actions.server']
+
+ def _get_states(self, cr, uid, context=None):
+ res = super(actions_server, self)._get_states(cr, uid, context=context)
+ res.insert(0, ('email', 'Send Email'))
+ return res
+
+ _columns = {
+ 'email_from': fields.char('From', readonly=True,
+ help="Sender address; define the template to see its value. If not set, the default "
+ "value will be the author's email alias if configured, or email address."),
+ 'email_to': fields.char('To (Emails)', readonly=True,
+ help="Comma-separated recipient addresses; define the template to see its value"),
+ 'partner_to': fields.char('To (Partners)', readonly=True,
+ help="Comma-separated ids of recipient partners; define the template to see its value"),
+ 'subject': fields.char('Subject', readonly=True,
+ help="Email subject; define the template to see its value"),
+ 'body_html': fields.text('Body', readonly=True,
+ help="Rich-text/HTML version of the message; define the template to see its value"),
+ 'template_id': fields.many2one('email.template', 'Email Template', ondelete='set null',
+ help="Define the email template to use for the email to send.")
+ }
+
+ def on_change_template_id(self, cr, uid, ids, template_id, context=None):
+ """ - mass_mailing: we cannot render, so return the template values
+ - normal mode: return rendered values """
+ if template_id:
+ fields = ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to', 'attachment_ids']
+ template_values = self.pool.get('email.template').read(cr, uid, template_id, fields, context)
+ values = dict((field, template_values[field]) for field in fields if template_values.get(field))
+ if not values.get('email_from'):
+ return {'warning': {'title': 'Incomplete template', 'message': 'Your template should define email_from'}, 'value': values}
+ else:
+ values = self.default_get(cr, uid, ['subject', 'body_html', 'email_from', 'email_to', 'partner_to'], context=context)
+
+ return {'value': values}
+
+ def run_action_email(self, cr, uid, action, eval_context=None, context=None):
+ if not action.template_id or not context.get('active_id'):
+ return False
+ self.pool['email.template'].send_mail(cr, uid, action.template_id.id, context.get('active_id'),
+ force_send=False, raise_exception=False, context=context)
+ return False
+
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/email_template/ir_actions_view.xml b/addons/email_template/ir_actions_view.xml
new file mode 100644
index 00000000000..f673fda687d
--- /dev/null
+++ b/addons/email_template/ir_actions_view.xml
@@ -0,0 +1,49 @@
+
+
+
+
+
+ ir.actions.server.form
+ ir.actions.server
+
+
+
+
+
+ Please set the Base Model before setting the action details.
+
+
+
+
+ Choose a template to display its values.
+
+
+ The values displayed hereunder are informative. When sending the email, the values
+ will be taken from the email template.
+
+
+
+
+
+
+
+ Your template does not defined any email_from. Please update your template.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/addons/email_template/tests/__init__.py b/addons/email_template/tests/__init__.py
index d63c5634cc3..9418985b06c 100644
--- a/addons/email_template/tests/__init__.py
+++ b/addons/email_template/tests/__init__.py
@@ -18,10 +18,11 @@
# along with this program. If not, see .
#
##############################################################################
-from . import test_mail
+from . import test_mail, test_ir_actions
checks = [
test_mail,
+ test_ir_actions,
]
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
diff --git a/addons/email_template/tests/test_ir_actions.py b/addons/email_template/tests/test_ir_actions.py
new file mode 100644
index 00000000000..d323ee36c1f
--- /dev/null
+++ b/addons/email_template/tests/test_ir_actions.py
@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Business Applications
+# Copyright (c) 2013-TODAY OpenERP S.A.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+from openerp.addons.base.tests.test_ir_actions import TestServerActionsBase
+
+
+class TestServerActionsEmail(TestServerActionsBase):
+
+ def test_00_state_email(self):
+ """ Test ir.actions.server email type """
+ cr, uid = self.cr, self.uid
+
+ # create email_template
+ template_id = self.registry('email.template').create(cr, uid, {
+ 'name': 'TestTemplate',
+ 'email_from': 'myself@example.com',
+ 'email_to': 'brigitte@example.com',
+ 'partner_to': '[%s]' % self.test_partner_id,
+ 'model_id': self.res_partner_model_id,
+ 'subject': 'About ${object.name}',
+ 'body_html': '
Dear ${object.name}, your parent is ${object.parent_id and object.parent_id.name or "False"}
',
+ 'ir_actions_server: TODO')
From ce19e05c9991f08da002a6d5adf090e83f804869 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?=
Date: Mon, 15 Jul 2013 17:25:33 +0200
Subject: [PATCH 2/9] [IMP] Addons: cleaned server action definition according
to refactoring.
bzr revid: tde@openerp.com-20130715152533-pok1xd9kde2mu6b3
---
addons/crm/crm_action_rule_demo.xml | 8 +-------
.../marketing_campaign_demo.xml | 6 +++---
2 files changed, 4 insertions(+), 10 deletions(-)
diff --git a/addons/crm/crm_action_rule_demo.xml b/addons/crm/crm_action_rule_demo.xml
index 7204f666db5..5dca69a40d4 100644
--- a/addons/crm/crm_action_rule_demo.xml
+++ b/addons/crm/crm_action_rule_demo.xml
@@ -14,13 +14,7 @@
Trueir.actions.serveremail
- object.user_id.email
- Reminder on Lead: [[object.id ]] [[object.partner_id and 'of ' +object.partner_id.name or '']]
- Warning unprocessed incoming lead is more than 5 day old.
-Name: [[object.name ]]
-ID: [[object.id ]]
-Description: [[object.description]]
-
+ Set Auto Reminder on leads which are not open since 5 days.
diff --git a/addons/marketing_campaign_crm_demo/marketing_campaign_demo.xml b/addons/marketing_campaign_crm_demo/marketing_campaign_demo.xml
index f6eb8a1d905..bdcbb984193 100644
--- a/addons/marketing_campaign_crm_demo/marketing_campaign_demo.xml
+++ b/addons/marketing_campaign_crm_demo/marketing_campaign_demo.xml
@@ -1,10 +1,10 @@
- Dummy Action
+ Dummy Python Code
- dummy
-
+ code
+ True
From 1dff0b7c4fe5b60a15012c6b69fe022e7f79432b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?=
Date: Fri, 26 Jul 2013 10:18:25 +0200
Subject: [PATCH 3/9] [DOC] email_template: added changelod
bzr revid: tde@openerp.com-20130726081825-xmq8agjvph3trb7t
---
addons/email_template/doc/changelog.rst | 11 +++++++++++
addons/email_template/doc/index.rst | 13 +++++++++++++
addons/email_template/ir_actions.py | 5 ++---
3 files changed, 26 insertions(+), 3 deletions(-)
create mode 100644 addons/email_template/doc/changelog.rst
create mode 100644 addons/email_template/doc/index.rst
diff --git a/addons/email_template/doc/changelog.rst b/addons/email_template/doc/changelog.rst
new file mode 100644
index 00000000000..2581175fe0b
--- /dev/null
+++ b/addons/email_template/doc/changelog.rst
@@ -0,0 +1,11 @@
+.. _changelog:
+
+Changelog
+=========
+
+`trunk (saas-2)`
+----------------
+
+ - Server action update
+
+ - added `email` server action type, now entirely based on email templates.
\ No newline at end of file
diff --git a/addons/email_template/doc/index.rst b/addons/email_template/doc/index.rst
new file mode 100644
index 00000000000..58cf9413601
--- /dev/null
+++ b/addons/email_template/doc/index.rst
@@ -0,0 +1,13 @@
+Email Template module documentation
+===================================
+
+Email Template documentation topics
+'''''''''''''''''''''''''''''''''''
+
+Changelog
+'''''''''
+
+.. toctree::
+ :maxdepth: 1
+
+ changelog.rst
diff --git a/addons/email_template/ir_actions.py b/addons/email_template/ir_actions.py
index ae2ce4f2f82..181cc9a1c5b 100644
--- a/addons/email_template/ir_actions.py
+++ b/addons/email_template/ir_actions.py
@@ -2,7 +2,7 @@
##############################################################################
#
# OpenERP, Open Source Business Applications
-# Copyright (c) 2014 OpenERP S.A.
+# Copyright (c) 2013 OpenERP S.A.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@@ -49,8 +49,7 @@ class actions_server(osv.Model):
}
def on_change_template_id(self, cr, uid, ids, template_id, context=None):
- """ - mass_mailing: we cannot render, so return the template values
- - normal mode: return rendered values """
+ """ Render the raw template in the server action fields. """
if template_id:
fields = ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to', 'attachment_ids']
template_values = self.pool.get('email.template').read(cr, uid, template_id, fields, context)
From 26ff871ab8f35b39129747a7ff69917efdcdf615 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?=
Date: Fri, 26 Jul 2013 10:54:26 +0200
Subject: [PATCH 4/9] [FIX] crm: fixed a typo in onchange method name
bzr revid: tde@openerp.com-20130726085426-gpw86mn4ugno43o1
---
addons/crm/crm_lead_view.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/addons/crm/crm_lead_view.xml b/addons/crm/crm_lead_view.xml
index cb4302166a1..aa5aac76b9d 100644
--- a/addons/crm/crm_lead_view.xml
+++ b/addons/crm/crm_lead_view.xml
@@ -408,7 +408,7 @@
From c4210aeeb0579850cd02d99bebf121112b10d4b6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?=
Date: Fri, 26 Jul 2013 11:12:12 +0200
Subject: [PATCH 5/9] [FIX] email_template: ir_actions: fixed email server
action form view, a copy and paste introduced an error
bzr revid: tde@openerp.com-20130726091212-kzt029fechedq0yp
---
addons/email_template/ir_actions_view.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/addons/email_template/ir_actions_view.xml b/addons/email_template/ir_actions_view.xml
index f673fda687d..c8a54997089 100644
--- a/addons/email_template/ir_actions_view.xml
+++ b/addons/email_template/ir_actions_view.xml
@@ -35,7 +35,7 @@
Your template does not defined any email_from. Please update your template.
-
+
From a3c546a6008c41a8557e73d1886974bbe1b2add3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?=
Date: Fri, 26 Jul 2013 11:13:05 +0200
Subject: [PATCH 6/9] [REM] crm: removed new_email_send, now unused and
deprecated with chatter / templates.
bzr revid: tde@openerp.com-20130726091305-8lsmidcxyau3shw0
---
addons/crm/crm_lead.py | 36 ------------------------------------
1 file changed, 36 deletions(-)
diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py
index 46a3f6e199e..c0f003f9792 100644
--- a/addons/crm/crm_lead.py
+++ b/addons/crm/crm_lead.py
@@ -945,42 +945,6 @@ class crm_lead(format_address, osv.osv):
vals.update(onchange_stage_values)
return super(crm_lead, self).write(cr, uid, ids, vals, context=context)
- def new_mail_send(self, cr, uid, ids, context=None):
- '''
- This function opens a window to compose an email, with the edi sale template message loaded by default
- '''
- assert len(ids) == 1, 'This option should only be used for a single id at a time.'
- ir_model_data = self.pool.get('ir.model.data')
- try:
- template_id = ir_model_data.get_object_reference(cr, uid, 'crm', 'email_template_opportunity_mail')[1]
- except ValueError:
- template_id = False
- try:
- compose_form_id = ir_model_data.get_object_reference(cr, uid, 'mail', 'email_compose_message_wizard_form')[1]
- except ValueError:
- compose_form_id = False
- if context is None:
- context = {}
- ctx = context.copy()
- ctx.update({
- 'default_model': 'crm.lead',
- 'default_res_id': ids[0],
- 'default_use_template': bool(template_id),
- 'default_template_id': template_id,
- 'default_composition_mode': 'comment',
- })
- return {
- 'name': _('Compose Email'),
- 'type': 'ir.actions.act_window',
- 'view_type': 'form',
- 'view_mode': 'form',
- 'res_model': 'mail.compose.message',
- 'views': [(compose_form_id, 'form')],
- 'view_id': compose_form_id,
- 'target': 'new',
- 'context': ctx,
- }
-
# ----------------------------------------
# Mail Gateway
# ----------------------------------------
From d758de88f06fe58b64bcf262757d32e7c4b70fcc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?=
Date: Fri, 26 Jul 2013 11:33:35 +0200
Subject: [PATCH 7/9] [IMP] email_template: server action: better management of
template fields, saved but not editable
bzr revid: tde@openerp.com-20130726093335-vxniwn121djpaw32
---
addons/email_template/ir_actions.py | 24 ++++++++++++++++++-----
addons/email_template/ir_actions_view.xml | 10 +++++-----
2 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/addons/email_template/ir_actions.py b/addons/email_template/ir_actions.py
index 181cc9a1c5b..bd860785da4 100644
--- a/addons/email_template/ir_actions.py
+++ b/addons/email_template/ir_actions.py
@@ -33,16 +33,16 @@ class actions_server(osv.Model):
return res
_columns = {
- 'email_from': fields.char('From', readonly=True,
+ 'email_from': fields.char('From',
help="Sender address; define the template to see its value. If not set, the default "
"value will be the author's email alias if configured, or email address."),
- 'email_to': fields.char('To (Emails)', readonly=True,
+ 'email_to': fields.char('To (Emails)',
help="Comma-separated recipient addresses; define the template to see its value"),
- 'partner_to': fields.char('To (Partners)', readonly=True,
+ 'partner_to': fields.char('To (Partners)',
help="Comma-separated ids of recipient partners; define the template to see its value"),
- 'subject': fields.char('Subject', readonly=True,
+ 'subject': fields.char('Subject',
help="Email subject; define the template to see its value"),
- 'body_html': fields.text('Body', readonly=True,
+ 'body_html': fields.text('Body',
help="Rich-text/HTML version of the message; define the template to see its value"),
'template_id': fields.many2one('email.template', 'Email Template', ondelete='set null',
help="Define the email template to use for the email to send.")
@@ -61,6 +61,20 @@ class actions_server(osv.Model):
return {'value': values}
+ def create(self, cr, uid, values, context=None):
+ if values.get('template_id'):
+ fields = ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to', 'attachment_ids']
+ template_values = self.pool.get('email.template').read(cr, uid, values.get('template_id'), fields, context)
+ values.update(dict((field, template_values[field]) for field in fields if template_values.get(field)))
+ return super(actions_server, self).create(cr, uid, values, context=context)
+
+ def write(self, cr, uid, ids, values, context=None):
+ if values.get('template_id'):
+ fields = ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to', 'attachment_ids']
+ template_values = self.pool.get('email.template').read(cr, uid, values.get('template_id'), fields, context)
+ values.update(dict((field, template_values[field]) for field in fields if template_values.get(field)))
+ return super(actions_server, self).write(cr, uid, ids, values, context=context)
+
def run_action_email(self, cr, uid, action, eval_context=None, context=None):
if not action.template_id or not context.get('active_id'):
return False
diff --git a/addons/email_template/ir_actions_view.xml b/addons/email_template/ir_actions_view.xml
index c8a54997089..fae9c364312 100644
--- a/addons/email_template/ir_actions_view.xml
+++ b/addons/email_template/ir_actions_view.xml
@@ -29,16 +29,16 @@
-
Your template does not defined any email_from. Please update your template.
-
-
-
-
+
+
+
+
From ac26676968d006723ddf1190c77df4ed5268bc8a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?=
Date: Fri, 26 Jul 2013 11:33:47 +0200
Subject: [PATCH 8/9] [IMP] crm: reminder to user: uses a different and more
adequate template
bzr revid: tde@openerp.com-20130726093347-jhu39cmvg2b947gj
---
addons/crm/crm_action_rule_demo.xml | 2 +-
addons/crm/crm_lead_data.xml | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/addons/crm/crm_action_rule_demo.xml b/addons/crm/crm_action_rule_demo.xml
index 5dca69a40d4..569b2d676e0 100644
--- a/addons/crm/crm_action_rule_demo.xml
+++ b/addons/crm/crm_action_rule_demo.xml
@@ -14,7 +14,7 @@
Trueir.actions.serveremail
-
+ Set Auto Reminder on leads which are not open since 5 days.
diff --git a/addons/crm/crm_lead_data.xml b/addons/crm/crm_lead_data.xml
index 92914542d9d..091a4d217de 100644
--- a/addons/crm/crm_lead_data.xml
+++ b/addons/crm/crm_lead_data.xml
@@ -220,6 +220,15 @@
${not object.partner_id and object.email_from}
+
+ Reminder to User
+
+
+ admin@example.com
+ [${object.user_id and object.user_id.email}]
+ Reminder
+ This opportunity did not have any activity since at least 5 days.
+
From b4d2fc5512352f57f9d684caa7f068994b3c6877 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?=
Date: Fri, 26 Jul 2013 11:56:38 +0200
Subject: [PATCH 9/9] [IMP] crm: improved reminder ot user template
bzr revid: tde@openerp.com-20130726095638-0pdkph3xl9cl8v3j
---
addons/crm/crm_lead_data.xml | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/addons/crm/crm_lead_data.xml b/addons/crm/crm_lead_data.xml
index 091a4d217de..219ff2cdeee 100644
--- a/addons/crm/crm_lead_data.xml
+++ b/addons/crm/crm_lead_data.xml
@@ -225,9 +225,14 @@
admin@example.com
- [${object.user_id and object.user_id.email}]
- Reminder
- This opportunity did not have any activity since at least 5 days.
+ ${object.user_id != False and object.user_id.email}
+ Reminder on Lead: ${object.id} from ${object.partner_id != False and object.partner_id.name or object.contact_name}
+ This opportunity did not have any activity since at least 5 days. Here are some details:
+