콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
17223 화면

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
13984
2
8월 18
4802
0
4월 16
9369
1
3월 15
3722