餐饮定时任务
This commit is contained in:
@@ -226,6 +226,50 @@ class YuthonCatering(models.Model):
|
||||
# 返回处理后的日期字符串
|
||||
return f'{month}月{day}日'
|
||||
|
||||
# 定时任务:每天晙21点自动补全当天缺失的餐饮数据,再自动确认
|
||||
def cron_fill_today_missing(self):
|
||||
today = fields.Date.today()
|
||||
# 检查当天是否有菜单记录,没有则跳过
|
||||
menu_today = self.env['yuthon.menu.setting'].search([('menu_date', '=', today)], limit=1)
|
||||
if not menu_today:
|
||||
return
|
||||
conf_records = self.env['yuthon.catering.conf'].search([])
|
||||
if not conf_records:
|
||||
return
|
||||
employee_ids = conf_records.mapped('employee_ids')
|
||||
if not employee_ids:
|
||||
return
|
||||
create_vals = []
|
||||
for employee in employee_ids:
|
||||
existing = self.search([
|
||||
('employee_id', '=', employee.id),
|
||||
('date', '=', today),
|
||||
], limit=1)
|
||||
if not existing:
|
||||
create_vals.append({
|
||||
'date': today,
|
||||
'employee_id': employee.id,
|
||||
'state': 'unconfirmed',
|
||||
})
|
||||
if create_vals:
|
||||
self.create(create_vals)
|
||||
# 补全后自动确认当天所有未确认记录
|
||||
self.cron_auto_confirm_today()
|
||||
|
||||
# 定时任务:每天晙21点把当天未确认的餐饮记录自动改为已确认
|
||||
def cron_auto_confirm_today(self):
|
||||
today = fields.Date.today()
|
||||
# 检查当天是否有菜单记录,没有则跳过
|
||||
menu_today = self.env['yuthon.menu.setting'].search([('menu_date', '=', today)], limit=1)
|
||||
if not menu_today:
|
||||
return
|
||||
unconfirmed_records = self.search([
|
||||
('date', '=', today),
|
||||
('state', '=', 'unconfirmed'),
|
||||
])
|
||||
if unconfirmed_records:
|
||||
unconfirmed_records.write({'state': 'confirmed'})
|
||||
|
||||
# 定义定时任务方法,每天九点半发送消息提醒
|
||||
def cron_send_message(self):
|
||||
"""
|
||||
@@ -236,7 +280,11 @@ class YuthonCatering(models.Model):
|
||||
local_time = current_utc_time + timedelta(hours=8)
|
||||
h = local_time.hour
|
||||
m = local_time.minute
|
||||
|
||||
# 检查明天是否有菜单记录,没有则跳过
|
||||
tomorrow = fields.Date.today() + timedelta(days=1)
|
||||
menu_tomorrow = self.env['yuthon.menu.setting'].search([('menu_date', '=', tomorrow)], limit=1)
|
||||
if not menu_tomorrow:
|
||||
return
|
||||
# 检查是否是上午9:30左右
|
||||
if not (h == 9 and 25 <= m <= 35): # 9:25-9:35之间
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user