From 9d14ccf4fc0e944e87161ae9dd411af8678f4e30 Mon Sep 17 00:00:00 2001 From: pengyuthon Date: Fri, 3 Oct 2025 17:02:49 +0800 Subject: [PATCH] 1 --- yuthon_salary/models/inherit_hr_payslip.py | 26 +++++-- yuthon_salary/wizard/salary_compute_wizard.py | 68 ++++++------------- 2 files changed, 41 insertions(+), 53 deletions(-) diff --git a/yuthon_salary/models/inherit_hr_payslip.py b/yuthon_salary/models/inherit_hr_payslip.py index 2d7ab777d..c9cc336a1 100644 --- a/yuthon_salary/models/inherit_hr_payslip.py +++ b/yuthon_salary/models/inherit_hr_payslip.py @@ -41,7 +41,7 @@ class InheritHrPayslip(models.Model): elderly_support = fields.Float(string='累计赡养老人') infant_care = fields.Float(string='累计3岁以下婴幼儿照护') seniority_salary = fields.Float(string='工龄工资', compute='_compute_salary', store=True) - union_dues = fields.Float(string='工会会费', compute='_compute_salary', store=True) + union_dues = fields.Float(string='工会会费') overtime_pay = fields.Float(string='加班费', compute='_compute_salary', store=True) meal_misunderstanding_fee = fields.Float(string='误餐费', compute='_compute_salary', store=True) personal_leave = fields.Float(string='事假', compute='_compute_salary', store=True) @@ -385,6 +385,24 @@ class InheritHrPayslip(models.Model): res = super(InheritHrPayslip, self).create(vals_list) return res + @api.model + def create(self, vals): + """ + 为了解决部分薪资生成未生效,单独处理计算公式 + 工会会费:round(abs(payslip.base_salary * 0.005) * -1, 2) --union_dues + :param vals: + :return: + """ + record = super().create(vals) + employee_id = self.env['hr.employee'].search([('id', '=', vals['employee_id'])]) + payroll = self.env['hr.contract'].search([('employee_id', '=', employee_id.id), ('state', '=', 'open')])[-1].structure_type_id.default_struct_id + if payroll.rule_ids.search([('name', '=', '基本工资'), ('struct_id', '=', payroll.id)]): + base_salary = payroll.rule_ids.search([('name', '=', '基本工资'), ('struct_id', '=', payroll.id)]).amount_fix + # if record.worked_days_line_ids.search([('name', '=', '工会会费')]): + # record.line_ids.search([('name', '=', '工会会费')]).total = round(abs(base_salary * 0.005) * -1, 2) + record.write({'union_dues': round(abs(base_salary * 0.005) * -1, 2)}) + return record + @api.ondelete(at_uninstall=False) def _unlink_if_draft_or_cancel(self): if any(payslip.state not in ('draft', 'cancel') for payslip in self): @@ -392,9 +410,7 @@ class InheritHrPayslip(models.Model): def action_refresh_from_work_entries(self): payslip_records = self.browse(self._context.get('active_ids', self._context.get('active_id'))) - payslips = payslip_records.filtered( - lambda slip: slip.employee_id.name != '王鸿怡' - ) + payslips = payslip_records.filtered(lambda slip: slip.employee_id.name != '王鸿怡') for rec in payslips: rec.compute_sheet() @@ -479,8 +495,6 @@ class InheritHrPayslip(models.Model): rec.performance_bonuses = line.total if line.name == '工龄工资': rec.seniority_salary = line.total - if line.name == '工会会费': - rec.union_dues = line.total if line.name == '通讯补贴': rec.commuting_allowance = line.total if line.name == '全勤奖': diff --git a/yuthon_salary/wizard/salary_compute_wizard.py b/yuthon_salary/wizard/salary_compute_wizard.py index 228704f1e..382b4ff1b 100644 --- a/yuthon_salary/wizard/salary_compute_wizard.py +++ b/yuthon_salary/wizard/salary_compute_wizard.py @@ -114,42 +114,24 @@ class SalaryComputeWizard(models.Model): ], limit=1) if vacation_report: update_vals = { - # 年假 - 'done_leave': vacation_report.done_leave, - # 加班时 - 'done_working_overtime': vacation_report.done_working_overtime, - # 调休 - 'compensatory_leave': vacation_report.compensatory_leave, - # 事假 - 'leave_of_absence': vacation_report.leave_of_absence, - # 法定加班 - 'statutory_leave': vacation_report.statutory_leave, - # 补休 - 'cop_leave': vacation_report.cop_leave, - # 值班调休 - 'duty_off_leave': vacation_report.duty_off_leave, - # 婚假 - 'marriage_leave': vacation_report.marriage_leave, - # 产假 - 'maternity_leave': vacation_report.maternity_leave, - # 陪产假 - 'paternity_leave': vacation_report.paternity_leave, - # 计生假 - 'family_planning_leave': vacation_report.family_planning_leave, - # 丧假 - 'bereavement_leave': vacation_report.bereavement_leave, - # 探亲假 - 'home_visit_leave': vacation_report.home_visit_leave, - # 家长会假 - 'parents_meeting_leave': vacation_report.parents_meeting_leave, - # 普通病假 - 'general_sick_leave': vacation_report.general_sick_leave, - # 住院病假 - 'hospital_sick_leave': vacation_report.hospital_sick_leave, - # 出院恢复期病假 - 'recovery_sick_leave': vacation_report.recovery_sick_leave, - # 考试假 - 'exam_leave': vacation_report.exam_leave, + 'done_leave': vacation_report.done_leave, # 年假 + 'done_working_overtime': vacation_report.done_working_overtime, # 加班时 + 'compensatory_leave': vacation_report.compensatory_leave, # 调休 + 'leave_of_absence': vacation_report.leave_of_absence, # 事假 + 'statutory_leave': vacation_report.statutory_leave, # 法定加班 + 'cop_leave': vacation_report.cop_leave, # 补休 + 'duty_off_leave': vacation_report.duty_off_leave, # 值班调休 + 'marriage_leave': vacation_report.marriage_leave, # 婚假 + 'maternity_leave': vacation_report.maternity_leave, # 产假 + 'paternity_leave': vacation_report.paternity_leave, # 陪产假 + 'family_planning_leave': vacation_report.family_planning_leave, # 计生假 + 'bereavement_leave': vacation_report.bereavement_leave, # 丧假 + 'home_visit_leave': vacation_report.home_visit_leave, # 探亲假 + 'parents_meeting_leave': vacation_report.parents_meeting_leave, # 家长会假 + 'general_sick_leave': vacation_report.general_sick_leave, # 普通病假 + 'hospital_sick_leave': vacation_report.hospital_sick_leave, # 住院病假 + 'recovery_sick_leave': vacation_report.recovery_sick_leave, # 出院恢复期病假 + 'exam_leave': vacation_report.exam_leave, # 考试假 } # 更新员工花名册记录 employee.write(update_vals) @@ -164,16 +146,9 @@ class SalaryComputeWizard(models.Model): # 查找有效合同:date_start <= start_date <= date_end(或date_end为空) contract_id = self.env['hr.contract'].search([ - ('employee_id', '=', employee.id), - ('date_start', '<=', start_date), - '|', - ('date_end', '>=', start_date), - ('date_end', '=', False), - ], limit=1) - existing_payslip = self.env['hr.payslip'].search([ - ('employee_id', '=', employee.id), - ('payslip_run_id', '=', payslip_run_id.id), + ('employee_id', '=', employee.id), ('date_start', '<=', start_date), '|', ('date_end', '>=', start_date), ('date_end', '=', False), ], limit=1) + existing_payslip = self.env['hr.payslip'].search([('employee_id', '=', employee.id), ('payslip_run_id', '=', payslip_run_id.id),], limit=1) if not existing_payslip: existing_payslip = self.env['hr.payslip'].create({ @@ -374,8 +349,7 @@ class SalaryComputeWizard(models.Model): year = int(self.select_year) month = int(self.select_time) - if not self._is_employee_turnover(employee, year, month) and not self._is_employee_in_probation( - employee, year, month): + if not self._is_employee_turnover(employee, year, month) and not self._is_employee_in_probation(employee, year, month): existing_payslip.compute_sheet()