Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
16982 Widoki

I am a beginner in python and I'm trying to write a function that allows calculate the difference between two fields and save the result in a third. Here is my method:

on_change_ecart def (self, cr, uid, ids, qter, qtep, context = None):
    if context is None:
        context = {}
    return {'value': {'ecartq': qtep - qter}}

and I get the following error:

TypeError: unsupported operand types (s) for -: 'NoneType' and 'unicode'
Awatar
Odrzuć
Najlepsza odpowiedź

Hi,

use float() or int() :

{'ecartq':float(qtep)-float(qter)}
#or
{'ecartq':int(qtep)-int(qter)}
Awatar
Odrzuć
Autor

thanks but when i try using float() or int() i getthis error :

Najlepsza odpowiedź

Hi,

do like this :

{'ecartq': (qtep and int(qtep) or 0) - (qter and int(qter) or 0)}

Thanks
Acespritech Solutions Pvt Ltd
http://www.acespritech.com
http://acespritechblog.wordpress.com

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
lip 25
2
2
kwi 21
13640
2
sie 18
4635
0
kwi 16
9058
1
mar 15
3569