Kuldeep Joshi(OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-bug-941428-kjo into 
lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)
Related bugs:
  Bug #941428 in OpenERP Addons: "[6.1.1.0] Invoice Email is send without 
attachment"
  https://bugs.launchpad.net/openobject-addons/+bug/941428

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-941428-kjo/+merge/101692

[FIX] Email is send without attachment in email_template


-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-941428-kjo/+merge/101692
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-bug-941428-kjo.
=== modified file 'email_template/email_template.py'
--- email_template/email_template.py	2012-03-22 14:11:53 +0000
+++ email_template/email_template.py	2012-04-12 07:11:19 +0000
@@ -22,6 +22,7 @@
 
 import base64
 import logging
+import time
 
 import netsvc
 from osv import osv
@@ -42,6 +43,8 @@
     _description = 'Email Templates'
     _rec_name = 'name' # override mail.message's behavior
 
+    _log = logging.getLogger('init')
+
     def render_template(self, cr, uid, template, model, res_id, context=None):
         """Render the given template text, replace mako expressions ``${expr}``
            with the result of evaluating these expressions with
@@ -342,6 +345,7 @@
         if template.report_template:
             report_name = self.render_template(cr, uid, template.report_name, template.model, res_id, context=context)
             report_service = 'report.' + report_xml_pool.browse(cr, uid, template.report_template.id, context).report_name
+            
             # Ensure report is rendered using template's language
             ctx = context.copy()
             if template.lang:
@@ -381,6 +385,9 @@
         ir_attachment = self.pool.get('ir.attachment')
         values = self.generate_email(cr, uid, template_id, res_id, context=context)
         assert 'email_from' in values, 'email_from is missing or empty after template rendering, send_mail() cannot proceed'
+        values['user_id'] = uid
+        values['date'] = time.strftime("%Y-%m-%d %H:%M:%S")
+
         attachments = values.pop('attachments') or {}
         msg_id = mail_message.create(cr, uid, values, context=context)
         # link attachments

=== modified file 'email_template/wizard/mail_compose_message.py'
--- email_template/wizard/mail_compose_message.py	2012-03-22 14:11:04 +0000
+++ email_template/wizard/mail_compose_message.py	2012-04-12 07:11:19 +0000
@@ -20,6 +20,7 @@
 ##############################################################################
 
 import base64
+import logging
 
 from osv import osv
 from osv import fields
@@ -43,6 +44,8 @@
 class mail_compose_message(osv.osv_memory):
     _inherit = 'mail.compose.message'
 
+    _log = logging.getLogger('init')
+
     def _get_templates(self, cr, uid, context=None):
         """
         Return Email Template of particular  Model.
@@ -95,7 +98,7 @@
                     for fname, fcontent in attachment.iteritems():
                         data_attach = {
                             'name': fname,
-                            'datas': fcontent,
+                            'datas': base64.b64encode(fcontent),
                             'datas_fname': fname,
                             'description': fname,
                             'res_model' : self._name,
@@ -159,4 +162,14 @@
     def render_template(self, cr, uid, template, model, res_id, context=None):
         return self.pool.get('email.template').render_template(cr, uid, template, model, res_id, context=context)
 
+    def send_mail(self, cr, uid, ids, context=None):
+        """Overrides 'mail.wizard' to use 'email.template' sending functionality.
+        """
+        for mail_compose in self.browse(cr, uid, ids, context=context):
+            res_id = context.get('active_id', False)
+
+            msg_id = self.pool.get('email.template').send_mail(cr, uid, mail_compose.template_id, res_id)
+            self._log.info('Message ID %s' % msg_id)
+
+        return {'type': 'ir.actions.act_window_close'}
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to