添加功能
This commit is contained in:
@@ -119,6 +119,12 @@ class SoongWorkflowMixin(models.AbstractModel):
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
res = super().create(vals_list)
|
||||
target_role = self.env['soong.user.role'].search(
|
||||
[('name', '=', '考勤校对'), ('company_id', '=', res.env.user.employee_id.company_id.id)],
|
||||
limit=1
|
||||
)
|
||||
target_role_id = target_role.id if target_role else None
|
||||
|
||||
for record in res:
|
||||
button_ids = record.sudo().workflow_id.node_ids.button_ids.search(
|
||||
[('workflow_id', '=', record.workflow_id.id)])
|
||||
@@ -129,7 +135,8 @@ class SoongWorkflowMixin(models.AbstractModel):
|
||||
current_user_role_ids.append(employee.user_role_id.id)
|
||||
if employee.user_role_ids:
|
||||
current_user_role_ids.extend(employee.user_role_ids.ids)
|
||||
|
||||
if target_role_id in current_user_role_ids:
|
||||
continue
|
||||
for button_id in button_ids:
|
||||
allowed_departments = button_id.node_id.department_id
|
||||
if allowed_departments and employee.department_id.id not in allowed_departments.ids:
|
||||
@@ -240,12 +247,6 @@ class SoongWorkflowMixin(models.AbstractModel):
|
||||
("approval_state", "!=", "2")
|
||||
]
|
||||
)
|
||||
self.log_ids[-1].approval_state = "3"
|
||||
self.log_ids[-1].lase_click_date = fields.Datetime.now()
|
||||
self.work_end = True
|
||||
self.env['soong.workflow.record'].search([('code', '=', self.code)]).write({'approve_state': 'end',
|
||||
"employee_ids": False,
|
||||
"node_id": False, })
|
||||
if apostille_log_obj:
|
||||
raise UserError("当前加签人员还有没有审批完成的!")
|
||||
# 继续正常流程
|
||||
|
||||
@@ -286,39 +286,6 @@ class YuthonVacationReports(models.Model):
|
||||
|
||||
record.medical_fee = max(total, 0.0)
|
||||
|
||||
def monthly_report(self):
|
||||
today = fields.Date.today()
|
||||
employees = self.env['hr.employee'].search([])
|
||||
current_month_first = today.replace(day=1)
|
||||
last_month_last = current_month_first - timedelta(days=1)
|
||||
last_month_first = last_month_last.replace(day=1)
|
||||
for employee in employees:
|
||||
resource_user_ids = employee.resource_calendar_id.resource_user_ids.ids
|
||||
is_resource_user = True if employee.id in resource_user_ids else False
|
||||
existing_record = self.search([
|
||||
('employee_id', '=', employee.id),
|
||||
('vacation_date', '=', today)
|
||||
], limit=1)
|
||||
if not existing_record and not is_resource_user:
|
||||
last_month_record = self.search([
|
||||
('employee_id', '=', employee.id),
|
||||
('vacation_date', '>=', fields.Date.to_string(last_month_first)),
|
||||
('vacation_date', '<=', fields.Date.to_string(last_month_last))
|
||||
], limit=1)
|
||||
inherit_vals = {}
|
||||
if last_month_record:
|
||||
inherit_vals = {
|
||||
'leave': last_month_record.leave,
|
||||
'working_overtime': last_month_record.working_overtime,
|
||||
'medical_fee': last_month_record.medical_fee,
|
||||
}
|
||||
|
||||
self.create({
|
||||
'employee_id': employee.id,
|
||||
'vacation_date': today,
|
||||
**inherit_vals
|
||||
})
|
||||
|
||||
def disposable_report(self):
|
||||
year = 2025
|
||||
months = range(1, 8)
|
||||
@@ -455,43 +422,53 @@ class YuthonVacationReports(models.Model):
|
||||
meal_total -= int(line.update_lines or 0)
|
||||
record.meal_fee = meal_total
|
||||
|
||||
def update_vacation(self):
|
||||
"""
|
||||
从hr.leave.allocation中汇总年假和补休数据,更新到8月份的假期报表
|
||||
"""
|
||||
# 定义目标月份:8月1号(当年)
|
||||
current_year = fields.Date.today().year
|
||||
target_month = date(current_year, 8, 4)
|
||||
target_month_str = fields.Date.to_string(target_month)
|
||||
# 获取所有员工
|
||||
def monthly_report(self):
|
||||
today = fields.Date.today()
|
||||
employees = self.env['hr.employee'].search([])
|
||||
current_month_first = today.replace(day=1)
|
||||
last_month_last = current_month_first - timedelta(days=1)
|
||||
last_month_first = last_month_last.replace(day=1)
|
||||
|
||||
for employee in employees:
|
||||
# 1. 处理年假分配
|
||||
annual_allocations = self.env['hr.leave.allocation'].search([
|
||||
('employee_id', '=', employee.id),
|
||||
('holiday_status_id.name', '=', '年假'),
|
||||
('state', '=', 'validate')
|
||||
])
|
||||
resource_user_ids = employee.resource_calendar_id.resource_user_ids.ids
|
||||
is_resource_user = employee.id in resource_user_ids
|
||||
|
||||
# 累加年假总小时数
|
||||
total_annual_hours = sum(alloc.number_of_hours_display for alloc in annual_allocations)
|
||||
|
||||
# 2. 处理补休分配
|
||||
comp_allocations = self.env['hr.leave.allocation'].search([
|
||||
existing_record = self.search([
|
||||
('employee_id', '=', employee.id),
|
||||
('holiday_status_id.name', '=', '补休'),
|
||||
('state', '=', 'validate') # 只处理已验证的分配
|
||||
])
|
||||
|
||||
# 累加补休总小时数
|
||||
total_comp_hours = sum(alloc.number_of_hours_display for alloc in comp_allocations)
|
||||
# 3. 查找或创建8月份的报表记录
|
||||
vacation_report = self.search([
|
||||
('employee_id', '=', employee.id),
|
||||
('vacation_date', '=', target_month_str)
|
||||
('vacation_date', '=', today)
|
||||
], limit=1)
|
||||
self._update_leave_lines(vacation_report, annual_allocations, total_annual_hours)
|
||||
self._update_over_lines(vacation_report, comp_allocations, total_comp_hours)
|
||||
|
||||
if not existing_record and not is_resource_user:
|
||||
# 获取上月记录
|
||||
last_month_record = self.search([
|
||||
('employee_id', '=', employee.id),
|
||||
('vacation_date', '>=', fields.Date.to_string(last_month_first)),
|
||||
('vacation_date', '<=', fields.Date.to_string(last_month_last))
|
||||
], limit=1)
|
||||
inherit_vals = {}
|
||||
if last_month_record:
|
||||
inherit_vals = {
|
||||
'leave': last_month_record.leave,
|
||||
'working_overtime': last_month_record.working_overtime,
|
||||
'medical_fee': last_month_record.medical_fee,
|
||||
}
|
||||
|
||||
# 创建本月报告主记录
|
||||
new_report = self.create({
|
||||
'employee_id': employee.id,
|
||||
'vacation_date': today,
|
||||
**inherit_vals
|
||||
})
|
||||
if last_month_record:
|
||||
# 处理年假明细行(继承额度)
|
||||
if last_month_record.leave:
|
||||
leave_hours = last_month_record.leave * 8
|
||||
self._update_leave_lines(new_report, [last_month_record], leave_hours)
|
||||
|
||||
# 处理补休明细行(继承额度)
|
||||
if last_month_record.working_overtime:
|
||||
overtime_hours = last_month_record.working_overtime * 8
|
||||
self._update_over_lines(new_report, [last_month_record], overtime_hours)
|
||||
|
||||
def _update_leave_lines(self, report, allocations, number_of_hours_display):
|
||||
for alloc in allocations:
|
||||
@@ -503,7 +480,7 @@ class YuthonVacationReports(models.Model):
|
||||
'update_lines': number_of_hours_display,
|
||||
'is_void': False,
|
||||
'allocation_type': 'allocation',
|
||||
'text': f"年假分配"
|
||||
'text': f"上月额度继承"
|
||||
})
|
||||
|
||||
def _update_over_lines(self, report, allocations, number_of_hours_display):
|
||||
@@ -518,10 +495,9 @@ class YuthonVacationReports(models.Model):
|
||||
'legal_day': 0,
|
||||
'public_holidays': 0,
|
||||
'meal_number': 0,
|
||||
'text': f"补休分配"
|
||||
'text': f"上月额度继承"
|
||||
})
|
||||
|
||||
|
||||
def log(self):
|
||||
return {
|
||||
"type": "ir.actions.act_window",
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
<field name="name">yuthon.vacation.my.reports.tree</field>
|
||||
<field name="model">yuthon.vacation.reports</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="我的假期额度记录" editable="bottom" default_order="vacation_date desc">
|
||||
<tree string="我的假期额度记录" editable="bottom" default_order="vacation_date desc" create="0">
|
||||
<field name="employee_id" options="{'no_open': True}"/>
|
||||
<field name="department_id" column_invisible="1"/>
|
||||
<field name="company_id" column_invisible="1"/>
|
||||
@@ -96,6 +96,12 @@
|
||||
<form string="假期额度日志">
|
||||
<sheet>
|
||||
<field name="employee_id" invisible="1"/>
|
||||
<div class="oe_title">
|
||||
<label for="name"/>
|
||||
<h1>
|
||||
<field name="vacation_date"/>
|
||||
</h1>
|
||||
</div>
|
||||
<group col="4">
|
||||
<group>
|
||||
<field name="leave" string="剩余年假"/>
|
||||
@@ -255,6 +261,12 @@
|
||||
<form string="我的假期额度记录" create="0" edit="0" delete="0">
|
||||
<sheet>
|
||||
<field name="employee_id" invisible="1"/>
|
||||
<div class="oe_title">
|
||||
<label for="name"/>
|
||||
<h1>
|
||||
<field name="vacation_date"/>
|
||||
</h1>
|
||||
</div>
|
||||
<group col="4">
|
||||
<group>
|
||||
<field name="leave" string="剩余年假" readonly="1"/>
|
||||
|
||||
Reference in New Issue
Block a user