Merge pull request !633 from 李鹏宇/dev
This commit is contained in:
李鹏宇
2024-12-02 01:28:24 +00:00
committed by Gitee
9 changed files with 55 additions and 24 deletions
@@ -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
+15 -3
View File
@@ -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
@@ -46,6 +46,7 @@ class DutyApprovals(models.Model):
elif self.related_issues_id:
raise UserError("已经创建了相关的上会记录,不能取消勾选")
class DutyApprovalsLine(models.Model):
_name = 'duty.approval.line'
_description = "值班人明细行"
+2 -1
View File
@@ -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("开始时间必须小于结束时间!")
raise UserError("开始时间必须小于结束时间!")
+24 -11
View File
@@ -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
record.week = False
@@ -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
@@ -17,6 +17,9 @@
<field name="model">card.approval</field>
<field name="arch" type="xml">
<form>
<header>
<button name="card_approval" type="object" string="Approve" class="oe_highlight"/>
</header>
<sheet>
<div class="col-12 text-center">
<h1>
@@ -15,7 +15,7 @@
<field name="is_early_card" optional="show" class="list_width"/>
<field name="is_late_card" optional="show" class="list_width"/>
<field name="is_abnormal" optional="show" class="list_width"/>
<field name="weed" optional="show"/>
<field name="week" optional="show"/>
<field name="work_time_type" optional="hidden"/>
<field name="check_in" optional="show" widget="time"/>
<!-- <field name="on_card_location" optional="show"/>-->
@@ -42,7 +42,7 @@
<field name="is_early_card" optional="show" class="list_width"/>
<field name="is_late_card" optional="show" class="list_width"/>
<field name="is_abnormal" optional="show" class="list_width"/>
<field name="weed" optional="show"/>
<field name="week" optional="show"/>
<field name="abnormal" optional="show" column_invisible="1"/>
<field name="work_time_type" optional="hidden"/>
<field name="check_in" optional="show" widget="time"/>
@@ -110,7 +110,7 @@
<field name="name">我的考勤</field>
<field name="res_model">hr.attendance</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('employee_id.user_id', '=', uid), ('weed', 'not in', ['星期日', '星期六'])]</field>
<field name="domain">[('employee_id.user_id', '=', uid), ('week', 'not in', ['seven', 'six'])]</field>
<field name="context">
{ "search_default_current_data": 1 }
</field>
@@ -122,7 +122,7 @@
<field name="name">我的异常</field>
<field name="res_model">hr.attendance</field>
<field name="view_mode">tree,form</field>
<field name="domain">[('employee_id.user_id', '=', uid), ('abnormal', '=', 1), ('weed', 'not in', ['星期日', '星期六'])]</field>
<field name="domain">[('employee_id.user_id', '=', uid), ('abnormal', '=', 1), ('week', 'not in', ['seven', 'six'])]</field>
<field name="context">{ "search_default_current_data": 1 }</field>
<field name="search_view_id" ref="hr_attendance_search_my"/>
<field name="view_ids" eval="[(5, 0, 0),
@@ -9,7 +9,7 @@
<field name="employee_id"/>
<field name="start_time"/>
<field name="end_time"/>
<field name="weed"/>
<field name="week"/>
<field name="is_photo"/>
<field name="is_photo_two"/>
<field name="is_photo_three"/>