Skip to Content
Menu
This question has been flagged
5 Replies
2944 Views

What is this error? How can I fix it: 


File "/opt/custom_addons/hr_presence/hr_timesheet.py", line 81, in _holidays
    start_date = datetime.datetime.strptime(record.date_from, '%Y-%m-%d')
Avatar
Discard

Can you please provide the whole traceback ?

Best Answer

Hello Wizardz

Try this code 

first import 

from datetime import datetime

from openerp.tools import DEFAULT_SERVER_DATE_FORMAT

then use

start_date = datetime.strptime(record.date_from, DEFAULT_SERVER_DATE_FORMAT)

Thanx

Avatar
Discard
Author

start_date = datetime.datetime.strptime(record.date_from, str(DEFAULT_SERVER_DATE_FORMAT)) TypeError: must be string, not bool How can I make this column in a string ?

Author

when I say date_from and date_to at the beginning of the record with a string '2000-01-01' it works.

can you tell what record.date_from returns value? because if record.date_from returns datetime then only it converts in date, if it returns true,false then not possible in date

Author

The return of record.date_from and record.date_to are "False"

Author Best Answer

Traceback (most recent call last):
  File "/opt/odoo/src/openerp/http.py", line 537, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/src/openerp/http.py", line 574, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/src/openerp/http.py", line 310, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/src/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/src/openerp/http.py", line 307, in checked_call
    return self.endpoint(*a, **kw)
  File "/opt/odoo/src/openerp/http.py", line 803, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/src/openerp/http.py", line 403, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/src/openerp/addons/web/controllers/main.py", line 944, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/opt/odoo/src/openerp/addons/web/controllers/main.py", line 936, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/opt/odoo/src/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/src/openerp/api.py", line 399, in old_api
    result = method(recs, *args, **kwargs)
  File "/opt/odoo/src/openerp/models.py", line 5920, in onchange
    record = self.new(values)
  File "/opt/odoo/src/openerp/api.py", line 266, in wrapper
    return new_api(self, *args, **kwargs)
  File "/opt/odoo/src/openerp/models.py", line 5484, in new
    record._cache.update(record._convert_to_cache(values, update=True))
  File "/opt/odoo/src/openerp/models.py", line 5379, in _convert_to_cache
    for name, value in values.iteritems()
  File "/opt/odoo/src/openerp/models.py", line 5380, in <dictcomp>
    if name in fields
  File "/opt/odoo/src/openerp/fields.py", line 1572, in convert_to_cache
    return record.env[self.comodel_name].new(value)
  File "/opt/odoo/src/openerp/api.py", line 266, in wrapper
    return new_api(self, *args, **kwargs)
  File "/opt/odoo/src/openerp/models.py", line 5484, in new
    record._cache.update(record._convert_to_cache(values, update=True))
  File "/opt/odoo/src/openerp/models.py", line 5379, in _convert_to_cache
    for name, value in values.iteritems()
  File "/opt/odoo/src/openerp/models.py", line 5380, in <dictcomp>
    if name in fields
  File "/opt/odoo/src/openerp/fields.py", line 1640, in convert_to_cache
    ids = OrderedSet(record[self.name].ids)
  File "/opt/odoo/src/openerp/models.py", line 5641, in __getitem__
    return self._fields[key].__get__(self, type(self))
  File "/opt/odoo/src/openerp/fields.py", line 834, in __get__
    self.determine_draft_value(record)
  File "/opt/odoo/src/openerp/fields.py", line 942, in determine_draft_value
    self._compute_value(record)
  File "/opt/odoo/src/openerp/fields.py", line 881, in _compute_value
    self.compute(records)
  File "/opt/odoo/src/openerp/api.py", line 266, in wrapper
    return new_api(self, *args, **kwargs)
  File "/opt/odoo/saas_addons/hr_presence/hr_timesheet.py", line 84, in _holidays
    start_date = datetime.datetime.strptime(record.date_from, '%Y-%m-%d')
TypeError: must be string, not bool


and this is the modul where the error comes from:


@api.multi

def _holidays(self):

for record in self:

start_date = datetime.datetime.strptime(str(record.date_from), '%Y-%m-%d') #error this line

end_date = datetime.datetime.strptime(record.date_to, '%Y-%m-%d') #error this line

end_date = end_date.replace(hour=23, minute=59, second=59)

date_start = str(start_date)

date_end = str(end_date)

record.holiday_ids = self.env['hr.holidays'].search(

['&', '&', ('employee_id', '=', record.employee_id.id), ('state', 'in', ['confirm', 'validate1', 'validate']),

'|',

'|',

'&', ('date_from', '>=', date_start), ('date_from', '<=', date_end),

'&', ('date_to', '>=', date_start), ('date_to', '<=', date_end),

'&', ('date_from', '<=', date_start), ('date_to', '>=', date_end)

])

Avatar
Discard

Wizards, Please check if you have set date_from value, as its getting date_from as False

Author

how ?

Related Posts Replies Views Activity
0
Aug 15
2439
3
Jun 22
12744
0
Sep 19
3042
1
Nov 16
2679
4
Sep 16
2644