Skip to content

[18.0][ADD] hr_timesheet_sheet_prefill#871

Open
yostashiro wants to merge 1 commit into
OCA:18.0from
qrtl:18.0-add-hr_timesheet_sheet_prefill
Open

[18.0][ADD] hr_timesheet_sheet_prefill#871
yostashiro wants to merge 1 commit into
OCA:18.0from
qrtl:18.0-add-hr_timesheet_sheet_prefill

Conversation

@yostashiro

@yostashiro yostashiro commented Feb 7, 2026

Copy link
Copy Markdown
Member

This module adds a "Prefill from Previous Period" button to the timesheet sheet form.
When clicked, it copies the project/task combinations from the employee's most recent
confirmed or approved timesheet sheet, creating empty placeholder lines for the current
period.

Depends on #868.

@qrtl QT6381

@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 18.0-add-hr_timesheet_sheet_prefill branch from 0c8e624 to 2e33c4e Compare February 10, 2026 03:12
Comment on lines +66 to +67
aal = self.aal_model.with_user(self.user).create(vals)
return aal

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Suggested change
aal = self.aal_model.with_user(self.user).create(vals)
return aal
self.aal_model.with_user(self.user).create(vals)

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.

Updated!

Comment on lines +70 to +76
prev_start = fields.Date.today() - relativedelta(weeks=2)
prev_end = prev_start + timedelta(days=6)
prev_sheet = self._create_sheet(prev_start, prev_end)
self._add_timesheet_line(prev_sheet, self.project_1, self.task_1)
self._add_timesheet_line(prev_sheet, self.project_2, self.task_2)
prev_sheet.action_timesheet_confirm()
self.assertEqual(prev_sheet.state, "confirm")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We can add a helper method for these steps.

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.

Updated!

}
self.assertEqual(len(after), 2)
self.assertIn((self.project_1.id, self.task_1.id), after)
self.assertIn((self.project_2.id, self.task_2.id), after)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Please assert that unit_amount == 0 as well.

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.

Updated!

f.employee_id = self.employee
f.date_start = date_start
f.date_end = date_end
return f.save()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I suppose the form is already saved at this point?

Suggested change
return f.save()
return f.record

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.

Updated!

@yostashiro
yostashiro marked this pull request as ready for review February 10, 2026 04:47
@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 18.0-add-hr_timesheet_sheet_prefill branch from 2e33c4e to 627ad8d Compare February 10, 2026 08:45

@yostashiro yostashiro left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Code looks good. :)

@yostashiro
yostashiro force-pushed the 18.0-add-hr_timesheet_sheet_prefill branch from 627ad8d to 6987671 Compare February 12, 2026 23:59

@AungKoKoLin1997 AungKoKoLin1997 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.

Code and Functional Review: LGTM

@nobuQuartile nobuQuartile left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Functional review: LGTM
・Prefill created empty lines for all project/task combos from the latest confirmed sheet.
・Existing combos were skipped (no duplicates).
・Errors raised when no previous sheet and nothing to create.

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

@nobuQuartile
nobuQuartile force-pushed the 18.0-add-hr_timesheet_sheet_prefill branch from 6987671 to 0c8ac75 Compare February 25, 2026 05:54
Comment thread hr_timesheet_sheet_prefill/i18n/ja.po Outdated
#. odoo-python
#: code:addons/hr_timesheet_sheet_prefill/models/hr_timesheet_sheet.py:0
msgid "No previous confirmed or approved timesheet sheet found."
msgstr "前期間の確認済みまたは承認済みのタイムシートが見つかりませんでした。"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Suggested change
msgstr "前期間の確認済みまたは承認済みのタイムシートが見つかりませんでした。"
msgstr "前期間の確認済みまたは承認済みのタイムシートレポートが見つかりませんでした。"

Comment thread hr_timesheet_sheet_prefill/i18n/ja.po Outdated
#. odoo-python
#: code:addons/hr_timesheet_sheet_prefill/models/hr_timesheet_sheet.py:0
msgid "You can only prefill a draft timesheet sheet."
msgstr "下書き状態のタイムシートのみ仮入力できます。"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Suggested change
msgstr "下書き状態のタイムシートのみ仮入力できます。"
msgstr "ドラフトのタイムシートレポートのみ仮入力できます。"

Comment thread hr_timesheet_sheet_prefill/i18n/ja.po Outdated
#. module: hr_timesheet_sheet_prefill
#: model_terms:ir.ui.view,arch_db:hr_timesheet_sheet_prefill.hr_timesheet_sheet_form
msgid "Prefill from Previous Period"
msgstr "前期間の内容を仮入力"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Suggested change
msgstr "前期間の内容を仮入力"
msgstr "前期間から明細行を作成"

@yostashiro

Copy link
Copy Markdown
Member Author

@nobuQuartile Please follow up on the translation suggestions

@nobuQuartile
nobuQuartile force-pushed the 18.0-add-hr_timesheet_sheet_prefill branch from 5dbaebb to c861fb9 Compare February 26, 2026 05:22

@alexey-pelykh alexey-pelykh 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.

Thanks for this addition -- the prefill pattern is a real time-saver for recurring timesheet setups, and the implementation reuses the parent module's helpers (_prepare_empty_analytic_line, _sheet_create) cleanly.

A few observations from going through the code:

Model (hr_timesheet_sheet.py)

The core logic is sound: state guard, previous sheet lookup, set-based dedup, and delegating line creation to the existing _sheet_create/_prepare_empty_analytic_line pipeline. One thing I'd flag for consideration:

  • The add_line() method in the parent module follows up _sheet_create with self.write({"timesheet_ids": [(4, new_line.id)]}). Here that's skipped, which works because _prepare_empty_analytic_line already sets sheet_id on the line and timesheet_ids is an inverse One2many. So functionally correct -- but if any downstream module hooks into writes on timesheet_ids they'd be bypassed. Not blocking, but worth being aware of.

Tests

Good coverage of the happy path and error cases. One missing scenario:

  • There's no test for the state guard (state not in ('new', 'draft')). Consider adding a test that confirms the sheet, then asserts UserError is raised when calling action_prefill_from_previous on a non-draft sheet.

i18n

  • The .pot file (i18n/hr_timesheet_sheet_prefill.pot) is missing. Other modules in this repo all ship one. It should be generated via oca-gen-addon-readme / the standard export.

Overall this is a clean, focused module. The missing .pot and the state-guard test are the main items I'd suggest addressing.

)
for project, task in lines_to_create:
vals = self._prepare_empty_analytic_line(project=project, task=task)
self.env["account.analytic.line"]._sheet_create(vals)

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.

Nit: the parent add_line() also calls self.write({"timesheet_ids": [(4, new_line.id)]}) after _sheet_create. Here it's technically unnecessary since sheet_id is set in the vals, but if any module hooks into writes on timesheet_ids (e.g. recomputation triggers), those would be missed. Not blocking, just flagging for consistency.

)
self._add_timesheet_line(cur_sheet, self.project_1, self.task_1)
with self.assertRaises(UserError):
cur_sheet.action_prefill_from_previous()

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.

Missing a test for the state guard -- e.g. confirm the sheet, then assert UserError on action_prefill_from_previous().

@github-actions

Copy link
Copy Markdown

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions Bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Jul 12, 2026
@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 18.0-add-hr_timesheet_sheet_prefill branch from c861fb9 to 09ec141 Compare July 13, 2026 06:57
@OCA-git-bot OCA-git-bot added series:18.0 mod:hr_timesheet_sheet_prefill Module hr_timesheet_sheet_prefill labels Jul 13, 2026
@AungKoKoLin1997

Copy link
Copy Markdown
Contributor

@alexey-pelykh I updated the PR with your suggestions except from .pot because it will be handled by ocabot after the PR is merged.

@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 18.0-add-hr_timesheet_sheet_prefill branch from 09ec141 to 46d1b18 Compare July 13, 2026 07:16
@AungKoKoLin1997

Copy link
Copy Markdown
Contributor

CI is failing because of odoo issue.
Fix at odoo/odoo#276119

@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 18.0-add-hr_timesheet_sheet_prefill branch from 46d1b18 to 4704f03 Compare July 15, 2026 01:21
@AungKoKoLin1997
AungKoKoLin1997 force-pushed the 18.0-add-hr_timesheet_sheet_prefill branch from 4704f03 to 5af297f Compare July 15, 2026 08:52
@github-actions github-actions Bot removed the stale PR/Issue without recent activity, it'll be soon closed automatically. label Jul 19, 2026
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