This commit is contained in:
gsinghpal
2026-03-16 08:14:56 -04:00
parent fdca9518ab
commit e56974d46f
196 changed files with 19739 additions and 3471 deletions

View File

@@ -8,6 +8,7 @@ import logging
from datetime import datetime, timedelta
from odoo import http, fields, _
from odoo.http import request
from odoo.addons.fusion_clock.models.tz_utils import get_local_today, get_local_day_boundaries
_logger = logging.getLogger(__name__)
@@ -126,7 +127,7 @@ class FusionClockAPI(http.Controller):
'scheduled_time': scheduled_dt,
'actual_time': actual_dt,
'penalty_minutes': deduction,
'date': actual_dt.date() if isinstance(actual_dt, datetime) else fields.Date.today(),
'date': actual_dt.date() if isinstance(actual_dt, datetime) else get_local_today(request.env, employee),
})
# Deduct penalty minutes from attendance (adds to break deduction)
@@ -266,7 +267,7 @@ class FusionClockAPI(http.Controller):
)
now = fields.Datetime.now()
today = now.date()
today = get_local_today(request.env, employee)
geo_info = {
'latitude': latitude,
@@ -529,24 +530,23 @@ class FusionClockAPI(http.Controller):
'location_id': att.x_fclk_location_id.id or False,
})
today_start = fields.Datetime.to_string(
datetime.combine(fields.Date.today(), datetime.min.time())
)
local_today = get_local_today(request.env, employee)
today_start_utc, today_end_utc = get_local_day_boundaries(request.env, local_today, employee)
today_atts = request.env['hr.attendance'].sudo().search([
('employee_id', '=', employee.id),
('check_in', '>=', today_start),
('check_in', '>=', fields.Datetime.to_string(today_start_utc)),
('check_in', '<', fields.Datetime.to_string(today_end_utc)),
('check_out', '!=', False),
])
result['today_hours'] = round(sum(a.x_fclk_net_hours or 0 for a in today_atts), 2)
today = fields.Date.today()
today = get_local_today(request.env, employee)
week_start = today - timedelta(days=today.weekday())
week_start_dt = fields.Datetime.to_string(
datetime.combine(week_start, datetime.min.time())
)
week_start_utc, _ = get_local_day_boundaries(request.env, week_start, employee)
week_atts = request.env['hr.attendance'].sudo().search([
('employee_id', '=', employee.id),
('check_in', '>=', week_start_dt),
('check_in', '>=', fields.Datetime.to_string(week_start_utc)),
('check_in', '<', fields.Datetime.to_string(today_end_utc)),
('check_out', '!=', False),
])
result['week_hours'] = round(sum(a.x_fclk_net_hours or 0 for a in week_atts), 2)
@@ -614,8 +614,8 @@ class FusionClockAPI(http.Controller):
return {'error': 'Access denied.'}
now = fields.Datetime.now()
today = fields.Date.today()
today_start = datetime.combine(today, datetime.min.time())
today = get_local_today(request.env)
today_start, _ = get_local_day_boundaries(request.env, today)
Attendance = request.env['hr.attendance'].sudo()
Employee = request.env['hr.employee'].sudo()

View File

@@ -9,6 +9,7 @@ from datetime import datetime, timedelta
from odoo import http, fields, _
from odoo.http import request
from odoo.addons.portal.controllers.portal import CustomerPortal
from odoo.addons.fusion_clock.models.tz_utils import get_local_today, get_local_day_boundaries
_logger = logging.getLogger(__name__)
@@ -48,7 +49,7 @@ class FusionClockPortal(CustomerPortal):
if 'clock_count' in counters:
employee = self._get_portal_employee()
if employee:
today_start = datetime.combine(fields.Date.today(), datetime.min.time())
today_start, _ = get_local_day_boundaries(request.env, get_local_today(request.env, employee), employee)
count = request.env['hr.attendance'].sudo().search_count([
('employee_id', '=', employee.id),
('check_in', '>=', today_start),
@@ -99,7 +100,7 @@ class FusionClockPortal(CustomerPortal):
], limit=1)
# Today stats
today_start = datetime.combine(fields.Date.today(), datetime.min.time())
today_start, _ = get_local_day_boundaries(request.env, get_local_today(request.env, employee), employee)
today_atts = request.env['hr.attendance'].sudo().search([
('employee_id', '=', employee.id),
('check_in', '>=', today_start),
@@ -108,9 +109,9 @@ class FusionClockPortal(CustomerPortal):
today_hours = sum(a.x_fclk_net_hours or 0 for a in today_atts)
# Week stats
today = fields.Date.today()
today = get_local_today(request.env, employee)
week_start = today - timedelta(days=today.weekday())
week_start_dt = datetime.combine(week_start, datetime.min.time())
week_start_dt, _ = get_local_day_boundaries(request.env, week_start, employee)
week_atts = request.env['hr.attendance'].sudo().search([
('employee_id', '=', employee.id),
('check_in', '>=', week_start_dt),
@@ -164,7 +165,7 @@ class FusionClockPortal(CustomerPortal):
schedule_type = ICP.get_param('fusion_clock.pay_period_type', 'biweekly')
period_start_str = ICP.get_param('fusion_clock.pay_period_start', '')
today = fields.Date.today()
today = get_local_today(request.env, employee)
# Calculate period dates
FusionReport = request.env['fusion.clock.report'].sudo()
@@ -190,10 +191,12 @@ class FusionClockPortal(CustomerPortal):
period_end -= timedelta(days=14)
# Get attendance records
period_start_utc, _ = get_local_day_boundaries(request.env, period_start, employee)
_, period_end_utc = get_local_day_boundaries(request.env, period_end, employee)
attendances = request.env['hr.attendance'].sudo().search([
('employee_id', '=', employee.id),
('check_in', '>=', datetime.combine(period_start, datetime.min.time())),
('check_in', '<', datetime.combine(period_end + timedelta(days=1), datetime.min.time())),
('check_in', '>=', period_start_utc),
('check_in', '<', period_end_utc),
], order='check_in desc')
total_hours = sum(a.worked_hours or 0 for a in attendances if a.check_out)