python 2.7 - Odoo - How to update a pre defined DATE field value -
i'm trying modify hr.contract model 'end_date
' field gets value of 'effective_date
' in model 'resignation_application
'. concept when employee fill resignation application updates contract end date.
here's 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 , 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 instance of model recs = recs.search([('state', '=', 'validate')]) # search returns recordset rec in recs: # iterate on records if self.employee_id == rec.employee_id: self.end_date = rec.effective_date return recs.write({'end_date': rec.effective_date})
but didn't return end date.. know there's wrong return statement don't know how fix it.. want add inverse method end_date
field hr officer can add end date employee contract. appreciated.
first, mixing v8 (decorators) , v7 (osv.osv , _columns) stuffs.
besides, in v8 don't need return nor write directly end_date
field in compute method, set field did. did try remove return statement?
Comments
Post a Comment