diff --git a/boolean_group_operator/models/__init__.py b/boolean_group_operator/models/__init__.py index 07bf836d5..2d9e99835 100644 --- a/boolean_group_operator/models/__init__.py +++ b/boolean_group_operator/models/__init__.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- -# import odoo -# -# from odoo.tools import SQL -# -# odoo.models.READ_GROUP_AGGREGATE.update({ -# 'count_true': lambda table, expr: SQL('COUNT(*) FILTER (WHERE %s = true)', expr), -# 'count_false': lambda table, expr: SQL('COUNT(*) FILTER (WHERE %s = false)', expr), -# }) +import odoo + +from odoo.tools import SQL + +odoo.models.READ_GROUP_AGGREGATE.update({ + 'count_true': lambda table, expr: SQL('COUNT(*) FILTER (WHERE %s = true)', expr), + 'count_false': lambda table, expr: SQL('COUNT(*) FILTER (WHERE %s = false)', expr), +}) # 哪个模型需要就移植到哪个模型下 # @api.model diff --git a/soong_workflow/models/soong_workflow_mixin.py b/soong_workflow/models/soong_workflow_mixin.py index 842205cb0..8f103a35a 100644 --- a/soong_workflow/models/soong_workflow_mixin.py +++ b/soong_workflow/models/soong_workflow_mixin.py @@ -277,7 +277,6 @@ class SoongWorkflowMixin(models.AbstractModel): ('department_id', '=', self.department_id.id), ('department_ids', 'in', self.department_id.id), ('yuthon_company', '=', self.create_uid.employee_id.yuthon_company)]) - employee_ids = employee_user_role_ids.ids if not next_state.is_automatic else employee_user_role_id.ids if not employee_ids: state = btn_rec.workflow_id.node_ids[self_state + 1] diff --git a/soong_workflow/models/soong_workflow_node.py b/soong_workflow/models/soong_workflow_node.py index 947ae1f9c..b29dada21 100644 --- a/soong_workflow/models/soong_workflow_node.py +++ b/soong_workflow/models/soong_workflow_node.py @@ -131,23 +131,6 @@ class SoongWorkflowNode(models.Model): "action_type": "code", "code": "obj.action_withdraw()", },), - # (0, 0, { - # "name": _("加签"), - # "workflow_id": val['workflow_id'], - # "sequence": 3, - # "action_type": "code", - # "has_comment": True, - # },), - # (0, 0, { - # "name": _("转交"), - # "workflow_id": val['workflow_id'], - # "sequence": 3, - # "action_type": "code", - # "btn_hide": True, - # "review_type": 'expression', - # # "reviewer_expression": "obj.action_withdraw()", # todo domain - # "has_comment": True, - # },), (0, 0, { "name": _("退回"), "workflow_id": val['workflow_id'], diff --git a/yuthon_hr_attendance/models/hr_attendance.py b/yuthon_hr_attendance/models/hr_attendance.py index 72e8a73bb..008ab5198 100644 --- a/yuthon_hr_attendance/models/hr_attendance.py +++ b/yuthon_hr_attendance/models/hr_attendance.py @@ -15,10 +15,10 @@ class HrAttendance(models.Model): _rec_name = 'current_data' is_clock_card = fields.Boolean(string="外勤") - is_no_card = fields.Boolean(string="缺卡", compute='_compute_attendance_flags', groups_operator='count_false') - is_early_card = fields.Boolean(string="早退", compute='_compute_attendance_flags', groups_operator='count_false') - is_late_card = fields.Boolean(string="迟到", compute='_compute_attendance_flags', groups_operator='count_false') - is_abnormal = fields.Boolean(string="异常", compute='_compute_is_abnormal', groups_operator='count_false') + is_no_card = fields.Boolean(string="缺卡", groups_operator='count_false') + is_early_card = fields.Boolean(string="早退", groups_operator='count_false') + is_late_card = fields.Boolean(string="迟到", groups_operator='count_false') + is_abnormal = fields.Boolean(string="异常", groups_operator='count_false') work_time_type = fields.Selection([('close_day', '休息日'), ('work_day', '工作日')], string="工作时间类型") company_id = fields.Many2one('res.company', string='公司', index=True, default=lambda self: self.env.company) on_card_location = fields.Char(string="上班打卡地点") @@ -37,15 +37,15 @@ class HrAttendance(models.Model): night_duty = fields.Datetime(string="晚值") is_approval = fields.Boolean(string="是否审批修正", default=False) - @api.model - def web_read_group(self, domain, fields, groupby, limit=None, offset=0, orderby=False, lazy=True): - result = super().web_read_group(domain, fields, groupby, limit, offset, orderby, lazy) - fields_dict = self.fields_get(fields) - for group in result.get('groups'): - for field in fields: - if fields_dict[field].get('type') == 'boolean': - group[field] = len([r for r in self.search_read(group['__domain'], fields=[field]) if r.get(field)]) - return result + # @api.model + # def web_read_group(self, domain, fields, groupby, limit=None, offset=0, orderby=False, lazy=True): + # result = super().web_read_group(domain, fields, groupby, limit, offset, orderby, lazy) + # fields_dict = self.fields_get(fields) + # for group in result.get('groups'): + # for field in fields: + # if fields_dict[field].get('type') == 'boolean': + # group[field] = len([r for r in self.search_read(group['__domain'], fields=[field]) if r.get(field)]) + # return result @api.depends('employee_id', 'check_in', 'check_out') def _compute_display_name(self): @@ -69,60 +69,60 @@ class HrAttendance(models.Model): format_datetime(self.env, attendance.check_out, dt_format="HH:mm"), ) - @api.depends('check_in', 'check_out') - def _compute_attendance_flags(self): - for record in self: - record.is_no_card = False - record.is_late_card = False - record.is_early_card = False - if not record.employee_id.resource_id.calendar_id.attendance_ids: - department_names = ['保安部', '班组A', '班组B', '班组C', '工程部', '运行班', '高压班', '综合班'] - department_ids = self.env['hr.department'].search([('name', 'in', department_names)]).ids - employee_ids = self.env['hr.employee'].search([('department_id', 'in', department_ids)]) - for employee_id in employee_ids: - planning_ids = self.env['planning.slot'].search([('resource_id', '=', employee_id.resource_id.id)]) - for planning_id in planning_ids: - start_date = planning_id.start_datetime.date() - attendance_id = self.env['hr.attendance'].search( - [('employee_id', '=', employee_id.id), ('current_data', '=', start_date)]) - if attendance_id: - if attendance_id.check_in: - check_in = attendance_id.check_in + timedelta(hours=8) - attendance_id.is_late_card = check_in > planning_id.start_datetime - else: - attendance_id.is_no_card = True - if attendance_id.check_out: - check_in = attendance_id.check_in + timedelta(hours=8) - attendance_id.is_early_card = planning_id.end_datetime > check_in - else: - attendance_id.is_no_card = True - else: - min_hour_from = record.employee_id.resource_id.calendar_id.attendance_ids[0].hour_from - min_hour = int(min_hour_from) - min_minute = int(min_hour_from * 10 % min_hour_from) - if record.check_in: - check_in = record.check_in + timedelta(hours=8) - will_datetime_start = check_in.replace(hour=min_hour, minute=min_minute) - record.is_late_card = check_in > will_datetime_start - else: - record.is_no_card = True - max_hour_to = record.employee_id.resource_id.calendar_id.attendance_ids[-1].hour_to - max_hour = int(max_hour_to) - max_minute = int(max_hour_to * 10 % max_hour_to) - if record.check_out: - check_out = record.check_out + timedelta(hours=8) - will_datetime_end = check_out.replace(hour=max_hour, minute=max_minute) - record.is_early_card = will_datetime_end > check_out - else: - record.is_no_card = True - if record.employee_id in record.employee_id.resource_id.calendar_id.resource_user_ids: - if record.check_in or record.check_out: - record.write({ - 'is_abnormal': False, - 'is_late_card': False, - 'is_early_card': False, - 'is_no_card': False - }) + # @api.depends('check_in', 'check_out') + # def _compute_attendance_flags(self): + # for record in self: + # record.is_no_card = False + # record.is_late_card = False + # record.is_early_card = False + # if not record.employee_id.resource_id.calendar_id.attendance_ids: + # department_names = ['保安部', '班组A', '班组B', '班组C', '工程部', '运行班', '高压班', '综合班'] + # department_ids = self.env['hr.department'].search([('name', 'in', department_names)]).ids + # employee_ids = self.env['hr.employee'].search([('department_id', 'in', department_ids)]) + # for employee_id in employee_ids: + # planning_ids = self.env['planning.slot'].search([('resource_id', '=', employee_id.resource_id.id)]) + # for planning_id in planning_ids: + # start_date = planning_id.start_datetime.date() + # attendance_id = self.env['hr.attendance'].search( + # [('employee_id', '=', employee_id.id), ('current_data', '=', start_date)]) + # if attendance_id: + # if attendance_id.check_in: + # check_in = attendance_id.check_in + timedelta(hours=8) + # attendance_id.is_late_card = check_in > planning_id.start_datetime + # else: + # attendance_id.is_no_card = True + # if attendance_id.check_out: + # check_in = attendance_id.check_in + timedelta(hours=8) + # attendance_id.is_early_card = planning_id.end_datetime > check_in + # else: + # attendance_id.is_no_card = True + # else: + # min_hour_from = record.employee_id.resource_id.calendar_id.attendance_ids[0].hour_from + # min_hour = int(min_hour_from) + # min_minute = int(min_hour_from * 10 % min_hour_from) + # if record.check_in: + # check_in = record.check_in + timedelta(hours=8) + # will_datetime_start = check_in.replace(hour=min_hour, minute=min_minute) + # record.is_late_card = check_in > will_datetime_start + # else: + # record.is_no_card = True + # max_hour_to = record.employee_id.resource_id.calendar_id.attendance_ids[-1].hour_to + # max_hour = int(max_hour_to) + # max_minute = int(max_hour_to * 10 % max_hour_to) + # if record.check_out: + # check_out = record.check_out + timedelta(hours=8) + # will_datetime_end = check_out.replace(hour=max_hour, minute=max_minute) + # record.is_early_card = will_datetime_end > check_out + # else: + # record.is_no_card = True + # if record.employee_id in record.employee_id.resource_id.calendar_id.resource_user_ids: + # if record.check_in or record.check_out: + # record.write({ + # 'is_abnormal': False, + # 'is_late_card': False, + # 'is_early_card': False, + # 'is_no_card': False + # }) def add_comment(self): self.ensure_one() @@ -153,13 +153,13 @@ class HrAttendance(models.Model): title="打卡异常提醒", description="本月迟到: {}\n本月缺卡: {}\n本月早退: {}\n".format(is_late_card, is_no_card, is_early_card), url=str, btntxt="详细信息") - @api.depends('is_no_card', 'is_early_card', 'is_late_card') - def _compute_is_abnormal(self): - for record in self: - record.is_abnormal = False - if record.week not in ["six", "seven"]: - record.is_abnormal = record.is_no_card or record.is_early_card or record.is_late_card - record.abnormal = int(record.is_no_card or record.is_early_card or record.is_late_card) + # @api.depends('is_no_card', 'is_early_card', 'is_late_card') + # def _compute_is_abnormal(self): + # for record in self: + # record.is_abnormal = False + # if record.week not in ["six", "seven"]: + # record.is_abnormal = record.is_no_card or record.is_early_card or record.is_late_card + # record.abnormal = int(record.is_no_card or record.is_early_card or record.is_late_card) def button_leave(self): form_id = self.env.ref('yuthon_holiday.view_hr_leave_batch_form').id diff --git a/yuthon_hr_attendance/views/hr_attendance_views.xml b/yuthon_hr_attendance/views/hr_attendance_views.xml index 49f8c7563..5b85c5d02 100644 --- a/yuthon_hr_attendance/views/hr_attendance_views.xml +++ b/yuthon_hr_attendance/views/hr_attendance_views.xml @@ -160,21 +160,21 @@ hr.attendance tree,form {"search_default_employee": 1} - [('employee_id.yuthon_company','=','thtz')] + [('employee_id.yuthon_company','=','thtz'), ('week', 'not in', ['seven', 'six'])]] 天河粮储 hr.attendance tree,form {"search_default_employee": 1} - [('employee_id.yuthon_company', '=', 'thlc')] + [('employee_id.yuthon_company', '=', 'thlc'), ('week', 'not in', ['seven', 'six'])]] 天河物管 hr.attendance tree,form {"search_default_employee": 1} - [('employee_id.yuthon_company', '=', 'thwg')] + [('employee_id.yuthon_company', '=', 'thwg'), ('week', 'not in', ['seven', 'six'])]] 考勤记录 diff --git a/yuthon_wechat/models/hr_attendance_detail.py b/yuthon_wechat/models/hr_attendance_detail.py index b686abddf..bf7b06ad2 100644 --- a/yuthon_wechat/models/hr_attendance_detail.py +++ b/yuthon_wechat/models/hr_attendance_detail.py @@ -244,152 +244,69 @@ class HrAttendanceDetail(models.Model): if not attendance_obj: res_user_obj = self.env['res.users'].search([("oauth_uid", "=", userid)], limit=1) hr_employee_obj = self.env['hr.employee'].sudo().search([("user_id", "=", res_user_obj.id)], limit=1) - if hr_employee_obj.resource_id.calendar_id.attendance_ids: - attendance_obj = self.env['hr.attendance'].sudo().create({ - 'employee_id': hr_employee_obj.id, - "userid": userid, - "current_data": current_data, - "attendance_type": "wx_work" + attendance_obj = self.env['hr.attendance'].sudo().create({ + 'employee_id': hr_employee_obj.id, + "userid": userid, + "current_data": current_data, + "attendance_type": "wx_work" + }) + # 获取考勤日历的上班下班时间 + min_hour_from = self.env['resource.calendar'].search([])[0].attendance_ids[0].hour_from + min_hour = int(min_hour_from) + min_minute = int(min_hour_from * 10 % min_hour_from) + max_hour_to = self.env['resource.calendar'].search([])[-1].attendance_ids[0].hour_to + max_hour = int(max_hour_to) + max_minute = int(max_hour_to * 10 % max_hour_to) + if attendance_obj.is_approval: + # 已经审批修复无需再次进行更新数据 + return True + # 赋值企业微信打卡数据 + attendance_obj.attendance_type = "wx_work" + checkin_type = data.get("checkin_type", "") + exception_type = data.get("exception_type", "") + will_datetime_start = checkin_time.replace(hour=min_hour, minute=min_minute) + will_datetime_end = checkin_time.replace(hour=max_hour, minute=max_minute) + if exception_type != "未打卡": + if checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and not attendance_obj.check_in: + attendance_obj.sudo().write({ + "sch_check_in_time": sch_checkin_time, + "check_in": checkin_time, + "is_late_card": checkin_time > will_datetime_start, }) - min_hour_from = attendance_obj.employee_id.resource_id.calendar_id.attendance_ids[0].hour_from - min_hour = int(min_hour_from) - min_minute = int(min_hour_from * 10 % min_hour_from) - max_hour_to = attendance_obj.employee_id.resource_id.calendar_id.attendance_ids[-1].hour_to - max_hour = int(max_hour_to) - max_minute = int(max_hour_to * 10 % max_hour_to) - if attendance_obj.is_approval: - # 已经审批修复无需再次进行更新数据 - return True - # 赋值企业微信打卡数据 - attendance_obj.attendance_type = "wx_work" - - checkin_type = data.get("checkin_type", "") - exception_type = data.get("exception_type", "") - if exception_type != "未打卡": - will_datetime_start = checkin_time.replace(hour=min_hour, minute=min_minute) - will_datetime_end = checkin_time.replace(hour=max_hour, minute=max_minute) - if checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and not attendance_obj.check_in: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > will_datetime_start - }) - elif checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": will_datetime_end > checkin_time - }) - - elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and checkin_time < attendance_obj.check_in: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > will_datetime_start - }) - elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and checkin_time > attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": will_datetime_end > checkin_time - }) - - elif checkin_time and exception_type != "未打卡" and not attendance_obj.check_in and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > will_datetime_start - }) - elif checkin_time and exception_type != "未打卡" and attendance_obj.check_in and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": will_datetime_end > checkin_time - }) - else: - attendance_obj.sudo().write({ - "is_no_card": True}) - if not hr_employee_obj.resource_id.calendar_id.attendance_ids: - current_datetime_start = datetime.datetime.combine(current_data, datetime.time.min) - current_datetime_end = datetime.datetime.combine(current_data, datetime.time.max) - planning_slot_id = self.env['planning.slot'].search([('resource_id', '=', hr_employee_obj.resource_id.id), - ('start_datetime', '>=', current_datetime_start), # 大于等于起始日期 - ('start_datetime', '<=', current_datetime_end)]) - attendance_obj = self.env['hr.attendance'].sudo().create({ - 'employee_id': hr_employee_obj.id, - "userid": userid, - "current_data": current_data, - "shift_id": planning_slot_id.id, - "attendance_type": "wx_work" + elif checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and not attendance_obj.check_out: + attendance_obj.sudo().write({ + "sch_check_out_time": sch_checkin_time, + "check_out": checkin_time, + "is_early_card": will_datetime_end > checkin_time, }) - if attendance_obj.is_approval: - # 已经审批修复无需再次进行更新数据 - return True - # 赋值企业微信打卡数据 - attendance_obj.attendance_type = "wx_work" - checkin_type = data.get("checkin_type", "") - exception_type = data.get("exception_type", "") - if exception_type != "未打卡": - if checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and not attendance_obj.check_in: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime - }) - elif checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": planning_slot_id.end_datetime > checkin_time - }) - elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and checkin_time < attendance_obj.check_in: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime - }) - elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and checkin_time > attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card":planning_slot_id.end_datetime > checkin_time - }) - elif checkin_time and exception_type != "未打卡" and not attendance_obj.check_in and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_in_time": sch_checkin_time, - "check_in": checkin_time, - "is_late_card": checkin_time > planning_slot_id.start_datetime - }) - elif checkin_time and exception_type != "未打卡" and attendance_obj.check_in and not attendance_obj.check_out: - attendance_obj.sudo().write({ - "sch_check_out_time": sch_checkin_time, - "check_out": checkin_time, - "is_early_card": planning_slot_id.end_datetime > checkin_time - }) - else: - attendance_obj.sudo().write({ - "is_no_card": True}) - - # if sch_checkin_time_now and str(sch_checkin_time_now.strftime("%H")) == "13" and checkin_type == "上班打卡" and exception_type != "未打卡": - # attendance_obj.sudo().write({ - # "sch_check_noon_time": sch_checkin_time, - # "check_noon": checkin_time - # }) - - # elif checkin_type == "上班打卡" and exception_type != "未打卡": - # attendance_obj.sudo().write({ - # "sch_check_in_time": sch_checkin_time, - # "check_in": checkin_time - # }) - # elif checkin_type == "下班打卡" and exception_type != "未打卡": - # attendance_obj.sudo().write({ - # "sch_check_out_time": sch_checkin_time, - # "check_out": checkin_time - # }) - # elif checkin_type == "外出打卡": - # attendance_obj.sudo().write({ - # "field_work_check": checkin_time, - # }) + elif attendance_obj.check_in and checkin_time and checkin_type == "上班打卡" and exception_type != "未打卡" and checkin_time < attendance_obj.check_in: + attendance_obj.sudo().write({ + "sch_check_in_time": sch_checkin_time, + "check_in": checkin_time, + "is_late_card": checkin_time > will_datetime_start, + }) + elif attendance_obj.check_out and checkin_time and checkin_type == "下班打卡" and exception_type != "未打卡" and checkin_time > attendance_obj.check_out: + attendance_obj.sudo().write({ + "sch_check_out_time": sch_checkin_time, + "check_out": checkin_time, + "is_early_card": will_datetime_end > checkin_time, + }) + elif checkin_time and exception_type != "未打卡" and not attendance_obj.check_in and not attendance_obj.check_out: + attendance_obj.sudo().write({ + "sch_check_in_time": sch_checkin_time, + "check_in": checkin_time, + "is_late_card": checkin_time > will_datetime_start, + }) + elif checkin_time and exception_type != "未打卡" and attendance_obj.check_in and not attendance_obj.check_out: + attendance_obj.sudo().write({ + "sch_check_out_time": sch_checkin_time, + "check_out": checkin_time, + "is_early_card": will_datetime_end > checkin_time, + }) + elif attendance_obj.is_early_card or attendance_obj.is_late_card: + attendance_obj.sudo().write({"is_abnormal": True}) + else: + attendance_obj.sudo().write({"is_no_card": True, "is_abnormal": True}) # 进行关联 attendance_detail_obj.hr_attendance_id = attendance_obj.id return True diff --git a/yuthon_wechat/views/hr_attendance_detail_views.xml b/yuthon_wechat/views/hr_attendance_detail_views.xml index f1c3b70f6..b2f1e798b 100644 --- a/yuthon_wechat/views/hr_attendance_detail_views.xml +++ b/yuthon_wechat/views/hr_attendance_detail_views.xml @@ -37,11 +37,11 @@ - - - - -