This commit is contained in:
李鹏宇
2026-01-30 17:39:12 +08:00
6 changed files with 110 additions and 35 deletions
@@ -42,7 +42,7 @@ class OvertimeApprovals(models.Model):
rest_start_time = fields.Datetime(string="休息开始时间")
rest_end_time = fields.Datetime(string="休息结束时间")
end_week = fields.Char(string="星期", compute='_compute_weekday')
type_overtime = fields.Selection([('work', '工作日加班'), ('weekend', '周末加班'), ('holiday', '节假日加班')],
type_overtime = fields.Selection([('work', '工作日加班'), ('weekend', '公休日加班'), ('holiday', '法定日加班')],
string="加班类型", compute="_compute_overtime_type", store=True)
urgency_level = fields.Selection([('normal', '普件'), ('urgent', '急件'), ('emergency', '特急件')], string='紧急度',
default='normal')
@@ -169,21 +169,36 @@ class OvertimeApprovals(models.Model):
@api.depends('users_id', 'duration')
def _compute_overtime_hours(self):
for rec in self:
employee = rec.users_id.employee_ids
# 一个月加班时长不能超过36小时
first_day = fields.Date.today().replace(day=1)
vacation_report = self.env['yuthon.vacation.reports'].search([
('employee_id', '=', employee.id),
('vacation_date', '=', first_day),
], limit=1)
cop_leave = vacation_report.done_working_overtime * 8 if vacation_report else 0.0
if cop_leave + rec.duration > 36 and not rec.is_thwg:
rec.overtime_hours = 0.0
message = f'本月已加班时长已超过 36 小时'
raise ValidationError(message)
rec.overtime_hours = 0.0
if not rec.users_id:
continue
now = datetime.now() # 获取当前时间(datetime类型)
first_datetime = datetime(now.year, now.month, 1, 0, 0, 0)
if now.month == 12:
next_month_datetime = datetime(now.year + 1, 1, 1, 0, 0, 0)
else:
rec.overtime_hours = cop_leave
next_month_datetime = datetime(now.year, now.month + 1, 1, 0, 0, 0)
last_datetime = next_month_datetime - timedelta(seconds=1)
workflow_records = self.env['soong.workflow.record'].search([
('workflow_id.name', '=', '加班'),
('create_uid', '=', rec.users_id.id),
('approve_state', 'in', ['pending', 'end']),
])
total_overtime = 0.0
for workflow in workflow_records:
related_model = self.env[workflow.res_model].browse(workflow.res_id)
start_time = related_model.start_time
if first_datetime <= start_time <= last_datetime:
if related_model.duration:
total_overtime += related_model.duration
rec.overtime_hours = total_overtime
@api.constrains('users_id')
def _check_overtime_hours(self):
if self.overtime_hours + self.duration > 36 and not self.is_thwg:
message = _('本月已加班时长已超过 36 小时')
raise ValidationError(message)
@api.depends('start_time', 'end_time', 'attendance_id', 'rest_start_time', 'rest_end_time')
def _compute_duration(self):
@@ -407,31 +422,47 @@ class OvertimeApprovals(models.Model):
@api.depends('start_time', 'end_time')
def _compute_overtime_type(self):
for record in self:
current_date = datetime.today()
if record.start_time and record.end_time:
if record.start_time > record.end_time:
raise UserError("开始时间不能晚于结束时间")
start_date = fields.Datetime.from_string(record.start_time)
end_date = fields.Datetime.from_string(record.end_time)
current_year = (fields.Date.today() + timedelta(hours=8)).year
query_start = datetime(current_year, 1, 1, 0, 0, 0) - timedelta(hours=8)
query_end = datetime(current_year, 12, 31, 23, 59, 59) - timedelta(hours=8)
public_holidays = self.env['resource.calendar.leaves'].search([("calendar_id.name", "=", "行政考勤工作日"),
("date_from", ">=", query_start),
("date_from", "<=", query_end)])
for holiday in public_holidays:
holiday_start = fields.Datetime.from_string(holiday.date_from)
holiday_end = fields.Datetime.from_string(holiday.date_to)
if start_date <= holiday_end and end_date >= holiday_start:
record.type_overtime = 'holiday'
break
start_date = record.start_time.date()
current_year = current_date.year
original_year_start = datetime(current_year, 1, 1, 0, 0, 0)
original_year_end = datetime(current_year, 12, 31, 23, 59, 59)
query_start = original_year_start - timedelta(hours=8)
query_end = original_year_end - timedelta(hours=8)
calendar_leaves = self.env['resource.calendar.leaves'].sudo().search([
("calendar_id.name", "=", "行政考勤工作日"),
("date_from", ">=", query_start),
("date_from", "<=", query_end)
])
holidays_set = set()
shift_days_set = set()
statutory_set = set()
for leave in calendar_leaves:
if leave.holidays:
statutory_set.update(leave.holidays.split(','))
if leave.alternate_rest_day:
holidays_set.update(leave.alternate_rest_day.split(','))
if leave.shift_replacement_day:
shift_days_set.update(leave.shift_replacement_day.split(','))
date_str = start_date.strftime('%m月%d日')
date_str = self.remove_leading_zero(date_str)
is_weekend = start_date.weekday() in [5, 6]
if date_str in statutory_set:
record.type_overtime = 'holiday'
elif date_str in holidays_set or is_weekend:
record.type_overtime = 'weekend'
else:
if start_date.weekday() < 5 and end_date.weekday() < 5: # Not Saturday or Sunday
record.type_overtime = 'work'
elif start_date.weekday() >= 5 or end_date.weekday() >= 5: # Saturday or Sunday
record.type_overtime = 'weekend'
else:
record.type_overtime = False
record.type_overtime = 'work'
def remove_leading_zero(self, date_str):
month, day = date_str.split('月')
month = month.lstrip('0')
day = day.rstrip('日')
day = day.lstrip('0')
return f'{month}月{day}日'
class OvertimeUserLine(models.Model):
_name = 'overtime.user.line'
@@ -1,6 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<data noupdate="1">
<record forcecreate="True" id="property_update_manage_new" model="ir.cron">
<field name="name">定时任务:更新物业管理信息</field>
<field name="model_id" ref="model_yuthon_property"/>
<field name="state">code</field>
<field name="code">model.update_manage()</field>
<field eval="True" name="active"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="nextcall" eval="(DateTime.now()).strftime('%Y-%m-%d 01:00:00')"/>
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
</record>
<record forcecreate="True" id="property_is_new" model="ir.cron">
<field name="name">定时任务:触发只显示最新物业方法</field>
<field name="model_id" ref="model_yuthon_property"/>
@@ -13,6 +13,7 @@ class YuthonProperty(models.Model):
_order = 'first_letter'
name = fields.Text(string="资产名称")
tax = fields.Float(string="税率", default=0.09)
users_id = fields.Many2one('res.users', string="申请人", default=lambda self: self.env.user.id)
code = fields.Char(string="物业编号", default=lambda self: self.env['ir.sequence'].next_by_code('yuthon_property_message_code'))
referred_id = fields.Many2one('yuthon.lot.setting', string="地段")
@@ -222,6 +223,11 @@ class YuthonProperty(models.Model):
'equity_area': latest_title.equity_area,
})
def update_manage(self):
property_ids = self.env['yuthon.property'].search([])
for record in property_ids:
record.compute_information_fields()
@api.depends('manage_information_ids.start_time', 'manage_information_ids.end_date',
'manage_information_ids.precinct_id', 'manage_information_ids.tenure_type',
'manage_information_ids.management_area', 'manage_information_ids.rent_area',
@@ -72,6 +72,7 @@
<field name="tenure_type" invisible="1"/>
<field name="precinct_id" invisible="1"/>
<field name="asset_type_id" options="{'no_open': True}"/>
<field name="tax"/>
<field name="management_area" invisible="1"/>
<field name="rent_area" invisible="1"/>
<field name="equity_area" invisible="1"/>
@@ -325,6 +325,28 @@ class PropertyLeaseContract(models.Model):
employee_ids = fields.Many2many('hr.employee', string="当前经办人", compute='_compute_workflow')
approve_state = fields.Selection([("start", "草稿"), ("pending", "审批中"), ("end", "结束")], string="审批状态", compute='_compute_workflow')
@api.onchange('term_start_time')
def onchange_lessor_id(self):
if not self.term_start_time:
return
if not self.lease_ids:
return
property_id = self.lease_ids[0].address_id.id
manage_line_domain = [
('yuthon_property_id', '=', property_id),
('start_time', '<=', self.term_start_time),
'|',
('end_date', '=', False),
('end_date', '>=', self.term_start_time)
]
manage_line = self.env['manage.information.line'].search(
manage_line_domain,
order='start_time desc',
limit=1
)
if manage_line and manage_line.company_id:
self.lessor_id = manage_line.company_id.id
@api.depends('code')
def _compute_workflow(self):
for record in self:
@@ -2351,6 +2373,7 @@ class PropertyLeaseContractLine(models.Model):
accounting_id = fields.Many2one('property.accounting.approval', string="关联建设工程委托监理合同审批")
supervising_id = fields.Many2one('property.supervising.approval', string="关联建设工程施工合同审批")
address_id = fields.Many2one('yuthon.property', string="物业地址")
tax = fields.Float(related='address_id.tax',string="税率")
admin_line_id = fields.Many2one(related='address_id.admin_id', string="管理员", store=True)
property_area = fields.Float(related='address_id.rent_area', string="可租面积", store=True)
message_standard_id = fields.Many2one(related='address_id.message_standard_id', string="管理费标准", store=True)
@@ -556,6 +556,7 @@
<field name="property_area"/>
<field name="evaluate_unit_price"/>
<field name="message_standard_id"/>
<field name="tax"/>
<field name="admin_line_id" options="{'no_open': True}"/>
<button name="open_record" string="详情" type="object" class="btn-primary"/>
</tree>