This commit is contained in:
李鹏宇
2026-07-08 19:02:29 +08:00
parent 8f89cef5f5
commit 285f228bcb
2 changed files with 29 additions and 14 deletions
+21
View File
@@ -1294,6 +1294,27 @@ class HolidaysRequestBatch(models.Model):
report = self.env.ref('yuthon_holiday.action_hr_leave_batch_print') report = self.env.ref('yuthon_holiday.action_hr_leave_batch_print')
return report.report_action(self, config=False) return report.report_action(self, config=False)
def get_allowance_total_days(self):
"""安全解析 holiday_allowance 多行文本中的年假总天数,供打印模板使用
holiday_allowance 格式示例:
上年年假剩余5.000天, 本年年假剩余3.000天
上年补休剩余16.0小时, 本年补休剩余8.0小时
"""
self.ensure_one()
text = self.holiday_allowance or ''
total = 0.0
for line in text.split('\n'): # 逐行处理,防止多行混在一起
line = line.strip()
if '年假' in line: # 只取年假行
for part in line.split(','):
digits = ''.join(c for c in part if c.isdigit() or c == '.')
if digits:
try:
total += float(digits)
except (ValueError, TypeError):
pass
return total
class HrLeaveLine(models.Model): class HrLeaveLine(models.Model):
_name = 'hr.leave.line' _name = 'hr.leave.line'
@@ -36,14 +36,8 @@
<t t-set="hour_total" t-value="sum(doc.hour_leave_ids.mapped('leave_hours')) if doc.hour_leave_ids else 0"/> <t t-set="hour_total" t-value="sum(doc.hour_leave_ids.mapped('leave_hours')) if doc.hour_leave_ids else 0"/>
<!-- 从可用额度字符串解析年假/补休数值,计算总时长 --> <!-- 总时长:调用模型方法安全解析年假天数 -->
<t t-set="allowance_text" t-value="doc.holiday_allowance or ''"/> <t t-set="allow_total" t-value="doc.get_allowance_total_days()"/>
<t t-set="allowance_parts" t-value="(allowance_text or '').split(',')"/>
<t t-set="allow_annual_raw" t-value="allowance_parts and allowance_parts[0] or ''"/>
<t t-set="allow_ot_raw" t-value="len(allowance_parts) > 1 and allowance_parts[1] or ''"/>
<t t-set="allow_annual_val" t-value="allow_annual_raw and ''.join([c for c in allow_annual_raw if (c.isdigit() or c=='.')]) or '0'"/>
<t t-set="allow_ot_val" t-value="allow_ot_raw and ''.join([c for c in allow_ot_raw if (c.isdigit() or c=='.')]) or '0'"/>
<t t-set="allow_total" t-value="(float(allow_annual_val or 0.0) if allow_annual_val else 0.0) + (float(allow_ot_val or 0.0) if allow_ot_val else 0.0)"/>
<!-- 预先取按天/按小时的请假行,直接搜索保障拿到数据 --> <!-- 预先取按天/按小时的请假行,直接搜索保障拿到数据 -->
<t t-set="day_leaves" t-value="doc.env['hr.leave'].sudo().search([('batch_id', '=', doc.id)])"/> <t t-set="day_leaves" t-value="doc.env['hr.leave'].sudo().search([('batch_id', '=', doc.id)])"/>
<t t-set="hour_leaves" t-value="doc.env['hr.leave'].sudo().search([('hour_batch_id', '=', doc.id)])"/> <t t-set="hour_leaves" t-value="doc.env['hr.leave'].sudo().search([('hour_batch_id', '=', doc.id)])"/>
@@ -76,12 +70,12 @@
</tr> </tr>
<!-- 总时长(= 可用额度中年假+补休) --> <!-- 总时长(= 可用额度中年假+补休) -->
<tr> <!-- <tr>-->
<td class="header-cell" style="text-align:center;"><strong>时长</strong></td> <!-- <td class="header-cell" style="text-align:center;"><strong>时长</strong></td>-->
<td colspan="3"> <!-- <td colspan="3">-->
<span t-esc="allow_total"/> 天 <!-- <span t-esc="allow_total"/> 天-->
</td> <!-- </td>-->
</tr> <!-- </tr>-->
<!-- 按天请假明细:有按天行就显示,优先级高于小时 --> <!-- 按天请假明细:有按天行就显示,优先级高于小时 -->
<t t-if="day_leaves"> <t t-if="day_leaves">