添加功能
This commit is contained in:
@@ -30,6 +30,15 @@ class OvertimeActiveLine(models.Model):
|
||||
validity = fields.Char(string="有效期")
|
||||
is_void = fields.Boolean(string="作废", default=False)
|
||||
|
||||
|
||||
def all_unlink(self):
|
||||
active_ids = self.env["overtime.active.line"].browse(
|
||||
self._context.get('active_ids', self._context.get('active_id')))
|
||||
for record in active_ids:
|
||||
if not record.is_void:
|
||||
raise UserError("只有作废的加班记录才能删除,请先撤销")
|
||||
record.unlink()
|
||||
|
||||
def action_export_overtime_active_excel(self):
|
||||
"""导出加班归档明细 Excel 报表 - 打开向导选择日期"""
|
||||
# 获取当前选中的记录 ID
|
||||
|
||||
@@ -33,6 +33,11 @@ class RemoveHolidayApprovals(models.Model):
|
||||
name_title = fields.Char(default=_get_default_name_title)
|
||||
self_users_ids = fields.Many2many('res.users', string="当前经办人", default=lambda self: [(6, 0, [self.env.user.id])])
|
||||
|
||||
@api.onchange('workflow_id1', 'users_id')
|
||||
def _onchange_name(self):
|
||||
if self.workflow_id1 and self.users_id:
|
||||
self.name = f"销假单-{self.workflow_id1.name}"
|
||||
|
||||
@api.onchange('is_issues')
|
||||
def _onchange_is_issues(self):
|
||||
if self.is_issues:
|
||||
@@ -49,6 +54,12 @@ class RemoveHolidayApprovals(models.Model):
|
||||
})
|
||||
|
||||
def remove_holiday_approval(self):
|
||||
"""
|
||||
核心方法:
|
||||
1. 标记假期明细行(leave/over/meal等)为作废
|
||||
2. 根据is_day/is_hour修改对应请假批次状态为refuse
|
||||
"""
|
||||
# 步骤1:定义需要作废的明细模型列表
|
||||
detail_models = [
|
||||
'vacation.leave.line',
|
||||
'vacation.over.line',
|
||||
@@ -60,12 +71,39 @@ class RemoveHolidayApprovals(models.Model):
|
||||
for model_name in detail_models:
|
||||
detail_model = self.env[model_name]
|
||||
domain = [
|
||||
('workflow_id', '=', self.workflow_id1),
|
||||
('workflow_record_id', '=', self.workflow_id1.id),
|
||||
('is_void', '=', False)
|
||||
]
|
||||
matching_detail_lines = detail_model.search(domain)
|
||||
if matching_detail_lines:
|
||||
matching_detail_lines.write({'is_void': True})
|
||||
matching_detail_lines.vacation_id.update_line()
|
||||
|
||||
record = self.env[self.workflow_id1.res_model].search([('id', '=', self.workflow_id1.res_id)])
|
||||
if record:
|
||||
leave_records = self.env['hr.leave']
|
||||
if record.is_day and record.leave_ids:
|
||||
leave_records += record.leave_ids
|
||||
if record.is_hour and record.hour_leave_ids:
|
||||
leave_records += record.hour_leave_ids
|
||||
|
||||
if leave_records:
|
||||
leave_records.sudo().write({'state': 'refuse'})
|
||||
for leave in leave_records:
|
||||
if not leave.date_from or not leave.date_to or not leave.employee_id:
|
||||
continue
|
||||
start_date = leave.date_from.date()
|
||||
end_date = leave.date_to.date()
|
||||
employee = leave.employee_id
|
||||
attend_records = self.env['hr.attendance'].sudo().search([
|
||||
('employee_id', '=', employee.id),
|
||||
('current_data', '>=', start_date),
|
||||
('current_data', '<=', end_date)
|
||||
])
|
||||
if attend_records:
|
||||
attend_records.compute_attend()
|
||||
attend_records.workflow_id = False
|
||||
attend_records.is_workflow = False
|
||||
|
||||
@api.depends('date_start', 'date_end')
|
||||
def _compute_duration(self):
|
||||
|
||||
@@ -30,6 +30,14 @@ class VacationMealActive(models.Model):
|
||||
default='pending',
|
||||
)
|
||||
|
||||
def all_unlink(self):
|
||||
active_ids = self.env["vacation.meal.active"].browse(
|
||||
self._context.get('active_ids', self._context.get('active_id')))
|
||||
for record in active_ids:
|
||||
if not record.select_revoke == 'done':
|
||||
raise UserError("只有撤销的误餐记录才能删除,请先撤销")
|
||||
record.unlink()
|
||||
|
||||
def revoke(self):
|
||||
self.ensure_one()
|
||||
self.select_revoke = 'done'
|
||||
|
||||
@@ -31,6 +31,14 @@ class VacationOvertimeActive(models.Model):
|
||||
remaining_quantity = fields.Float(string="剩余数")
|
||||
select_revoke = fields.Selection([('to_do', '待撤销'), ('done', '已撤销')], string='状态')
|
||||
|
||||
def all_unlink(self):
|
||||
active_ids = self.env["vacation.overtime.active"].browse(
|
||||
self._context.get('active_ids', self._context.get('active_id')))
|
||||
for record in active_ids:
|
||||
if not record.select_revoke == 'done':
|
||||
raise UserError("只有撤销的加班记录才能删除,请先撤销")
|
||||
record.unlink()
|
||||
|
||||
def revoke(self):
|
||||
self.ensure_one()
|
||||
self.select_revoke = 'done'
|
||||
|
||||
@@ -190,7 +190,7 @@ class YuthonVacationReports(models.Model):
|
||||
# ========== 第一步:处理年假逻辑 ==========
|
||||
for rec in self:
|
||||
valid_leave_lines = rec.leave_ids.filtered(
|
||||
lambda l: l.workflow_record_id and l.update_type == 'reduce'
|
||||
lambda l: l.workflow_record_id and l.update_type == 'reduce' and l.is_void != True
|
||||
)
|
||||
total_leave_deduct = sum(line.update_lines for line in valid_leave_lines if line.update_lines > 0)/8
|
||||
|
||||
@@ -212,7 +212,7 @@ class YuthonVacationReports(models.Model):
|
||||
# ========== 第二步:处理补休逻辑 ==========
|
||||
for rec in self:
|
||||
reduce_overtime_lines = rec.overtime_ids.filtered(
|
||||
lambda o: o.update_type == 'reduce' and (o.workflow_record_id or o.overtime_methods == 'fee')
|
||||
lambda o: o.update_type == 'reduce' and (o.workflow_record_id or o.overtime_methods == 'fee') and o.is_void != True
|
||||
)
|
||||
# 计算补休扣减总天数
|
||||
total_overtime_deduct = sum(
|
||||
@@ -237,7 +237,7 @@ class YuthonVacationReports(models.Model):
|
||||
rec.used_this_year1 += deduct_from_current1 # 累加到本年已休
|
||||
remaining_overtime_deduct -= deduct_from_current1
|
||||
|
||||
add_overtime_lines = rec.overtime_ids.filtered(lambda o: o.workflow_record_id and o.update_type == 'add')
|
||||
add_overtime_lines = rec.overtime_ids.filtered(lambda o: o.workflow_record_id and o.update_type == 'add' and o.is_void != True)
|
||||
# 计算补休新增总天数
|
||||
workday_overtime_add = sum((line.workday or 0) for line in add_overtime_lines) / 8
|
||||
holidays_overtime_add = sum((line.public_holidays or 0) for line in add_overtime_lines) / 8
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<t t-name="meal_active_export_module.ListView.Buttons" t-inherit="web.ListView.Buttons">
|
||||
<xpath expr="//div[hasclass('o_list_buttons')]" position="after">
|
||||
<button type="button" class="btn btn-success" style="margin-left: 10px;" t-on-click="exportMealActiveExcel">
|
||||
导出误餐归档明细
|
||||
导出
|
||||
</button>
|
||||
</xpath>
|
||||
</t>
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
<field name="model">overtime.active.line</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="加班归档详情" editable="bottom" decoration-muted="is_void">
|
||||
<header>
|
||||
<button name="all_unlink" string="删除" type="object" icon="fa-trash" groups="base.group_system" confirm="确定要删除选中的记录吗?"/>
|
||||
</header>
|
||||
<field name="overtime_name"/>
|
||||
<field name="employee_id" string="员工"/>
|
||||
<field name="department_id" string="部门"/>
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<tree string="误餐记录" editable="bottom" js_class="custom_meal_active_export_button" create="false" delete="false" edit="false">
|
||||
<header>
|
||||
<button name="all_revoke" type="object" string="批量撤销" class="oe_highlight"/>
|
||||
<button name="all_unlink" string="删除" type="object" class="oe_highlight" groups="base.group_system" confirm="确定要删除选中的记录吗?"/>
|
||||
</header>
|
||||
<field name="meal_name"/>
|
||||
<field name="employee_id"/>
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<tree string="加班情况(归档)" editable="bottom" js_class="custom_overtime_active_export_button" create="false" delete="false" edit="false">
|
||||
<header>
|
||||
<button name="revoke" type="object" string="批量撤销" class="oe_highlight"/>
|
||||
<button name="all_unlink" string="删除" type="object" class="oe_highlight" groups="base.group_system" confirm="确定要删除选中的记录吗?"/>
|
||||
</header>
|
||||
<field name="employee_id"/>
|
||||
<field name="select_year" column_invisible="1"/>
|
||||
|
||||
Reference in New Issue
Block a user