summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorMiqdad <ahmadmiqdad27@gmail.com>2025-09-04 15:26:48 +0700
committerMiqdad <ahmadmiqdad27@gmail.com>2025-09-04 15:26:48 +0700
commit4da5af474edea6a61453dcc8485cefaa7fe6dd42 (patch)
tree0c26f2de8a77d9e0dce3802090404564d64ca4dc /indoteknik_custom/models
parentd956020b6b588e5216f1238b82f87b6fb35b2afc (diff)
<Miqdad> Done x
Diffstat (limited to 'indoteknik_custom/models')
-rwxr-xr-xindoteknik_custom/models/__init__.py3
-rw-r--r--indoteknik_custom/models/report_logbook_sj.py51
-rw-r--r--indoteknik_custom/models/sj_tele.py59
3 files changed, 69 insertions, 44 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index 3a9f9312..c0aa7085 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -156,4 +156,5 @@ from . import refund_sale_order
# from . import patch
from . import tukar_guling
from . import tukar_guling_po
-from . import update_date_planned_po_wizard \ No newline at end of file
+from . import update_date_planned_po_wizard
+from . import sj_tele \ No newline at end of file
diff --git a/indoteknik_custom/models/report_logbook_sj.py b/indoteknik_custom/models/report_logbook_sj.py
index 85ab755d..6915ad9b 100644
--- a/indoteknik_custom/models/report_logbook_sj.py
+++ b/indoteknik_custom/models/report_logbook_sj.py
@@ -39,6 +39,10 @@ class ReportLogbookSJ(models.Model):
count_line = fields.Char(string='Count Line', compute='_compute_count_line')
+ def write(self, vals):
+ self.action_send_to_telegram()
+ res = super(ReportLogbookSJ, self).write(vals)
+
@api.depends('report_logbook_sj_line')
def _compute_count_line(self):
for rec in self:
@@ -67,49 +71,10 @@ class ReportLogbookSJ(models.Model):
raise UserError('Hanya Accounting yang bisa Approve')
- @api.model
- def cron_daily_logbook_gap_to_telegram(self):
- bot_mqdd = '8203414501:AAHy_XwiUAVrgRM2EJzW7sZx9npRLITZpb8'
- chat_id_mqdd = '-4885333032'
- apiURL = f'https://api.telegram.org/bot{bot_mqdd}/sendMessage'
-
- # ambil dari 1 Februari 2024 (UTC)
- dt_from = datetime(2024, 2, 1, 0, 0, 0)
-
- self.env.cr.execute("""
- SELECT sp.id, sp.name
- FROM stock_picking sp
- LEFT JOIN report_logbook_sj_line rlsl
- ON rlsl.picking_id = sp.id
- OR (rlsl.name IS NOT NULL AND rlsl.name = sp.name)
- WHERE sp.picking_type_id = 29
- AND sp.state = 'done'
- AND sp.create_date >= %s
- AND rlsl.id IS NULL
- ORDER BY sp.create_date ASC limit 20
- """, (dt_from,))
- rows = self.env.cr.fetchall()
-
- if not rows:
- return True
-
- header = "berikut merupakan nomor picking yang belum ada di Logbook SJ report:\n"
- body = "\n".join(f"{name} ({pid})" for pid, name in rows if name)
- text = header + body
-
- # kirim satu pesan (tanpa pemotongan)
- try:
- resp = requests.post(apiURL, json={'chat_id': chat_id_mqdd, 'text': text}, timeout=15)
- resp.raise_for_status()
- except requests.HTTPError:
- _logger.error("Telegram response: %s", resp.text) # <— LIHAT DESKRIPSINYA DI LOG
- raise
- except Exception as e:
- # log saja; biar cron tidak crash
- logging.getLogger(__name__).exception("Gagal kirim Telegram: %s", e)
- return True
-
def action_send_to_telegram(self):
+ user_logistic = self.env.ref('indoteknik_custom.group_role_logistic')
+ if self.user != user_logistic:
+ return
entries = []
pickings = self.report_logbook_sj_line.mapped('picking_id')
for p in pickings:
@@ -130,7 +95,7 @@ class ReportLogbookSJ(models.Model):
seen.add(key)
unique_entries.append((name, pid))
- header = "berikut merupakan nomor picking yang belum ada di Logbook SJ report:\n"
+ header = f"Saya {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
diff --git a/indoteknik_custom/models/sj_tele.py b/indoteknik_custom/models/sj_tele.py
new file mode 100644
index 00000000..c359d6d8
--- /dev/null
+++ b/indoteknik_custom/models/sj_tele.py
@@ -0,0 +1,59 @@
+from odoo import models, fields, api
+import requests
+import json
+import logging
+
+_logger = logging.getLogger(__name__)
+
+class SjTele(models.Model):
+ _name = 'sj.tele'
+ _description = 'sj.tele'
+
+
+ picking_id = fields.Many2one('stock.picking', string='Picking')
+ picking_name = fields.Char(string='Picking Name')
+ create_date = fields.Datetime(string='Create Date')
+
+ @api.model
+ def woi(self):
+ bot_mqdd = '8203414501:AAHy_XwiUAVrgRM2EJzW7sZx9npRLITZpb8'
+ chat_id_mqdd = '-4885333032'
+ apiURL = f'https://api.telegram.org/bot{bot_mqdd}/sendMessage'
+
+ self.env.cr.execute("""
+ SELECT
+ COALESCE(sp.id, st.picking_id) AS pid,
+ COALESCE(sp.name, st.picking_name) AS pname
+ FROM sj_tele st
+ LEFT JOIN stock_picking sp
+ ON sp.id = st.picking_id
+ LEFT JOIN report_logbook_sj_line rlsl
+ ON (rlsl.picking_id = COALESCE(sp.id, st.picking_id))
+ OR (rlsl.name IS NOT NULL AND rlsl.name = COALESCE(sp.name, st.picking_name))
+ WHERE rlsl.id IS NULL
+ AND COALESCE(sp.name, st.picking_name) IS NOT NULL
+ ORDER BY st.create_date ASC
+ LIMIT 20
+ """)
+ rows = self.env.cr.fetchall()
+
+ if not rows:
+ _logger.info("SJ Tele: tidak ada data untuk dikirim (staging kosong atau semua sudah di logbook).")
+ text = "Selamat anda menamatkan Logbook SJ Report"
+ try:
+ resp = requests.post(apiURL, json={'chat_id': chat_id_mqdd, 'text': text}, timeout=15)
+ except Exception as e:
+ logging.getLogger(__name__).exception("Gagal kirim Telegram: %s", e)
+ return True
+
+ header = "Berikut merupakan nomor BU/OUT yang belum ada di Logbook SJ report:\n"
+ body = "\n".join(f"{name} ({pid})" for pid, name in rows if name)
+ text = header + body
+ try:
+ resp = requests.post(apiURL, json={'chat_id': chat_id_mqdd, 'text': text}, timeout=15)
+ except requests.HTTPError:
+ _logger.error("Telegram response: %s", resp.text)
+ raise
+ except Exception as e:
+ logging.getLogger(__name__).exception("Gagal kirim Telegram: %s", e)
+ return True \ No newline at end of file