19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:31:00 +01:00
parent a1137a1456
commit e1d89e11e3
2789 changed files with 1093187 additions and 605897 deletions

View file

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import hr_employee_delete_wizard

View file

@ -0,0 +1,63 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import _, api, fields, models
class HrEmployeeDeleteWizard(models.TransientModel):
_name = 'hr.employee.delete.wizard'
_description = 'Employee Delete Wizard'
employee_ids = fields.Many2many('hr.employee', string='Employees', context={'active_test': False}, export_string_translation=False)
has_active_employee = fields.Boolean(string='Has Active Employee', compute='_compute_has_active_employee', export_string_translation=False)
has_timesheet = fields.Boolean(string='Has Timesheet', compute='_compute_has_timesheet', compute_sudo=True, export_string_translation=False)
@api.depends('employee_ids')
def _compute_has_timesheet(self):
timesheet_read_group = self.env['account.analytic.line']._read_group([
('employee_id', 'in', self.employee_ids.ids)],
['employee_id'],
)
timesheet_employee_map = {employee.id for [employee] in timesheet_read_group}
for wizard in self:
wizard.has_timesheet = timesheet_employee_map & set(wizard.employee_ids.ids)
@api.depends('employee_ids')
def _compute_has_active_employee(self):
unarchived_employees = self.env['hr.employee'].search([('id', '=', self.employee_ids.ids)])
for wizard in self:
wizard.has_active_employee = any(emp in wizard.employee_ids for emp in unarchived_employees)
def action_archive(self):
self.ensure_one()
return {
'name': _('Employee Termination'),
'type': 'ir.actions.act_window',
'res_model': 'hr.departure.wizard',
'views': [[False, 'form']],
'view_mode': 'form',
'target': 'new',
'context': {
'active_ids': self.employee_ids.ids,
'employee_termination': True,
},
}
def action_confirm_delete(self):
self.ensure_one()
self.employee_ids.unlink()
return self.env['ir.actions.act_window']._for_xml_id('hr.open_view_employee_list_my')
def action_open_timesheets(self):
self.ensure_one()
employees = self.with_context(active_test=False).employee_ids
action = {
'name': _('Employees\' Timesheets'),
'type': 'ir.actions.act_window',
'res_model': 'account.analytic.line',
'view_mode': 'list,form',
'views': [(False, 'list'), (False, 'form')],
'domain': [('employee_id', 'in', employees.ids), ('project_id', '!=', False)],
}
if len(employees) == 1:
action['name'] = _('Timesheets of %(name)s', name=employees.name)
return action

View file

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="hr_employee_delete_wizard_form" model="ir.ui.view">
<field name="name">Delete Employee</field>
<field name="model">hr.employee.delete.wizard</field>
<field name="arch" type="xml">
<form string="Delete Employee">
<field name="has_timesheet" invisible="1"/>
<field name="has_active_employee" invisible="1"/>
<span invisible="not has_timesheet">
Uh-oh! The employee youre trying to delete still has some timesheets hanging around and cant be deleted.
<span invisible="not has_active_employee">
So here are your two options: either delete those timesheets or consider archiving the employee instead.
</span>
<span invisible="has_active_employee" groups="hr_timesheet.group_hr_timesheet_approver">
Please first delete all of their timesheets.
</span>
</span>
<span invisible="has_timesheet">
Are you sure you want to delete these employees?
</span>
<footer invisible="not has_timesheet">
<button string="Archive Employees" type="object" name="action_archive" class="btn btn-primary"
invisible="not has_active_employee" data-hotkey="q"/>
<button string="See Timesheets" type="object" name="action_open_timesheets" class="btn btn-primary" groups="hr_timesheet.group_hr_timesheet_approver"
invisible="has_active_employee" data-hotkey="w"/>
<button string="See Timesheets" type="object" name="action_open_timesheets" class="btn btn-secondary" groups="hr_timesheet.group_hr_timesheet_approver"
invisible="not has_active_employee" data-hotkey="w"/>
<button string="Discard" special="cancel" data-hotkey="x"/>
</footer>
<footer invisible="has_timesheet">
<button string="Ok" type="object" name="action_confirm_delete" class="btn btn-primary" data-hotkey="q"/>
<button string="Discard" special="cancel" data-hotkey="x"/>
</footer>
</form>
</field>
</record>
</data>
</odoo>