From a183ac5368bb3f582befa5747be653108a9d56ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?=
<9664676+pengyuthon@user.noreply.gitee.com>
Date: Thu, 29 Jan 2026 18:45: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
---
.../models/yuthon_medical_manage.py | 128 +++++++++++-------
.../views/yuthon_medical_manage_views.xml | 70 +++-------
2 files changed, 96 insertions(+), 102 deletions(-)
diff --git a/yuthon_hr_employee/models/yuthon_medical_manage.py b/yuthon_hr_employee/models/yuthon_medical_manage.py
index 89e0bdba6..618dbd3b0 100644
--- a/yuthon_hr_employee/models/yuthon_medical_manage.py
+++ b/yuthon_hr_employee/models/yuthon_medical_manage.py
@@ -11,25 +11,49 @@ class YuthonMedicalManage(models.Model):
employee_id = fields.Many2one('hr.employee', string="员工姓名")
year = fields.Char(string="年份")
current_year_remaining = fields.Float(string="本年剩余", compute="_compute_current_year_remaining")
- last_year_quota = fields.Float(string="上年额度")
- last_year_balance = fields.Float(string="上年结余")
- last_year_used = fields.Float(string="上年使用")
- last_year_remaining = fields.Float(string="上年剩余")
- prev_last_year_quota = fields.Float(string="前年额度")
- prev_last_year_balance = fields.Float(string="前年结余")
- prev_last_year_used = fields.Float(string="前年使用")
+ last_year_quota = fields.Float(string="去年额度")
+ last_year_used = fields.Float(string="去年使用", compute="_compute_last_year_used")
+ last_year_remaining = fields.Float(string="去年剩余")
prev_last_year_remaining = fields.Float(string="前年剩余")
- this_year_usage = fields.Float(string='本年使用')
+ this_year_usage = fields.Float(string='本年使用', compute="_compute_this_year_usage")
this_year_quota = fields.Float(string='本年额度')
- medical_line_ids = fields.One2many('yuthon.medical.line', 'medical_manage_id', string="体检费明细")
company_id = fields.Many2one(related="employee_id.company_id", string="公司", default=lambda self: self.env.company)
- @api.depends('this_year_quota', 'this_year_usage', 'last_year_balance')
+ @api.depends('this_year_quota', 'this_year_usage', 'last_year_remaining')
def _compute_current_year_remaining(self):
for record in self:
- record.current_year_remaining = record.this_year_quota + record.last_year_balance - record.this_year_usage
+ record.current_year_remaining = record.this_year_quota + record.last_year_remaining - record.this_year_usage
- def _calculate_medical_quota(self, employee, current_date):
+ @api.depends('employee_id', 'year')
+ def _compute_last_year_used(self):
+ if not self:
+ return
+ for record in self:
+ line_domain = ([
+ ('employee_id', '=', record.employee_id.id),
+ ('enable', '=', True),
+ ('medical_date', '>=', f"{str(int(record.year)-1)}-01-01"),
+ ('medical_date', '<=', f"{str(int(record.year)-1)}-12-31")
+ ])
+ all_lines = self.env['yuthon.medical.line'].search(line_domain)
+ record.last_year_used = sum(all_lines.mapped('medical_fee'))
+
+ @api.depends('employee_id', 'year')
+ def _compute_this_year_usage(self):
+ if not self:
+ return
+ for record in self:
+ line_domain = ([
+ ('employee_id', '=', record.employee_id.id),
+ ('enable', '=', True),
+ ('medical_date', '>=', f"{record.year}-01-01"),
+ ('medical_date', '<=', f"{record.year}-12-31")
+ ])
+ all_lines = self.env['yuthon.medical.line'].search(line_domain)
+ record.this_year_usage = sum(all_lines.mapped('medical_fee'))
+
+ def _calculate_medical_quota(self, employee, year):
+ current_date = fields.Date.today()
valid_rules = self.env['yuthon.medical.rule'].search([
('start_date', '<=', current_date),
'|', ('end_date', '>=', current_date), ('end_date', '=', False)
@@ -43,42 +67,39 @@ class YuthonMedicalManage(models.Model):
increment_times = exceed_age_years // rule.increase_interval_years
base_quota += rule.increment_amount * increment_times
+ if rule.cap > 0:
+ base_quota = min(base_quota, rule.cap)
+
# 女性婚姻状态补助
final_quota = base_quota
- if employee.gender == 'female':
+ if employee.user_sex == 'girl':
if employee.marital == 'single':
final_quota += rule.allowance_unmarried_women
elif employee.marital == 'married':
final_quota += rule.allowance_married_women
entry_date = fields.Date.from_string(employee.entry_date)
- current_year = current_date.year
entry_year = entry_date.year
# 判断是否为当年入职
- if entry_year == current_year:
+ if entry_year == year:
entry_month = entry_date.month
ratio = (12 - entry_month + 1) / 12
final_quota = final_quota * ratio
final_quota = max(final_quota, 0.0)
- if rule.cap > 0:
- final_quota = min(base_quota, rule.cap)
-
return final_quota
def medical_manage(self):
current_date = fields.Date.today()
current_year = str(current_date.year)
last_year = str(int(current_year) - 1)
- prev_last_year = str(int(current_year) - 2)
- open_contracts = self.env['hr.contract'].search([
- ('state', '=', 'open'),
+ last_year_medical_recs = self.env['yuthon.medical.manage'].search([
+ ('year', '=', last_year),
+ ('company_id.name', '=', '集团本部')
])
- open_employees = open_contracts.mapped('employee_id')
-
+ open_employees = last_year_medical_recs.mapped('employee_id')
for employee in open_employees:
- # 查找/创建该员工的本年体检费记录
medical_manage_rec = self.env['yuthon.medical.manage'].search([
('employee_id', '=', employee.id),
('year', '=', current_year)
@@ -93,8 +114,9 @@ class YuthonMedicalManage(models.Model):
else:
continue
- this_year_quota = self._calculate_medical_quota(employee, current_date)
- medical_manage_rec.write({'this_year_quota': this_year_quota})
+ this_year_quota = self._calculate_medical_quota(employee, current_year)
+ medical_manage_rec.write({'this_year_quota': this_year_quota,
+ })
# 回填上年数据
last_year_rec = self.env['yuthon.medical.manage'].search([
@@ -104,33 +126,23 @@ class YuthonMedicalManage(models.Model):
if last_year_rec:
medical_manage_rec.write({
'last_year_quota': last_year_rec.this_year_quota,
- 'last_year_used': last_year_rec.this_year_usage,
'last_year_remaining': last_year_rec.current_year_remaining,
- 'last_year_balance': last_year_rec.current_year_remaining,
- })
-
- # 回填前年数据
- prev_last_year_rec = self.env['yuthon.medical.manage'].search([
- ('employee_id', '=', employee.id),
- ('year', '=', prev_last_year)
- ], limit=1)
- if prev_last_year_rec:
- medical_manage_rec.write({
- 'prev_last_year_quota': prev_last_year_rec.this_year_quota,
- 'prev_last_year_used': prev_last_year_rec.this_year_usage,
- 'prev_last_year_remaining': prev_last_year_rec.current_year_remaining,
- 'prev_last_year_balance': prev_last_year_rec.current_year_remaining,
})
+ # 回填前年数据
+ prev_last_year_vals = {
+ 'prev_last_year_remaining': last_year_rec.last_year_remaining,
+ }
+ medical_manage_rec.write(prev_last_year_vals)
def button_details(self):
- form_id = self.env.ref('yuthon_hr_employee.view_yuthon_medical_manage_form').id
+ tree_id = self.env.ref('yuthon_hr_employee.yuthon_medical_line_tree').id
return {
"type": "ir.actions.act_window",
- "name": "修正申请",
- "res_model": "yuthon.medical.manage",
- "views": [[form_id, "form"]],
- "res_id": self.id,
+ "name": "查看详情",
+ "res_model": "yuthon.medical.line",
+ "views": [[tree_id, "tree"]],
+ "domain": [('employee_id', '=', self.employee_id.id)],
}
def property_reimbursement_form(self):
@@ -151,16 +163,30 @@ class YuthonMedicalManage(models.Model):
'target': 'new',
}
- def update_year(self):
+ def update_initial_value(self):
medical_ids = self.env["yuthon.medical.manage"].browse(
self._context.get('active_ids', self._context.get('active_id')))
for rec in medical_ids:
- rec.year = 2025
+ current_year = str(rec.year)
+ last_year = str(int(current_year) - 1)
+ prev_last_year = str(int(current_year) - 2)
+ last_year_quota = self._calculate_medical_quota(rec.employee_id, last_year)
+ prev_last_year_quota = self._calculate_medical_quota(rec.employee_id, prev_last_year)
+ this_year_quota = self._calculate_medical_quota(rec.employee_id, current_year)
+ rec.write({
+ 'this_year_quota': this_year_quota,
+ 'last_year_quota': last_year_quota,
+ 'prev_last_year_quota': prev_last_year_quota,
+ })
+
+
class YuthonMedicalLine(models.Model):
_name = 'yuthon.medical.line'
_description = '体检费明细'
- medical_manage_id = fields.Many2one('yuthon.medical.manage', string="关联体检费管理")
- medical_date = fields.Date(string="体检日期")
- medical_fee = fields.Float(string="费用")
+ employee_id = fields.Many2one('hr.employee', string="姓名")
+ medical_date = fields.Date(string="报销日期")
+ medical_fee = fields.Float(string="金额")
+ enable = fields.Boolean(string="启用", default=True)
+
diff --git a/yuthon_hr_employee/views/yuthon_medical_manage_views.xml b/yuthon_hr_employee/views/yuthon_medical_manage_views.xml
index f8e4ed9c2..85d386334 100644
--- a/yuthon_hr_employee/views/yuthon_medical_manage_views.xml
+++ b/yuthon_hr_employee/views/yuthon_medical_manage_views.xml
@@ -11,64 +11,27 @@
-
-
+
+
+
-
-
-
-
-
-
-
+
+
-
- yuthon.medical.manage.form
- yuthon.medical.manage
+
+ 体检报销费
+ yuthon.medical.line
-
+
+
+
+
+
+
@@ -99,5 +62,10 @@
code
action = model.medical_manage_wizard()
+
+ 体检报销费
+ yuthon.medical.line
+ tree
+