[IMP]add template_id in hr_recruitment_stage for mail functionality.
authorDarshan Kalola (OpenERP) <dka@tinyerp.com>
Fri, 20 Sep 2013 10:28:18 +0000 (15:58 +0530)
committerDarshan Kalola (OpenERP) <dka@tinyerp.com>
Fri, 20 Sep 2013 10:28:18 +0000 (15:58 +0530)
bzr revid: dka@tinyerp.com-20130920102818-xj7ua08i5406wi16

addons/hr_recruitment/hr_recruitment.py
addons/hr_recruitment/hr_recruitment_data.xml
addons/hr_recruitment/hr_recruitment_view.xml

index fbbe530..9903fa0 100644 (file)
@@ -54,6 +54,7 @@ class hr_recruitment_stage(osv.osv):
         'department_id':fields.many2one('hr.department', 'Specific to a Department', help="Stages of the recruitment process may be different per department. If this stage is common to all departments, keep this field empty."),
         'fold': fields.boolean('Hide in views if empty', help="This stage is not visible, for example in status bar or kanban view, when there are no records in that stage to display."),
         'requirements': fields.text('Requirements'),
+        'template_id': fields.many2one('email.template', 'Use template', help="Use this email template, so that an email will be sent to applicant if application stage is changed to this stage.")
     }
     _defaults = {
         'sequence': 1,
@@ -255,6 +256,16 @@ class hr_applicant(osv.Model):
     _group_by_full = {
         'stage_id': _read_group_stage_ids
     }
+    
+    def _get_mail_template(self, cr, uid, ids, template, context):
+        mail_obj = self.pool.get('mail.mail')
+        assert template._name == 'email.template'
+        for applications in self.browse(cr, uid, ids, context):
+            if applications.email_from:
+                mail_id = self.pool.get('email.template').send_mail(cr, uid, template.id, applications.id, True, context=context)
+                mail_state = mail_obj.read(cr, uid, mail_id, ['state'], context=context)
+                if mail_state and mail_state['state'] == 'exception':
+                    raise self.pool.get('res.config.settings').get_config_warning(cr, _("Cannot send email: no outgoing email server configured.\nYou can configure it under %(menu:base_setup.menu_general_configuration)s."), context)
 
     def onchange_job(self, cr, uid, ids, job_id=False, context=None):
         if job_id:
@@ -429,6 +440,9 @@ class hr_applicant(osv.Model):
         # stage_id: track last stage before update
         if 'stage_id' in vals:
             vals['date_last_stage_update'] = fields.datetime.now()
+            stage_obj = self.pool.get('hr.recruitment.stage').browse(cr, uid, vals.get('stage_id'), context=context)
+            if stage_obj and stage_obj.template_id:
+                self._get_mail_template(cr, uid, ids, stage_obj.template_id, context)
             for applicant in self.browse(cr, uid, ids, context=None):
                 vals['last_stage_id'] = applicant.stage_id.id
                 res = super(hr_applicant, self).write(cr, uid, [applicant.id], vals, context=context)
index d3cbc9f..9cd3213 100644 (file)
         <field name="name">Interview</field>
     </record>
 
+<!-- Templates DATA for  refuse and approve -->
+    <record id="email_template_refuse_applicant" model="email.template">
+        <field name="name">Refuse Application</field>
+        <field name="email_from">${user.email or ''}</field>
+        <field name="subject">We refuse your application</field>
+        <field name="email_to">${object.email_from}</field>
+        <field name="lang">${object.lang}</field>
+        <field name="model_id" ref="hr_recruitment.model_hr_applicant"/>
+        <field eval="0" name="user_signature"/>
+        <field name="body_html"><![CDATA[<p>Dear Applicant,</p>
+        <p>We thank you for your interest in our company and for your application.
+        Unfortunately, your profile does not match with our needs or our recruitment campaign has reached its term.</p>
+        <p>If you want more details, feel free to contact us by phone.</p>
+        <p>Kind regards,</p>
+        <br/>
+         ${object.user_id.signature}
+        <br/>]]></field>
+    </record>
+
+    <record id="email_template_approve_applicant" model="email.template">
+        <field name="name">Interested in Application</field>
+        <field name="email_from">${user.email or ''}</field>
+        <field name="email_to">${object.email_from}</field>
+        <field name="subject">We are interested in your application</field>
+        <field name="lang">${object.lang}</field>
+        <field name="model_id" ref="hr_recruitment.model_hr_applicant"/>
+        <field eval="0" name="user_signature"/>
+        <field name="body_html"><![CDATA[<p>Dear Applicant,</p>
+        <p>Congrats! Your resume's got our interest!
+        I will call you as soon as possible to make a 10 minutes phone interview and  plan a first meeting.</p>
+        <p>If we can’t reach you or if you miss our call, feel free to reach me back on the number 001 312 349 3030
+        If I do not answer, please let me a message with some schedules to call you back.</p>
+        <p>Kind regards,</p>
+        <br/>
+         ${object.user_id.signature}
+        <br/>]]></field>
+    </record>
+
         <!--    HR Recruitment Source        -->
 
     <record model="hr.recruitment.source" id="source_linkedin">
     </record>
     <record model="hr.recruitment.stage" id="stage_job5">
         <field name="name">Contract Signed</field>
+        <field name="template_id" ref="email_template_approve_applicant"/>
         <field name="sequence">5</field>
     </record>
     <record model="hr.recruitment.stage" id="stage_job6">
         <field name="name">Refused</field>
         <field name="sequence">6</field>
+        <field name="template_id" ref="email_template_refuse_applicant"/>
         <field name="fold" eval="True"/>
     </record>
     <record id="survey_job_0" model="survey">
         <field eval="0" name="allow_comment"/>
     </record>
 
-       <!-- Templates DATA for  refuse and approve -->
-                
-    <record id="email_template_refuse_applicant" model="email.template">
-        <field name="name">Refuse Application</field>
-        <field name="email_from">${user.email or ''}</field>
-        <field name="subject">We refuse your application</field>
-        <field name="email_to">${object.email_from}</field>
-        <field name="lang">${object.lang}</field>
-        <field name="model_id" ref="hr_recruitment.model_hr_applicant"/>
-        <field eval="0" name="user_signature"/>
-        <field name="body_html"><![CDATA[<p>Dear Applicant,</p>
-        <p>We thank you for your interest in our company and for your application.
-        Unfortunately, your profile does not match with our needs or our recruitment campaign has reached its term.</p>
-        <p>If you want more details, feel free to contact us by phone.</p>
-        <p>Kind regards,</p>
-        <br/>
-         ${object.user_id.signature}
-        <br/>]]></field>
-    </record>
-
-    <record id="email_template_approve_applicant" model="email.template">
-        <field name="name">Interested in Application</field>
-        <field name="email_from">${user.email or ''}</field>
-        <field name="email_to">${object.email_from}</field>
-        <field name="subject">We are interested in your application</field>
-        <field name="lang">${object.lang}</field>
-        <field name="model_id" ref="hr_recruitment.model_hr_applicant"/>
-        <field eval="0" name="user_signature"/>
-        <field name="body_html"><![CDATA[<p>Dear Applicant,</p>
-        <p>Congrats! Your resume's got our interest!
-        I will call you as soon as possible to make a 10 minutes phone interview and  plan a first meeting.</p>
-        <p>If we can’t reach you or if you miss our call, feel free to reach me back on the number 001 312 349 3030
-        If I do not answer, please let me a message with some schedules to call you back.</p>
-        <p>Kind regards,</p>
-        <br/>
-         ${object.user_id.signature}
-        <br/>]]></field>
-    </record>
-            
     <record id="survey_answer_job_70" model="survey.answer">
         <field name="in_visible_answer_type">1</field>
         <field name="answer">Male</field>
index a07a2d5..ea3b616 100644 (file)
                     <group>
                         <field name="sequence"/>
                         <field name="fold"/>
+                        <field name="template_id" domain= "[('model_id.model', '=', 'hr.applicant')]"/>
                     </group>
                 </group>
                 <separator string="Requirements"/>