changes
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
# Copyright 2026 Nexa Systems Inc.
|
||||
# License OPL-1 (Odoo Proprietary License v1.0)
|
||||
|
||||
from datetime import timedelta
|
||||
from odoo import models, fields, api
|
||||
|
||||
|
||||
@@ -86,19 +85,11 @@ class ResConfigSettings(models.TransientModel):
|
||||
string='Pay Period',
|
||||
config_parameter='fusion_clock.pay_period_type',
|
||||
default='biweekly',
|
||||
help="How often pay periods repeat. Semi-Monthly uses 1st-15th and 16th-end; "
|
||||
"Weekly and Bi-Weekly use the anchor date below.",
|
||||
)
|
||||
fclk_pay_period_start = fields.Date(
|
||||
fclk_pay_period_start = fields.Char(
|
||||
string='Pay Period Anchor Date',
|
||||
help="The first day of any real pay period. All periods are calculated "
|
||||
"forward and backward from this date. For example, if your biweekly "
|
||||
"pay period runs Jan 17 - Jan 30, set this to Jan 17.",
|
||||
)
|
||||
fclk_pay_period_preview = fields.Char(
|
||||
string='Current Period Preview',
|
||||
compute='_compute_pay_period_preview',
|
||||
help="Shows the current pay period based on today's date and your settings.",
|
||||
config_parameter='fusion_clock.pay_period_start',
|
||||
help="Start date for pay period calculations (YYYY-MM-DD format, anchor for weekly/biweekly).",
|
||||
)
|
||||
|
||||
# -- Reports --
|
||||
@@ -131,85 +122,3 @@ class ResConfigSettings(models.TransientModel):
|
||||
config_parameter='fusion_clock.enable_sounds',
|
||||
default=True,
|
||||
)
|
||||
|
||||
@api.depends('fclk_pay_period_type', 'fclk_pay_period_start')
|
||||
def _compute_pay_period_preview(self):
|
||||
HrAtt = self.env['hr.attendance']
|
||||
today = fields.Date.context_today(self)
|
||||
for rec in self:
|
||||
schedule = rec.fclk_pay_period_type or 'biweekly'
|
||||
anchor = rec.fclk_pay_period_start
|
||||
if not anchor and schedule in ('weekly', 'biweekly'):
|
||||
rec.fclk_pay_period_preview = 'Set anchor date to see preview'
|
||||
continue
|
||||
period_start, period_end = HrAtt._calc_period(schedule, anchor, today)
|
||||
rec.fclk_pay_period_preview = (
|
||||
f"{period_start.strftime('%b %d, %Y')} - "
|
||||
f"{period_end.strftime('%b %d, %Y')}"
|
||||
)
|
||||
|
||||
def action_backfill_reports(self):
|
||||
"""Generate reports for all historical pay periods without sending email."""
|
||||
count = self.env['fusion.clock.report'].sudo()._backfill_historical_reports()
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'display_notification',
|
||||
'params': {
|
||||
'title': 'Historical Reports',
|
||||
'message': f'Created {count} reports for past pay periods.',
|
||||
'type': 'success',
|
||||
'sticky': False,
|
||||
},
|
||||
}
|
||||
|
||||
def action_backfill_breaks(self):
|
||||
"""Apply break deduction to all past attendance records missing it,
|
||||
then regenerate any existing report PDFs so they reflect the new totals."""
|
||||
count = self.env['hr.attendance'].sudo().action_backfill_breaks()
|
||||
|
||||
# Regenerate existing report PDFs so stored files match updated totals
|
||||
if count:
|
||||
reports = self.env['fusion.clock.report'].sudo().search([
|
||||
('state', 'in', ['generated', 'sent']),
|
||||
])
|
||||
for report in reports:
|
||||
try:
|
||||
report._generate_pdf()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'display_notification',
|
||||
'params': {
|
||||
'title': 'Break Backfill',
|
||||
'message': f'Applied break deduction to {count} attendance records. Report PDFs regenerated.',
|
||||
'type': 'success',
|
||||
'sticky': False,
|
||||
},
|
||||
}
|
||||
|
||||
@api.model
|
||||
def get_values(self):
|
||||
res = super().get_values()
|
||||
ICP = self.env['ir.config_parameter'].sudo()
|
||||
anchor_str = ICP.get_param('fusion_clock.pay_period_start', '')
|
||||
if anchor_str:
|
||||
try:
|
||||
res['fclk_pay_period_start'] = fields.Date.from_string(anchor_str)
|
||||
except Exception:
|
||||
res['fclk_pay_period_start'] = False
|
||||
return res
|
||||
|
||||
def set_values(self):
|
||||
super().set_values()
|
||||
ICP = self.env['ir.config_parameter'].sudo()
|
||||
val = self.fclk_pay_period_start
|
||||
ICP.set_param(
|
||||
'fusion_clock.pay_period_start',
|
||||
fields.Date.to_string(val) if val else '',
|
||||
)
|
||||
# Recompute all pay periods so existing records match current settings
|
||||
self.env['hr.attendance'].sudo().search([
|
||||
('check_in', '!=', False),
|
||||
])._compute_pay_period()
|
||||
|
||||
Reference in New Issue
Block a user