timesheet icon indicating copy to clipboard operation
timesheet copied to clipboard

[17.0][ADD] hr_timesheet_autofill_project_off

Open innovara opened this issue 9 months ago • 1 comments

This module disables the project field being automatically filled when a new line is added to a timesheet.

Details about the feature that this module disables on https://github.com/odoo/odoo/commit/ad1b64ab02c5d31087f25c1c7fae64a2659a2249 and a relevant fix on https://github.com/odoo/odoo/commit/623ecff069f360fad7c9583d8008f97459ed6008

According to the description of the so-called improvement, if the last five timesheets belong to the same project then that project is considered a favorite project.

Why five is anybody's guess but the real problem with this is that it induces errors. Inevitably the user will fail to change the project when the automatic selection is incorrect, and book time to another project. If the mistake is not picked before billing then the risk is that the client will do so and then good luck explaining why you are charging them for work done for others.

While the feature might work well for those working on one project at a time, a good number of professional services' users billing on hourly rates juggle between many assignments concurrently so the project that is filled automatically will often be incorrect thus not saving them time while adding the risk explained above.

innovara avatar Mar 20 '25 22:03 innovara

@miquelalzanillas @lbarry-apsl @BernatObrador @peluko00 @javierobcn @ppyczko @mpascuall

Would you kindly review this PR for me please? Same as my previous request. I of course would be very happy to review any of your PRs.

innovara avatar Apr 08 '25 15:04 innovara

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). 🤖

OCA-git-bot avatar Jun 21 '25 18:06 OCA-git-bot

Hello @innovara one question: why not overriding default_get() method (https://github.com/odoo/odoo/blob/fb74d9f2d6cc001ac1b5968d8cd81096d721df05/addons/hr_timesheet/models/hr_timesheet.py#L29-L38) instead of invalidating for all _get_favorite_project_id()? Not tested, but you might obtain the same desired behavior, and others that could need use _get_favorite_project_id shouldn't be affected.

dalonsod avatar Jul 02 '25 13:07 dalonsod

Maintainability, I’d say. As far as I can see, _get_favourite_project_id() is only used there. Overriding default_get() would require keeping track of changes to that method upstream, so you’d need to maintain the same code minus the call to _get_favourite_project_id(). With that in mind, I feel this is the better approach. However, if you have any other idea about how default_get() could be overridden without the burden of mirroring the method upstream, please do let me know.

innovara avatar Jul 07 '25 14:07 innovara

Well, not tested as you'll guess, but my idea for default_get() override should be the following:

def default_get(self, field_list)
    result = super().default_get(field_list)
    if not self._context.get('default_project_id') and self._context.get('is_timesheet') and result.get("project_id", False):
        # project_is filled, and filled by https://github.com/odoo/odoo/blob/22c333d0ed7eba1165f6462e668998d37fcabb73/addons/hr_timesheet/models/hr_timesheet.py#L35
        # so, we reset its value
        result["project_id"] = False
    return result

dalonsod avatar Jul 09 '25 16:07 dalonsod

I see. That would be preferable. I'm testing the proposed change and will update this PR if I don't encounter any issues.

innovara avatar Jul 09 '25 23:07 innovara

@dalonsod I'm preparing to push a revised version of this PR based on your suggestion. I've been running it for a week without any issues.

I'd like to credit you as a contributor. Would the following be acceptable?

- [Solvos](https://www.solvos.es):
   - David Alonso

innovara avatar Jul 18 '25 12:07 innovara

Looks perfect, thanks!

dalonsod avatar Jul 18 '25 12:07 dalonsod

@pedrobaeza could I kindly ask you to review this PR when you get a chance? I'm happy to make any adjustments if needed. If it looks good and it's merged, I'd like to prepare a port to 18.0 afterwards.

innovara avatar Sep 24 '25 10:09 innovara

Merging due to the existing reviews and being a new module.

/ocabot merge nobump

pedrobaeza avatar Sep 24 '25 15:09 pedrobaeza

This PR looks fantastic, let's merge it! Prepared branch 17.0-ocabot-merge-pr-755-by-pedrobaeza-bump-nobump, awaiting test results.

OCA-git-bot avatar Sep 24 '25 15:09 OCA-git-bot

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

OCA-git-bot avatar Sep 24 '25 15:09 OCA-git-bot

Thanks a lot

innovara avatar Sep 24 '25 15:09 innovara