Skip to content

[19.0][IMP] hr_timesheet_time_control_begin_end: Improve unit amount calculation by handling datetime string conversion#899

Merged
OCA-git-bot merged 1 commit into
OCA:19.0from
c4a8-odoo:19.0-imp-hr_timehseet_time_control_begin_end
Apr 30, 2026
Merged

[19.0][IMP] hr_timesheet_time_control_begin_end: Improve unit amount calculation by handling datetime string conversion#899
OCA-git-bot merged 1 commit into
OCA:19.0from
c4a8-odoo:19.0-imp-hr_timehseet_time_control_begin_end

Conversation

@CRogos

@CRogos CRogos commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Compatibility issue with #898

@CRogos

CRogos commented Apr 23, 2026

Copy link
Copy Markdown
Contributor Author

@NICO-SOLUTIONS, @MohamedOsman7 could you do a quick review... The user base of this module is very small. (probably just me)

@NICO-SOLUTIONS NICO-SOLUTIONS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your changes cover string values returned by default_get where the ORM expects datetime... 👍
It might also make sense to guard the assignment and sign handling of unit_amount.

Comment thread hr_timesheet_time_control_begin_end/models/account_analytic_line.py Outdated
@CRogos CRogos force-pushed the 19.0-imp-hr_timehseet_time_control_begin_end branch from bd737ec to 38e0868 Compare April 23, 2026 18:53
@CRogos

CRogos commented Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

@MohamedOsman7 could you review

@MohamedOsman7 MohamedOsman7 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pedrobaeza pedrobaeza added this to the 19.0 milestone Apr 29, 2026
date_time = vals.get("date_time")
date_time_end = vals.get("date_time_end")
if isinstance(date_time, str):
date_time = fields.Datetime.from_string(date_time)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid doing this conversion if not needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now changed the strings to date/datetime type.

@CRogos CRogos force-pushed the 19.0-imp-hr_timehseet_time_control_begin_end branch 2 times, most recently from c53f04c to 243c5c8 Compare April 29, 2026 13:06
@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

ctx["default_date"] = datetime.fromisoformat(
self.env.context.get("default_date_time")
).date()
ctx["default_date"] = self.env.context.get("default_date_time").date()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change needed? What happen with timezones?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my understanding, the default_date_time should never be a sting and therefore can bypass fromisoformat.
But regarding the timezone you may be right. How about?

Suggested change
ctx["default_date"] = self.env.context.get("default_date_time").date()
default_date_time = self.env.context.get("default_date_time")
if default_date_time:
ctx["default_date"] = default_date_time.astimezone(ZoneInfo("UTC")).date()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't say how the conversion should go, sorry.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a test for _get_default with default_date_time having a timezone and received an error from odoo:

ValueError: Datetime field expects a naive datetime: 2025-06-15 23:00:00+00:00

Therefore I've removed the UTC conversion because the default_date_time may not have timezone information.
Do you have more comments/suggestions/improvements?

@CRogos CRogos force-pushed the 19.0-imp-hr_timehseet_time_control_begin_end branch 3 times, most recently from 3d1fac2 to 8315af2 Compare April 30, 2026 15:50
…ation by handling datetime

Co-authored-by: Copilot <copilot@github.com>
@CRogos CRogos force-pushed the 19.0-imp-hr_timehseet_time_control_begin_end branch from 8315af2 to 6d74ce4 Compare April 30, 2026 15:53

@pedrobaeza pedrobaeza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, let's go!

/ocabot merge patch

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 19.0-ocabot-merge-pr-899-by-pedrobaeza-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 75cd7d6 into OCA:19.0 Apr 30, 2026
5 of 7 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at 8a26891. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants