From f7d9b26e6611d305bbeb745b360a269cc1662b67 Mon Sep 17 00:00:00 2001 From: Vijay Date: Thu, 29 Aug 2024 13:18:42 +0530 Subject: [PATCH] [IMP] hr_timesheet_sheet: _check_can_write on account.analytic.line and sheet_id in timesheets.analysis.report --- hr_timesheet_sheet/__init__.py | 1 + .../models/account_analytic_line.py | 28 ++++++++++++++++++- hr_timesheet_sheet/report/__init__.py | 3 ++ .../report/timesheets_analysis_report.py | 22 +++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 hr_timesheet_sheet/report/__init__.py create mode 100644 hr_timesheet_sheet/report/timesheets_analysis_report.py diff --git a/hr_timesheet_sheet/__init__.py b/hr_timesheet_sheet/__init__.py index 31660d6a96..91fd52a41b 100644 --- a/hr_timesheet_sheet/__init__.py +++ b/hr_timesheet_sheet/__init__.py @@ -1,3 +1,4 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from . import models +from . import report diff --git a/hr_timesheet_sheet/models/account_analytic_line.py b/hr_timesheet_sheet/models/account_analytic_line.py index eb2fa3d98b..70aba6d8b7 100644 --- a/hr_timesheet_sheet/models/account_analytic_line.py +++ b/hr_timesheet_sheet/models/account_analytic_line.py @@ -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) diff --git a/hr_timesheet_sheet/report/__init__.py b/hr_timesheet_sheet/report/__init__.py new file mode 100644 index 0000000000..3c5f5942a2 --- /dev/null +++ b/hr_timesheet_sheet/report/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import timesheets_analysis_report diff --git a/hr_timesheet_sheet/report/timesheets_analysis_report.py b/hr_timesheet_sheet/report/timesheets_analysis_report.py new file mode 100644 index 0000000000..3087b46487 --- /dev/null +++ b/hr_timesheet_sheet/report/timesheets_analysis_report.py @@ -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 + """ + )