Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Sending email programatically from OpenERP 7.0

By
Saghir A. Khatri
on 12/2/14, 5:59 AM 1,026 views

Hello all! i am trying to send email when a deadline is passed.

currently i am trying this simple code to test whether email works or not.

    post_vars = {'subject': "Message subject",
                 'body': "Message body",
                 'partner_ids': [(4, 3)],} # Where "4" adds the ID to the list
                                           # of followers and "3" is the partner ID
                thread_pool = self.pool.get('mail.thread')
                thread_pool.message_post(
                    cr, uid, False,
                    type="notification",
                    subtype="mt_comment",
                    context=context,
                    **post_vars)

but it is not working. I am trying to sort out this issue. Kindly let me know. I have also tried mail_composed, but nothing happens.

Please point me to right direction thanks.

 

Edit

 

I cant add comment because of low karma, but libu's solution will open a wizard window. i want to select users in method and send email direclty without going to wizard. Is that possible??

-1

Odoo

--Odoo --
1328
| 5 2 5
kerala, India
--Odoo --

Working as a Odoo Functional and Technical Expert

Odoo
On 12/2/14, 6:40 AM

Hi This is a my sample custom code for email sending,You just changes wherever you want

class hr_employee(osv.osv):

     _name='hr.employee'
     _inherit=['hr.employee','mail.thread']

     _columns={
              'date_of_join' :fields.date('Date of Join',required=True),
              'current_date':fields.date('Applied date',required=True),
              'eligible_details':fields.char('Eligibility Details'),
              'visaexpiry_date':fields.date('Visa Expiry Date'),
               'residence_expiry_date':fields.date('Residence Expiry',required=True),
               'work_permit_date':fields.date('Work Permit'),
               'insurance_expiry_date':fields.date('Insurance date'),
               'license_date':fields.date('License date',required=True)
                             }


     def check_residence_expiry_date(self, cr, uid, ids, context=None):
      
        print "total_days#############################"
         
        expir_var=self.read(cr,uid,ids,['residence_expiry_date','date_of_join'],context=context)
        dateformat="%Y-%m-%d"
        d1=datetime.strptime(expir_var[0]['residence_expiry_date'],dateformat)
        d2=datetime.strptime(expir_var[0]['date_of_join'],dateformat)
        v1=d1-d2
        total_days=v1.days
        print "total_days#############################",total_days
        
        if total_days<=20:
            print "total_days#############################",total_days

              #This is the email template code

            ir_model_data = self.pool.get('ir.model.data')
            try:
                compose_form_id = ir_model_data.get_object_reference(cr, uid, 'mail', 'email_compose_message_wizard_form')[1]
            except ValueError:
                compose_form_id = False
    
            return {
                'type': 'ir.actions.act_window',
                'view_type': 'form',
                'view_mode': 'form',
                'res_model': 'mail.compose.message',
                'views': [(compose_form_id, 'form')],
                'view_id': compose_form_id,
                'target': 'new',
                'context': {},
            }

        else:
            raise osv.except_osv(_('Hi!'), _('Your Residence Expiry Date is not Reached'))

hr_employee()

\xml file-----------------------

<record  model="ir.ui.view"  id="hr_employee_inherited">
                <field name="name">hr employee inherited</field>
                <field name="model">hr.employee</field>
                <field name="inherit_id"  ref="hr.view_employee_form"/>
               <field name="arch"  type="xml">
               
               
               <xpath expr=" /form/sheet/notebook/page[2]/group/group[4]/field[@name='birthday']"  position="after">
                           
        <group> <group>  
            <field name="date_of_join" />
            <field name="visaexpiry_date" />
               <field name="residence_expiry_date" />
                <field name="work_permit_date" />
                <field name="insurance_expiry_date" />
                 <field name="license_date" /></group>
        </group>
                <group><button name="check_license_expiry" string="License Expiry"
                                type="object" icon="gtk-apply" />
                    <button name="check_residence_expiry_date" string="Residence Expiry"
                                type="object" icon="gtk-apply" /></group>
                       
               </xpath>
               </field>
 </record>

 

 

 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/2/14, 5:59 AM
Seen: 1026 times
Last updated: 3/16/15, 8:10 AM