summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/sj_tele.py
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2025-11-19 14:49:01 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2025-11-19 14:49:01 +0700
commitbb2be920076aabc49b4f9fdd896d14e096e633eb (patch)
tree588196ba53fb7e41d96a61272bdb74b4821fe661 /indoteknik_custom/models/sj_tele.py
parent9c4f131ffaf37ca47a78b320a68f7de4e846ecfb (diff)
parent58623e9509789381dbe334969de647b4ad0302a4 (diff)
Merge branch 'odoo-backup' into locatorlocator
# Conflicts: # indoteknik_custom/models/__init__.py # indoteknik_custom/models/stock_move.py # indoteknik_custom/security/ir.model.access.csv # indoteknik_custom/views/stock_picking.xml
Diffstat (limited to 'indoteknik_custom/models/sj_tele.py')
-rw-r--r--indoteknik_custom/models/sj_tele.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/indoteknik_custom/models/sj_tele.py b/indoteknik_custom/models/sj_tele.py
index 3ef4b877..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__)
@@ -18,8 +19,18 @@ 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)
+
+ @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}'
@@ -27,7 +38,11 @@ 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')
+ # Select Data
+ 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 +98,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"