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

[Solved]TypeError: cannot concatenate 'str' and 'bool' objects - api.onchange function

By
Siobhan
on 5/18/15, 3:23 AM 1,822 views

this code worked perfect on Friday and today it just stopped working. Any reason?


@api.onchange('res_users_id')

def do_stuff(self):

if self.res_users_id != '':

self.beschreibung = 'Some text' + '\n' + self.beschreibung


Full error message:


Traceback (most recent call last):

File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 530, in _handle_exception

return super(JsonRequest, self)._handle_exception(exception)

File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 567, in dispatch

result = self._call_function(**self.params)

File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 303, in _call_function

return checked_call(self.db, *args, **kwargs)

File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper

return f(dbname, *args, **kwargs)

File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 300, in checked_call

return self.endpoint(*a, **kw)

File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 796, in __call__

return self.method(*args, **kw)

File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 396, in response_wrap

response = f(*args, **kw)

File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 936, in call_kw

return self._call_kw(model, method, args, kwargs)

File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 928, in _call_kw

return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)

File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper

return old_api(self, *args, **kwargs)

File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 363, in old_api

result = method(recs, *args, **kwargs)

File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 5846, in onchange

record._onchange_eval(name, field_onchange[name], result)

File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 5727, in _onchange_eval

method_res = method(self)

File "/home/vagrant/addons/training/training.py", line 28, in do_stuff

self.beschreibung = 'Some text' + '\n' + self.beschreibung

TypeError: cannot concatenate 'str' and 'bool' objects

1

Temur

--Temur--
2894
| 6 5 7
Tbilisi, Georgia
--Temur--
Programmer
Temur
On 5/18/15, 6:38 AM




@api.onchange('res_users_id')
def do_stuff(self):
if self.res_users_id != '':
self.beschreibung = 'Some text' + '\n' + self.beschreibung and self.beschreibung or ""


OR

@api.onchange('res_users_id')
def do_stuff(self):
if self.res_users_id != '':
self.beschreibung = 'Some text' + '\n' + unicode(self.beschreibung)


Thank you Temur. This works great I am just curious why it stopped working in the first place also it now seems not to like the "\n" anymore: self.beschreibung = 'Some text' + '\n' + str(self.beschreibung) UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 25: ordinal not in range(128) I will keep working on it..

Siobhan
on 5/19/15, 1:57 AM

You're right, str() will give ascii codec error if it gets unicode string. here unicode() is more appropriate, I'll update my answer with it. Thanks

Temur
on 5/19/15, 4:12 AM
0
Siobhan
On 5/29/15, 3:58 AM

Solved: added unicode instead of str self.beschreibung = 'Some text' + '\n' + unicode(self.beschreibung)

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: 5/18/15, 3:23 AM
Seen: 1822 times
Last updated: 5/29/15, 3:58 AM