Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FW][FIX] resource: prevent traceback with false start date #163311

Conversation

fw-bot
Copy link
Contributor

@fw-bot fw-bot commented Apr 25, 2024

This traceback arises when the user tries to remove the start date

Steps to produce

  1. Install resource
  2. Open Settings/Technical/resource/Resource Time Off
  3. Create a new record and remove the start date

Error:

  File "odoo/http.py", line 2251, in __call__
    response = request._serve_db()
  File "odoo/http.py", line 1826, in _serve_db
    return self._transactioning(_serve_ir_http, readonly=ro)
  File "odoo/http.py", line 1847, in _transactioning
    return service_model.retrying(func, env=self.env)
  File "odoo/service/model.py", line 134, in retrying
    result = func()
  File "odoo/http.py", line 1824, in _serve_ir_http
    return self._serve_ir_http(rule, args)
  File "odoo/http.py", line 1832, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "odoo/http.py", line 2057, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
  File "odoo/addons/base/models/ir_http.py", line 222, in _dispatch
    result = endpoint(**request.params)
  File "odoo/http.py", line 740, in route_wrapper
    result = endpoint(self, *args, **params_ok)
  File "addons/web/controllers/dataset.py", line 34, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "addons/web/controllers/dataset.py", line 30, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "odoo/api.py", line 458, in call_kw
    result = getattr(recs, name)(*args, **kwargs)
  File "addons/web/models/models.py", line 1073, in onchange
    todo = [
  File "addons/web/models/models.py", line 1076, in <listcomp>
    if field_name not in done and snapshot0.has_changed(field_name)
  File "addons/web/models/models.py", line 1189, in has_changed
    return self[field_name] != self.record[field_name]
  File "odoo/models.py", line 6664, in __getitem__
    return self._fields[key].__get__(self, self.env.registry[self._name])
  File "odoo/fields.py", line 1138, in __get__
    self.recompute(record)
  File "odoo/fields.py", line 1353, in recompute
    apply_except_missing(self.compute_value, recs)
  File "odoo/fields.py", line 1326, in apply_except_missing
    func(records)
  File "odoo/fields.py", line 1375, in compute_value
    records._compute_field_value(self)
  File "odoo/models.py", line 4982, in _compute_field_value
    fields.determine(field.compute, self)
  File "odoo/fields.py", line 102, in determine
    return needle(*args)
  File "addons/resource/models/resource_calendar_leaves.py", line 58, in _compute_date_to
    date_to_tz = user_tz.localize(leave.date_from) + relativedelta(hour=23, minute=59, second=59)
  File "pytz/tzinfo.py", line 317, in localize
    if dt.tzinfo is not None:

when the user tries to remove the start date, an error will be produced because _compute_date_to seems to be computing the date_to based on the date_from field. when removing the date_from from calculations on empty or none

which leads to traceback from here

@api.depends('date_from')
def _compute_date_to(self):
user_tz = timezone(self.env.user.tz or self._context.get('tz') or self.company_id.resource_calendar_id.tz or 'UTC')
for leave in self:
date_to_tz = user_tz.localize(leave.date_from) + relativedelta(hour=23, minute=59, second=59)
leave.date_to = date_to_tz.astimezone(utc).replace(tzinfo=None)

This PR solves the above issue by computing date_to for records that have
date_from. Apart from that, this PR also removes # -*- coding: utf-8 -*-
from the first line of the modified file.

sentry-4983497879

Forward-Port-Of: #163136
Forward-Port-Of: #154555

This traceback arises when  the user tries to remove the start date

Steps to produce

1. Install 'resource'
2. Open 'Settings/Technical/resource/Resource Time Off'
3. Create a new record and remove start date

AttributeError
'bool' object has no attribute 'tzinfo'

when the user tries to remove the start date, an error will be
produced because _compute_date_to seems to be computing the date_to
based on the date_from field. when removing the date_from  from calculations
on empty or none

which leads to traceback from here
https://github.com/odoo/odoo/blob/322e7ea19b7c069fdb92d3b86e5615c55489ca21/addons/resource/models/resource_calendar_leaves.py#L54-L59

This commit solves the above issue by computing `date_to` for records that have
`date_from`. Apart from that, this commit also removes `# -*- coding: utf-8 -*-`
from the first line of the modified file.

sentry-4983497879

X-original-commit: 5032a8f
@robodoo
Copy link
Contributor

robodoo commented Apr 25, 2024

@fw-bot
Copy link
Contributor Author

fw-bot commented Apr 25, 2024

This PR targets 17.0 and is part of the forward-port chain. Further PRs will be created up to master.

More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port

@robodoo robodoo added the forwardport This PR was created by @fw-bot label Apr 25, 2024
@C3POdoo C3POdoo added the RD research & development, internal work label Apr 25, 2024
@robodoo robodoo closed this in 1d1dcef Apr 25, 2024
willylohws pushed a commit to willylohws/odoo that referenced this pull request May 1, 2024
This traceback arises when  the user tries to remove the start date

Steps to produce

1. Install 'resource'
2. Open 'Settings/Technical/resource/Resource Time Off'
3. Create a new record and remove start date

AttributeError
'bool' object has no attribute 'tzinfo'

when the user tries to remove the start date, an error will be
produced because _compute_date_to seems to be computing the date_to
based on the date_from field. when removing the date_from  from calculations
on empty or none

which leads to traceback from here
https://github.com/odoo/odoo/blob/322e7ea19b7c069fdb92d3b86e5615c55489ca21/addons/resource/models/resource_calendar_leaves.py#L54-L59

This commit solves the above issue by computing `date_to` for records that have
`date_from`. Apart from that, this commit also removes `# -*- coding: utf-8 -*-`
from the first line of the modified file.

sentry-4983497879

closes odoo#163311

X-original-commit: 5032a8f
Signed-off-by: Bertrand Dossogne (bedo) <bedo@odoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
forwardport This PR was created by @fw-bot RD research & development, internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants