コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
17129 ビュー

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

アバター
破棄
関連投稿 返信 ビュー 活動
0
7月 25
2
2
4月 21
13852
2
8月 18
4714
0
4月 16
9230
1
3月 15
3644