diff options
| author | HafidBuroiroh <hafidburoiroh09@gmail.com> | 2025-11-01 09:12:16 +0700 |
|---|---|---|
| committer | HafidBuroiroh <hafidburoiroh09@gmail.com> | 2025-11-01 09:12:16 +0700 |
| commit | 416823e12f3b76b440e504bf170c8c27c02caca3 (patch) | |
| tree | f9b916053b6404266e8aef5d7492171140ad7a9c | |
| parent | ac64cc0792558e7c4922c6fc9c2f0a4c5c532967 (diff) | |
coba tele
| -rw-r--r-- | indoteknik_custom/models/sourcing_job_order.py | 29 |
1 files changed, 29 insertions, 0 deletions
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' |
