DEV: Sequence genartion for Employee Code
This commit is contained in:
parent
54541998c5
commit
8877a4ebc4
|
|
@ -1,5 +1,5 @@
|
|||
from . import resource_calendar_period
|
||||
from . import late_coming_request
|
||||
from . import ot_request
|
||||
from . import attendance_data
|
||||
from . import hr_employee_inherit
|
||||
from . import attendance_data
|
||||
|
|
|
|||
|
|
@ -104,6 +104,19 @@ class AttendanceAnalytics(models.Model):
|
|||
shift_name = fields.Char(
|
||||
string='Shift'
|
||||
)
|
||||
attendance_mode = fields.Selection(
|
||||
related='employee_id.attendance_mode',
|
||||
string='Attendance Mode',
|
||||
store=True,
|
||||
readonly=True,
|
||||
)
|
||||
work_mode = fields.Selection(
|
||||
[
|
||||
('office', 'Office'),
|
||||
('wfh', 'Work From Home'),
|
||||
],
|
||||
string='Work Mode'
|
||||
)
|
||||
|
||||
@api.depends('late_minutes')
|
||||
def _compute_late_time(self):
|
||||
|
|
@ -305,17 +318,12 @@ class AttendanceAnalytics(models.Model):
|
|||
self.env.cr.execute("""
|
||||
|
||||
CREATE OR REPLACE VIEW attendance_analytics AS (
|
||||
|
||||
WITH employee_dates AS (
|
||||
|
||||
SELECT
|
||||
|
||||
emp.id AS employee_id,
|
||||
|
||||
emp.department_id,
|
||||
|
||||
emp.resource_calendar_id,
|
||||
|
||||
emp.attendance_mode,
|
||||
generate_series(
|
||||
DATE(emp.create_date),
|
||||
CURRENT_DATE,
|
||||
|
|
@ -323,7 +331,6 @@ class AttendanceAnalytics(models.Model):
|
|||
)::date AS date
|
||||
|
||||
FROM hr_employee emp
|
||||
|
||||
WHERE emp.active = true
|
||||
),
|
||||
|
||||
|
|
@ -430,6 +437,7 @@ class AttendanceAnalytics(models.Model):
|
|||
row_number() OVER() AS id,
|
||||
ed.employee_id,
|
||||
ed.department_id,
|
||||
ed.attendance_mode AS attendance_mode,
|
||||
rc.id AS shift_id,
|
||||
rc.name AS shift_name,
|
||||
ed.date,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class HREmployee(models.Model):
|
|||
)
|
||||
attendance_mode = fields.Selection(
|
||||
[
|
||||
('office', 'Office Based'),
|
||||
('office', 'Office'),
|
||||
('remote', 'Remote'),
|
||||
('hybrid', 'Hybrid'),
|
||||
('shift', 'Shift Based'),
|
||||
|
|
@ -19,6 +19,10 @@ class HREmployee(models.Model):
|
|||
default='office',
|
||||
tracking=True,
|
||||
)
|
||||
work_mode = fields.Selection([
|
||||
('office', 'Office'),
|
||||
('wfh', 'Work From Home'),
|
||||
], default='office')
|
||||
|
||||
def _compute_attendance_analytics_count(self):
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ class ResourceCalendar(models.Model):
|
|||
'dayofweek': day.code,
|
||||
'hour_from': rec.shift_start_time,
|
||||
'hour_to': rec.shift_end_time,
|
||||
'work_mode': 'office',
|
||||
}))
|
||||
|
||||
# Single write operation
|
||||
|
|
@ -110,4 +111,12 @@ class ResourceCalendarDepartmentGrace(models.Model):
|
|||
grace_period = fields.Integer(
|
||||
string="Grace Period (Minutes)",
|
||||
required=True
|
||||
)
|
||||
)
|
||||
|
||||
class ResourceCalendarAttendance(models.Model):
|
||||
_inherit = 'resource.calendar.attendance'
|
||||
|
||||
work_mode = fields.Selection([
|
||||
('office', 'Office'),
|
||||
('wfh', 'Work From Home'),
|
||||
])
|
||||
|
|
@ -23,6 +23,7 @@
|
|||
<field name="is_compensation_pending"/>
|
||||
<field name="late_approved"/>
|
||||
<field name="shift_id"/>
|
||||
<field name="attendance_mode"/>
|
||||
<!-- <field name="shift_name"/>-->
|
||||
<field name="status"
|
||||
widget="badge"
|
||||
|
|
@ -136,9 +137,13 @@
|
|||
</record>
|
||||
|
||||
<menuitem id="menu_attendance_analytics"
|
||||
name="Attendance Data"
|
||||
name="Attendances"
|
||||
parent="hr_attendance.menu_hr_attendance_root"
|
||||
action="action_attendance_analytics"
|
||||
sequence="50"/>
|
||||
<menuitem id="menu_attendance_analytics_data"
|
||||
name="Attendance Data"
|
||||
parent="menu_attendance_analytics"
|
||||
action="action_attendance_analytics"
|
||||
sequence="-51"/>
|
||||
|
||||
</odoo>
|
||||
|
|
@ -97,10 +97,14 @@
|
|||
]
|
||||
</field>
|
||||
</record>
|
||||
<menuitem id="menu_late_coming_request"
|
||||
<menuitem id="menu_late_coming_request_perm"
|
||||
name="Permission Requests"
|
||||
parent="hr_attendance.menu_hr_attendance_root"
|
||||
action="action_late_coming_request"
|
||||
parent="menu_attendance_analytics"
|
||||
sequence="30"/>
|
||||
<menuitem id="menu_late_coming_request"
|
||||
name="Late Coming Requests"
|
||||
parent="menu_late_coming_request_perm"
|
||||
action="action_late_coming_request"
|
||||
sequence="31"/>
|
||||
|
||||
</odoo>
|
||||
|
|
@ -92,7 +92,7 @@
|
|||
|
||||
<menuitem id="menu_overtime_request"
|
||||
name="Overtime Requests"
|
||||
parent="hr_attendance.menu_hr_attendance_root"
|
||||
parent="menu_late_coming_request_perm"
|
||||
action="action_overtime_request"
|
||||
sequence="35"/>
|
||||
|
||||
|
|
|
|||
|
|
@ -77,10 +77,22 @@
|
|||
|
||||
</page>
|
||||
</xpath>
|
||||
|
||||
|
||||
<xpath expr="//sheet/notebook"
|
||||
position="inside">
|
||||
<page string="Hybrid Schedule Details">
|
||||
<field name="attendance_ids">
|
||||
<list editable="bottom">
|
||||
<field name="name"/>
|
||||
<field name="dayofweek"/>
|
||||
<field name="hour_from"
|
||||
widget="float_time"/>
|
||||
<field name="hour_to"
|
||||
widget="float_time"/>
|
||||
<field name="work_mode"/>
|
||||
</list>
|
||||
</field>
|
||||
</page>
|
||||
</xpath>
|
||||
</field>
|
||||
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
|
@ -26,6 +26,7 @@
|
|||
'security/ir.model.access.csv',
|
||||
'data/cron.xml',
|
||||
'data/mail.xml',
|
||||
'data/sequence.xml',
|
||||
'views/res_config_settings.xml',
|
||||
'views/hr_employee.xml',
|
||||
'views/bank_details.xml',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data noupdate="1">
|
||||
|
||||
<record id="seq_hr_employee" model="ir.sequence">
|
||||
<field name="name">Employee Sequence</field>
|
||||
<field name="code">hr.employee.running</field>
|
||||
<field name="padding">4</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
|
|
@ -33,7 +33,19 @@ class HrEmployeeBase(models.AbstractModel):
|
|||
('AB-', 'AB-'),
|
||||
], string="Blood Group")
|
||||
|
||||
@api.constrains('employee_id')
|
||||
def _check_employee_code_unique(self):
|
||||
for rec in self:
|
||||
if rec.employee_id:
|
||||
duplicate = self.search([
|
||||
('id', '!=', rec.id),
|
||||
('employee_id', '=', rec.employee_id)
|
||||
], limit=1)
|
||||
|
||||
if duplicate:
|
||||
raise ValidationError(
|
||||
_("Employee Code '%s' already exists.") % rec.employee_id
|
||||
)
|
||||
|
||||
@api.constrains('identification_id')
|
||||
def _check_identification_id(self):
|
||||
|
|
@ -158,6 +170,37 @@ class HrEmployee(models.Model):
|
|||
previous_company_pf_no = fields.Char(string='Previous Company PF No')
|
||||
previous_company_uan_no = fields.Char(string='Previous Company UAN No')
|
||||
|
||||
def _generate_employee_code(self, vals):
|
||||
|
||||
location = self.env['hr.work.location'].browse(
|
||||
vals.get('work_location_id')
|
||||
)
|
||||
|
||||
department = self.env['hr.department'].browse(
|
||||
vals.get('department_id')
|
||||
)
|
||||
|
||||
loc_code = location.location_number or location.name or "GEN"
|
||||
|
||||
dept_code = getattr(department, 'code', False) or department.name or "GEN"
|
||||
|
||||
year = fields.Date.today().year
|
||||
|
||||
seq = self.env['ir.sequence'].next_by_code(
|
||||
'hr.employee.running'
|
||||
) or '0001'
|
||||
|
||||
return f"{loc_code}-{dept_code}-{year}-{seq}"
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
|
||||
for vals in vals_list:
|
||||
if not vals.get('employee_id'):
|
||||
vals['employee_id'] = self._generate_employee_code(vals)
|
||||
|
||||
return super().create(vals_list)
|
||||
|
||||
def hr_employee_event_remainder(self):
|
||||
self.send_birthday_reminders()
|
||||
today = fields.Date.today()
|
||||
|
|
|
|||
Loading…
Reference in New Issue