From d39ca5310f1482380027fc8cd607c454f1137678 Mon Sep 17 00:00:00 2001 From: zhou <123@> Date: Sun, 27 Jul 2025 16:03:41 +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 --- .../models/inherit_hr_payroll_structure.py | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/yuthon_salary/models/inherit_hr_payroll_structure.py b/yuthon_salary/models/inherit_hr_payroll_structure.py index 16c88b05e..1fcabeeed 100644 --- a/yuthon_salary/models/inherit_hr_payroll_structure.py +++ b/yuthon_salary/models/inherit_hr_payroll_structure.py @@ -57,7 +57,7 @@ class HrPayrollStructure(models.Model): name_pinyin = pinyin(field_name, style=Style.FIRST_LETTER) code = "".join([p[0][0] for p in name_pinyin]).upper() salary_id = self.env['hr.salary.rule'].search( - [('name', '=', field_name), ('struct_id', '=', self.id.origin)], limit=1) + [('name', '=', field_name), ('struct_id', '=', self.id)], limit=1) if not salary_id: self.env['hr.salary.rule'].create({ 'name': field_name, @@ -110,15 +110,18 @@ class HrPayrollStructure(models.Model): def write(self, vals): result = super(HrPayrollStructure, self).write(vals) - field_mapping = { - 'base_salary': '基本工资', - 'rank_salary': '职级工资', - 'communication_subsidy': '通讯补贴', - 'position_salary': '岗位工资' - } - for field, name in field_mapping.items(): - if field in vals: - self._handle_salary_rule(name, self[field]) + if result: + field_mapping = { + 'base_salary': '基本工资', + 'rank_salary': '职级工资', + 'communication_subsidy': '通讯补贴', + 'position_salary': '岗位工资', + 'advance_performance_bonuses': '预发绩效奖金' # 补充新增字段 + } + for record in self: + for field, name in field_mapping.items(): + if field in vals: + record._handle_salary_rule(name, record[field]) return result def action_yuthon_payroll_wizard(self): @@ -235,18 +238,16 @@ class HrPayrollStructure(models.Model): def rank_log_time(self): """定时任务:根据日志记录的生效时间更新主模型字段值""" + # 出发一下 today = date.today() for structure in self.env['hr.payroll.structure'].search([('company_id.name', '=', '集团本部')]): # 获取该职级下所有有效的日志记录 valid_logs = structure.renk_log_ids.filtered( - lambda log: log.is_enable and - log.effective_date and - log.effective_date <= today and - (not log.lapse_date or log.lapse_date >= today) + lambda log: log.is_enable and log.effective_date and log.effective_date <= today and (not log.lapse_date or log.lapse_date >= today) ).sorted(key=lambda l: l.effective_date, reverse=True) if valid_logs: latest_log = valid_logs[0] - structure.write({ + structure.sudo().write({ 'base_salary': latest_log.base_salary, 'rank_salary': latest_log.rank_salary, 'communication_subsidy': latest_log.communication_subsidy,