From adafea307399d897df586fe13029c92efcdb8e80 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Tue, 7 Oct 2025 19:48:39 +0700 Subject: multiple chat bubble SJ Tele --- indoteknik_custom/models/sj_tele.py | 73 +++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 40 deletions(-) diff --git a/indoteknik_custom/models/sj_tele.py b/indoteknik_custom/models/sj_tele.py index d44aa338..5ea08340 100644 --- a/indoteknik_custom/models/sj_tele.py +++ b/indoteknik_custom/models/sj_tele.py @@ -19,41 +19,18 @@ class SjTele(models.Model): create_date = fields.Datetime(string='Create Date') date_doc_kirim = fields.Datetime(string='Tanggal Kirim SJ') - # @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() - - # return True - def woi(self): bot_mqdd = '8203414501:AAHy_XwiUAVrgRM2EJzW7sZx9npRLITZpb8' chat_id_mqdd = '-1003087280519' api_base = f'https://api.telegram.org/bot{bot_mqdd}' + # bot_testing = '8306689189:AAHEFe5xwAkapoQ8xKoNZs-6gVfv3kO3kaU' + # chat_id_testing = '-4920864331' + # api_testing = f'https://api.telegram.org/bot{bot_testing}' - data = self.search([], order='create_date asc', limit=15) + data = self.search([], order='create_date asc') if not data: - text = "Berikut merupakan nomor BU/OUT yang belum ada di Logbook SJ report:\nāœ… tidak ada data (semua sudah tercatat)." + text = "āœ… tidak ada data (semua sudah tercatat)." try: r = requests.post(api_base + "/sendMessage", json={'chat_id': chat_id_mqdd, 'text': text}, @@ -74,7 +51,6 @@ class SjTele(models.Model): 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] @@ -84,19 +60,36 @@ class SjTele(models.Model): if name: 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) - - try: - r = requests.post(api_base + "/sendMessage", - json={'chat_id': chat_id_mqdd, 'text': text}) - r.raise_for_status() - except Exception as e: - _logger.exception("Gagal kirim Telegram: %s", e) - return True \ No newline at end of file + BUB = 20 # jumlah baris per bubble + + for i in range(0, len(lines), BUB): + body = "\n".join(lines[i:i + BUB]) + text = header + body + try: + r = requests.post( + api_base + "/sendMessage", + json={'chat_id': chat_id_mqdd, 'text': text}, + timeout=20 + ) + r.raise_for_status() + except Exception as e: + _logger.exception("Gagal kirim Telegram (batch %s-%s): %s", i + 1, min(i + BUB, len(lines)), e) + time.sleep(5) # jeda kecil biar rapi & aman rate limit + + return True + + # header = "Berikut merupakan nomor BU/OUT yang belum ada di Logbook SJ report:\n" + # text = header + "\n".join(lines) + # + # try: + # r = requests.post(api_base + "/sendMessage", + # json={'chat_id': chat_id_mqdd, 'text': text}) + # r.raise_for_status() + # except Exception as e: + # _logger.exception("Gagal kirim Telegram: %s", e) + # return True \ No newline at end of file -- cgit v1.2.3 From d72c8fb9cd97552ef15aee0b70f7e1248b4c4696 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Wed, 8 Oct 2025 10:00:56 +0700 Subject: constrain delivery departure date to denise and faishal --- indoteknik_custom/models/stock_picking.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 4772c433..217e76cb 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -178,6 +178,14 @@ class StockPicking(models.Model): area_name = fields.Char(string="Area", compute="_compute_area_name") is_bu_iu = fields.Boolean('Is BU/IU', compute='_compute_is_bu_iu', default=False, copy=False, readonl=True) + @api.constrains('driver_departure_date') + def _constrains_driver_departure_date(self): + allowed_user_ids = [17, 6277, 25] + for record in self: + if record.driver_departure_date and self.env.user.id not in allowed_user_ids: + raise UserError("Hanya Denise dan Faishal yang dapat mengubah Delivery Departure Date.") + + @api.depends('name') def _compute_is_bu_iu(self): for record in self: -- cgit v1.2.3