75 lines
3.4 KiB
Python
75 lines
3.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo import api, fields, models, tools, _
|
|
from datetime import datetime, time, timedelta
|
|
|
|
|
|
class OvertimeApprovals(models.Model):
|
|
_name = 'overtime.approval'
|
|
_description = "加班审批"
|
|
# _inherit = ['mail.thread.main.attachment', 'mail.activity.mixin', 'soong.workflow.mixin']
|
|
_inherit = ['mail.thread.main.attachment', 'mail.activity.mixin','soong.workflow.mixin']
|
|
_rec_name = 'name'
|
|
|
|
company_page = fields.Selection([('tz', '天河投资'), ('wg', '天河物管'), ('lc', '天河粮储')], string="公司")
|
|
name = fields.Char(string="名称")
|
|
code = fields.Char(string="编号",default=lambda self: self.env['ir.sequence'].next_by_code('overtime_approval'))
|
|
users_id = fields.Many2one('res.users', string="申请人",default=lambda self: self.env.user.id)
|
|
overtime_approval_ids = fields.One2many('overtime.user.line', 'overtime_approval_id', string="加班审批行")
|
|
department_id = fields.Many2one('hr.department', string="部门")
|
|
|
|
@api.onchange('overtime_department_id')
|
|
def onchange_overtime_users(self):
|
|
users_data_list = []
|
|
default_datetime = datetime.combine(datetime.now().date(), time(hour=17, minute=30)) - timedelta(hours=8),
|
|
users_list = []
|
|
for user in self.overtime_user_ids:
|
|
users_list.append(user.user_id.id)
|
|
for over in self:
|
|
if not over.overtime_department_id:
|
|
if over.users_id.id not in users_list:
|
|
users_data_list.append((0, 0, {
|
|
'overtime_approval_id': over.id,
|
|
'user_id': over.users_id.id,
|
|
'start_time': default_datetime[0],
|
|
'type_overtime': 'work',
|
|
'compensation_mode': 'salary',
|
|
}))
|
|
else:
|
|
employee_ids = self.env['hr.employee'].search(
|
|
[('department_id', '=', self.overtime_department_id.id)])
|
|
for user in employee_ids:
|
|
if user.user_id.id not in users_list:
|
|
users_data_list.append((0, 0, {
|
|
'overtime_approval_id': over.id,
|
|
'user_id': user.user_id.id,
|
|
'start_time': default_datetime[0],
|
|
'type_overtime': 'work',
|
|
'compensation_mode': 'salary',
|
|
}))
|
|
over.overtime_user_ids = users_data_list
|
|
|
|
|
|
class OvertimeUserLine(models.Model):
|
|
_name = 'overtime.user.line'
|
|
_rec_name = 'overtime_approval_id'
|
|
_description = "加班明细行"
|
|
|
|
overtime_approval_id = fields.Many2one('overtime.approval', string="加班单号")
|
|
overtime_people = fields.Many2one('hr.employee',string="加班人员")
|
|
reason_application = fields.Char(string="事由")
|
|
department_id = fields.Many2one('hr.department', string="部门")
|
|
overtime_hours = fields.Float(string="本月加班时长")
|
|
documents_ids = fields.Many2many('documents.document', string="附件")
|
|
|
|
# def attendance_button(self):
|
|
# return {
|
|
# 'type': 'ir.actions.client',
|
|
# 'tag': 'display_notification',
|
|
# 'target': 'new',
|
|
# 'params': {
|
|
# 'title': '考勤信息',
|
|
# 'message': _(self.user_id.name + "的签到时间:2024-7-12 8:00:00 签出时间:2024-7-12 20:00:00"),
|
|
# 'sticky': True
|
|
# }
|
|
# }
|