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


Hi All,

I have a two date field in hr.employee form  and two date field in res.users form

My task is when  I change these date field from hr.employee ,these two field will should automatically come from hr.user form 

I tried via onchange method ,but I got Error ,Need a help

class res_users(osv.osv):

_inherit='res.users'

_columns={

'is_employee':fields.boolean('Is an Employee'),

'documnet_expiry':fields.date('Iqama Expiry Date'),

'passport_expiry':fields.date('Passport Expiry Date')

}


class hr_employee(osv.osv):

_inherit='hr.employee'

_columns={

'documnet_expiry_hr':fields.date('Iqama Expiry Date'),

'passport_expiry_hr':fields.date('Passport Expiry Date')

}

def onchange_date1_date2(self,cr,uid,ids,documnet_expiry_hr,passport_expiry_hr,context=None):

print('DDDDDDDDDDDDDDDDDDD documnet_expiry_hr',documnet_expiry_hr)

print('DDDDDDDDDDDDDDDDDDD@@@@@@@@@@@@@@@@ passport_expiry_hr',passport_expiry_hr)

res={}

val=self.pool.get('res.users').browse(cr,uid,ids,context)

print("@@@@Val Document ",val['documnet_expiry'])

print("@@@@Val Passport ",val ['passport_expiry'])

user_val=self.browse(cr,uid,ids)

print('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@',documnet_expiry_hr)

print('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@',passport_expiry_hr)

val['documnet_expiry']=documnet_expiry_hr

val['passport_expiry']=passport_expiry_hr

return {'value':val}

Avatar
Discard
Best Answer

hi  Dep

https://www.odoo.com/documentation/8.0/reference/orm.html

this link may help you to slove your problme

Avatar
Discard
Best Answer

Hi friend :

It is not with this way that you can work with the on_change function.

Here is a simple example for you friend:

Pyhton:


def get_inputs(self, cr, uid,ids, state, project, context=None):

ret = []

print ('--------------------get_inputs---------------------')

project_id = _get_project_id_by_name (self,cr, uid, project, context)

print ('project =')

print project_id

obj = self.pool.get('test.project.service')

obj_ids = obj.search(cr, uid, [], context=context)

res = obj.read(cr, uid, obj_ids, ['id', 'int_service','ext_service','unit_service','int_service_unit','ext_service_unit','service_type','service_condition'], context)

for r in res :

inputs = {

'project_id' : project_id,

'int_services': r['int_service'],

'ext_services': r['ext_service'],

'unit_services': r['unit_service'],

'int_services_unit': r['int_service_unit'],

'ext_services_unit': r['ext_service_unit'],

'service_type': r['service_type'],

'service_condition' : r['service_condition'],

}

ret.append(inputs)

print ('------------liste de services-------')

print ret

return ret


def on_change_state_id(self, cr, uid, ids,state, project, credit, context=None): 

if state==1:

project_id = _get_project_id_by_name (self,cr, uid, project, context)

res = {'value':{'service_ids': self.get_inputs(cr, uid, ids, state, project,context=context),

}

}

return res

else:

return False

XML:

<field name="state" on_change="on_change_state_id(state, project, credit)"/>

Regards.

Avatar
Discard

Please vote if its helping you friend :)