From 6afab9f052dfe056a52518950772295487c32607 Mon Sep 17 00:00:00 2001 From: zhou <123@> Date: Fri, 28 Mar 2025 15:08:53 +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 --- .../wizard/hr_attendance_month_wizard.py | 1 + .../models/yuthon_hr_employee.py | 54 ++++++++++++++++++- .../views/yuthon_hr_employee_views.xml | 2 + 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/yuthon_hr_attendance/wizard/hr_attendance_month_wizard.py b/yuthon_hr_attendance/wizard/hr_attendance_month_wizard.py index 755535be3..196207784 100644 --- a/yuthon_hr_attendance/wizard/hr_attendance_month_wizard.py +++ b/yuthon_hr_attendance/wizard/hr_attendance_month_wizard.py @@ -166,6 +166,7 @@ class HrAttendanceMonthWizard(models.TransientModel): '年假': 'annual_leave', '事假': 'unpaid_leave', '补休': 'cop_leave', + '产假': 'maternity_leave', } leave_days = {} year = int(self.current_year) diff --git a/yuthon_hr_employee/models/yuthon_hr_employee.py b/yuthon_hr_employee/models/yuthon_hr_employee.py index 7a7e10966..6f6d28686 100644 --- a/yuthon_hr_employee/models/yuthon_hr_employee.py +++ b/yuthon_hr_employee/models/yuthon_hr_employee.py @@ -168,13 +168,63 @@ class YuthonHrEmployee(models.Model): is_salary = fields.Boolean(string="是否薪资计算", default=True) last_month_attendance_deduction = fields.Float(string="上月考勤扣款") last_month_base_salary_deduction = fields.Float(string="上月基本薪资扣款") - last_month_performance_deduction = fields.Float(string="上月绩效扣款") - last_month_commuting_deduction = fields.Float(string='上月通信扣款') + last_month_performance_deduction = fields.Float(string="上月绩效扣款", compute='_compute_last_month_deductions') + last_month_commuting_deduction = fields.Float(string='上月通信扣款', compute='_compute_last_month_deductions') + commuting = fields.Float(string='通信补贴', compute='_compute_employee_salary') + performance = fields.Float(string='绩效奖金', compute='_compute_employee_salary') medical_insurance_base = fields.Float(string='基本医疗费基数', compute='_compute_insurance_bases') pension_insurance_base = fields.Float(string='基本养老费基数', compute='_compute_insurance_bases') work_injury_insurance_base = fields.Float(string='工伤保险费基数', compute='_compute_insurance_bases') housing_fund_base = fields.Float(string='住房公积金基数', compute='_compute_insurance_bases') + def _compute_employee_salary(self): + for record in self: + # 获取上个月的时间范围 + now = datetime.now() + last_month_start = (now.replace(day=1) - relativedelta(months=1)) + last_month_end = last_month_start + relativedelta(day=31) + payslip_record = self.env['hr.payslip'].search([ + ('employee_id', '=', record.id), + ('date_from', '>=', last_month_start), + ('date_to', '<=', last_month_end) + ]) + if payslip_record: + record.commuting = payslip_record.commuting_allowance + record.performance = payslip_record.performance_bonuses + else: + record.commuting = 0 + record.performance = 0 + + @api.depends('commuting', 'performance') + def _compute_last_month_deductions(self): + today = datetime.today() + last_month = today - relativedelta(months=1) + last_month_year = str(last_month.year) + last_month_month = str(last_month.month) + for record in self: + # 查找上个月的考勤月度明细记录 + attendance_record = self.env['hr.attendance.month.detail'].search([ + ('employee_id', '=', record.id), + ('current_year', '=', last_month_year), + ('current_month', '=', last_month_month) + ]) + if attendance_record: + # 计算总产假天数 + maternity_leave = attendance_record.maternity_leave + # 计算月天数 + if last_month.month in [1, 3, 5, 7, 8, 10, 12]: + end_day = 31 + elif last_month.month in [4, 6, 9, 11]: + end_day = 30 + elif (last_month.month % 4 == 0 and last_month.year % 100 != 0) or (last_month.year % 400 == 0): + end_day = 29 + else: + end_day = 28 + + # 计算扣款 + record.last_month_commuting_deduction = record.commuting / end_day * maternity_leave + record.last_month_performance_deduction = record.performance / end_day * maternity_leave + @api.depends('social_base_on', 'social_base_off') def _compute_insurance_bases(self): current_month = datetime.now().month diff --git a/yuthon_hr_employee/views/yuthon_hr_employee_views.xml b/yuthon_hr_employee/views/yuthon_hr_employee_views.xml index 482ddacdd..17850dfc3 100644 --- a/yuthon_hr_employee/views/yuthon_hr_employee_views.xml +++ b/yuthon_hr_employee/views/yuthon_hr_employee_views.xml @@ -147,6 +147,8 @@ + +