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

error in timesheet.py

By
wizardz
on 2/17/16, 4:00 AM 395 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')

Can you please provide the whole traceback ?

Priyesh
on 2/17/16, 6:09 PM
0
Bhavik Bagadiya
On 4/18/16, 1:34 AM

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

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 ?

wizardz
on 4/18/16, 3:32 AM

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

wizardz
on 4/18/16, 3:44 AM

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

Bhavik Bagadiya
on 4/18/16, 5:05 AM

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

wizardz
on 7/20/16, 3:05 AM
0
wizardz
On 4/15/16, 5:34 AM

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)

])

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

Pawan
on 4/15/16, 7:52 AM

how ?

wizardz
on 4/15/16, 8:03 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

1 follower(s)

Stats

Asked: 2/17/16, 4:00 AM
Seen: 395 times
Last updated: 4/18/16, 1:34 AM