add hr_timesheet_sheet_no_review, hr_timesheet_sheet_holidays, hr_timesheet_sheet_delete_cascade
This commit is contained in:
parent
b07082f70d
commit
8b0d0bb6cc
53 changed files with 3953 additions and 0 deletions
2
hr_timesheet_sheet_holidays/models/__init__.py
Normal file
2
hr_timesheet_sheet_holidays/models/__init__.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
from . import account_analytic_line
|
||||
from . import hr_timesheet_sheet
|
||||
74
hr_timesheet_sheet_holidays/models/account_analytic_line.py
Normal file
74
hr_timesheet_sheet_holidays/models/account_analytic_line.py
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
# Copyright 2026 Criptomart
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import _, models
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tools.misc import format_date
|
||||
|
||||
# The context of an RPC call is controlled by the client: odoo.api.call_kw
|
||||
# rebuilds the environment with whatever dictionary arrives in the request, so
|
||||
# a flag carrying a JSON value could be forged by any authenticated user. These
|
||||
# sentinels are compared by identity and cannot be produced by a deserializer,
|
||||
# so they only ever reach the consumer from inside this process.
|
||||
_SHEET_LINK_WRITE = object()
|
||||
_SHEET_RECOMPUTE = object()
|
||||
|
||||
|
||||
class AccountAnalyticLine(models.Model):
|
||||
_inherit = "account.analytic.line"
|
||||
|
||||
def _sheet_neutral_fields(self):
|
||||
"""Hook for extensions"""
|
||||
return {"sheet_id"}
|
||||
|
||||
def _sheet_link_write_token(self):
|
||||
"""Hook for extensions"""
|
||||
return _SHEET_LINK_WRITE
|
||||
|
||||
def _sheet_recompute_token(self):
|
||||
"""Hook for extensions"""
|
||||
return _SHEET_RECOMPUTE
|
||||
|
||||
def _in_sheet_link_write(self):
|
||||
return (
|
||||
self.env.context.get("sheet_link_write") is self._sheet_link_write_token()
|
||||
)
|
||||
|
||||
def _detach_leave_lines_on_unlink(self):
|
||||
"""Hook for extensions"""
|
||||
return self.env.context.get("sheet_recompute") is self._sheet_recompute_token()
|
||||
|
||||
def _check_can_update_timesheet(self):
|
||||
if self._in_sheet_link_write():
|
||||
return True
|
||||
if not self.env.su and self.filtered("holiday_id"):
|
||||
return False
|
||||
return super()._check_can_update_timesheet()
|
||||
|
||||
def write(self, vals):
|
||||
if vals and self.filtered("holiday_id"):
|
||||
if set(vals) <= self._sheet_neutral_fields():
|
||||
linking = self.with_context(
|
||||
sheet_link_write=self._sheet_link_write_token()
|
||||
)
|
||||
return super(AccountAnalyticLine, linking).write(vals)
|
||||
if not self._check_can_update_timesheet():
|
||||
line = self.filtered("holiday_id")[:1]
|
||||
raise UserError(
|
||||
_(
|
||||
"Time off hours are managed from the Time Off application"
|
||||
" and cannot be changed from a timesheet sheet.\n"
|
||||
"Sheet: %(sheet)s\n"
|
||||
"Day: %(day)s",
|
||||
sheet=line.sheet_id.complete_name or "-",
|
||||
day=format_date(self.env, line.date),
|
||||
)
|
||||
)
|
||||
return super().write(vals)
|
||||
|
||||
def unlink(self):
|
||||
leave_lines = self.filtered("holiday_id")
|
||||
if leave_lines and leave_lines._detach_leave_lines_on_unlink():
|
||||
leave_lines.write({"sheet_id": False})
|
||||
return super(AccountAnalyticLine, self - leave_lines).unlink()
|
||||
return super().unlink()
|
||||
21
hr_timesheet_sheet_holidays/models/hr_timesheet_sheet.py
Normal file
21
hr_timesheet_sheet_holidays/models/hr_timesheet_sheet.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Copyright 2026 Criptomart
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class Sheet(models.Model):
|
||||
_inherit = "hr_timesheet.sheet"
|
||||
|
||||
def _with_sheet_recompute(self):
|
||||
"""Hook for extensions"""
|
||||
token = self.env["account.analytic.line"]._sheet_recompute_token()
|
||||
return self.with_context(sheet_recompute=token)
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
sheets = super(Sheet, self._with_sheet_recompute()).create(vals_list)
|
||||
return sheets.with_env(self.env)
|
||||
|
||||
def write(self, vals):
|
||||
return super(Sheet, self._with_sheet_recompute()).write(vals)
|
||||
Loading…
Add table
Add a link
Reference in a new issue