100 lines
4.9 KiB
Python
100 lines
4.9 KiB
Python
from odoo import _, api, fields, models
|
|
|
|
|
|
class HrEmployeeBase(models.Model):
|
|
_inherit = "hr.employee"
|
|
|
|
def fetch_all_employees_info(self, user_id=None):
|
|
if user_id:
|
|
employee = self.env['hr.employee'].sudo().search([('user_id','=',user_id)], limit=1)
|
|
|
|
if employee:
|
|
|
|
data = {
|
|
'id': str(employee.id),
|
|
'employee_code': str(employee.employee_id),
|
|
'name': str(employee.name),
|
|
'work_email': str(employee.work_email),
|
|
'work_phone': str(employee.work_phone),
|
|
'job_title': str(employee.job_title),
|
|
'department_name': str(employee.department_id.name),
|
|
'work_location_name': str(employee.work_location_id.name),
|
|
'manager': str(employee.parent_id.name),
|
|
'address': str(", ".join(
|
|
filter(None, [
|
|
employee.private_street,
|
|
employee.private_street2,
|
|
employee.private_city,
|
|
employee.private_state_id.name if employee.private_state_id else False,
|
|
employee.private_zip,
|
|
employee.private_country_id.name if employee.private_country_id else False
|
|
])
|
|
) or 'N/A'),
|
|
'bank_account_id': str(employee.bank_account_id.acc_number if employee.bank_account_id else 'N/A'),
|
|
'bank_name': str(employee.bank_account_id.bank_id.name if employee.bank_account_id and employee.bank_account_id.bank_id else 'N/A'),
|
|
'bank_ifsc': str(employee.bank_account_id.bank_id.bic if employee.bank_account_id and employee.bank_account_id.bank_id else 'N/A'),
|
|
'doj': str(fields.Date.from_string(employee.doj).strftime('%d-%m-%Y') if employee.doj else False),
|
|
'birthday': str(fields.Date.from_string(employee.birthday).strftime('%d-%m-%Y') if employee.birthday else False),
|
|
'gender': str(employee.gender).upper(),
|
|
'marital': str(employee.marital).upper(),
|
|
'aadhar_no': str(employee.identification_id),
|
|
'pan_no': str(employee.pan_no),
|
|
'profile_pic': employee.image_1920,
|
|
}
|
|
return data
|
|
|
|
def mobile_check_in_out(self,is_check_in,longitude=None,latitude=None,in_ip_address=None):
|
|
"""
|
|
Check in or check out logic.
|
|
:param latitude: Latitude from the mobile app.
|
|
:param longitude: Longitude from the mobile app.
|
|
:param is_check_in: Boolean to check whether it is check-in or check-out.
|
|
"""
|
|
employee = self.env.user.employee_id
|
|
attendance_obj = self.env['hr.attendance']
|
|
|
|
# Check if there is an existing attendance record with no checkout
|
|
attendance = attendance_obj.search([
|
|
('employee_id', '=', employee.id),
|
|
('check_out', '=', False)
|
|
], limit=1)
|
|
|
|
if not is_check_in:
|
|
# If it's check-in, create a new attendance record
|
|
if not attendance:
|
|
record = attendance_obj.create({
|
|
'employee_id': employee.id,
|
|
'check_in': fields.Datetime.now(),
|
|
'in_latitude': latitude if latitude and latitude!=0 else False,
|
|
'in_longitude': longitude if longitude and longitude!=0 else False,
|
|
'in_mode': 'systray' if latitude != 0 else 'manual',
|
|
'in_ip_address': in_ip_address if in_ip_address else False,
|
|
'in_browser': 'Mobile'
|
|
|
|
})
|
|
return {
|
|
'message': 'Checked in successfully',
|
|
'attendance_id': record.id
|
|
}
|
|
else:
|
|
return {
|
|
'message': 'Already checked in',
|
|
}
|
|
else:
|
|
# If it's check-out, update the existing attendance record
|
|
if attendance:
|
|
attendance.write({
|
|
'check_out': fields.Datetime.now(),
|
|
'out_latitude': latitude if latitude and latitude != 0 else False,
|
|
'out_longitude': longitude if longitude and longitude != 0 else False,
|
|
'out_mode': 'systray' if latitude != 0 else 'manual',
|
|
'out_ip_address': in_ip_address if in_ip_address else False,
|
|
'out_browser': 'Mobile'
|
|
})
|
|
return {
|
|
'message': 'Checked out successfully',
|
|
}
|
|
else:
|
|
return {
|
|
'message': 'No active check-in found',
|
|
} |