title: How to attach pdf report to automatically send mail after importing data in odoo v8?
body: <p>When i import data at that time i need to attach pdf report which will  automatically send with declare part of body. If i send manual mail its going on with attachment of report.</p>
  
  <pre><code>class import_data(osv.osv):
  
      _name = "import.data"
      _columns = {
          'csv_file' : fields.binary('CSV FILE', required="1"),
          'type':fields.selection([('NSE','NSE'),('BSE','BSE'),('Unlisted','Unlisted')],'Exchange Type',required="1")
          }
  </code></pre>
  
  <p>def send_mail_user(self,cr,uid,ids,data, context=None):</p>
  
  <pre><code>    res_user_obj = self.pool.get('res.users')
      user = res_user_obj.browse(cr,uid, [uid], context)[0]
      mail_mail = self.pool.get('mail.mail')
      this_context = context
      if data.excess &lt; 0.0:
          subject  =  'Share Valuation Report for'  "%s" % (data.name.name) + ' | Deposite security values'
      else:
          subject  =  'Share Valuation Report for'  "%s" % (data.name.name) + ' '         
  
      if user.login:
          body = '''
                      Dear Sir/Madam,
  
                      &lt;p&gt;Kindly find the share valuation report. The minimum security ratio has been maintained as on &lt;b&gt;''' "%s" % data.write_date +'''&lt;/b&gt;.
  </code></pre>
  
  <p></p> 
                          <p> </p></p>
  
  <pre><code>                    &lt;p&gt;&lt;table&gt;
                              &lt;tr&gt;
                                  &lt;td&gt;Current Loan :
                                      &lt;b&gt;''' "%s" % data.loan +'''&lt;/b&gt;                    
                                  &lt;/td&gt;
  
                                  &lt;td&gt;Date :
                                      &lt;b&gt;''' "%s" % data.write_date +'''&lt;/b&gt;
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                              &lt;tr&gt;
                                  &lt;td&gt;Requisite Security Ratio :
                                      &lt;b&gt;''' "%s" % data.rs_ratio +'''&lt;/b&gt;                    
                                  &lt;/td&gt;
  
                                  &lt;td&gt;Share Type :
                                      &lt;b&gt;''' "%s" % data.type +'''&lt;/b&gt;
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                              &lt;tr&gt;
                                  &lt;td&gt;Requisite Security Value :
                                      &lt;b&gt;''' "%s" % data.rs_value +'''&lt;/b&gt;                    
                                  &lt;/td&gt;
  
                                  &lt;td&gt;Excesss/(Shortfall) :
                                      &lt;b&gt;''' "%s" % data.excess +'''&lt;/b&gt;
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                              &lt;tr&gt;
                                  &lt;td&gt;Total Share :
                                      &lt;b&gt;''' "%s" % data.total_share +'''&lt;/b&gt;                    
                                  &lt;/td&gt;
  
                                  &lt;td&gt;Number of Share :
                                      &lt;b&gt;''' "%s" % data.no_share +'''&lt;/b&gt;
                                  &lt;/td&gt;
                              &lt;/tr&gt;
  
                          &lt;/table&gt;&lt;/p&gt;
  
                      &lt;p&gt;If you have any query/ clairification please contact your Relationship Manager &lt;/p&gt;
                      &lt;p&gt;Regards, &lt;/p&gt; 
                      &lt;p&gt;''' "%s" % user.name +''' &lt;/p&gt;
                      &lt;p&gt;''' "%s" % user.email +''' &lt;/p&gt;
                      &lt;p&gt;''' "%s" % user.phone +''' &lt;/p&gt;
                      &lt;p&gt;*** This is an automatically generated email, please do not reply ***&lt;/p&gt; 
                      ''' 
          mail_values = {
              'email_from': user.email,
              'email_to': data.name.email,
              'email_cc': user.email,
              'subject': subject,
              'body_html': body,
              'state': 'outgoing',
              'type': 'email',
              }
          mail_id = mail_mail.create(cr, uid, mail_values, context=this_context)    
          a=mail_mail.send(cr, uid, [mail_id],  auto_commit=True, context=this_context)
      return True        
  </code></pre>
  
  <p>def import_data(self,cr,uid,ids,context=None):</p>
  
  <pre><code>        form = self.read(cr, uid, ids, [])
          if not form[0].get('csv_file'):
              raise osv.except_osv(_('Warning!'), _('Please Import CSV!'))
          fdata = form and base64.decodestring(form[0]['csv_file']) or False
  
          input = cStringIO.StringIO(fdata)
          input.seek(0)
          try:
              data = list(csv.reader(input, quotechar='"' or '"', delimiter=','))
          except:
               raise osv.except_osv(_('Error!'), _('please imported CSV data file is not properly set for the delimiter  !'))
          mix_log=""
          if data and form[0].get('type') == 'NSE':
              self.create_nse(cr,uid,ids,data,context=None)
          if data and form[0].get('type') == 'BSE':
              self.create_bse(cr,uid,ids,data,context=None)    
  
          share_mon_obj= self.pool.get('share.monitors')
          his_obj=self.pool.get('share.monitors.history')
          share_mon_ids= share_mon_obj.search(cr,uid,[])
          vals={}
          if share_mon_ids:
              for share_id in share_mon_ids:
                  if share_id:
                      c_data = share_mon_obj.browse(cr,uid,share_id)
                      if not c_data.share_line:
                          raise osv.except_osv(_('Error!'), _('please create the company and share details!'))
  
                      for c_line in c_data.share_line:
                          val={
                              'company_names' : c_line.names and c_line.names.id or False,
                              'isin': c_line.isin_no,
                              'shares' : c_line.share,
                              'price_quote': c_line.quote_price,
                              'value_gross': c_line.gross_value,
                              'ratio_rs': c_line.rs_ratio,
                              'ratio_as': c_line.as_ratio,
                              'write_dates' : c_line.write_date, 
                              'monitor_ids': c_line.monitor_id and c_line.monitor_id.id or False,
                              'share_type':c_line.share_type or False,
                          }
                          for  csv_line in data:
                              if form[0].get('type') == 'NSE':
                                  if c_line.isin_no == csv_line[12] and c_line.share_type == 'NSE':
                                      vals={
                                          'quote_price':csv_line[5] or 0.00,
                                      }
                                      his_create_id=his_obj.create(cr,uid,val)
                                      a=self.pool.get('share.monitors.info').write(cr,uid,c_line.id,vals)
  
                              if form[0].get('type') == 'BSE':
                                  if c_line.isin_no == csv_line[0] and c_line.share_type == 'BSE':
                                      vals={
                                          'quote_price':csv_line[7] or 0.00,
                                      }
                                      his_create_id=his_obj.create(cr,uid,val)
                                      a=self.pool.get('share.monitors.info').write(cr,uid,c_line.id,vals)   
  
                      self.send_mail_user(cr, uid,ids,c_data,context=context)
  
          return True
  </code></pre>