Skip to content

Commit

Permalink
[IMP] hr_timesheet_sheet: _check_can_write on account.analytic.line a…
Browse files Browse the repository at this point in the history
…nd sheet_id in timesheets.analysis.report
  • Loading branch information
Vijaiy-Selvaraj committed Aug 23, 2024
1 parent eef5668 commit 157bde4
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
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 report
28 changes: 27 additions & 1 deletion hr_timesheet_sheet/models/account_analytic_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,30 @@ def merge_timesheets(self):
return self[0]

def _check_can_write(self, values):
return super()._check_can_write(values) or not self.filtered("sheet_id")
is_installed = (
self.env["ir.module.module"]
.sudo()
.search(
[
("name", "=", "project_timesheet_holidays"),
("state", "=", "installed"),
]
)
)
if is_installed:
if not self.env.su:
if (
hasattr(self, "holiday_id")
and self.holiday_id
and values.get("sheet_id", False)
): # Dont raise error during create
return True
if hasattr(self, "holiday_id") and self.holiday_id and self.sheet_id:
raise UserError(
_(
"""You cannot modify timesheets that are linked to \
time off requests.
Please use the Time Off application to modify your time off requests instead."""
)
)
return super()._check_can_write(values)
3 changes: 3 additions & 0 deletions hr_timesheet_sheet/report/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import timesheets_analysis_report
22 changes: 22 additions & 0 deletions hr_timesheet_sheet/report/timesheets_analysis_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2018 ForgeFlow, S.L.
# Copyright 2018-2019 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class TimesheetsAnalysisReport(models.Model):
_inherit = "timesheets.analysis.report"

sheet_id = fields.Many2one(
comodel_name="hr_timesheet.sheet", string="Sheet", readonly=True
)

@api.model
def _select(self):
return (
super()._select()
+ """,
A.sheet_id AS sheet_id
"""
)
4 changes: 2 additions & 2 deletions hr_timesheet_sheet/tests/test_hr_timesheet_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,8 +1015,8 @@ def test_employee_no_user(self):
sheet_form.save()

sheet = Form(self.sheet_model.with_user(self.user)).save()
with self.assertRaises(UserError):
with Form(sheet.with_user(self.user)) as sheet_form:
with Form(sheet.with_user(self.user)) as sheet_form:
with self.assertRaises(UserError):
sheet_form.employee_id = self.employee_no_user

def test_workflow(self):
Expand Down

0 comments on commit 157bde4

Please sign in to comment.