← Back to team overview

credativ team mailing list archive

[Branch ~credativ/openobject-addons/6.1] Rev 7062: [FIX] Apply fix for lp bug 1193220 where reports are not attached to followup emails

 

------------------------------------------------------------
revno: 7062
committer: Craig Gowing (credativ) <craig.gowing@xxxxxxxxxxxxxx>
branch nick: addons
timestamp: Tue 2014-11-18 10:54:03 +0000
message:
  [FIX] Apply fix for lp bug 1193220 where reports are not attached to followup emails
modified:
  account_followup/i18n/account_followup.pot
  account_followup/wizard/account_followup_print.py


--
lp:~credativ/openobject-addons/6.1
https://code.launchpad.net/~credativ/openobject-addons/6.1

Your team credativ is subscribed to branch lp:~credativ/openobject-addons/6.1.
To unsubscribe from this branch go to https://code.launchpad.net/~credativ/openobject-addons/6.1/+edit-subscription
=== modified file 'account_followup/i18n/account_followup.pot'
--- account_followup/i18n/account_followup.pot	2012-02-08 01:08:30 +0000
+++ account_followup/i18n/account_followup.pot	2014-11-18 10:54:03 +0000
@@ -332,6 +332,12 @@
 msgstr ""
 
 #. module: account_followup
+#: code:addons/account_followup/wizard/account_followup_print.py:303
+#, python-format
+msgid "Followup-"
+msgstr ""
+
+#. module: account_followup
 #: help:account.followup.print,date:0
 msgid "This field allow you to select a forecast date to plan your follow-ups"
 msgstr ""

=== modified file 'account_followup/wizard/account_followup_print.py'
--- account_followup/wizard/account_followup_print.py	2012-02-13 16:03:19 +0000
+++ account_followup/wizard/account_followup_print.py	2014-11-18 10:54:03 +0000
@@ -25,6 +25,8 @@
 import tools
 from osv import fields, osv
 from tools.translate import _
+import base64
+import netsvc
 
 class account_followup_print(osv.osv_memory):
     _name = 'account.followup.print'
@@ -227,7 +229,16 @@
             msg_sent = ''
             msg_unsent = ''
             data_user = user_obj.browse(cr, uid, uid, context=context)
-            for partner in self.pool.get('res.partner').browse(cr, uid, partners, context=context):
+            line_ids = line_obj.search(cr,uid,[('partner_id', 'in', partners)])
+            partners = []
+            dict_lines = {}
+            for line in line_obj.browse(cr, uid, line_ids, context=context):
+                if line.partner_id.id not in dict_lines.keys():
+                    partners.append(line.partner_id)
+                    dict_lines[line.partner_id.id] = [line]
+                else:
+                    dict_lines[line.partner_id.id].append(line)
+            for partner in partners:
                 ids_lines = move_obj.search(cr,uid,[('partner_id','=',partner.id),('reconcile_id','=',False),('account_id.type','in',['receivable']),('company_id','=',context.get('company_id', False))])
                 data_lines = move_obj.browse(cr, uid, ids_lines, context=context)
                 total_amt = 0.0
@@ -242,7 +253,8 @@
                         if (not dest) and adr.type=='default':
                             if adr.email:
                                 dest = [adr.email]
-                src = tools.config.options['email_from']
+                user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
+                src = user.user_email or tools.config.get('email_from', False)
                 if not data.partner_lang:
                     body = data.email_body
                 else:
@@ -282,7 +294,17 @@
                 msg = ''
                 if dest:
                     try:
-                        mail_message.schedule_with_attach(cr, uid, src, dest, sub, body, context=context)
+                        company_id = context.get('company_id')
+                        data_dict = {'form':{'partner_ids':[partner.id * 10000 + company_id], 'date': time.strftime('%Y-%m-%d'), 'followup_id': context.get('followup_id')}}
+                        ctx = context.copy()
+                        ctx['lang'] = partner.lang or ctx.get('lang')
+                        datax,frmt = netsvc.LocalService('report.account_followup.followup.print').create(cr, uid, [], data_dict, ctx)
+                        params = {
+                            'datas': base64.encodestring( datax ),
+                            'datas_fname': _('Followup-') + str(partner.name) + '.' + frmt,
+                        }
+                        attach = dict(map(lambda x: (x['datas_fname'], base64.decodestring(x['datas'])), [params]))
+                        mail_message.schedule_with_attach(cr, uid, src, dest, sub, body, attachments=attach, context=context)
                         msg_sent += partner.name + '\n'
                     except Exception, e:
                         raise osv.except_osv('Error !', e )