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

I have some 5 fields.

field_1: fields.char("Field") 
field_2: fields.char("Field")
field_3: fields.char("Field")
field_4: fields.char("Field")
field_5: fields.selection((('Incomplete','Incomplete'),('Completed','Completed')),'Field'),

By default field_5 will always be 'Incomplete':

_defaults = { 
'field_5': 'Incomplete',
}

My query is when all four fields has values, field_5 should automatically change to 'Completed' How to do this?

I had written an on_change function:

def on_change_module_code(self, cr, uid, ids, field_1,field_2,field_3,field_4): 
if field_1 :
return {'value': {'field_5': 'Completed'}}
if field_2 :
return {'value': {'field_5': 'Completed'}}
if field_3 :
return {'value': {'field_5': 'Completed'}}
if field_4 :
return {'value': {'field_5': 'Completed'}}

And in XML:

<field name="field_1" on_change="on_change_module_code(field_1,field_2,field_3,field_4)"/>;

Here when i enter first field, data is turning to 'Completed'. But it should turn to 'Completed' when all the fields has value.

How to do this?

아바타
취소
베스트 답변

Hello my friend;

here is the answer to your question:

Python:

def on_change_field(self, cr, uid, ids, field_1,field_2,field_3,field_4, context=None):

if field_1 and field_2 and field_3 and field_4:

return {'value': {'field_5': 'Completed'}}

 else:

return {'value': {'field_5': 'Inompleted'}}

XML: Call the onchange function in every field(field1, field2, field3, field4)

<field name="field_1" on_change="on_change_field(field_1,field_2,field_3,field_4)"/>

<field name="field_2" on_change="on_change_field(field_1,field_2,field_3,field_4)"/>

<field name="field_3" on_change="on_change_field(field_1,field_2,field_3,field_4)"/>

<field name="field_4" on_change="on_change_field(field_1,field_2,field_3,field_4)"/>

Best Regards.

아바타
취소

plz my friend make me know if its Ok :)

작성자

@Drees Far. Thank you for the answer. It is working. But i am getting a error message for for all fields when i am trying to enter a message. Error Message is "TypeError: Cannot read property 'value' of null" What is this? I

i have understood you because when you call the onchange from the first field the other fields are empty so you have to use the invisible attribute then call the onchange in the last field. if you didnt understand tell me im here for your help but plz vote ;)

베스트 답변

Hello,

in the xml:


<field name="field_1" on_change="on_change_module_code(field_1,field_2,field_3,field_4)"/>
<field name="field_2" on_change="on_change_module_code(field_1,field_2,field_3,field_4)"/>
<field name="field_3" on_change="on_change_module_code(field_1,field_2,field_3,field_4)"/>
<field name="field_4" on_change="on_change_module_code(field_1,field_2,field_3,field_4)"/>


in .py:

def on_change_module_code(self, cr, uid, ids, field_1,field_2,field_3,field_4, context=None):
if field_1 and field_2 and field_3 and field_4:
  return {'value': {'field_5': 'Completed'}}
return {'value': {'field_5': Incomplete'}} 


I hope it'll help

Regards,

아바타
취소
작성자

@Ahmed. Thank you for the answer. It is working. But i am getting a error message for for all fields when i am trying to enter a message. Error Message is "TypeError: Cannot read property 'value' of null" What is this? I

I think you wrongly return the dict. kindly can you post your on_change method ...