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

Why this error? TypeError: must be string, not bool

By
Giovanny Vizcaya
on 9/13/15, 4:51 PM 889 views

Good day,

i'm working with recruitment module, i added 2 fields fecha_nacimiento (birtdate) and edad (age), and when i write the birthdate automatically appear the age...that works perfectly....


but when i'm going to create a new applicant, this error appears:

Odoo Server Error

Traceback (most recent call last):

File "/home/gio666/odoo/openerp/http.py", line 537, in _handle_exception

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

File "/home/gio666/odoo/openerp/http.py", line 574, in dispatch

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

File "/home/gio666/odoo/openerp/http.py", line 310, in _call_function

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

File "/home/gio666/odoo/openerp/service/model.py", line 113, in wrapper

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

File "/home/gio666/odoo/openerp/http.py", line 307, in checked_call

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

File "/home/gio666/odoo/openerp/http.py", line 803, in __call__

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

File "/home/gio666/odoo/openerp/http.py", line 403, in response_wrap

response = f(*args, **kw)

File "/home/gio666/odoo/openerp/addons/web/controllers/main.py", line 948, in call_kw

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

File "/home/gio666/odoo/openerp/addons/web/controllers/main.py", line 940, in _call_kw

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

File "/home/gio666/odoo/openerp/service/model.py", line 113, in wrapper

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

File "/home/gio666/odoo/openerp/addons/web/controllers/main.py", line 939, in checked_call

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

File "/home/gio666/odoo/openerp/api.py", line 241, in wrapper

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

File "/home/gio666/odoo/openerp/api.py", line 363, in old_api

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

File "/home/gio666/odoo/openerp/models.py", line 5897, in onchange

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

File "/home/gio666/odoo/openerp/models.py", line 5815, in _onchange_eval

method_res = getattr(self._model, method)(*args)

File "/home/gio666/odoo/openerp/api.py", line 241, in wrapper

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

File "/home/gio666/odoo/openerp/addons/hr_recruitment/hr_recruitment.py", line 364, in onchange_edad

edad = (datetime.now().date() - datetime.strptime(fecha_nacimiento, '%Y-%m-%d').date()).days / 365

TypeError: must be string, not bool


i think that problem is 'cause the field fecha_nacimiento(birthdate) is empty.. how can i solve it?, this is the code

def onchange_edad(self, cr, uid, ids, fecha_nacimiento, context=None):

res = {}

edad = (datetime.now().date() - datetime.strptime(fecha_nacimiento, '%Y-%m-%d').date()).days / 365

if edad < 0:

edad = 0

res = {'edad': edad}

return {'value': res}


and xml line:

<field name="fecha_nacimiento" on_change="onchange_edad(fecha_nacimiento)" placeholder="dd/mm/yyyy"/>

<field name="edad"/>


3

Tarek Mohamed Ibrahim

--Tarek Mohamed Ibrahim--
896
| 5 3 7
Gîza, Egypt
--Tarek Mohamed Ibrahim--

I am an old VFP developer on ERP

I have moved to 2p since Nov-2014 and started developing with Python on Odoo.

https://www.linkedin.com/profile/public-profile-settings?trk=prof-edit-edit-public_profile

tibrahim@2p.com.sa

Tarek Mohamed Ibrahim
On 9/13/15, 5:18 PM

When creating a new applicant the birthdate field is normally empty, but the on change function is triggered. In that case you can add a check if the  birthdate is not empty then do your calculation, else do nothing:

def onchange_edad(self, cr, uid, ids, fecha_nacimiento, context=None): 
    res = {}
    if fecha_nacimiento:
        edad = (datetime.now().date() - datetime.strptime(fecha_nacimiento, '%Y-%m-%d').d ate()).days / 365
        if edad < 0:
            edad = 0
        res = {'edad': edad}     
    return {'value': res}

 

exactly

Axel Mendoza
on 9/13/15, 8:10 PM
0
Giovanny Vizcaya
On 9/14/15, 10:46 AM

Thank you Tarek, it works.

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

1 follower(s)

Stats

Asked: 9/13/15, 4:51 PM
Seen: 889 times
Last updated: 9/14/15, 10:46 AM