This question has been flagged
1 Reply
3407 Views

With this fonction below, my goal is to write hr.payslip.run lines states into done when i am closing it. So i write this but anything happenp on hr.payslip.run lines states


    def validate_sheet(self, cr, uid, ids, context=None):
        emp_pool = self.pool.get('hr.employee')
        slip_pool = self.pool.get('hr.payslip')
        run_pool = self.pool.get('hr.payslip.run')              
        for sheet in slip_pool.browse(cr, uid, ids, context=None):                         
            date_end = sheet.contract_id and sheet.contract_id.date_end or False
            date_from = sheet.date_from or False
            if date_end < date_from:
                slip_pool.write(cr, uid, ids, {'state':'echu'}, context=context)         
            slip_pool.write(cr, uid, ids, {'state':'done'}, context=context)
            self.write(cr, uid, ids, {'state': 'confirm'}, context=context)
        return True
            

 

Avatar
Discard
Best Answer

Hello,

You can inherit hr.payslip.run and override close_payslip_run function and call the process_sheet function in hr.payslip model, so this is the code :

class hr_payslip_run(osv.osv):
    _inherit = 'hr.payslip.run'

    def close_payslip_run(self, cr, uid, ids, context=None):
        slip_pool = self.pool.get('hr.payslip')
        slip_ids = [x.id for x in self.browse(cr, uid,ids[0], context=context).slip_ids]
        slip_pool.process_sheet(cr, uid, slip_ids, context=context)
        return self.write(cr, uid, ids, {'state': 'close'}, context=context)


I hope this could help ...

Avatar
Discard