diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2025-09-16 09:09:47 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2025-09-16 09:09:47 +0000 |
| commit | 07d8129d96f1e48838e27c33ad762673a04d465e (patch) | |
| tree | b3dc5f07488ddb86a60dc917ea5230680b04591e /indoteknik_custom/models/report_logbook_sj.py | |
| parent | 07a46fdbd16d72e60895d38047b6bb2e344dc18f (diff) | |
| parent | af7fc5db50d7c3f78b70a2b75186db4b4c1f3674 (diff) | |
Merged in sj_tele (pull request #416)
Sj tele
Diffstat (limited to 'indoteknik_custom/models/report_logbook_sj.py')
| -rw-r--r-- | indoteknik_custom/models/report_logbook_sj.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/indoteknik_custom/models/report_logbook_sj.py b/indoteknik_custom/models/report_logbook_sj.py index 66edbf99..b45eab03 100644 --- a/indoteknik_custom/models/report_logbook_sj.py +++ b/indoteknik_custom/models/report_logbook_sj.py @@ -4,6 +4,11 @@ from odoo import models, fields, api from odoo.exceptions import UserError from pytz import timezone from datetime import datetime +import requests +import json +import logging + +_logger = logging.getLogger(__name__) class ReportLogbookSJ(models.Model): _name = 'report.logbook.sj' @@ -83,6 +88,44 @@ class ReportLogbookSJ(models.Model): from odoo import models, fields, api + + + def action_send_to_telegram(self): + + entries = [] + pickings = self.report_logbook_sj_line.mapped('picking_id') + for p in pickings: + if p: + entries.append((p.name, p.id)) + + fallback_names = [l.name for l in self.report_logbook_sj_line if not l.picking_id and l.name] + if fallback_names: + picks = self.env['stock.picking'].search([('name', 'in', list(set(fallback_names)))]) + name2id = {p.name: p.id for p in picks} + for n in fallback_names: + entries.append((n, name2id.get(n))) + + seen, unique_entries = set(), [] + for name, pid in entries: + key = pid or name + if key and key not in seen: + seen.add(key) + unique_entries.append((name, pid)) + + header = f"{self.env.user.name} sudah mengisi di Logbook SJ Report:\n" + body = "\n".join(f"{name} ({pid or '-'})" for name, pid in unique_entries) if unique_entries else "- (tidak ada)" + text = header + body + + bot_mqdd = '8203414501:AAHy_XwiUAVrgRM2EJzW7sZx9npRLITZpb8' + chat_id_mqdd = '-4885333032' + apiURL = f'https://api.telegram.org/bot{bot_mqdd}/sendMessage' + try: + hehe = requests.post(apiURL, json={'chat_id': chat_id_mqdd, 'text': text}) + _logger.info(hehe) + except Exception as e: + print(e) + + class ReportLogbookSJLine(models.Model): _name = 'report.logbook.sj.line' _order = 'sequence, id' # urut default di UI & ORM (drag pakai sequence) |
