Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

type error unsupported operand types (s)

By
test23
on 6/22/13, 7:10 AM 3,356 views

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'
1
Dharmesh Rathod
On 6/22/13, 1:32 PM

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

1

Borni DHIFI

--Borni DHIFI--
5102
| 6 8 9
Tunis, Tunisia
--Borni DHIFI--

Techno Functional Consultant Odoo(OpenERP) 

http://www.linkedin.com/in/borni

Skype : dhifi.borni

Borni DHIFI
On 6/22/13, 7:42 AM

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 :

test23
on 6/22/13, 7:52 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 6/22/13, 7:10 AM
Seen: 3356 times
Last updated: 3/16/15, 8:10 AM