[MERGE] [IMP] hr_recruitment: store current stage before doing stage modification...
authorThibault Delavallée <tde@openerp.com>
Wed, 4 Sep 2013 14:10:24 +0000 (16:10 +0200)
committerThibault Delavallée <tde@openerp.com>
Wed, 4 Sep 2013 14:10:24 +0000 (16:10 +0200)
bzr revid: tde@openerp.com-20130904141024-gku10b6841jwqh5y

1  2  3  4  5 
addons/hr_recruitment/hr_recruitment.py

@@@@@@ -182,6 -182,6 -182,6 -182,6 -182,6 +182,8 @@@@@@ class hr_applicant(osv.Model)
             'write_date': fields.datetime('Update Date', readonly=True),
             'stage_id': fields.many2one ('hr.recruitment.stage', 'Stage', track_visibility='onchange',
                             domain="['|', ('department_id', '=', department_id), ('department_id', '=', False)]"),
+++++        'last_stage_id': fields.many2one('hr.recruitment.stage', 'Last Stage',
+++++                                         help='Stage of the applicant before being in the current stage. Used for lost cases analysis.'),
             'categ_ids': fields.many2many('hr.applicant_category', string='Tags'),
             'company_id': fields.many2one('res.company', 'Company'),
             'user_id': fields.many2one('res.users', 'Responsible', track_visibility='onchange'),
             'emp_id': fields.many2one('hr.employee', string='Employee',
                 help='Employee linked to the applicant.'),
             'user_email': fields.related('user_id', 'email', type='char', string='User Email', readonly=True),
 -           'last_stage_id': fields.many2one ('hr.recruitment.stage', 'Last Stage'),
         }
     
         _defaults = {
             """
             if custom_values is None: custom_values = {}
             val = msg.get('from').split('<')[0]
 -- -        desc = html2plaintext(msg.get('body')) if msg.get('body') else ''
             defaults = {
                 'name':  msg.get('subject') or _("No Subject"),
 -- -            'description': desc,
                 'partner_name':val,
                 'email_from': msg.get('from'),
                 'email_cc': msg.get('cc'),
         def write(self, cr, uid, ids, vals, context=None):
             if isinstance(ids, (int, long)):
                 ids = [ids]
             # user_id change: update date_start
             if vals.get('user_id'):
                 vals['date_start'] = fields.datetime.now()
-----
 -           if 'stage_id' not in vals:
 -               return super(hr_applicant, self).write(cr, uid, ids, vals, context=context)
 -   
 -           for data in self.browse(cr, uid, ids, context=context):
 -               # stage change: update date_last_stage_update
+++++        # stage_id: track last stage before update
+++++        if 'stage_id' in vals:
+ +++            vals['date_last_stage_update'] = fields.datetime.now()
 -               vals['last_stage_id'] = data.stage_id.id
 -               super(hr_applicant, self).write(cr, uid, data.id, vals, context=context)
 -           return True
+++++            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)
+++++            return res
 +           return super(hr_applicant, self).write(cr, uid, ids, vals, context=context)
     
         def create_employee_from_applicant(self, cr, uid, ids, context=None):
             """ Create an hr.employee from the hr.applicants """