From a1862d78377710020c40361401af79766ea9ca70 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Wed, 22 Oct 2025 11:48:36 +0700 Subject: fix sj tele message sent multiple chat bubble with same message --- indoteknik_custom/models/sj_tele.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models/sj_tele.py') diff --git a/indoteknik_custom/models/sj_tele.py b/indoteknik_custom/models/sj_tele.py index 3ef4b877..d3d7dfce 100644 --- a/indoteknik_custom/models/sj_tele.py +++ b/indoteknik_custom/models/sj_tele.py @@ -18,6 +18,7 @@ class SjTele(models.Model): sale_name = fields.Char(string='Sale Name') create_date = fields.Datetime(string='Create Date') date_doc_kirim = fields.Datetime(string='Tanggal Kirim SJ') + is_sent = fields.Boolean(default=False) def woi(self): bot_mqdd = '8203414501:AAHy_XwiUAVrgRM2EJzW7sZx9npRLITZpb8' @@ -27,7 +28,9 @@ class SjTele(models.Model): # chat_id_testing = '-4920864331' # api_testing = f'https://api.telegram.org/bot{bot_testing}' - data = self.search([], order='create_date asc') + data = self.search([('is_sent', '=', False)], order='create_date asc') + # Old + # data = self.search([], order='create_date asc') if not data: text = "✅ tidak ada data (semua sudah tercatat)." @@ -83,6 +86,9 @@ class SjTele(models.Model): _logger.exception("Gagal kirim Telegram (batch %s-%s): %s", i + 1, min(i + BUB, len(lines)), e) time.sleep(5) # jeda kecil biar rapi & aman rate limit + # Set sent = true ketika sudah terkirim + data.write({'is_sent': True}) + return True # header = "Berikut merupakan nomor BU/OUT yang belum ada di Logbook SJ report:\n" -- cgit v1.2.3 From 9f916d880c5d061ee2ba66a80d26fbca76355054 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Wed, 22 Oct 2025 11:49:37 +0700 Subject: fix sj tele message sent multiple chat bubble with same message --- indoteknik_custom/models/sj_tele.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indoteknik_custom/models/sj_tele.py') diff --git a/indoteknik_custom/models/sj_tele.py b/indoteknik_custom/models/sj_tele.py index d3d7dfce..53ba26fc 100644 --- a/indoteknik_custom/models/sj_tele.py +++ b/indoteknik_custom/models/sj_tele.py @@ -28,7 +28,9 @@ class SjTele(models.Model): # chat_id_testing = '-4920864331' # api_testing = f'https://api.telegram.org/bot{bot_testing}' + # Select Data data = self.search([('is_sent', '=', False)], order='create_date asc') + # Old # data = self.search([], order='create_date asc') -- cgit v1.2.3 From 0e026757427842dc865a5cbf17f2e3d85a30875c Mon Sep 17 00:00:00 2001 From: Miqdad Date: Mon, 17 Nov 2025 17:10:38 +0700 Subject: prevent schedule action --- indoteknik_custom/models/sj_tele.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'indoteknik_custom/models/sj_tele.py') diff --git a/indoteknik_custom/models/sj_tele.py b/indoteknik_custom/models/sj_tele.py index 53ba26fc..ed363f59 100644 --- a/indoteknik_custom/models/sj_tele.py +++ b/indoteknik_custom/models/sj_tele.py @@ -5,6 +5,7 @@ import json import logging, subprocess import time from collections import OrderedDict +import socket _logger = logging.getLogger(__name__) @@ -20,7 +21,16 @@ class SjTele(models.Model): date_doc_kirim = fields.Datetime(string='Tanggal Kirim SJ') is_sent = fields.Boolean(default=False) + @staticmethod + def is_local_env(): + hostname = socket.gethostname().lower() + keywords = ['andri', 'miqdad', 'fin', 'stephan', 'hafid', 'nathan'] + return any(keyword in hostname for keyword in keywords) + def woi(self): + if self.is_local_env(): + _logger.warning("📪 Local environment detected — skip sending email reminders.") + return bot_mqdd = '8203414501:AAHy_XwiUAVrgRM2EJzW7sZx9npRLITZpb8' chat_id_mqdd = '-1003087280519' api_base = f'https://api.telegram.org/bot{bot_mqdd}' -- cgit v1.2.3