Skip to Content
Menu
This question has been flagged
2 Replies
2431 Views

hi,

how to update the state of contract of employee based on filter, such as,  if I want the change state running to renew before one month of the expirations of the contract.

Thank you in advance.

Avatar
Discard
Author

I'm new to odoo, how to do the scheduled action?

Best Answer

Hi,
You can do with the cron job(Scheduled Actions).


<record id="ir_cron_update_contract_state_based_on_dates" model="ir.cron">

<field name="name">Check Today Date to update statefield>

<field name="interval_number">1field>

<field name="interval_type">daysfield>

<field name="numbercall">0field>

<field name="doall" eval="False" />

<field name="model_id" ref="hr_contract.model_hr_contract" />

<field name="code">model._cron_update_state_on_today_date()field>

<field name="state">codefield>

in py file

inside hr_contract model


# this method called every day based on cron interval_type and interval_number

@api.model
def _cron_update_state_on_today_date():

    your logic here to update state based on date.


sorry for syntax, Please correct the syntax.
Thanks,

Avatar
Discard
Best Answer

Hi  jenan ,

To do this you need to make changes in update_state  function in hr.contract

Hope it helps,
Kiran K

Avatar
Discard
Author

but the update_state is not called in the state field
can I call the function as:
@api.depends('state')
def _get_contract_state(self):
self.search([
('state', '=', 'open'),
'|',
'&',
('date_end', '<=', fields.Date.to_string(date.today() + relativedelta(month=1))),
('date_end', '>=', fields.Date.to_string(date.today() + relativedelta(days=1))),
]).write({
'state': 'pending'
})
self.search([
('state', 'in', ('open', 'pending')),
'|',
('date_end', '<=', fields.Date.to_string(date.today() + relativedelta(days=1))),
('visa_expire', '<=', fields.Date.to_string(date.today() + relativedelta(days=1))),
]).write({
'state': 'close'
})

return True
state = fields.Selection([
('draft', 'New'),
('open', 'Running'),
('pending', 'To Renew'),
('close', 'Expired'),
('cancel', 'Cancelled')
], string='Status', compute='_get_contract_state', default='draft')

Its a scheduler, Running daily to update the contract
Activate Developer Mode
Goto Settings > Technical Settings>Scheduled Actions and search for 'HR Contract: Update State'

To change the state to 'Renew' before 30 days override update_state function and make changes

Related Posts Replies Views Activity
0
Mar 24
275
0
Oct 22
1521
0
Sep 22
666
1
Jul 22
4090
0
Jun 22
836