Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to invoke mails in account module in OpenERP(Odoo)?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 544
    Comment on it

    In OpenERP first create custom module and inherit the email_template object in your own module. Then create templates in .xml file.


    Follow these step given below:

    Step1- First, create module like: test and then create .py file like as: file in your module and pass this file in file.

    Using this code given below
    class email_template_send_wizard(osv.osv_memory):
        _name = 'email_template.send.wizard'                                    
        _inherit = 'email_template.send.wizard'
        def save_to_mailbox(self, cr, uid, ids, context=None):
            user = self.pool.get('res.users').browse(cr, uid, uid).name
            def get_end_value(id, value):
                if len(context['src_rec_ids']) > 1: # Multiple Mail: Gets value from the template
                    return self.get_value(cr, uid, template, value, context, id)
                    return value  
            if context is None:
                context = {}
            mail_ids = []
            template = self._get_template(cr, uid, context)
            for id in context['src_rec_ids']:
                screen_vals =, uid, ids[0], [],context)
                account = self.pool.get('email_template.account').read(cr, uid, screen_vals['from'], context=context)
                vals = {
                    'email_from': tools.ustr(account['name']) + "<" + tools.ustr(account['email_id']) + ">",
                    'email_to': get_end_value(id, screen_vals['to']),
                    'email_cc': get_end_value(id, screen_vals['cc']),
                    'email_bcc': get_end_value(id, screen_vals['bcc']),
                    'subject': get_end_value(id, screen_vals['subject']),
                    'body_text': get_end_value(id, screen_vals['body_text']),
                    'body_html': get_end_value(id, screen_vals['body_html']),
                    'account_id': screen_vals['from'],
                body = vals['body_text']
                vals['body_text'] = (body or ' ') + '\n\nFrom:\n' + str(user)
                if screen_vals['signature']:
                    signature = self.pool.get('res.users').read(cr, uid, uid, ['signature'], context)['signature']
                    if signature:
                        vals['body_text'] = tools.ustr(vals['body_text'] or '') + signature
                        vals['body_html'] = tools.ustr(vals['body_html'] or '') + signature
                attachment_ids = []
                #Create partly the mail and later update attachments
                mail_id = self.pool.get('email_template.mailbox').create(cr, uid, vals, context)
                if template.report_template:
                    reportname = 'report.' + self.pool.get('').read(cr, uid,, ['report_name'], context)['report_name']
                    data = {}
                    data['model'] = self.pool.get('ir.model').browse(cr, uid, screen_vals['rel_model'], context).model
                    ctx = context.copy()
                    if template.lang:
                        ctx['lang'] = self.get_value(cr, uid, template, template.lang, context, id)
                    service = netsvc.LocalService(reportname)
                    (result, format) = service.create(cr, uid, [id], data, ctx)
                    attachment_id = self.pool.get('ir.attachment').create(cr, uid, {
                        'name': _('%s (Email Attachment)') % tools.ustr(vals['subject']),
                        'datas': base64.b64encode(result),
                        'datas_fname': tools.ustr(get_end_value(id, screen_vals['report']) or _('Report')) + "." + format,
                        'description': vals['body_text'] or _("No Description"),
                        'res_model': 'email_template.mailbox',
                        'res_id': mail_id
                    }, context)
                    attachment_ids.append( attachment_id )   
                # Add document attachments
                for attachment_id in screen_vals.get('attachment_ids',[]):
                    new_id = self.pool.get('ir.attachment').copy(cr, uid, attachment_id, {
                        'res_model': 'email_template.mailbox',
                        'res_id': mail_id,
                    }, context)
                    attachment_ids.append( new_id )   
                if attachment_ids:
                    self.pool.get('email_template.mailbox').write(cr, uid, mail_id, {
                        'attachments_ids': [[6, 0, attachment_ids]],
                        'mail_type': 'multipart/mixed'
                    }, context)
            return mail_ids


    Step2- Then, create another file like: a test.xml file in your own module and pass this file in the file.

    Use this code given below

    <?xml version="1.0" encoding="UTF-8"?>
     		<record model="ir.ui.view" id="email_template_send_wizard_form_ezure_1">
    				<field name="name">email_template.send.wizard.form</field>
    				<field name="model">email_template.send.wizard</field>
    				<field name="inherit_id" ref="email_template.email_template_send_wizard_form"/>
    				<field name="type">form</field>
    				<field name="arch" type="xml">
    				<field name="bcc" select="2" colspan="4" position="replace">
    				<field name="bcc" select="2" colspan="4" invisible="1"/>

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: