Odoo Help


How to update a pre defined DATE field value

on 2/28/16, 11:26 AM 487 views


I'm trying to modify hr.contract model so the '`end_date`' field gets the value of '`effective_date`' which is in another model '`resignation_application`'.

The concept is when an employee fill a resignation application it updates the contract end date.

Here's my code:

    class resignation_application(osv.osv):
_name = 'resignation.application'
_columns = {
'employee_id': fields.many2one('hr.employee', "Employee", select=True, invisible=False, readonly=True, states={'draft':[('readonly',False)], 'confirm':[('readonly',False)]}),
'effective_date': fields.date('Effective Date', readonly=True, states={'draft':[('readonly',False)], 'confirm':[('readonly',False)]}, select=True, copy=False),
class hr_contract(osv.osv):
_inherit = 'hr.contract'
_columns = {
'end_date': fields.date('End Date', compute= '_compute_effective_date', store=True),
def create(self, values):
if 'end_date' in values and not values['end_date']:
return super(hr_contract, self).create(values)
def _compute_effective_date(self):
recs = self.env['resignation.application'] # retrieve an instance of MODEL
recs = recs.search([('state', '=', 'validate')]) # search returns a recordset
for rec in recs: # iterate over the records
if self.employee_id == rec.employee_id:
self.end_date = rec.effective_date
return recs.write({'end_date': rec.effective_date})

But it didn't return the end date.. I know there's something wrong with my return statement but I don't know how to fix it.. Also I want to add an inverse method to `end_date` field so the hr officer can add an end date to the employee contract. Any help will be appreciated.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

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

1 follower(s)


Asked: 2/28/16, 11:26 AM
Seen: 487 times
Last updated: 2/28/16, 1:46 PM