48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
# Copyright 2026 Criptomart
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
|
|
|
import logging
|
|
|
|
from odoo import api, models
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class HrTimesheetSheet(models.Model):
|
|
_inherit = "hr_timesheet.sheet"
|
|
|
|
@api.model
|
|
def _unfreeze_domain(self):
|
|
"""Hook for extensions: which sheets are considered frozen."""
|
|
return [("state", "in", ("confirm", "done"))]
|
|
|
|
@api.model
|
|
def _unfreeze_sheets(self):
|
|
"""Send frozen sheets back to draft. Returns the number of sheets affected.
|
|
|
|
The update is issued in SQL on purpose: going through ``write()`` would
|
|
trigger the sheet recomputation and one tracking message per sheet, on a
|
|
volume that is measured in thousands of records.
|
|
"""
|
|
sheets = self.search(self._unfreeze_domain())
|
|
if not sheets:
|
|
_logger.info("No frozen timesheet sheets to unfreeze.")
|
|
return 0
|
|
sheets.check_access_rights("write")
|
|
sheets.check_access_rule("write")
|
|
self.env.flush_all()
|
|
self.env.cr.execute(
|
|
"""
|
|
UPDATE hr_timesheet_sheet
|
|
SET state = 'draft',
|
|
reviewer_id = NULL,
|
|
write_uid = %s,
|
|
write_date = (now() at time zone 'UTC')
|
|
WHERE id IN %s
|
|
""",
|
|
(self.env.uid, tuple(sheets.ids)),
|
|
)
|
|
count = self.env.cr.rowcount
|
|
self.env.invalidate_all(flush=False)
|
|
_logger.info("Unfroze %s timesheet sheet(s).", count)
|
|
return count
|