CybroOdoo / OpenHRMS

GNU Affero General Public License v3.0
126 stars 214 forks source link

HR Dashboard check in - Missing Record #116

Open budu7x opened 3 months ago

budu7x commented 3 months ago

When Administrator user is trying to Check In in the HR Dashboard, gets:

Missing Record

Record does not exist or has been deleted. (Record: hr.employee(2,), User: 2).

After creating another account, to have user 2. Now, when Administrator(user 1) is checking in, it's showing in the time attendance logs a check in for user 2.

When user 2 to is trying to clock in, returns this:

Missing Record

Record does not exist or has been deleted. (Record: hr.employee(6,), User: 6)

I tried with a 3rd user and returns this: Missing Record

Record does not exist or has been deleted. (Record: hr.employee(7,), User: 7)

All these on Odoo17 with OpenHRMS.

budu7x commented 3 months ago

Temporary fix that seems to work:

~/addons/hrms_dashboard/models/hr_employee.py

import pandas as pd
from collections import defaultdict
from datetime import timedelta, datetime, date
from dateutil.relativedelta import relativedelta
from pytz import utc
from odoo import api, fields, models, _
# from odoo.http import request # Removed based on best practices
from odoo.tools import float_utils
import logging  # Added for logging

_logger = logging.getLogger(__name__)  # Added for logging

ROUNDING_FACTOR = 16

class HrEmployee(models.Model):
    """ Inherit hr.employee to add birthday field and custom methods. """
    _inherit = 'hr.employee'

    birthday = fields.Date(string='Date of Birth', groups="base.group_user",
                           help="Birthday")

    def attendance_manual(self):
        _logger.info(f"attendance_manual method called for employee ID: {self.id} - Name: {self.name}")  # Logging the employee
        # The following line is commented out as it's incorrect to use request in the model directly
        # employee = request.env['hr.employee'].sudo().browse(request.session.uid)
        self.sudo()._attendance_action_change({
            'city': _('Unknown'),
            'country_name': _('Unknown'),
            'latitude': False,
            'longitude': False,
            'ip_address': _('Unknown'),
            'browser': _('Unknown'),
            'mode': 'kiosk'
        })
        return self