Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
4 Antwoorden
3624 Weergaven

I have one field in my .py file and I've created two different function for it:

scode=  fields.Char('Code', size=3, required=True)

def uppercase(self, cr, uid, ids, scode, context=None):
if scode:
result = {'value': {'scode': str(scode).upper()}}
return result

def get_lenght(self, cr, uid, ids, scode, context=None):
if scode and len(scode) != 3:
My_error_Msg = 'Error'
raise osv.except_osv(("Warning!"), (My_error_Msg))
return

else:
return scode

def onchange_length_id(self, cr, uid, ids, scode, context=None):
res = {'value': {'scode': self.get_lenght(cr, uid, ids, scode, context=context)}}
return res

Now, my question is: how can I use both functions in my view?

If I had only one method, I would write:

<field name="scode" on_change="uppercase(scode)"/> 

Any idea?


Thanks!

Avatar
Annuleer

Drees based his answer on merging the two methods in one. You can only use one 'on_change' method for a field.

Beste antwoord

Here is a solution friend:

Python:

scode=  fields.Char('Code', size=3, required=True)

def uppercase(self, cr, uid, ids, scode, context=None):
if scode:
result = {'value': {'scode': str(scode).upper()}}
return result

def get_lenght(self, cr, uid, ids, scode, context=None):
if scode and len(scode) != 3:
My_error_Msg = 'Error'
raise osv.except_osv(("Warning!"), (My_error_Msg))
return

else:
return scode

def onchange_length_id(self, cr, uid, ids, scode, context=None):
res = {'value': {'scode': self.get_lenght(cr, uid, ids, scode, context=context),
'scode': self.uppercase(cr, uid, ids, scode, context=context)
}}
return res

XML:

<field name="scode" on_change="onchange_length_id(scode)"/>

Hope this may help you :)

Regards.

Avatar
Annuleer
Auteur

Thank you for your reply. With your code, I get '{'value': {'scode_macro_attivita': str(scode_macro_attivita).upper()}}' when I put the value of scode. I set a 3 character value (eg. aaa) and when I fill the next field 'aaa' turn into '{'v' (the first 3 char of 'result').

Auteur

Solved! In the upper function I need to write 'return str(scode_macro_attivita).upper()'. Please Drees, modify your reply so I could give you a +1. Thank you for your help!

Gerelateerde posts Antwoorden Weergaven Activiteit
10
jun. 16
33076
1
okt. 15
9277
1
mrt. 15
4728
5
mrt. 15
12121
1
mrt. 15
3812