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),
}
@api.model
def create(self, values):
if 'end_date' in values and not values['end_date']:
del(values['end_date'])
return super(hr_contract, self).create(values)
@api.one
@api.depends('end_date','employee_id')
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.