Odoo Help

Welcome!

This community 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.

0

Onchange Function is Not working in Odoo

By
Odoo
on 8/14/15, 12:40 AM 534 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}

1
Indrabhan Bhamare
On 8/14/15, 4:35 AM

hi  Dep

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

this link may help you to slove your problme

0

Drees Far

--Drees Far--
1130
| 5 2 6
Tunis, Tunisia
--Drees Far--
Drees Far
On 8/14/15, 5:03 AM

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.

Please vote if its helping you friend :)

Drees Far
on 8/14/15, 5:04 AM

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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 8/14/15, 12:40 AM
Seen: 534 times
Last updated: 8/14/15, 5:03 AM