From 95bc260713098c5a6f7d776cd4c47613e2f06320 Mon Sep 17 00:00:00 2001 From: zhou <123@> Date: Wed, 2 Jul 2025 16:49:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yuthon_holiday/models/inherit_hr_leave.py | 22 +++----- .../models/inherit_hr_leave_allocation.py | 53 +++++++++++++++++-- .../models/yuthon_vacation_reports.py | 17 +++++- .../inherit_hr_leave_allocation_views.xml | 7 +++ .../views/yuthon_vacation_reports_views.xml | 2 +- yuthon_hr_attendance/models/go_approval.py | 3 +- .../models/overtime_approval.py | 8 +-- .../models/yuthon_hr_employee.py | 10 +++- .../property_accounts_receivable_views.xml | 4 +- .../views/property_deposit_list_views.xml | 4 +- .../views/property_electric_reading_views.xml | 8 +-- .../views/property_evaluation_plan_view.xml | 2 +- .../views/property_management_list_views.xml | 4 +- .../views/property_meter_archives_views.xml | 2 +- .../views/property_meter_water_views.xml | 6 +-- .../views/property_other_list_views.xml | 2 +- .../views/property_penalty_list_views.xml | 6 +-- .../views/property_rent_list_views.xml | 8 +-- .../views/property_tariff_list_views.xml | 6 +-- .../views/property_water_list_views.xml | 4 +- .../views/property_water_reading_views.xml | 8 +-- .../views/yuthon_property_views.xml | 2 +- ...erit_property_tenant_information_views.xml | 4 +- .../views/inherit_yuthon_property_views.xml | 46 ++++++++-------- .../property_accounting_approval_views.xml | 4 +- .../property_accounts_approval_views.xml | 4 +- .../property_construction_approval_views.xml | 4 +- .../views/property_design_approval_views.xml | 4 +- .../property_evaluate_application_views.xml | 4 +- .../views/property_handover_views.xml | 2 +- .../views/property_lease_contract.xml | 4 +- .../views/property_management.xml | 16 +++--- .../views/property_merge_approval_views.xml | 6 +-- .../views/property_offline_registration.xml | 4 +- .../views/property_penalty_relief.xml | 6 +-- .../views/property_project_approval_views.xml | 2 +- .../views/property_record_views.xml | 6 +-- .../views/property_rent_relief.xml | 6 +-- .../views/property_rental_conditions.xml | 2 +- .../views/property_rental_form_views.xml | 2 +- .../views/property_split_approval_views.xml | 2 +- .../views/property_transaction_confirmed.xml | 2 +- .../views/property_transfer_views.xml | 2 +- .../wizard/choose_contract_wizard_views.xml | 2 +- 44 files changed, 191 insertions(+), 131 deletions(-) diff --git a/yuthon_holiday/models/inherit_hr_leave.py b/yuthon_holiday/models/inherit_hr_leave.py index c5ba9c586..052909ea3 100644 --- a/yuthon_holiday/models/inherit_hr_leave.py +++ b/yuthon_holiday/models/inherit_hr_leave.py @@ -383,6 +383,7 @@ class HolidaysRequestBatch(models.Model): workflow_record_id = self.env['soong.workflow.record'].search([ ('code', '=', self.code) ]) + for line in self.hour_leave_ids: if line.holiday_status_id.name == '年假': match = re.search(r'(\d+(?:\.\d+)?)', line.number_of_hours_text or '') @@ -390,12 +391,13 @@ class HolidaysRequestBatch(models.Model): for leave in self.leave_ids: if leave.holiday_status_id.name == '年假': days += leave.number_of_days + leave_list.append((0, 0, { 'vacation_id': reports_id.id, 'update_type': 'reduce', 'workflow_record_id':workflow_record_id.id, 'update_date': fields.Datetime.now(), - 'update_lines': days, + 'update_lines': days, 'text': '审批' })) reports_id.write({'leave_ids': leave_list}) @@ -484,22 +486,14 @@ class HolidaysRequestBatch(models.Model): else: self.name = "" - @api.depends('users_id') def _compute_holiday_allowance(self): - number_of_days = 0 for record in self: - holiday_status_id = self.env['hr.leave.type'].search([('name', '=', '年假')]) - leave_ids = self.env['hr.leave.allocation'].search([('employee_id', '=', record.users_id.employee_id.id), - ('holiday_status_id', '=', holiday_status_id.id)]) - employee = self.env['hr.employee'].search([('id', '=', record.users_id.employee_id.id)]) - all_overtime_hours = round(employee.all_overtime_hours / 8, 1) - if leave_ids: - for leave_id in leave_ids: - number_of_days += leave_id.number_of_days - else: - number_of_days = 0 - record.holiday_allowance = (f"年假{number_of_days}天, 补休{all_overtime_hours}天") + reports_id = self.env['yuthon.vacation.reports'].search([('employee_id', '=', record.users_id.employee_id.id)]) + if reports_id: + leave = round(reports_id.leave / 8, 1) + working_overtime = round(reports_id.working_overtime / 8, 1) + record.holiday_allowance = (f"年假{leave}天, 补休{working_overtime}天") class HrLeaveLine(models.Model): _name = 'hr.leave.line' diff --git a/yuthon_holiday/models/inherit_hr_leave_allocation.py b/yuthon_holiday/models/inherit_hr_leave_allocation.py index 056bfa4f1..b15aab3fa 100644 --- a/yuthon_holiday/models/inherit_hr_leave_allocation.py +++ b/yuthon_holiday/models/inherit_hr_leave_allocation.py @@ -101,23 +101,68 @@ class HrLeaveAllocation(models.Model): leave_ids = self.env["hr.leave.allocation"].browse( self._context.get('active_ids', self._context.get('active_id'))) for leave in leave_ids: - leave.employee_id.write({'remainder_year': leave.number_of_hours_display, - 'quota_issued': leave.number_of_hours_display}) + leave.employee_id.write({'quota_issued': leave.number_of_hours_display}) @api.model def create(self, vals): # 调用原始创建方法获取记录 allocation = super(HrLeaveAllocation, self).create(vals) + # 处理年假类型的分配 if allocation.holiday_status_id.name == '年假': employee = allocation.employee_id days = allocation.number_of_hours_display - # 累计员工字段 employee.write({ - 'remainder_year': employee.remainder_year + days, 'quota_issued': employee.quota_issued + days }) + reports_id = self.env['yuthon.vacation.reports'].search([ + ('employee_id', '=', employee.id) + ], limit=1) + # 创建假期明细记录 + self.env['yuthon.vacation.line'].create({ + 'vacation_id': reports_id.id, + 'update_type': 'add', + 'update_date': fields.Datetime.now(), + 'update_lines': days, + 'text': allocation.name + }) return allocation + def unlink(self): + """删除记录时同步删除对应的假期明细行""" + for record in self: + # 检查是否有需要同步的员工记录 + if record.employee_id and record.holiday_status_id.name == '年假': + employee = record.employee_id + days = record.number_of_hours_display + lines_to_delete = self.env['yuthon.vacation.line'].search([ + ('vacation_id.employee_id', '=', employee.id), + ('update_type', '=', 'add'), + ('update_lines', '=', days), + ('text', '=', record.name) + ]) + if lines_to_delete: + lines_to_delete.unlink() + employee.write({ + 'quota_issued': employee.quota_issued - days + }) + return super(HrLeaveAllocation, self).unlink() + + def update_vacation(self): + leave_ids = self.env["hr.leave.allocation"].browse( + self._context.get('active_ids', self._context.get('active_id'))) + for leave in leave_ids: + leave_list = [] + if leave.holiday_status_id.name == '年假': + reports_id = self.env['yuthon.vacation.reports'].search([('employee_id', '=', leave.employee_id.id)]) + if reports_id: + leave_list.append([0, 0, {'vacation_id': reports_id.id, + 'update_type': 'add', + 'update_date': fields.Datetime.now(), + 'update_lines': leave.number_of_hours_display, + 'text': leave.name + }]) + reports_id.write({'leave_ids': leave_list}) + # def allocation_date(self): # date = datetime(2025, 1, 1) # leave_id = self.env['hr.leave.allocation'].search([]) diff --git a/yuthon_holiday/models/yuthon_vacation_reports.py b/yuthon_holiday/models/yuthon_vacation_reports.py index 7ec4be504..ab0b0f71b 100644 --- a/yuthon_holiday/models/yuthon_vacation_reports.py +++ b/yuthon_holiday/models/yuthon_vacation_reports.py @@ -13,7 +13,6 @@ class YuthonVacationReports(models.Model): leave_ids = fields.One2many('vacation.leave.line', 'vacation_id', string='年假明细') overtime_ids = fields.One2many('vacation.over.line', 'vacation_id', string='加班明细') meal_fee_ids = fields.One2many('vacation.meal.line', 'vacation_id', string='误餐明细') - allocate_credits = fields.Float(string='分配额度') leave = fields.Float(string='年假', compute='_compute_leave', store=True) working_overtime = fields.Float(string='加班时', compute='_compute_working_overtime', store=True) @@ -136,7 +135,6 @@ class VacationLeaveLine(models.Model): workflow_record_id = fields.Many2one('soong.workflow.record', string='流程') update_type= fields.Selection([('add', '增加'), ('reduce', '减少')], string='更新类型') update_date = fields.Date(string='更新时间') - allocate_credits = fields.Float(string='分配额度') update_lines = fields.Float(string='更新额度') text = fields.Text(string='备注') @@ -144,6 +142,21 @@ class VacationLeaveLine(models.Model): def create(self, vals): return super(VacationLeaveLine, self).create(vals) + def _sync_to_employee(self, reverse=False): + """将年假数据同步到关联员工" + :param reverse: 是否反向操作(用于删除场景) + """ + sign = -1 if reverse else 1 + employee = self.vacation_id.employee_id + employee.write({ + 'user_year': employee.user_year + self.update_lines * sign, + }) + + def unlink(self): + """删除记录时同步扣减员工加班时长""" + self._sync_to_employee(reverse=True) + return super(VacationLeaveLine, self).unlink() + class VacationOverline(models.Model): _name = 'vacation.over.line' _description = '加班明细' diff --git a/yuthon_holiday/views/inherit_hr_leave_allocation_views.xml b/yuthon_holiday/views/inherit_hr_leave_allocation_views.xml index 56fc6fd17..cb327f5bb 100644 --- a/yuthon_holiday/views/inherit_hr_leave_allocation_views.xml +++ b/yuthon_holiday/views/inherit_hr_leave_allocation_views.xml @@ -62,6 +62,13 @@ code action = model.action_uninstall_wizard() + + 更新报表 + + + code + action = model.update_vacation() + 一次性更新 diff --git a/yuthon_holiday/views/yuthon_vacation_reports_views.xml b/yuthon_holiday/views/yuthon_vacation_reports_views.xml index aaaaf3e1c..7cbaf765e 100644 --- a/yuthon_holiday/views/yuthon_vacation_reports_views.xml +++ b/yuthon_holiday/views/yuthon_vacation_reports_views.xml @@ -30,8 +30,8 @@ - +