Odoo Help


desactivation of employee

on 11/11/14, 6:06 PM 1,333 views

I would like to set active field on employee to False when his contract end date is passed. I plan to do it with automated actions and server actions(type=python code). Thanks


Atchuthan - Technical Consultant, Sodexis Inc

--Atchuthan - Technical Consultant, Sodexis Inc--
| 5 5 8
Puducherry, India
--Atchuthan - Technical Consultant, Sodexis Inc--
Passionate coder in Python/Odoo(formerly known as OpenERP).

Contact me via GMail: atchuthantu@gmail.com via Skype: atchuthan_skype
via Linkedin: http://in.linkedin.com/in/atchuthantu
Atchuthan - Technical Consultant, Sodexis Inc
On 11/12/14, 2:28 AM

1. Create a Scheduled Action using XML

        <record forcecreate="True" id="ir_cron_check" model="ir.cron">
            <field name="name">Test CRON Job</field>
            <field eval="True" name="active" />
            <field name="user_id" ref="base.user_root" />
            <field name="interval_number">1</field>
            <field name="interval_type">days</field>
            <field name="numbercall">-1</field>
            <field eval="False" name="doall" />
            <field eval="'MODEL NAME'" name="model" />
            <field eval="'run_cron_job'" name="function" />
            <field eval="'()'" name="args" />

2. Add the function at Python file.

Version 7:
    def run_cron_job(self, cr, uid, context=None):
        contract_obj = self.pool.get('hr.contract')
        employee_obj = self.pool.get('hr.employee')
        contract_ids = contract_obj.search(cr, uid, [('date_end', '<', time.strftime('%Y-%m-%d'))], context=context)
        for contract in contract_obj.browse(cr, uid, contract_ids, context=context):
            employee_obj.write(cr, uid, contract.employee_id.id, {'active': False}, context=context)

Version 8:
    def run_cron_job(self):
        CODE HERE
        print "Hello"

Thanks Atchuthan, i am not developper so i need help for the code. I don't know what to write. I try this : employee = self.pool.get('hr.employee') employee.write(cr, uid,{'active' : False},context=context) But it is not working

on 11/12/14, 4:05 AM

You need to find the employee_ids for which you are trying to write some value. employee_ids=employee.search(cr, uid, [('name', 'ilike', 'Administrator')] employee.write(cr, uid, employee_ids, {'active': False}, context=context) https://doc.odoo.com/v6.0/developer/2_5_Objects_Fields_Methods/methods.html/#osv.osv.osv.write. The concept is that you have to know for what employee the active= False needs to be set

Atchuthan - Technical Consultant, Sodexis Inc
on 11/12/14, 4:29 AM

Thanks again. I will try it. My goal is that the system detect this employee whose contract is finish and desactivates it automatically according the setting in the scheduler.

on 11/12/14, 4:43 AM

check the python method

Atchuthan - Technical Consultant, Sodexis Inc
on 11/12/14, 4:57 AM



| 6 8 7
Bangalore, India
On 11/11/14, 11:13 PM

Hi you can achieve this by writing the schedular or automated action to run every day, that will  check whether the employee's contract period end date is passed.

in you write method, need to pass ids(employee_id)

employee = self.pool.get('hr.employee') employee.write(cr, uid,ids,{'active' : False},context=context)

in automated action form I write this : employee = self.pool.get('hr.employee') employee.write(cr, uid,{'active' : False},context=context) But It is not working.

on 11/12/14, 4:10 AM

Med Said BARA

--Med Said BARA--

| 5 5 7
--Med Said BARA--
Med Said BARA
On 11/12/14, 8:56 AM

Use hr_contract_state and hr_employee_state ...... https://github.com/OCA/hr/tree/7.0  

There is already a field "Active" for the object "hr.emplyee" ( under the "HR Settings" Tab), why not using it (but this field is related to resource.resource) !!!

I'm testing on Runbot and will submit the results ...

Thanks. I have these module but i would like to configure a server action for doing this. I don't want to add workflow on contract and employee models.

on 11/12/14, 9:27 AM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 11/11/14, 6:06 PM
Seen: 1333 times
Last updated: 3/16/15, 8:10 AM