diff --git a/yuthon_hr_attendance/controllers/attendance_banner_route.py b/yuthon_hr_attendance/controllers/attendance_banner_route.py index 69f112083..61a8e6a89 100644 --- a/yuthon_hr_attendance/controllers/attendance_banner_route.py +++ b/yuthon_hr_attendance/controllers/attendance_banner_route.py @@ -17,7 +17,7 @@ class AttendanceBannerRoute(Controller): ('employee_id.user_id', '=', request.env.user.id), ('check_in', '>=', month_start), ('check_in', '<=', month_end), - ('weed', 'not in', ['星期日', '星期六']) + ('week', 'not in', ['seven', 'six']) ] attendance = request.env['hr.attendance'].sudo().search(domain) is_no_card = 0 diff --git a/yuthon_hr_attendance/models/card_approval.py b/yuthon_hr_attendance/models/card_approval.py index a80a95f75..b4808db7e 100644 --- a/yuthon_hr_attendance/models/card_approval.py +++ b/yuthon_hr_attendance/models/card_approval.py @@ -11,7 +11,7 @@ class CardApprovals(models.Model): _rec_name = 'name' yuthon_company = fields.Selection(related='users_id.employee_id.yuthon_company', string="公司") - name = fields.Char(string="标题") + name = fields.Char(string="标题", compute='_compute_name') 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) department_id = fields.Many2one(related='users_id.employee_id.department_id', string="部门") @@ -19,7 +19,7 @@ class CardApprovals(models.Model): related_issues_id = fields.Many2one('issue.library', string="关联议题") reason_application = fields.Html(string="申请事由") replacement_time = fields.Selection([('work', '上班卡'), ('quitting', '下班卡'), ('all', '全天卡')], string="补卡") - actual_punch = fields.Datetime(string="实际打卡") + actual_punch = fields.Date(string="实际打卡日期") documents_ids = fields.Many2many('ir.attachment', string="附件") @api.onchange('is_issues') @@ -40,6 +40,18 @@ class CardApprovals(models.Model): raise UserError("已经创建了相关的上会记录,不能取消勾选") def card_approval(self): - pass + for record in self: + hr_attendance_id = self.env['hr.attendance'].search([('employee_id', '=', record.users_id.employee_id.id), ('current_data', '=', record.actual_punch)]) + hr_attendance_id.write({'is_no_card': False}) + + @api.depends('users_id', 'replacement_time', 'actual_punch') + def _compute_name(self): + for record in self: + if record.users_id and record.actual_punch: + record.name = f"{record.users_id.name}补卡{record.actual_punch.strftime('%Y-%m-%d')}" + else: + record.name = False + + diff --git a/yuthon_hr_attendance/models/duty_approval.py b/yuthon_hr_attendance/models/duty_approval.py index 6461bc836..1cb801170 100644 --- a/yuthon_hr_attendance/models/duty_approval.py +++ b/yuthon_hr_attendance/models/duty_approval.py @@ -46,6 +46,7 @@ class DutyApprovals(models.Model): elif self.related_issues_id: raise UserError("已经创建了相关的上会记录,不能取消勾选") + class DutyApprovalsLine(models.Model): _name = 'duty.approval.line' _description = "值班人明细行" diff --git a/yuthon_hr_attendance/models/go_approval.py b/yuthon_hr_attendance/models/go_approval.py index ea956851e..fa825d219 100644 --- a/yuthon_hr_attendance/models/go_approval.py +++ b/yuthon_hr_attendance/models/go_approval.py @@ -70,4 +70,5 @@ class GoApprovalsLine(models.Model): for record in self: if record.date_start and record.date_end: if record.date_start >= record.date_end: - raise UserError("开始时间必须小于结束时间!") \ No newline at end of file + raise UserError("开始时间必须小于结束时间!") + diff --git a/yuthon_hr_attendance/models/hr_attendance.py b/yuthon_hr_attendance/models/hr_attendance.py index 5a0912ee1..2f6991b3c 100644 --- a/yuthon_hr_attendance/models/hr_attendance.py +++ b/yuthon_hr_attendance/models/hr_attendance.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- from datetime import datetime, time - from odoo import models, fields, api, exceptions, _ from datetime import timedelta from dateutil.relativedelta import relativedelta @@ -24,7 +23,9 @@ class HrAttendance(models.Model): out_card_location = fields.Char(string="外出打卡地点") work_hours = fields.Float(string="工作时长") current_data = fields.Date(string='打卡日期', tracking=True) - weed = fields.Char(string='星期', compute='_compute_weed') + week = fields.Selection([('one', '星期一'), ('two', '星期二'), ('three', '星期三'), + ('four', '星期四'), ('five', '星期五'), ('six', '星期六'), + ('seven', '星期日')], string='星期', compute='_compute_week', store=True) abnormal = fields.Integer(string="异常计算") @api.depends('check_in', 'check_out') @@ -67,7 +68,7 @@ class HrAttendance(models.Model): ('employee_id.user_id', '=', rec.employee_id.user_id.id), ('check_in', '>=', month_start), ('check_in', '<=', month_end), - ('weed', 'not in', ['星期日', '星期六']) + ('week', 'not in', ['seven', 'six']) ] is_no_card = 0 is_early_card = 0 @@ -88,7 +89,7 @@ class HrAttendance(models.Model): def _compute_is_abnormal(self): for record in self: record.is_abnormal = False - if record.weed not in ["星期六", "星期日"]: + 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) @@ -121,22 +122,34 @@ class HrAttendance(models.Model): def button_card_approval(self): form_id = self.env.ref('yuthon_hr_attendance.card_approval_form').id + replacement_time = '' + for record in self: + if not record.check_in: + replacement_time = 'work' + elif not record.check_out: + replacement_time = 'quitting' + elif not record.check_in and not record.check_out: + replacement_time = 'all' return { "type": "ir.actions.act_window", "name": "补卡申请", "res_model": "card.approval", "views": [[form_id, "form"]], "context": { + 'default_actual_punch': self.current_data, + 'default_replacement_time': replacement_time, 'default_users_id': self.employee_id.user_id.id, } } - @api.depends('check_in') - def _compute_weed(self): + @api.depends('current_data') + def _compute_week(self): for record in self: - if record.check_in: - weekday = record.check_in.weekday() - weekdays_cn = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"] - record.weed = weekdays_cn[weekday] + if record.current_data: + weekday = record.current_data + timedelta(hours=8).weekday() + weekdays_cn = {0: 'one', 1: 'two', 2: 'three', + 3: 'four', 4: 'five', 5: 'six', + 6: 'seven'} + record.week = weekdays_cn[weekday] else: - record.weed = False \ No newline at end of file + record.week = False \ No newline at end of file diff --git a/yuthon_hr_attendance/models/yuthon_duty_arrangement.py b/yuthon_hr_attendance/models/yuthon_duty_arrangement.py index 71c936465..99c2ff704 100644 --- a/yuthon_hr_attendance/models/yuthon_duty_arrangement.py +++ b/yuthon_hr_attendance/models/yuthon_duty_arrangement.py @@ -2,6 +2,7 @@ from odoo import api, fields, models, tools, _ from datetime import datetime, time, timedelta,date from odoo.exceptions import UserError + class YuthonDutyArrangement(models.Model): _name = 'yuthon.duty.arrangement' _description = '值班安排' @@ -24,7 +25,7 @@ class YuthonDutyArrangement(models.Model): duration_three = fields.Datetime(string='时长3') is_abnormal = fields.Boolean(string='异常', compute='_compute_is_abnormal') weekday_count = fields.Float(string='值班次数') - weed = fields.Char(string='星期', compute='_compute_weed') + week = fields.Char(string='星期', compute='_compute_week') is_weekend = fields.Boolean(string='是否周末', compute='_compute_is_weekend') @api.depends('duration', 'duration_two', 'duration_three') @@ -83,12 +84,12 @@ class YuthonDutyArrangement(models.Model): raise UserError('当前日期无异常') @api.depends('start_time') - def _compute_weed(self): + def _compute_week(self): for record in self: if record.start_time: weekday = record.start_time.weekday() weekdays_cn = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"] - record.weed = weekdays_cn[weekday] + record.week = weekdays_cn[weekday] else: record.weed = False diff --git a/yuthon_hr_attendance/views/card_approval.xml b/yuthon_hr_attendance/views/card_approval.xml index bbf0eb827..9f14406cb 100644 --- a/yuthon_hr_attendance/views/card_approval.xml +++ b/yuthon_hr_attendance/views/card_approval.xml @@ -17,6 +17,9 @@ card.approval
+
+

diff --git a/yuthon_hr_attendance/views/hr_attendance_views.xml b/yuthon_hr_attendance/views/hr_attendance_views.xml index da33b9578..b1c253b96 100644 --- a/yuthon_hr_attendance/views/hr_attendance_views.xml +++ b/yuthon_hr_attendance/views/hr_attendance_views.xml @@ -15,7 +15,7 @@ - + @@ -42,7 +42,7 @@ - + @@ -110,7 +110,7 @@ 我的考勤 hr.attendance tree,form - [('employee_id.user_id', '=', uid), ('weed', 'not in', ['星期日', '星期六'])] + [('employee_id.user_id', '=', uid), ('week', 'not in', ['seven', 'six'])] { "search_default_current_data": 1 } @@ -122,7 +122,7 @@ 我的异常 hr.attendance tree,form - [('employee_id.user_id', '=', uid), ('abnormal', '=', 1), ('weed', 'not in', ['星期日', '星期六'])] + [('employee_id.user_id', '=', uid), ('abnormal', '=', 1), ('week', 'not in', ['seven', 'six'])] { "search_default_current_data": 1 } - +