Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
17033 Lượt xem

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'
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

use float() or int() :

{'ecartq':float(qtep)-float(qter)}
#or
{'ecartq':int(qtep)-int(qter)}
Ảnh đại diện
Huỷ bỏ
Tác giả

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

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 7 25
2
2
thg 4 21
13708
2
thg 8 18
4672
0
thg 4 16
9139
1
thg 3 15
3590