diff options
| author | FIN-IT_AndriFP <it@fixcomart.co.id> | 2025-10-08 11:44:33 +0700 |
|---|---|---|
| committer | FIN-IT_AndriFP <it@fixcomart.co.id> | 2025-10-08 11:44:33 +0700 |
| commit | 27657d8a4de29ae21ccc0562ab63dc7f1cd79f6b (patch) | |
| tree | 3e093d644e4bf46f690c2c525db54887726030ce | |
| parent | 51155d702da715c82ea55322ee049d9b1ee34faa (diff) | |
| parent | d72c8fb9cd97552ef15aee0b70f7e1248b4c4696 (diff) | |
Merge branch 'odoo-backup' of https://bitbucket.org/altafixco/indoteknik-addons into odoo-backup
| -rw-r--r-- | indoteknik_custom/models/sj_tele.py | 73 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 8 |
2 files changed, 41 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 <result>ERROR</result>, anggap gagal - # if "<result>ERROR</result>" 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 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: |
