From b88d85e06ca4789e519b3e66cd047d92aa82a7dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= <9664676+pengyuthon@user.noreply.gitee.com> Date: Thu, 25 Jun 2026 18:48:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yuthon_catering/data/yuthon_catering_cron.xml | 4 ++-- yuthon_catering/models/yuthon_catering.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) 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(