Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
14461 Näkymät

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?

Avatar
Hylkää
Paras vastaus

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.

Avatar
Hylkää

plz my friend make me know if its Ok :)

Tekijä

@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 ;)

Paras vastaus

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,

Avatar
Hylkää
Tekijä

@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 ...