添加功能

This commit is contained in:
李鹏宇
2025-12-04 19:00:14 +08:00
parent cab00444bd
commit 79345afce4
6 changed files with 54 additions and 10 deletions
@@ -63,6 +63,21 @@ class SoongWorkflowRecord(models.Model):
res.append_date2(res)
return res
def restore(self):
workflow_ids = self.env["soong.workflow.record"].browse(
self._context.get('active_ids', self._context.get('active_id', [])))
for workflow in workflow_ids:
record_id = self.env[workflow.res_model].search([('id', '=', workflow.res_id)])
if record_id.log_ids:
record_id.log_ids[-1].approval_state = '0'
if hasattr(record_id, 'work_end'):
record_id.work_end = False
if hasattr(record_id, 'self_users_ids'):
record_id.self_users_ids = [(6, 0, [record_id.log_ids[-1].done_by.id])]
workflow.employee_ids = [(6, 0, [record_id.log_ids[-1].done_by.employee_id.id])]
workflow.soong_state = 'to_do'
workflow.approve_state = 'pending'
def append_date2(self, res):
res.workflow_happen_date = False
if res.approvals_group_id.name == '考勤':
@@ -157,6 +172,8 @@ class SoongWorkflowRecord(models.Model):
})
workflow.approve_state = 'end'
workflow.soong_state = 'done'
workflow.employee_ids = [(6, 0, [])]
def execute_button_code(self, button_id, res_model, res_id):
@@ -255,6 +255,14 @@
<field name="code">action = model.admin_end()</field>
<field name="groups_id" eval="[(4, ref('base.group_system'))]"/>
</record>
<record id="action_admin_restore" model="ir.actions.server">
<field name="name">恢复</field>
<field name="model_id" ref="soong_workflow.model_soong_workflow_record"/>
<field name="binding_model_id" ref="soong_workflow.model_soong_workflow_record"/>
<field name="state">code</field>
<field name="code">action = model.restore()</field>
<field name="groups_id" eval="[(4, ref('base.group_system'))]"/>
</record>
<record id="action_admin_delete_end22" model="ir.actions.server">
<field name="name">发生日期</field>
<field name="model_id" ref="soong_workflow.model_soong_workflow_record"/>
@@ -23,5 +23,6 @@ class SoongBouncedWizard(models.Model):
log_ids[-1].unlink()
log_ids[-2].write({'approval_state': '1'})
record.write({'state': log_ids[-2].name,
'work_end': False
'work_end': False,
'soong_state': 'to_do'
})
@@ -29,8 +29,8 @@ class OvertimeApprovals(models.Model):
related_issues_id = fields.Many2one('issue.library', string="关联议题")
documents_ids = fields.Many2many('ir.attachment', string="附件")
overtime_methods = fields.Selection([('leave', '补休'), ('fee', '加班费结算')], string='加班补偿方式', default='leave')
duration = fields.Float(string="时长", compute='_compute_duration', store=True, help="如果时长大于8则按8小时算")
overtime_hours = fields.Float(string="本月加班时长")
duration = fields.Float(string="结算时长", compute='_compute_duration', store=True)
overtime_hours = fields.Float(string="本月加班时长", compute='_compute_duration')
start_time = fields.Datetime(string="开始时间")
attendance_id = fields.Many2one('hr.attendance', string="当天考勤")
start_week = fields.Char(string="星期", compute='_compute_weekday')
@@ -44,7 +44,8 @@ class OvertimeApprovals(models.Model):
default='normal')
active = fields.Boolean('Active', default=True, tracking=True)
work_end = fields.Boolean(string="结束")
test_field = fields.Char(string="测试字段")
is_over = fields.Boolean(string="超过", compute="_compute_duration")
over_remake = fields.Text(string="备注", compute="_compute_duration")
def _get_default_name_title(self):
return self._description if self._description else self._name
@@ -88,6 +89,7 @@ class OvertimeApprovals(models.Model):
@api.depends('start_time', 'end_time', 'attendance_id', 'rest_start_time', 'rest_end_time')
def _compute_duration(self):
for rec in self:
rec.over_remake = None
rec.duration = 0.0
if not (rec.start_time and rec.end_time):
continue
@@ -111,6 +113,17 @@ class OvertimeApprovals(models.Model):
else:
max_hours = 8.0
rec.duration = min(calculated_hours, max_hours)
rec.is_over = calculated_hours > max_hours
base_note = f"加班时长为{original_hours}小时\n"
if rec.type_overtime == 'work':
if rec.is_over:
rec.over_remake = f"{base_note}工作日加班不得超过3小时"
else:
if rec.is_over:
rec.over_remake = f"{base_note}节假日加班不得超过{max_hours}小时"
if rec.rest_end_time and rec.rest_end_time:
rec.duration -= (rec.rest_end_time - rec.c).total_seconds() / 3600
employee = rec.users_id.employee_id
if not employee:
@@ -127,14 +140,12 @@ class OvertimeApprovals(models.Model):
cop_leave = vacation_report.done_working_overtime * 8 if vacation_report else 0.0
leave_hours = calculated_hours
if cop_leave + leave_hours > 36:
rec.duration = 0.0
rec.overtime_hours = 0.0
message = f'本月已加班时长已超过 36 小时'
raise ValidationError(message)
else:
rec.duration = calculated_hours
rec.overtime_hours = cop_leave
if rec.rest_end_time and rec.rest_end_time:
rec.duration -= (rec.rest_end_time - rec.c).total_seconds()/3600
@api.depends('start_time', 'end_time')
def _compute_weekday(self):
@@ -192,7 +203,6 @@ class OvertimeApprovals(models.Model):
for record in self:
employee_id = self.env['hr.employee'].search([('id', '=', record.users_id.employee_ids.id)])
meal_number = employee_id.meal_number
record.overtime_hours = employee_id.holiday_overtime_hours + employee_id.weekend_overtime_hours + employee_id.normal_overtime_hours
if self.meal == 'yes':
meal_number += 1
employee_id.write({'meal_number': meal_number})
@@ -68,6 +68,7 @@ class YuthonVacationReports(models.Model):
att_mount = fields.Integer(string="出勤天数", compute='compute_attendance_fields', store=True, group_operator=None)
attendance_message_log_ids = fields.One2many('attendance.message.log', 'vacation_id')
admin_confirms = fields.Boolean(string="是否管理员确认")
vacation_state = fields.Selection(
@@ -84,12 +84,19 @@
<field name="rest_start_time"/>
<field name="rest_end_time"/>
<field name="type_overtime"/>
<field name="is_over" invisible="1"/>
</group>
<group/>
</group>
<group>
<label for="duration"/>
<div>
<field name="duration" class="oe_inline" style="max-width: 12rem !important;"/>
<field name="over_remake" class="oe_inline" invisible="not is_over" style="color: red; font-weight: bold;"/>
</div>
</group>
<group col="2">
<group>
<field name="duration"/>
<field name="employee_ids" widget="many2many_tags" options="{'no_create': True}"/>
<field name="department_id" invisible="1"/>
<field name="attendance_id"/>