添加功能

This commit is contained in:
李鹏宇
2025-10-20 18:56:49 +08:00
parent 3053fb656e
commit 6ad5e0d2b9
7 changed files with 103 additions and 52 deletions
@@ -50,9 +50,9 @@ class YuthonVacationReports(models.Model):
hospital_sick_leave = fields.Float(string='病假(住院期)', digits=(16, 3), compute='_compute_other_leave', store=True, group_operator=None)
recovery_sick_leave = fields.Float(string='病假(出院恢复期)', digits=(16, 3), compute='_compute_other_leave', store=True, group_operator=None)
exam_leave = fields.Integer(string='考试假', compute='_compute_other_leave', store=True, group_operator=None)
right_days = fields.Float(string='转正天数', group_operator=None)
internship_days = fields.Float(string='实习天数', group_operator=None, compute='compute_attendance_fields')
test_days = fields.Float(string='试用天数', group_operator=None)
right_days = fields.Float(string='转正天数', group_operator=None, compute='compute_attendance_fields')
internship_days = fields.Float(string='实习天数', group_operator=None)
test_days = fields.Float(string='试用天数', group_operator=None, compute='compute_attendance_fields')
should_attendance = fields.Float(string="应到", store=True, group_operator=None, compute='compute_attendance_fields')
actual_attendance = fields.Float(string="实到", compute='compute_attendance_fields', store=True,group_operator=None)
@@ -168,7 +168,8 @@ class YuthonVacationReports(models.Model):
is_no = 0
is_work = 0
leave_days = 0
internship_days = 0 # 实习期天数
test_days = 0
right_days = 0
is_abnormal = 0
actual_attendance = 0 # 实到天数 = 应到天数 - 请假总天数
total_leave_days = 0 # 请假工作流总天数(含小时折算)
@@ -179,7 +180,7 @@ class YuthonVacationReports(models.Model):
days_in_month = calendar.monthrange(year, month)[1]
month_start = date(year, month, 1)
month_end = date(year, month, days_in_month)
leave_days, internship_days = rec._create_leave_record(rec.employee_id, month_start, month_end)
leave_days = rec._create_leave_record(rec.employee_id, month_start, month_end)
entry_date = rec.employee_id.entry_date
if not entry_date or month_start > entry_date:
start_day = 1
@@ -221,8 +222,25 @@ class YuthonVacationReports(models.Model):
actual_attendance = round(max(0, leave_days - total_leave_days), 1)
rec.internship_days = internship_days
month_start = date(year, month, 1)
month_end = date(year, month, calendar.monthrange(year, month)[1])
leave_days = rec._create_leave_record(rec.employee_id, month_start, month_end)
probation_contract = self.env['hr.contract'].search([
('employee_id', '=', rec.employee_id.id),
('is_probation', '=', True),
('end_date', '>=', month_start),
('end_date', '<=', month_end)
], limit=1)
if probation_contract:
test_days = rec._create_leave_record(rec.employee_id, month_start, probation_contract.end_date)
right_days = max(0.0, leave_days - test_days)
else:
test_days = 0
right_days = 0
rec.should_attendance = leave_days
rec.test_days = test_days
rec.right_days = right_days
rec.is_late_card = is_late
rec.is_early_card = is_early
rec.is_no_card = is_no
@@ -321,13 +339,8 @@ class YuthonVacationReports(models.Model):
shift_days_list = [self.remove_leading_zero(date) for date in shift_days_list]
work_days = 0 # 工作日计数
probation_days = 0 # 实习期工作日计数
current_date = actual_start_date
# 检查员工是否处于实习期
contract = employee_id.contract_id
is_in_probation = contract.is_probation and contract.start_date and contract.end_date
while current_date <= end_date:
current_date_str = current_date.strftime('%m月%d日')
current_date_str = self.remove_leading_zero(current_date_str)
@@ -339,15 +352,8 @@ class YuthonVacationReports(models.Model):
if is_shift_day or (not is_weekend and not is_holiday):
work_days += 1
# 计算实习期工作日(仅对处于实习期的员工)
if is_in_probation:
# 检查当前日期是否在实习期范围内
if (contract.start_date <= current_date <= contract.end_date):
probation_days += 1
current_date += timedelta(days=1)
return work_days, probation_days
return work_days
def remove_leading_zero(self, date_str):
month, day = date_str.split('月')
@@ -917,6 +923,44 @@ class VacationMedicalLine(models.Model):
return record
def create_leave_record(self, start_date, end_date):
calendar_leaves = self.env['resource.calendar.leaves'].search([("calendar_id", "=", "行政考勤工作日")])
holidays_list = []
shift_days_list = []
# 提取节假日和调休日
for leave in calendar_leaves:
if leave.holidays:
holidays_list.extend(leave.holidays.split(','))
if leave.alternate_rest_day:
holidays_list.extend(leave.alternate_rest_day.split(','))
if leave.shift_replacement_day:
shift_days_list.extend(leave.shift_replacement_day.split(','))
holidays_list = [self.remove_leading_zero(date) for date in holidays_list]
shift_days_list = [self.remove_leading_zero(date) for date in shift_days_list]
days = 0 # 初始化工作日计数
current_date = start_date
while current_date <= end_date:
current_date_str = current_date.strftime('%m月%d日')
current_date_str = self.remove_leading_zero(current_date_str)
is_weekend = current_date.weekday() in [5, 6]
if current_date_str in holidays_list:
# 如果是法定节假日,不计为工作日
pass
elif current_date_str in shift_days_list:
# 如果是调休日,无论是否周末都算作工作日
days += 1
elif not is_weekend:
# 如果不是周末且不是节假日,算作工作日
days += 1
current_date += timedelta(days=1)
return days
class VacationOtherLine(models.Model):
_name = 'vacation.other.line'
_description = '其他'
@@ -9,17 +9,16 @@
<field name="department_id" column_invisible="1"/>
<field name="company_id" column_invisible="1"/>
<field name="vacation_date" column_invisible="1"/>
<field name="should_attendance" options='{ "fg_color": "white: should_attendance == False"}'/>
<field name="actual_attendance" options='{ "fg_color": "white: actual_attendance == False"}'/>
<field name="right_days" options='{ "fg_color": "white: right_days == False"}'/>
<field name="test_days" options='{ "fg_color": "white: test_days == False"}'/>
<field name="is_late_card" options='{ "fg_color": "white: is_late_card == False"}'/>
<field name="is_early_card" options='{ "fg_color": "white: is_early_card == False"}'/>
<field name="is_no_card" options='{ "fg_color": "white: is_no_card == False"}'/>
<field name="is_work" options='{ "fg_color": "white: is_work == False"}'/>
<field name="is_abnormal" options='{ "fg_color": "white: not is_abnormal"}'/>
<field name="late_allowed" options='{ "fg_color": "white: late_allowed == False"}'/>
<field name="should_attendance" options='{ "fg_color": "white: should_attendance == False"}'/>
<field name="actual_attendance" options='{ "fg_color": "white: actual_attendance == False"}'/>
<field name="right_days" options='{ "fg_color": "white: right_days == False"}'/>
<field name="internship_days" options='{ "fg_color": "white: internship_days == False"}'/>
<field name="test_days" options='{ "fg_color": "white: test_days == False"}'/>
<field name="done_leave" options='{ "fg_color": "white: done_leave == False"}'/>
<field name="done_working_overtime" options='{ "fg_color": "white: done_working_overtime == False"}'/>
<field name="meal_fee" options='{ "fg_color": "white: meal_fee == False"}'/>
@@ -56,18 +55,16 @@
<field name="department_id" column_invisible="1"/>
<field name="company_id" column_invisible="1"/>
<field name="vacation_date" column_invisible="1"/>
<field name="late_allowed"/>
<field name="should_attendance" options='{ "fg_color": "white: should_attendance == False"}'/>
<field name="actual_attendance" options='{ "fg_color": "white: actual_attendance == False"}'/>
<field name="right_days" options='{ "fg_color": "white: right_days == False"}'/>
<field name="test_days" options='{ "fg_color": "white: test_days == False"}'/>
<field name="is_late_card" options='{ "fg_color": "white: is_late_card == False"}'/>
<field name="is_early_card" options='{ "fg_color": "white: is_early_card == False"}'/>
<field name="is_no_card" options='{ "fg_color": "white: is_no_card == False"}'/>
<field name="is_work" options='{ "fg_color": "white: is_work == False"}'/>
<field name="is_abnormal" options='{ "fg_color": "white: not is_abnormal"}'/>
<field name="late_allowed" options='{ "fg_color": "white: late_allowed == False"}'/>
<field name="should_attendance" options='{ "fg_color": "white: should_attendance == False"}'/>
<field name="actual_attendance" options='{ "fg_color": "white: actual_attendance == False"}'/>
<field name="right_days" options='{ "fg_color": "white: right_days == False"}'/>
<field name="internship_days" options='{ "fg_color": "white: internship_days == False"}'/>
<field name="test_days" options='{ "fg_color": "white: test_days == False"}'/>
<field name="done_leave" options='{ "fg_color": "white: done_leave == False"}'/>
<field name="done_working_overtime" options='{ "fg_color": "white: done_working_overtime == False"}'/>
<field name="meal_fee" options='{ "fg_color": "white: meal_fee == False"}'/>
@@ -205,7 +205,7 @@ class PropertyMeterArchives(models.Model):
class MeterArchivesLine(models.Model):
_name = "meter.archives.line"
_description = "电表库明细行"
_order = "number asc, sequence asc"
_order = "number asc, sequence asc, last_meter asc"
archives_id = fields.Many2one("property.meter.archives", string="电表库", required=True, ondelete="cascade")
# name = fields.Char(string='仪表编号')
@@ -174,7 +174,7 @@ class PropertyMeterWater(models.Model):
class MeterWaterLine(models.Model):
_name = "meter.water.line"
_description = "水表库明细行"
_order = "number asc, sequence asc"
_order = "number asc, sequence asc, last_meter asc"
# name = fields.Char(string='仪表编号')
water_id = fields.Many2one("property.meter.water", string="水表库", required=True, ondelete="cascade")
@@ -13,12 +13,12 @@
<field name="sequence1"/>
<field name="number" column_invisible="1"/>
<field name="name" required="1"/>
<field name="unit_number"/>
<field name="gauge_magnification"/>
<field name="epitope_values" column_invisible="1"/>
<field name="epitope_values_id" domain="[('type', '=', 'ammeter')]" />
<field name="lessee_id" options="{'no_create': True}"/>
<field name="yuthon_property_ids" string="物业信息" widget="many2many_tags"/>
<field name="unit_number"/>
<field name="gauge_magnification"/>
<field name="lessee_id" options="{'no_create': True}"/>
<field name="type"/>
<field name="start_time"/>
<field name="end_time"/>
@@ -120,7 +120,11 @@
<field name="model">property.meter.archives</field>
<field name="arch" type="xml">
<search string="电表">
<field name="name"
string="综合搜索"
filter_domain="['|', '|', '|', ('name', 'ilike', self), ('lessee_id.name', 'ilike', self), ('yuthon_property_ids.name', 'ilike', self), ('unit_number.name', 'ilike', self)]"/>
<field name="name"/>
<field name="unit_number"/>
<field name="epitope_values_id"/>
<field name="yuthon_property_ids"/>
<field name="lessee_id"/>
@@ -12,22 +12,21 @@
<!-- <button class="oe_highlight" name="update_epitope_values" string="更新"-->
<!-- type="object" />-->
</header>
<field name="sequence1" />
<field name="number" column_invisible="1" />
<field name="name" required="1" />
<field name="epitope_values" column_invisible="1" />
<field name="epitope_values_id" domain="[('type', '=', 'watermeter')]" options="{'no_open': True}"/>
<field name="lessee_id" options="{'no_create': True, 'no_open': True}"/>
<field name="yuthon_property_ids" string="物业信息" widget="many2many_tags" options="{'no_open': True}"/>
<field name="unit_number" />
<field name="gauge_magnification" />
<field name="type" />
<field name="start_time" />
<field name="end_time" />
<field name="water_state" />
<field name="remarks" />
<field name="employee_ids" widget="many2many_tags" options="{'no_create': True}"/>
<field name="maximum_count" />
<field name="sequence1"/>
<field name="number" column_invisible="1"/>
<field name="name" required="1"/>
<field name="unit_number"/>
<field name="gauge_magnification"/>
<field name="epitope_values" column_invisible="1"/>
<field name="epitope_values_id" domain="[('type', '=', 'ammeter')]" />
<field name="yuthon_property_ids" string="物业信息" widget="many2many_tags"/>
<field name="lessee_id" options="{'no_create': True}"/>
<field name="type"/>
<field name="start_time"/>
<field name="end_time"/>
<field name="remarks"/>
<field name="water_state"/>
<field name="maximum_count"/>
<button name="open_record" string="详情" type="object" class="oe_highlight" />
</tree>
</field>
@@ -128,7 +127,11 @@
<field name="model">property.meter.water</field>
<field name="arch" type="xml">
<search string="水表">
<field name="name"
string="综合搜索"
filter_domain="['|', '|', '|', ('name', 'ilike', self), ('lessee_id.name', 'ilike', self), ('yuthon_property_ids.name', 'ilike', self), ('unit_number.name', 'ilike', self)]"/>
<field name="name" />
<field name="unit_number" />
<field name="epitope_values_id" />
<field name="yuthon_property_ids" />
<field name="lessee_id" />
@@ -636,7 +636,7 @@ class PropertyLeaseContract(models.Model):
button_ids = self.env["soong.workflow.node.button"].browse(
self._context.get('active_ids', self._context.get('active_id')))
@api.depends('actual_end_time', 'term_start_time')
@api.depends('actual_end_time', 'term_start_time', 'term_end_time')
def _compute_end_comparison(self):
for record in self:
now = date.today()
@@ -654,6 +654,9 @@ class PropertyLeaseContract(models.Model):
else:
record.end_comparison = None
if record.actual_end_time < record.term_end_time:
record.end_comparison = 'red'
if record.actual_end_time == record.term_start_time:
record.is_equal = True
else: