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 Oct 18, 2024
1 parent 62855c4 commit 9cee80f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
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
"""
)

0 comments on commit 9cee80f

Please sign in to comment.