pengyuthon wechat

This commit is contained in:
李鹏宇
2024-12-17 19:40:33 +08:00
parent c2ae1d1827
commit 302893f624
7 changed files with 151 additions and 252 deletions
+8 -8
View File
@@ -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
@@ -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]
@@ -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'],
+74 -74
View File
@@ -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
@@ -160,21 +160,21 @@
<field name="res_model">hr.attendance</field>
<field name="view_mode">tree,form</field>
<field name="context">{"search_default_employee": 1}</field>
<field name="domain">[('employee_id.yuthon_company','=','thtz')]</field>
<field name="domain">[('employee_id.yuthon_company','=','thtz'), ('week', 'not in', ['seven', 'six'])]]</field>
</record>
<record id="action_attendance_yuthon_company_form2" model="ir.actions.act_window">
<field name="name">天河粮储</field>
<field name="res_model">hr.attendance</field>
<field name="view_mode">tree,form</field>
<field name="context">{"search_default_employee": 1}</field>
<field name="domain">[('employee_id.yuthon_company', '=', 'thlc')]</field>
<field name="domain">[('employee_id.yuthon_company', '=', 'thlc'), ('week', 'not in', ['seven', 'six'])]]</field>
</record>
<record id="action_attendance_yuthon_company_form3" model="ir.actions.act_window">
<field name="name">天河物管</field>
<field name="res_model">hr.attendance</field>
<field name="view_mode">tree,form</field>
<field name="context">{"search_default_employee": 1}</field>
<field name="domain">[('employee_id.yuthon_company', '=', 'thwg')]</field>
<field name="domain">[('employee_id.yuthon_company', '=', 'thwg'), ('week', 'not in', ['seven', 'six'])]]</field>
</record>
<record id="hr_attendance_action2" model="ir.actions.act_window">
<field name="name">考勤记录</field>
+61 -144
View File
@@ -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
@@ -37,11 +37,11 @@
<field name="checkin_type"/>
<field name="checkin_time"/>
<field name="sch_checkin_time"/>
<field name="exception_type" />
<field name="location_title"/>
<field name="notes"/>
<field name="attendance_detail_image_ids" />
<button name="action_show_details" string="打卡图片" type="object" title="Show Details" icon="fa-list"/>
<!-- <field name="exception_type" />-->
<!-- <field name="location_title"/>-->
<!-- <field name="notes"/>-->
<!-- <field name="attendance_detail_image_ids" />-->
<!-- <button name="action_show_details" string="打卡图片" type="object" title="Show Details" icon="fa-list"/>-->
</tree>
</field>
</record>