Employees Without Running Contracts 1 # Retrieve employees: # - with no open contract, and date_end in the past # - with no contract, and not green draft contract employees_without_contracts = self.env['hr.employee'] all_employees = self.env['hr.employee'].search([ ('employee_type', '=', 'employee'), ('company_id', 'in', self.env.companies.ids), ]) today = date.today() for employee in all_employees: version = employee.version_id.sudo() if not version.contract_date_start or (version.contract_date_end and version.contract_date_end < today): employees_without_contracts += employee if employees_without_contracts: warning_count = len(employees_without_contracts) warning_records = employees_without_contracts Employees With Multiple Open Payslips of Same Type 3 employee_payslips = defaultdict(lambda: defaultdict(lambda: self.env['hr.payslip'])) for slip in last_batches.slip_ids: if slip.state == 'cancel': continue employee = slip.employee_id struct = slip.struct_id employee_payslips[struct][employee] |= slip employees_multiple_payslips = self.env['hr.payslip'] for dummy, employee_slips in employee_payslips.items(): for employee, payslips in employee_slips.items(): if len(payslips) > 1: employees_multiple_payslips |= payslips if employees_multiple_payslips: warning_count = len(employees_multiple_payslips.employee_id) warning_records = employees_multiple_payslips additional_context = {'search_default_group_by_employee_id': 1} Employees (With Running Contracts) missing from open batches 2 employees_missing_payslip = self.env['hr.employee'].search([ ('company_id', 'in', last_batches.company_id.ids), ('id', 'not in', last_batches.slip_ids.employee_id.ids)]).filtered(lambda e: e.is_in_contract) if employees_missing_payslip: warning_count = len(employees_missing_payslip) warning_records = employees_missing_payslip Conflicts 5 start_month = date.today().replace(day=1) next_month = start_month + relativedelta(months=1) work_entries_in_conflict = self.env['hr.work.entry'].search_count([ ('state', '=', 'conflict'), ('date', '>=', start_month), ('date', '<', next_month)]) if work_entries_in_conflict: warning_count = work_entries_in_conflict warning_action = 'hr_work_entry.hr_work_entry_action_conflict' Employees with running contracts coming to an end 5 # Nearly expired contracts nearly_expired_contracts = self.env['hr.version'] for company in self.env.companies: outdated_days = date.today() + relativedelta(days=company.contract_expiration_notice_period) nearly_expired_contracts += self.env['hr.version']._get_nearly_expired_contracts(outdated_days, company.id) if nearly_expired_contracts: warning_count = len(nearly_expired_contracts.employee_id) warning_records = nearly_expired_contracts.employee_id Payslips Generated On Previous Contract 6 employee_payslip_contracts = defaultdict(lambda: self.env['hr.version']) for slip in last_batches.slip_ids: if slip.state == 'cancel': continue employee = slip.employee_id contract = slip.version_id employee_payslip_contracts[employee] |= contract employees_previous_contract = self.env['hr.employee'] for employee, used_contracts in employee_payslip_contracts.items(): if employee.version_id not in used_contracts: employees_previous_contract |= employee if employees_previous_contract: warning_count = len(employees_previous_contract) warning_records = employees_previous_contract Payslips With Negative NET 4 payslips_with_negative_net = self.env['hr.payslip'] for slip in last_batches.slip_ids: if slip.state == 'cancel': continue if slip.net_wage < 0: payslips_with_negative_net |= slip if payslips_with_negative_net: warning_count = len(payslips_with_negative_net) warning_records = payslips_with_negative_net Employees Without Identification Number 8 employees_wo_id = self.env['hr.employee'].search([ ('identification_id', '=', False), ('company_id', 'in', self.env.context.get('allowed_company_ids')), ]) if employees_wo_id: warning_count = len(employees_wo_id) warning_records = employees_wo_id Employees Without Bank account Number 9 employees_wo_bnk_acc = self.env['hr.employee'].search([ ('bank_account_ids', '=', False), ('company_id', 'in', self.env.context.get('allowed_company_ids')), ]) if employees_wo_bnk_acc: warning_count = len(employees_wo_bnk_acc) warning_records = employees_wo_bnk_acc Employees with untrusted Bank Account numbers 10 untrusted_bank_accounts_ids = self.env['hr.employee']._get_untrusted_bank_account_ids() untrusted_bank_accounts = self.env['res.partner.bank'].browse(untrusted_bank_accounts_ids) if untrusted_bank_accounts: warning_count = len(untrusted_bank_accounts) warning_records = untrusted_bank_accounts Payslips are overdue for payments today = date.today() done_payslips = self.env['hr.payslip'].search([ ('state', '=', 'validated'), ('company_id', 'in', self.env.companies.ids), ]) overdue_payslips = self.env['hr.payslip'] for payslip in done_payslips: if (today - payslip.create_date.date()).days >= 30: overdue_payslips += payslip if overdue_payslips: warning_count = len(overdue_payslips) warning_records = overdue_payslips