[16.0][FIX]hr_timesheet_sheet: handle new analityc line when previous sheet was confirmed
When creating a new line on a project task via the "Start Work", if there is another line which is present in a hr_timesheet_sheet in state confirm or done, the new line will be created by duplicating the last one.
Which means creating a new line with the same sheet_id.
The new line is then updated with a new sheet (the corresponding one if there is one, None otherwise).
This sheet change triggers the _check_state method before assigning the new sheet, which raises the error.
Steps to reproduce on runboat:
- log as admin into baseonly db
- install
hr_timesheet_sheetandproject_timesheet_time_controlmodules - create a new timesheet for the current week (also stop tasks that are currently active)
- select a task and change one of the lines' day to the last working day of this week
- confirm timesheet
- go on the same task where you changed day, click on "Start Work" to create a new line. Let it start in the following week
- observe error "You cannot modify an entry in a confirmed timesheet sheet"
Expected behavior: you should be able to create a line on the following week, like in version 14.0
I'm not entirely sure how it worked on v14, but I think a more elegant solution would be set copy=False on field sheet_id of account.analytic.line so that the duplicated line is not immediately linked to the old sheet..
What do you think? Would that work?
I'm not entirely sure how it worked on v14, but I think a more elegant solution would be set
copy=Falseon fieldsheet_idofaccount.analytic.lineso that the duplicated line is not immediately linked to the old sheet..What do you think? Would that work?
Yes, that would also work. But I'm not sure if some other module in this repo in relying on the copy of sheet_id.
I will go on with your solution as it is indeed more elegant.
@OCA/human-resources-maintainers can this small fix be merged please :pray:
/ocabot merge minor
What a great day to merge this nice PR. Let's do it! Prepared branch 16.0-ocabot-merge-pr-754-by-Saran440-bump-minor, awaiting test results.
Congratulations, your PR was merged at 681cd85f29a82453bf7b0cfa1d321fca57d7d909. Thanks a lot for contributing to OCA. ❤️