From 416823e12f3b76b440e504bf170c8c27c02caca3 Mon Sep 17 00:00:00 2001 From: HafidBuroiroh Date: Sat, 1 Nov 2025 09:12:16 +0700 Subject: coba tele --- indoteknik_custom/models/sourcing_job_order.py | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/indoteknik_custom/models/sourcing_job_order.py b/indoteknik_custom/models/sourcing_job_order.py index 5fd3067b..7b6f6569 100644 --- a/indoteknik_custom/models/sourcing_job_order.py +++ b/indoteknik_custom/models/sourcing_job_order.py @@ -568,6 +568,35 @@ class SourcingJobOrder(models.Model): return {'type': 'ir.actions.client', 'tag': 'reload'} + def action_send_untaken_to_telegram(self): + bot_sjo = '8335015210:AAGbObP0jQf7ptyqJhYdBYn5Rm0CWOd_yIM' + chat_sjo = '-5081839952' + api_base = f'https://api.telegram.org/bot{bot_sjo}' + + data = self.search([('state', '=', 'draft')], order='create_date asc') + if not data: + text = "✅ tidak ada Sourcing Job (SJO) yang berstatus Untaken Saat ini" + else: + text = "⚠️ *Daftar SJO yang masih Untaken:*\n" + for sjo in data: + text += f"- {sjo.name} | Requested By: {sjo.create_uid.name}\n" + + payload = { + 'chat_id': chat_sjo, + 'text': text + } + + try: + response = requests.post(f"{api_base}/sendMessage", data=payload, timeout=20) + if response.status_code == 200: + _logger.info(f"✅ Telegram notification sent successfully at {datetime.now()}") + else: + _logger.error(f"❌ Failed to send Telegram message: {response.text}") + except Exception as e: + _logger.error(f"⚠️ Error while sending Telegram message: {str(e)}") + + return True + class SourcingJobOrderLine(models.Model): _name = 'sourcing.job.order.line' -- cgit v1.2.3