콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
4240 화면

Hi

I want inherit these field to modify the result in functional field but inherited function not calling


class hr_employee_inherit(osv.osv):
_inherit = 'hr.employee'

def _get_leave_status(self, cr, uid, ids, name, args, context=None):
holidays_obj = self.pool.get('hr.holidays')
holidays_id = holidays_obj.search(cr, uid,
[('employee_id', 'in', ids), ('leave_from','<=',fields.date.context_today),
('leave_to','>=',time.strftime('%Y-%m-%d')),('type','=','remove'),('state','not in',('cancel','refuse'))],
context=context)
print holidays_id,ids,'holidays_id****In INHERIT***********-------------------------',time.strftime('%Y-%m-%d'),fields.date.context_today
result = {}
for id in ids:
result[id] = {
'current_leave_state': False,
'current_leave_id': False,
'leave_date_from':False,
'leave_date_to':False,
}
for holiday in self.pool.get('hr.holidays').browse(cr, uid, holidays_id, context=context):
result[holiday.employee_id.id]['leave_date_from'] = holiday.date_from
result[holiday.employee_id.id]['leave_date_to'] = holiday.date_to
result[holiday.employee_id.id]['current_leave_state'] = holiday.state
result[holiday.employee_id.id]['current_leave_id'] = holiday.holiday_status_id.id
print result,'Reslu leave status---------------******-----------'
return result

_columns = {
'current_leave_id': fields.function(_get_leave_status, multi="leave_status", string="Current Leave Type",type='many2one', relation='hr.holidays.status'),
'leave_date_from': fields.function(_get_leave_status, multi='leave_status', type='date', string='From Date'),
'leave_date_to': fields.function(_get_leave_status, multi='leave_status', type='date', string='To Date'),
}


help me out


thanks

아바타
취소
베스트 답변

Hi,

If you want to inherit the functional fields and make some changes, you may redefine the fields and function in new api and make the changes you need. For eg, you may try like this:

class hr_employee(models.Model):
_inherit="hr.employee"

current_leave_id = fields.Many2one('hr.holidays.status', compute='_get_leave_status', string="Current Leave Type")
leave_date_from = fields.Date(compute='_get_leave_status', string='From Date')
leave_date_to = fields.Date(compute='_get_leave_status', string='To Date')


@api.one
@api.depends('employee_id')
def _get_leave_status(self):
holidays_obj = self.env['hr.holidays']
holidays = holidays_obj.search([('employee_id', 'in', self.ids), ('date_from','<=',time.strftime('%Y-%m-%d %H:%M:%S')),
('date_to','>=',time.strftime('%Y-%m-%d 23:59:59')),('type','=','remove'),('state','not in',('cancel','refuse'))])

for holiday in holidays:
self.leave_date_from = holiday.date_from
self.leave_date_to = holiday.date_to
self.current_leave_state = holiday.state
self.current_leave_id = holiday.holiday_status_id.id

Please check it n let me know.

아바타
취소
작성자 베스트 답변

Hi, that's fine now able to inherit but in the function I have changed main code because 'self' contained all employees ,So I looped on self instead of holidays as per this code it raising error, So I modified like this working fine  

@api.multi

def _get_leave_status(self):

holidays_obj = self.env['hr.holidays']

print self.ids,'holidays_id****In INHERIT***********-------------------------',fields.date.context_today(self,self.env.cr,self.env.uid)

print self.env.context,'Context ***********8-------------------------',self,self.env.cr,self.env.uid

holidays_id = holidays_obj.search(

[('employee_id', 'in', self.ids), ('leave_from','<=',fields.date.context_today(self,self.env.cr,self.env.uid)),

('leave_to','>=',fields.date.context_today(self,self.env.cr,self.env.uid)),('type','=','remove'),('state','not in',('cancel','refuse'))],

)

print holidays_id,'holidays_id****In INHERIT***********-------------------------',fields.date.context_today(self,self.env.cr,self.env.uid)

#result = {}

'''

for id in ids:

result[id] = {

'current_leave_state': False,

'current_leave_id': False,

'leave_date_from':False,

'leave_date_to':False,

}

'''

for holiday in holidays_id:

print holiday,'****************************',holiday.holiday_status_id.id

for rec in self:

print rec.ids,'Rec*88888888888888888888'

holidays_id = holidays_obj.search(

[('employee_id', 'in', rec.ids), ('leave_from','<=',fields.date.context_today(self,self.env.cr,self.env.uid)),

('leave_to','>=',fields.date.context_today(self,self.env.cr,self.env.uid)),('type','=','remove'),('state','not in',('cancel','refuse'))],

)

rec.leave_date_from = holidays_id and holidays_id[0].date_from or None

rec.leave_date_to = holidays_id and holidays_id[0].date_to or None

rec.current_leave_state = holidays_id and holidays_id[0].state or None

rec.current_leave_id = holidays_id and holidays_id[0].holiday_status_id.id or None


Thanks

아바타
취소

Hi did you manage to solve it? Is it working now?

작성자

Yes working fine.Resolved I inherited fields along with function as computed fields Thanks.

Instead of looping on self, I used "@api.one" decorator. Both should have same effect. Anyway I didn't get time to check by running the above. Hope, it helped you in solving the problem.

작성자

Thanks Akhil.

관련 게시물 답글 화면 활동
3
2월 25
17140
2
10월 21
4062
0
11월 16
4058
1
7월 16
4442
0
7월 16
5298