def _mass_mail_send(self, cr, uid, data, context):
	nbr = 0
	partners = pooler.get_pool(cr.dbname).get('labo.analysis.request').browse(cr, uid, data['ids'], context)
	for p in partners:
		partner=p.ref_client
		for adr in partner.address:
			if adr.email:
				name = adr.name or partner.name
				to = '%s <%s>' % (name, adr.email)
#TODO: add some tests to check for invalid email addresses
#CHECKME: maybe we should use res.partner/email_send
				attach_ids = pooler.get_pool(cr.dbname).get('ir.attachment').search(cr, uid,
							[('res_model', '=', 'labo.analysis.request'),
								('res_id', '=', p.id)])
				res = pooler.get_pool(cr.dbname).get('ir.attachment').read(cr, uid,
							attach_ids, ['datas_fname','datas'])
				res = map(lambda x: (x['datas_fname'],
						base64.decodestring(x['datas'])), res)
				tools.email_send_attach(data['form']['from'], [to], data['form']['subject'], data['form']['text'],attach=res)
				nbr += 1
	#	pooler.get_pool(cr.dbname).get('res.partner.event').create(cr, uid,
	#			{'name': 'Email sent through mass mailing',
	#			 'partner_id': partner,
	#			 'description': data['form']['text'], })
#TODO: log number of message sent
	return {'email_sent': nbr}
Esempio n. 2
0
def _mass_mail_send(self, cr, uid, data, context):
    nbr = 0
    partners = pooler.get_pool(cr.dbname).get('labo.analysis.request').browse(
        cr, uid, data['ids'], context)
    for p in partners:
        partner = p.ref_client
        for adr in partner.address:
            if adr.email:
                name = adr.name or partner.name
                to = '%s <%s>' % (name, adr.email)
                #TODO: add some tests to check for invalid email addresses
                #CHECKME: maybe we should use res.partner/email_send
                attach_ids = pooler.get_pool(
                    cr.dbname).get('ir.attachment').search(
                        cr, uid, [('res_model', '=', 'labo.analysis.request'),
                                  ('res_id', '=', p.id)])
                res = pooler.get_pool(cr.dbname).get('ir.attachment').read(
                    cr, uid, attach_ids, ['datas_fname', 'datas'])
                res = map(
                    lambda x:
                    (x['datas_fname'], base64.decodestring(x['datas'])), res)
                tools.email_send_attach(data['form']['from'], [to],
                                        data['form']['subject'],
                                        data['form']['text'],
                                        attach=res)
                nbr += 1
    #	pooler.get_pool(cr.dbname).get('res.partner.event').create(cr, uid,
    #			{'name': 'Email sent through mass mailing',
    #			 'partner_id': partner,
    #			 'description': data['form']['text'], })


#TODO: log number of message sent
    return {'email_sent': nbr}
Esempio n. 3
0
def _mass_mail_send(cr, uid, data, context, adr):
    import re
    # change the [[field]] tags with the partner address values
    pattern = re.compile('\[\[\S+\]\]')
    fields = pattern.findall(data['form']['text'])
    texts = []
    for field in fields:
        text = getattr(adr, field[2:-2])
        if text and field[-5:-2] == '_id':  # State or country field
            text = text.name
        if text and field[2:-2] == 'function':  # functions field
            text = text.name
        texts.append(text or '')
    mail = str(pattern.sub('%s', data['form']['text']))
    mail = mail % tuple(texts)
    #print mail

    # The adr.email field can contain several email addresses separated by ,
    name = adr.name or adr.partner_id.name
    to = ['%s <%s>' % (name, email) for email in adr.email.split(',')]
    #print to

    # List of attached files: List of tuples with (file_name, file_content)
    f_attach = []
    if data['form']['file1']:
        f_attach.append(
            (data['form']['name1']
             or 'attached_file1', base64.decodestring(data['form']['file1'])))
    if data['form']['file2']:
        f_attach.append(
            (data['form']['name2']
             or 'attached_file2', base64.decodestring(data['form']['file2'])))
    if data['form']['file3']:
        f_attach.append(
            (data['form']['name3']
             or 'attached_file3', base64.decodestring(data['form']['file3'])))

#TODO: add some tests to check for invalid email addresses
#CHECKME: maybe we should use res.partner/email_send
    tools.email_send_attach(data['form']['from'],
                            to,
                            data['form']['subject'],
                            mail,
                            attach=f_attach)

    # Add a partner event
    c_id = pooler.get_pool(cr.dbname).get('res.partner.canal').search(
        cr, uid, [('name', 'ilike', 'EMAIL'), ('active', '=', True)])
    c_id = c_id and c_id[0] or False
    pooler.get_pool(cr.dbname).get('res.partner.event').create(
        cr, uid, {
            'name': 'Email sent through mass mailing',
            'partner_id': adr.partner_id.id,
            'description': mail,
            'canal_id': c_id,
            'user_id': uid,
        })
    def _send_mail(self, cr, uid, data, context):

        ptrn = re.compile('(\w+@\w+(?:\.\w+)+)')
        result = ptrn.search(data['form']['email'])
        if result==None:
            raise wizard.except_wizard('Error !', 'Enter Valid E-Mail Address.')

        fields=['Id','Name','Partner','Related Type of Carnet','Emission Date','Validity Date','Holder Name','Holder Address','Holder City','Representer Name','Representer Address','Representer City','Usage','Goods','Area','Insurer Agreement','Own Risks','Goods Value','Double Signature','Initial No. of Pages','Additional No. of Pages','Warranty','Related Warranty Product','Date of Return','State','Date of Closure','Date of Sending to the Federation','Apply the Member Price']
        # For First CSV

        month=data['form']['month']
        yr=int(time.strftime('%Y'))
        self.first_day=datetime.date(yr,int(month),1)
        self.last_day=datetime.date(yr,int(month),lengthmonth(yr, int(month)))

        period="to_date('" + self.first_day.strftime('%Y-%m-%d') + "','yyyy-mm-dd') and to_date('" + self.last_day.strftime('%Y-%m-%d') +"','yyyy-mm-dd')"

        cr.execute('select id from cci_missions_ata_carnet where federation_sending_date is  null and ok_state_date between %s'%(period))
        res_file1=cr.fetchall()
        lines=[]
        root_path=tools.config.options['root_path']
        if res_file1:
            lines=self.make_csv(cr, uid,res_file1,file2=0)
            self.write_csv(root_path+'/carnet_1.csv',fields,lines)
        # First CSV created
        # Process for second CSV -Start
        today=datetime.datetime.today()
        _date=datetime.date(today.year-2,today.month,today.day)
        comp_date=_date.strftime('%Y-%m-%d')
        cr.execute('select id from cci_missions_ata_carnet where federation_sending_date is  null and state='"'pending'"' and return_date <='"'%s'"''%(str(comp_date)))
        res_file2=cr.fetchall()
        lines=[]
        if res_file2:
            lines=self.make_csv(cr, uid,res_file2,file2=1)
            self.write_csv(root_path+'/carnet_2.csv',fields,lines)
        # Second CSV created.
        if res_file1==[] and res_file2==[]:
            raise wizard.except_wizard('Notification !', 'No Records Found to make the CSV files.Choose other criteria.')
        files_attached=[]

        if res_file1:
            file_csv1=tools.file_open(root_path+'/carnet_1.csv','rb',subdir=None)
            files_attached=[('Ata_carnet_csv_1.csv',file_csv1.read())]
        if res_file2:
            file_csv2=tools.file_open(root_path+'/carnet_2.csv','rb',subdir=None)
            files_attached.append(('Ata_carnet_csv_2.csv',file_csv2.read()))

        src=tools.config.options['smtp_user']
        dest=[data['form']['email']]
        body="Hello,\nHere are the CSV files for Federation Sending.\nThanks You For Using TinyERP.\nThink Big Use Tiny."
        tools.email_send_attach(src,dest,"Federation Sending Files From TinyERP",body,attach=files_attached)
        return {}
Esempio n. 5
0
    def _send_mail(self, cr, uid, data, context):

        ptrn = re.compile('(\w+@\w+(?:\.\w+)+)')
        result = ptrn.search(data['form']['email'])
        if result == None:
            raise wizard.except_wizard('Error !',
                                       'Enter Valid E-Mail Address.')

        fields = [
            'Id', 'Name', 'Partner', 'Related Type of Carnet', 'Emission Date',
            'Validity Date', 'Holder Name', 'Holder Address', 'Holder City',
            'Representer Name', 'Representer Address', 'Representer City',
            'Usage', 'Goods', 'Area', 'Insurer Agreement', 'Own Risks',
            'Goods Value', 'Double Signature', 'Initial No. of Pages',
            'Additional No. of Pages', 'Warranty', 'Related Warranty Product',
            'Date of Return', 'State', 'Date of Closure',
            'Date of Sending to the Federation', 'Apply the Member Price'
        ]
        # For First CSV

        month = data['form']['month']
        yr = int(time.strftime('%Y'))
        self.first_day = datetime.date(yr, int(month), 1)
        self.last_day = datetime.date(yr, int(month),
                                      lengthmonth(yr, int(month)))

        period = "to_date('" + self.first_day.strftime(
            '%Y-%m-%d'
        ) + "','yyyy-mm-dd') and to_date('" + self.last_day.strftime(
            '%Y-%m-%d') + "','yyyy-mm-dd')"

        cr.execute(
            'select id from cci_missions_ata_carnet where federation_sending_date is  null and ok_state_date between %s'
            % (period))
        res_file1 = cr.fetchall()
        lines = []
        root_path = tools.config.options['root_path']
        if res_file1:
            lines = self.make_csv(cr, uid, res_file1, file2=0)
            self.write_csv(root_path + '/carnet_1.csv', fields, lines)
        # First CSV created
        # Process for second CSV -Start
        today = datetime.datetime.today()
        _date = datetime.date(today.year - 2, today.month, today.day)
        comp_date = _date.strftime('%Y-%m-%d')
        cr.execute(
            'select id from cci_missions_ata_carnet where federation_sending_date is  null and state='
            "'pending'"
            ' and return_date <='
            "'%s'"
            '' % (str(comp_date)))
        res_file2 = cr.fetchall()
        lines = []
        if res_file2:
            lines = self.make_csv(cr, uid, res_file2, file2=1)
            self.write_csv(root_path + '/carnet_2.csv', fields, lines)
        # Second CSV created.
        if res_file1 == [] and res_file2 == []:
            raise wizard.except_wizard(
                'Notification !',
                'No Records Found to make the CSV files.Choose other criteria.'
            )
        files_attached = []

        if res_file1:
            file_csv1 = tools.file_open(root_path + '/carnet_1.csv',
                                        'rb',
                                        subdir=None)
            files_attached = [('Ata_carnet_csv_1.csv', file_csv1.read())]
        if res_file2:
            file_csv2 = tools.file_open(root_path + '/carnet_2.csv',
                                        'rb',
                                        subdir=None)
            files_attached.append(('Ata_carnet_csv_2.csv', file_csv2.read()))

        src = tools.config.options['smtp_user']
        dest = [data['form']['email']]
        body = "Hello,\nHere are the CSV files for Federation Sending.\nThanks You For Using TinyERP.\nThink Big Use Tiny."
        tools.email_send_attach(src,
                                dest,
                                "Federation Sending Files From TinyERP",
                                body,
                                attach=files_attached)
        return {}