Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
pengyuthon
2026-03-09 19:04:17 +08:00
4 changed files with 88 additions and 26 deletions
+51
View File
@@ -303,6 +303,57 @@ class RoomBooking(models.Model):
room_name=booking.room_id.name
))
@api.model
def create(self, vals):
"""创建会议后同步生成日程"""
import logging
_logger = logging.getLogger(__name__)
booking = super(RoomBooking, self).create(vals)
# 同步生成yuthon.will.task记录
if booking:
try:
# 处理所有可能为空的字段
if not booking.start_datetime:
_logger.error('会议开始时间为空,无法创建日程')
return booking
# 提取参会人员(从room_users_ids转换为hr.employee)
employee_records = self.env['hr.employee'].search([('user_id', 'in', booking.room_users_ids.ids)]) if booking.room_users_ids else self.env['hr.employee']
# 确保name字段有值
task_name = booking.name or f'会议_{booking.start_datetime.date()}'
# 确保room_id有值
address = booking.room_id.name if booking.room_id else ''
# 确保meeting_data有值
remarks = booking.meeting_data or ''
# 确保room_users_ids有值
room_users_ids = booking.room_users_ids.ids if booking.room_users_ids else []
# 确保self_users_ids有值
self_users_ids = booking.self_users_ids.ids if booking.self_users_ids else []
# 创建日程记录
task = self.env['yuthon.will.task'].create({
'name': task_name,
'start_date': booking.start_datetime.date(),
'task_type': 'meet',
'room_booking_id': booking.id,
'employee_ids': [(6, 0, employee_records.ids)] if employee_records else [(5, 0, 0)],
'task_state': 'will',
'address': address,
'remarks': remarks,
'users_ids': [(6, 0, room_users_ids)] if room_users_ids else [(5, 0, 0)],
'self_users_ids': [(6, 0, self_users_ids)] if self_users_ids else [(5, 0, 0)],
})
_logger.info('日程创建成功,ID: %s, 会议ID: %s', task.id, booking.id)
except Exception as e:
_logger.error('创建日程失败: %s', str(e))
return booking
# ------------------------------------------------------
# CRUD / ORM
# ------------------------------------------------------
+2 -2
View File
@@ -10,8 +10,8 @@ class YuthonCatering(models.Model):
week_day = fields.Char(string='星期', compute='_compute_week_day', store=True)
dept_id = fields.Many2one(string='部门', comodel_name='hr.department', related='employee_id.department_id', store=True)
employee_id = fields.Many2one(string='员工', comodel_name='hr.employee', required=True)
breakfast = fields.Boolean(string='早餐', default=False)
lunch = fields.Boolean(string='午餐', default=False)
breakfast = fields.Boolean(string='早餐', default=False, group_operator='count_true')
lunch = fields.Boolean(string='午餐', default=False, group_operator='count_true')
menu_day_id = fields.Many2one('yuthon.menu.setting', string='菜单')
amount = fields.Float(string='结算费用', compute='_compute_amount', store=True)
@@ -941,8 +941,7 @@ class AppletAttendance(Controller):
# 电表数据
electric_result_dict = {}
# 处理电表
duplicate_checker = {} # 用于记录已处理的 (code, unit_number) 组合
for electric in electric_records:
property_infos = electric.yuthon_property_ids if electric.yuthon_property_ids else [None]
for property_info in property_infos:
@@ -959,28 +958,39 @@ class AppletAttendance(Controller):
room = ''
address = ''
employee_name = ''
state = electric.state
electric_value = {
'id': electric.id,
'current_read': electric.current_read,
'code': electric.archives_id.name or '',
'last_dosage': electric.last_dosage or 0,
'mater_data': str(electric.meter_date) if electric.meter_date else '',
'last_mater_data': str(electric.last_meter) if electric.last_meter else '',
'meter_type': 'electric',
'employee_name': employee_name,
'address': address,
'building': '天河商贸大厦',
'floor': floor,
'room': room,
'epitope_values': electric.epitope_values_id.name,
'unit_number': electric.unit_number,
'state': electric.state, # 状态 reading unreading
'last_read': electric.last_read,
}
electric_result_dict.setdefault(state, {}).setdefault(building, {}).setdefault(floor, []).append(
electric_value)
state = electric.state
code = electric.archives_id.name or ''
unit_number = electric.unit_number or ''
# 构建唯一标识键(核心去重逻辑)
unique_key = (code, unit_number)
# 检查是否已处理过该唯一键,未处理过才添加
if unique_key not in duplicate_checker:
# 标记为已处理
duplicate_checker[unique_key] = True
electric_value = {
'id': electric.id,
'current_read': electric.current_read,
'code': code,
'last_dosage': electric.last_dosage or 0,
'mater_data': str(electric.meter_date) if electric.meter_date else '',
'last_mater_data': str(electric.last_meter) if electric.last_meter else '',
'meter_type': 'electric',
'employee_name': employee_name,
'address': address,
'building': building,
'floor': floor,
'room': room,
'epitope_values': electric.epitope_values_id.name if electric.epitope_values_id else '',
'unit_number': electric.unit_number,
'state': state,
'last_read': electric.last_read,
}
# 按层级添加到结果字典
electric_result_dict.setdefault(state, {}) \
.setdefault(building, {}) \
.setdefault(floor, []).append(electric_value)
electric_result = []
for state, building_dict in electric_result_dict.items():
@@ -111,11 +111,12 @@ class YuthonShiftApproval(models.Model):
def _get_slot(self, resource_id, date):
if not resource_id or not date:
return False
return self.env['planning.slot'].search([
slot = self.env['planning.slot'].search([
('resource_id', '=', resource_id),
('start_datetime', '>=', f"{date} 00:00:00"),
('end_datetime', '<=', f"{date} 23:59:59")
], limit=1)
return slot
@api.onchange('is_issues')
def _onchange_is_issues(self):