diff --git a/yuthon_catering/data/yuthon_catering_cron.xml b/yuthon_catering/data/yuthon_catering_cron.xml index 1ab6cbc12..93cbbd08e 100644 --- a/yuthon_catering/data/yuthon_catering_cron.xml +++ b/yuthon_catering/data/yuthon_catering_cron.xml @@ -8,9 +8,9 @@ model.task_catering() - -1 + 1 days - + -1 diff --git a/yuthon_catering/models/yuthon_catering.py b/yuthon_catering/models/yuthon_catering.py index b18e30bf1..25a9873d6 100644 --- a/yuthon_catering/models/yuthon_catering.py +++ b/yuthon_catering/models/yuthon_catering.py @@ -118,6 +118,12 @@ class YuthonCatering(models.Model): def task_catering(self): today = fields.Date.today() + # 全局日级别防重:避免同一 cron 因并发或调度问题当天重复发送 + last_run_key = 'yuthon_catering.task_catering_last_run_date' + last_run = self.env['ir.config_parameter'].sudo().get_param(last_run_key) + if last_run == str(today): + return + tomorrow = today + timedelta(days=1) employee_ids = self._get_active_conf_employees() if not self._process_shift_days(today): @@ -129,6 +135,8 @@ class YuthonCatering(models.Model): ], limit=1) if not tomorrow_menu: return + # 真正开始发送前再写一次运行日期,防止并发重复 + self.env['ir.config_parameter'].sudo().set_param(last_run_key, str(today)) for emp in employee_ids: url = f"https://phone.thtzjt.com/phone/Restaurant/{emp.user_id.id}" self.sudo().env["wecom.apps"].sync_send_message_textcard(