Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
16991 Представления

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'
Аватар
Отменить
Лучший ответ

Hi,

use float() or int() :

{'ecartq':float(qtep)-float(qter)}
#or
{'ecartq':int(qtep)-int(qter)}
Аватар
Отменить
Автор

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

Лучший ответ

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

Аватар
Отменить
Related Posts Ответы Просмотры Активность
0
июл. 25
2
2
апр. 21
13659
2
авг. 18
4647
0
апр. 16
9077
1
мар. 15
3575