From d956020b6b588e5216f1238b82f87b6fb35b2afc Mon Sep 17 00:00:00 2001 From: Miqdad Date: Wed, 3 Sep 2025 18:05:00 +0700 Subject: send bu out to tele --- indoteknik_custom/models/report_logbook_sj.py | 83 ++++++++++++++++++++++++ indoteknik_custom/views/report_logbook_sj.xml | 91 +++++++++++++++------------ 2 files changed, 133 insertions(+), 41 deletions(-) diff --git a/indoteknik_custom/models/report_logbook_sj.py b/indoteknik_custom/models/report_logbook_sj.py index 17119c12..85ab755d 100644 --- a/indoteknik_custom/models/report_logbook_sj.py +++ b/indoteknik_custom/models/report_logbook_sj.py @@ -2,6 +2,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' @@ -60,6 +65,84 @@ class ReportLogbookSJ(models.Model): self.state = 'terima_semua' else: 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): + 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 = "berikut merupakan nomor picking yang belum ada 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' diff --git a/indoteknik_custom/views/report_logbook_sj.xml b/indoteknik_custom/views/report_logbook_sj.xml index 94f6c2ab..6458af40 100644 --- a/indoteknik_custom/views/report_logbook_sj.xml +++ b/indoteknik_custom/views/report_logbook_sj.xml @@ -12,9 +12,10 @@ + - + report.logbook.sj.line.tree @@ -42,50 +43,48 @@
-
-
+
+ - - - - - - - - - - - - + + + - - - - - - -
- - -
+ + + + + + + +
+ + + + + + +
+ + +
- report.logbook.sj.search.view - report.logbook.sj - - - - - - + report.logbook.sj.search.view + report.logbook.sj + + + + + + Report Logbook SJ @@ -94,9 +93,19 @@ tree,form - + + + + + Daily Logbook SJ Gap → Telegram + + code + model.cron_daily_logbook_gap_to_telegram() + 1 + days + -1 + + False + + \ No newline at end of file -- cgit v1.2.3 From 4da5af474edea6a61453dcc8485cefaa7fe6dd42 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Thu, 4 Sep 2025 15:26:48 +0700 Subject: Done x --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/__init__.py | 3 +- indoteknik_custom/models/report_logbook_sj.py | 51 ++++------------------ indoteknik_custom/models/sj_tele.py | 59 ++++++++++++++++++++++++++ indoteknik_custom/security/ir.model.access.csv | 3 +- indoteknik_custom/views/sj_tele.xml | 15 +++++++ 6 files changed, 87 insertions(+), 45 deletions(-) create mode 100644 indoteknik_custom/models/sj_tele.py create mode 100644 indoteknik_custom/views/sj_tele.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 31685005..d852d2e1 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -177,6 +177,7 @@ 'views/tukar_guling_po.xml', # 'views/refund_sale_order.xml', 'views/update_date_planned_po_wizard_view.xml', + 'views/sj_tele.xml' ], 'demo': [], 'css': [], 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 diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 3a320510..0d2789b3 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -195,4 +195,5 @@ access_tukar_guling_mapping_koli_all_users,tukar.guling.mapping.koli.all.users,m access_purchase_order_update_date_wizard,access.purchase.order.update.date.wizard,model_purchase_order_update_date_wizard,base.group_user,1,1,1,1 access_sync_promise_date_wizard,access.sync.promise.date.wizard,model_sync_promise_date_wizard,base.group_user,1,1,1,1 access_sync_promise_date_wizard_line,access.sync.promise.date.wizard.line,model_sync_promise_date_wizard_line,base.group_user,1,1,1,1 -access_change_date_planned_wizard,access.change.date.planned.wizard,model_change_date_planned_wizard,,1,1,1,1 \ No newline at end of file +access_change_date_planned_wizard,access.change.date.planned.wizard,model_change_date_planned_wizard,,1,1,1,1 +access_sj_tele,access.sj.tele,model_sj_tele,base.group_system,1,1,1,1 \ No newline at end of file diff --git a/indoteknik_custom/views/sj_tele.xml b/indoteknik_custom/views/sj_tele.xml new file mode 100644 index 00000000..cefcc968 --- /dev/null +++ b/indoteknik_custom/views/sj_tele.xml @@ -0,0 +1,15 @@ + + + + SJ TELE + + code + model.woi() + 1 + days + -1 + + False + + + \ No newline at end of file -- cgit v1.2.3 From dd2bc67bbdaa771adf6bbedc01ba23a98ea03574 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Thu, 4 Sep 2025 15:46:05 +0700 Subject: Gk jadi --- indoteknik_custom/models/report_logbook_sj.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/indoteknik_custom/models/report_logbook_sj.py b/indoteknik_custom/models/report_logbook_sj.py index 6915ad9b..e67ea724 100644 --- a/indoteknik_custom/models/report_logbook_sj.py +++ b/indoteknik_custom/models/report_logbook_sj.py @@ -39,10 +39,6 @@ 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: @@ -51,6 +47,8 @@ class ReportLogbookSJ(models.Model): @api.model def create(self, vals): vals['name'] = self.env['ir.sequence'].next_by_code('report.logbook.sj') or '0' + # if self.env.user.has_group('indoteknik_custom.group_role_logistic'): + # self.action_send_to_telegram() result = super(ReportLogbookSJ, self).create(vals) return result @@ -72,9 +70,7 @@ class ReportLogbookSJ(models.Model): 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: @@ -95,7 +91,7 @@ class ReportLogbookSJ(models.Model): seen.add(key) unique_entries.append((name, pid)) - header = f"Saya {self.env.user.name} sudah mengisi di Logbook SJ Report:\n" + 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 -- cgit v1.2.3 From 666232252b4f5c5626bb5f276f645d4989495fa1 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Thu, 4 Sep 2025 18:38:12 +0700 Subject: Add SO --- indoteknik_custom/models/sj_tele.py | 60 +++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/indoteknik_custom/models/sj_tele.py b/indoteknik_custom/models/sj_tele.py index c359d6d8..50e47e78 100644 --- a/indoteknik_custom/models/sj_tele.py +++ b/indoteknik_custom/models/sj_tele.py @@ -11,49 +11,43 @@ class SjTele(models.Model): picking_id = fields.Many2one('stock.picking', string='Picking') + sale_id = fields.Many2one('sale.order', string='Sales Order') picking_name = fields.Char(string='Picking Name') create_date = fields.Datetime(string='Create Date') - @api.model - def woi(self): + 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" + api_base = f'https://api.telegram.org/bot{bot_mqdd}' + + data = self.search([], order='create_date asc', limit=15) + + if not data: + text = "Berikut merupakan nomor BU/OUT yang belum ada di Logbook SJ report:\nāœ… tidak ada data (semua sudah tercatat)." try: - resp = requests.post(apiURL, json={'chat_id': chat_id_mqdd, 'text': text}, timeout=15) + r = requests.post(api_base + "/sendMessage", + json={'chat_id': chat_id_mqdd, 'text': text}, + timeout=20) + r.raise_for_status() except Exception as e: - logging.getLogger(__name__).exception("Gagal kirim Telegram: %s", e) + _logger.exception("Gagal kirim Telegram (no data): %s", e) return True + lines = [] + for rec in data: + name = rec.picking_name or (rec.picking_id.name if rec.picking_id else '') + pid = rec.picking_id.id if rec.picking_id else '-' + so = rec.sale_id.name if rec.sale_id else '-' + if name: + lines.append(f"{name} - {so} ({pid})") + 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 + text = header + "\n".join(lines) + 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 + r = requests.post(api_base + "/sendMessage", + json={'chat_id': chat_id_mqdd, 'text': text}) + r.raise_for_status() except Exception as e: - logging.getLogger(__name__).exception("Gagal kirim Telegram: %s", e) + _logger.exception("Gagal kirim Telegram: %s", e) return True \ No newline at end of file -- cgit v1.2.3 From cae2e6978066469505167da9469519ea2de14cab Mon Sep 17 00:00:00 2001 From: Miqdad Date: Fri, 5 Sep 2025 07:27:44 +0700 Subject: oke --- indoteknik_custom/models/sj_tele.py | 1 + 1 file changed, 1 insertion(+) diff --git a/indoteknik_custom/models/sj_tele.py b/indoteknik_custom/models/sj_tele.py index 50e47e78..9559a541 100644 --- a/indoteknik_custom/models/sj_tele.py +++ b/indoteknik_custom/models/sj_tele.py @@ -13,6 +13,7 @@ class SjTele(models.Model): picking_id = fields.Many2one('stock.picking', string='Picking') sale_id = fields.Many2one('sale.order', string='Sales Order') picking_name = fields.Char(string='Picking Name') + sale_name = fields.Char(string='Sale Name') create_date = fields.Datetime(string='Create Date') def woi(self): -- cgit v1.2.3 From ba8b646073ee09b962d58b24b340f47d18aa611f Mon Sep 17 00:00:00 2001 From: IT Fixcomart Date: Fri, 5 Sep 2025 00:54:20 +0000 Subject: sj_tele.py edited online with Bitbucket --- indoteknik_custom/models/sj_tele.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/sj_tele.py b/indoteknik_custom/models/sj_tele.py index 9559a541..246c0f43 100644 --- a/indoteknik_custom/models/sj_tele.py +++ b/indoteknik_custom/models/sj_tele.py @@ -37,8 +37,8 @@ class SjTele(models.Model): lines = [] for rec in data: name = rec.picking_name or (rec.picking_id.name if rec.picking_id else '') - pid = rec.picking_id.id if rec.picking_id else '-' - so = rec.sale_id.name if rec.sale_id else '-' + pid = rec.picking_id.id if rec.picking_id else '' + so = rec.sale_id.name or rec.sale_name or '' if name: lines.append(f"{name} - {so} ({pid})") -- cgit v1.2.3 From f82137850801cb8d4c8cb482f607b68181ef1cb6 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Sat, 6 Sep 2025 08:33:49 +0700 Subject: carte --- indoteknik_custom/models/sj_tele.py | 27 ++++++++++++++++++++++++++- indoteknik_custom/views/sj_tele.xml | 2 +- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/sj_tele.py b/indoteknik_custom/models/sj_tele.py index 246c0f43..c8f7c0c6 100644 --- a/indoteknik_custom/models/sj_tele.py +++ b/indoteknik_custom/models/sj_tele.py @@ -1,7 +1,8 @@ from odoo import models, fields, api +from odoo.exceptions import UserError import requests import json -import logging +import logging, subprocess _logger = logging.getLogger(__name__) @@ -16,6 +17,30 @@ class SjTele(models.Model): sale_name = fields.Char(string='Sale Name') create_date = fields.Datetime(string='Create Date') + @api.model + def run_pentaho_carte(self): + carte = "http://127.0.0.1:8080" + job_kjb = r"C:/Users/ThinkPad/Desktop/tes.kjb" + params = {"job": job_kjb, "level": "Basic", "block": "Y"} + try: + r = requests.get( + f"{carte}/kettle/executeJob/", + params=params, + auth=("cluster", "cluster"), + timeout=900, + ) + r.raise_for_status() + # kalau Carte mengembalikan ERROR, anggap gagal + if "ERROR" in r.text: + raise UserError(f"Carte error: {r.text}") + except Exception as e: + _logger.exception("Carte call failed: %s", e) + raise UserError(f"Gagal memanggil Carte: {e}") + + self.env['sj.tele'].sudo().woi() + + return True + def woi(self): bot_mqdd = '8203414501:AAHy_XwiUAVrgRM2EJzW7sZx9npRLITZpb8' chat_id_mqdd = '-4885333032' diff --git a/indoteknik_custom/views/sj_tele.xml b/indoteknik_custom/views/sj_tele.xml index cefcc968..2e1e5120 100644 --- a/indoteknik_custom/views/sj_tele.xml +++ b/indoteknik_custom/views/sj_tele.xml @@ -4,7 +4,7 @@ SJ TELE code - model.woi() + model.run_pentaho_carte() 1 days -1 -- cgit v1.2.3 From ea6364616f5a6ecbcf933249aeb95a7f3c8b4555 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Sat, 6 Sep 2025 11:33:02 +0700 Subject: Comment --- indoteknik_custom/models/sj_tele.py | 45 ++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/indoteknik_custom/models/sj_tele.py b/indoteknik_custom/models/sj_tele.py index c8f7c0c6..c00279ec 100644 --- a/indoteknik_custom/models/sj_tele.py +++ b/indoteknik_custom/models/sj_tele.py @@ -3,6 +3,7 @@ from odoo.exceptions import UserError import requests import json import logging, subprocess +import time _logger = logging.getLogger(__name__) @@ -17,29 +18,31 @@ class SjTele(models.Model): sale_name = fields.Char(string='Sale Name') create_date = fields.Datetime(string='Create Date') - @api.model - def run_pentaho_carte(self): - carte = "http://127.0.0.1:8080" - job_kjb = r"C:/Users/ThinkPad/Desktop/tes.kjb" - params = {"job": job_kjb, "level": "Basic", "block": "Y"} - try: - r = requests.get( - f"{carte}/kettle/executeJob/", - params=params, - auth=("cluster", "cluster"), - timeout=900, - ) - r.raise_for_status() - # kalau Carte mengembalikan ERROR, anggap gagal - if "ERROR" in r.text: - raise UserError(f"Carte error: {r.text}") - except Exception as e: - _logger.exception("Carte call failed: %s", e) - raise UserError(f"Gagal memanggil Carte: {e}") + # @api.model + # def run_pentaho_carte(self): + # carte = "http://127.0.0.1:8080" + # job_kjb = r"C:/Users/Indoteknik/Desktop/tes.kjb" + # params = {"job": job_kjb, "level": "Basic", "block": "Y"} + # try: + # r = requests.get( + # f"{carte}/kettle/executeJob/", + # params=params, + # auth=("cluster", "cluster"), + # timeout=900, + # ) + # r.raise_for_status() + # # kalau Carte mengembalikan ERROR, anggap gagal + # if "ERROR" in r.text: + # raise UserError(f"Carte error: {r.text}") + # except Exception as e: + # _logger.exception("Carte call failed: %s", e) + # raise UserError(f"Gagal memanggil Carte: {e}") + + # time.sleep(3) - self.env['sj.tele'].sudo().woi() + # self.env['sj.tele'].sudo().woi() - return True + # return True def woi(self): bot_mqdd = '8203414501:AAHy_XwiUAVrgRM2EJzW7sZx9npRLITZpb8' -- cgit v1.2.3 From 76676d8b0c41672d11ae392500dfb5a6db1cfd91 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Sat, 6 Sep 2025 11:33:57 +0700 Subject: fix called method --- indoteknik_custom/views/sj_tele.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/views/sj_tele.xml b/indoteknik_custom/views/sj_tele.xml index 2e1e5120..cefcc968 100644 --- a/indoteknik_custom/views/sj_tele.xml +++ b/indoteknik_custom/views/sj_tele.xml @@ -4,7 +4,7 @@ SJ TELE code - model.run_pentaho_carte() + model.woi() 1 days -1 -- cgit v1.2.3 From 7f49cfa92bed67bea8359433ff5c08cb069f284e Mon Sep 17 00:00:00 2001 From: Miqdad Date: Tue, 9 Sep 2025 11:49:54 +0700 Subject: add tanggal kirim sj --- indoteknik_custom/models/sj_tele.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/sj_tele.py b/indoteknik_custom/models/sj_tele.py index c00279ec..8864a313 100644 --- a/indoteknik_custom/models/sj_tele.py +++ b/indoteknik_custom/models/sj_tele.py @@ -4,6 +4,7 @@ import requests import json import logging, subprocess import time +from collections import OrderedDict _logger = logging.getLogger(__name__) @@ -17,6 +18,7 @@ class SjTele(models.Model): picking_name = fields.Char(string='Picking Name') sale_name = fields.Char(string='Sale Name') create_date = fields.Datetime(string='Create Date') + date_doc_kirim = fields.Datetime(string='Tanggal Kirim SJ') # @api.model # def run_pentaho_carte(self): @@ -62,13 +64,32 @@ class SjTele(models.Model): _logger.exception("Gagal kirim Telegram (no data): %s", e) return True + lines = [] + groups = OrderedDict() + for rec in data: name = rec.picking_name or (rec.picking_id.name if rec.picking_id else '') pid = rec.picking_id.id if rec.picking_id else '' - so = rec.sale_id.name or rec.sale_name or '' + so = rec.sale_id.name or rec.sale_name or '' + dttm = (rec.picking_id.date_doc_kirim if (rec.picking_id and rec.picking_id.date_doc_kirim) + else getattr(rec, 'date_doc_kirim', None)) + + # format header tanggal (string), tanpa konversi Waktu/WIB + if dttm: + date_header = dttm if isinstance(dttm, str) else fields.Datetime.to_string(dttm) + date_header = date_header[:10] + else: + date_header = '(Tidak ada tanggal kirim SJ)' + if name: - lines.append(f"{name} - {so} ({pid})") + groups.setdefault(date_header, []).append(f"- ({pid}) - {name} - {so}") + + # build output berurutan per tanggal + for header_date, items in groups.items(): + lines.append(header_date) + lines.extend(items) + header = "Berikut merupakan nomor BU/OUT yang belum ada di Logbook SJ report:\n" text = header + "\n".join(lines) -- cgit v1.2.3 From 7748c35d64c802ff5fc3d93aaf41c465b1f78e10 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Mon, 15 Sep 2025 09:18:54 +0700 Subject: Update add date doc kirim --- indoteknik_custom/models/sj_tele.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/indoteknik_custom/models/sj_tele.py b/indoteknik_custom/models/sj_tele.py index c00279ec..43709f45 100644 --- a/indoteknik_custom/models/sj_tele.py +++ b/indoteknik_custom/models/sj_tele.py @@ -4,19 +4,21 @@ import requests import json import logging, subprocess import time +from collections import OrderedDict + +logger = logging.getLogger(__name__) -_logger = logging.getLogger(__name__) class SjTele(models.Model): _name = 'sj.tele' _description = 'sj.tele' - picking_id = fields.Many2one('stock.picking', string='Picking') sale_id = fields.Many2one('sale.order', string='Sales Order') picking_name = fields.Char(string='Picking Name') sale_name = fields.Char(string='Sale Name') create_date = fields.Datetime(string='Create Date') + date_doc_kirim = fields.Datetime(string='Tanggal Kirim SJ') # @api.model # def run_pentaho_carte(self): @@ -37,7 +39,7 @@ class SjTele(models.Model): # except Exception as e: # _logger.exception("Carte call failed: %s", e) # raise UserError(f"Gagal memanggil Carte: {e}") - + # time.sleep(3) # self.env['sj.tele'].sudo().woi() @@ -63,12 +65,29 @@ class SjTele(models.Model): return True lines = [] + groups = OrderedDict() + for rec in data: name = rec.picking_name or (rec.picking_id.name if rec.picking_id else '') - pid = rec.picking_id.id if rec.picking_id else '' + pid = rec.picking_id.id if rec.picking_id else '' so = rec.sale_id.name or rec.sale_name or '' + dttm = (rec.picking_id.date_doc_kirim if (rec.picking_id and rec.picking_id.date_doc_kirim) + else getattr(rec, 'date_doc_kirim', None)) + + # format header tanggal (string), tanpa konversi Waktu/WIB + if dttm: + date_header = dttm if isinstance(dttm, str) else fields.Datetime.to_string(dttm) + date_header = date_header[:10] + else: + date_header = '(Tidak ada tanggal kirim SJ)' + if name: - lines.append(f"{name} - {so} ({pid})") + groups.setdefault(date_header, []).append(f"- ({pid}) - {name} - {so}") + + # build output berurutan per tanggal + for header_date, items in groups.items(): + lines.append(header_date) + lines.extend(items) header = "Berikut merupakan nomor BU/OUT yang belum ada di Logbook SJ report:\n" text = header + "\n".join(lines) @@ -78,5 +97,5 @@ class SjTele(models.Model): json={'chat_id': chat_id_mqdd, 'text': text}) r.raise_for_status() except Exception as e: - _logger.exception("Gagal kirim Telegram: %s", e) + logger.exception("Gagal kirim Telegram: %s", e) return True \ No newline at end of file -- cgit v1.2.3