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

[15.0][IMP] hr_timesheet_sheet: add My Current Timesheet menu. #654

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions hr_timesheet_sheet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
from . import wizard
1 change: 1 addition & 0 deletions hr_timesheet_sheet/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_hr_timesheet_sheet_user,hr_timesheet.sheet,model_hr_timesheet_sheet,base.group_user,1,1,1,1
access_hr_timesheet_sheet_line,hr_timesheet.sheet.line,model_hr_timesheet_sheet_line,hr_timesheet.group_hr_timesheet_user,1,1,1,1
access_hr_timesheet_sheet_new_analytic_line,hr_timesheet.sheet.new.analyticline,model_hr_timesheet_sheet_new_analytic_line,hr_timesheet.group_hr_timesheet_user,1,1,1,1
access_hr_timesheet_user_open_current,hr_timesheet.current.open,model_hr_timesheet_current_open,base.group_user,1,1,1,1
16 changes: 16 additions & 0 deletions hr_timesheet_sheet/views/hr_timesheet_sheet_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -512,4 +512,20 @@
parent="menu_hr_to_review"
sequence="11"
/>
<record id="ir_actions_server_timesheet_sheet" model="ir.actions.server">
<field name="sequence" eval="5" />
<field name="state">code</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="model_hr_timesheet_current_open" />
<field name="code">action = model.open_timesheet()</field>
<field name="name">My Timesheet</field>
</record>

<menuitem
name="My Current Timesheet"
id="menu_act_hr_timesheet_sheet_form_my_current"
parent="hr_timesheet.menu_hr_time_tracking"
action="ir_actions_server_timesheet_sheet"
sequence="2"
/>
</odoo>
3 changes: 3 additions & 0 deletions hr_timesheet_sheet/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import hr_timesheet_current
42 changes: 42 additions & 0 deletions hr_timesheet_sheet/wizard/hr_timesheet_current.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import _, api, fields, models


class HrTimesheetCurrentOpen(models.TransientModel):
_name = "hr.timesheet.current.open"
_description = "hr.timesheet.current.open"

@api.model
def open_timesheet(self):
view_type = "form,tree"

Check warning on line 12 in hr_timesheet_sheet/wizard/hr_timesheet_current.py

View check run for this annotation

Codecov / codecov/patch

hr_timesheet_sheet/wizard/hr_timesheet_current.py#L12

Added line #L12 was not covered by tests

sheets = (

Check warning on line 14 in hr_timesheet_sheet/wizard/hr_timesheet_current.py

View check run for this annotation

Codecov / codecov/patch

hr_timesheet_sheet/wizard/hr_timesheet_current.py#L14

Added line #L14 was not covered by tests
self.env["hr_timesheet.sheet"]
.sudo()
.search(
[
("user_id", "=", self._uid),
("state", "in", ("draft", "new")),
("date_start", "<=", fields.Date.today()),
("date_end", ">=", fields.Date.today()),
]
)
)
if len(sheets) > 1:
view_type = "tree,form"
domain = "[('id', 'in', " + str(sheets.ids) + "),('user_id', '=', uid)]"

Check warning on line 28 in hr_timesheet_sheet/wizard/hr_timesheet_current.py

View check run for this annotation

Codecov / codecov/patch

hr_timesheet_sheet/wizard/hr_timesheet_current.py#L27-L28

Added lines #L27 - L28 were not covered by tests
else:
domain = "[('user_id', '=', uid)]"
value = {

Check warning on line 31 in hr_timesheet_sheet/wizard/hr_timesheet_current.py

View check run for this annotation

Codecov / codecov/patch

hr_timesheet_sheet/wizard/hr_timesheet_current.py#L30-L31

Added lines #L30 - L31 were not covered by tests
"domain": domain,
"name": _("Open Timesheet"),
"view_type": "form",
"view_mode": view_type,
"res_model": "hr_timesheet.sheet",
"view_id": False,
"type": "ir.actions.act_window",
}
if len(sheets) == 1:
value["res_id"] = sheets.ids[0]
return value

Check warning on line 42 in hr_timesheet_sheet/wizard/hr_timesheet_current.py

View check run for this annotation

Codecov / codecov/patch

hr_timesheet_sheet/wizard/hr_timesheet_current.py#L41-L42

Added lines #L41 - L42 were not covered by tests