diff --git a/header_search_panel/static/src/search/control_panel/control_panel.xml b/header_search_panel/static/src/search/control_panel/control_panel.xml index e02514450..c61f7f77b 100644 --- a/header_search_panel/static/src/search/control_panel/control_panel.xml +++ b/header_search_panel/static/src/search/control_panel/control_panel.xml @@ -1,11 +1,10 @@ - - + - - + + diff --git a/yuthon_hr_attendance/models/hr_attendance_wechat.py b/yuthon_hr_attendance/models/hr_attendance_wechat.py index f787ee526..4e2450571 100644 --- a/yuthon_hr_attendance/models/hr_attendance_wechat.py +++ b/yuthon_hr_attendance/models/hr_attendance_wechat.py @@ -6,25 +6,63 @@ from odoo import api, fields, models, tools, _ class HrAttendance(models.Model): _inherit = "hr.attendance" - _order = 'current_data desc, check_in desc' + _order = "current_data desc, check_in desc" - userid = fields.Char(string='userid') - groupname = fields.Char(string='打卡规则名称') - current_data = fields.Date(string='打卡日期', tracking=True) - sch_check_in_time = fields.Datetime(string='上班正常时间') - sch_check_out_time = fields.Datetime(string='下班正常时间') - sch_check_noon_time = fields.Datetime(string='中午正常时间') - check_noon = fields.Datetime(string='中午打卡', tracking=True) - check_in = fields.Datetime(string="上班打卡", required=False, default=False, tracking=True) + userid = fields.Char(string="userid") + groupname = fields.Char(string="打卡规则名称") + current_data = fields.Date(string="打卡日期", tracking=True) + current_data_month = fields.Char( + string="打卡日期(月份)", + compute="_compute_current_data_month", + store=True, + index=True, + ) + + def _compute_current_data_month(self): + for rec in self: + if rec.current_data: + rec.current_data_month = rec.current_data.strftime("%Y-%m") + else: + rec.current_data_month = False + + sch_check_in_time = fields.Datetime(string="上班正常时间") + sch_check_out_time = fields.Datetime(string="下班正常时间") + sch_check_noon_time = fields.Datetime(string="中午正常时间") + check_noon = fields.Datetime(string="中午打卡", tracking=True) + check_in = fields.Datetime( + string="上班打卡", required=False, default=False, tracking=True + ) check_out = fields.Datetime(string="下班打卡", tracking=True) - attendance_type = fields.Selection([('wx_work', '企业微信')], readonly=True, string='来源') + attendance_type = fields.Selection( + [("wx_work", "企业微信")], readonly=True, string="来源" + ) # field_work_check = fields.Datetime(string="外勤打卡") - attendance_detail_ids = fields.One2many(string="打卡详情", comodel_name='hr.attendance.detail', inverse_name='hr_attendance_id') - replacement_approval_ids = fields.One2many(string="补卡详情", comodel_name='approval2.request', compute='_compute_replacement_approval_ids') - go_out_approval_ids = fields.One2many(string="外出详情", comodel_name='approval2.request', compute='_compute_go_out_approval_ids') - work_overtime_approval_ids = fields.One2many(string="加班详情", comodel_name='approval2.request', compute='_compute_work_overtime_approval_ids') - hr_leave_approval_ids = fields.One2many(string="请假详情", comodel_name='hr.leave', compute='_compute_hr_leave_approval_ids') + attendance_detail_ids = fields.One2many( + string="打卡详情", + comodel_name="hr.attendance.detail", + inverse_name="hr_attendance_id", + ) + replacement_approval_ids = fields.One2many( + string="补卡详情", + comodel_name="approval2.request", + compute="_compute_replacement_approval_ids", + ) + go_out_approval_ids = fields.One2many( + string="外出详情", + comodel_name="approval2.request", + compute="_compute_go_out_approval_ids", + ) + work_overtime_approval_ids = fields.One2many( + string="加班详情", + comodel_name="approval2.request", + compute="_compute_work_overtime_approval_ids", + ) + hr_leave_approval_ids = fields.One2many( + string="请假详情", + comodel_name="hr.leave", + compute="_compute_hr_leave_approval_ids", + ) is_approval = fields.Boolean(string="是否审批修正", default=False) def action_show_details(self): @@ -40,17 +78,16 @@ class HrAttendance(models.Model): "view_id": view.id, "target": "current", "res_id": self.id, - "domain": [('hr_attendance_id', '=', self.id)], - "context": {'hr_attendance_id': self.id} + "domain": [("hr_attendance_id", "=", self.id)], + "context": {"hr_attendance_id": self.id}, } - @api.constrains('check_in', 'check_out', 'employee_id') + @api.constrains("check_in", "check_out", "employee_id") def _check_validity(self): for attendance in self: - if attendance.attendance_type != 'wx_work': + if attendance.attendance_type != "wx_work": super(HrAttendance, attendance)._check_validity() - def get_work_time(self, attendance_data, current_date, tz): """ 当前时间的工作时间段 @@ -61,16 +98,28 @@ class HrAttendance(models.Model): """ work_time_list = [] for work_time in attendance_data: - work_time_list.append(self.time_to_utc_time(self.str_to_time(current_date, work_time.hour_from), tz)) - work_time_list.append(self.time_to_utc_time(self.str_to_time(current_date, work_time.hour_to), tz)) + work_time_list.append( + self.time_to_utc_time( + self.str_to_time(current_date, work_time.hour_from), tz + ) + ) + work_time_list.append( + self.time_to_utc_time( + self.str_to_time(current_date, work_time.hour_to), tz + ) + ) work_time_sorted = sorted(work_time_list) go_from, go_to, off_from, off_to = work_time_sorted return go_from, go_to, off_from, off_to, current_date - @api.depends('check_in', 'sch_check_in_time') + @api.depends("check_in", "sch_check_in_time") def is_come_late(self): self.ensure_one() - if self.check_in and self.sch_check_in_time and self.check_in > self.sch_check_in_time: + if ( + self.check_in + and self.sch_check_in_time + and self.check_in > self.sch_check_in_time + ): return True return False @@ -93,7 +142,10 @@ class HrAttendance(models.Model): if not attendance_ids: return False # 是不是工作时间 - attendance_data = resource_calendar.attendance_ids.filtered(lambda s: s.dayofweek == str(current_week) and s.day_period in ["morning", "afternoon"]) + attendance_data = resource_calendar.attendance_ids.filtered( + lambda s: s.dayofweek == str(current_week) + and s.day_period in ["morning", "afternoon"] + ) if not attendance_data: return False # 获取工作时间 @@ -102,7 +154,9 @@ class HrAttendance(models.Model): return False go_from, go_to, off_from, off_to, current_date = work_time # 早上和下午上班 判断当天 是不是公休日 - if self.get_leave_day(global_leave, go_from, tz) and self.get_leave_day(global_leave, off_from, tz): + if self.get_leave_day(global_leave, go_from, tz) and self.get_leave_day( + global_leave, off_from, tz + ): return False return go_from, go_to, off_from, off_to, current_date @@ -117,7 +171,11 @@ class HrAttendance(models.Model): if not global_leave: return False for leave in global_leave: - if self.utc_time_to_tz(tz, leave.date_from) <= current_time.strftime("%Y-%m-%d %H:%M:%S") <= self.utc_time_to_tz(tz, leave.date_to): + if ( + self.utc_time_to_tz(tz, leave.date_from) + <= current_time.strftime("%Y-%m-%d %H:%M:%S") + <= self.utc_time_to_tz(tz, leave.date_to) + ): return True return False @@ -129,7 +187,7 @@ class HrAttendance(models.Model): :param chin: 时间 :return: 转换时间 """ - time_timezone = pytz.timezone('utc').localize(chin, is_dst=False) + time_timezone = pytz.timezone("utc").localize(chin, is_dst=False) time_to_utc = time_timezone.astimezone(pytz.timezone(tz)) utc_time_str = time_to_utc.strftime("%Y-%m-%d %H:%M:%S") return utc_time_str diff --git a/yuthon_hr_attendance/views/hr_attendance_views.xml b/yuthon_hr_attendance/views/hr_attendance_views.xml index 15c970d36..882b90e5b 100644 --- a/yuthon_hr_attendance/views/hr_attendance_views.xml +++ b/yuthon_hr_attendance/views/hr_attendance_views.xml @@ -5,56 +5,71 @@ hr.attendance + edit="false" delete="false" create="false" duplicate="false" + decoration-danger="is_workflow or is_approval" + decoration-muted="is_week" + decoration-success="is_holiday" + editable="bottom" + default_order="current_data desc,current_data_month desc">
- - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -